-
Notifications
You must be signed in to change notification settings - Fork 138
Add TCPRoute and UDPRoute Support for L4 Load Balancing #3688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,11 @@ const ( | |
defaultInitialDelaySeconds = int32(3) | ||
) | ||
|
||
type PortInfo struct { | ||
Port int32 | ||
Protocol corev1.Protocol | ||
} | ||
|
||
Comment on lines
+46
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why did you make this struct? For example, on line Then the loop on line for port, protocol := range ports { servicePort := corev1.ServicePort{ Name: fmt.Sprintf("port-%d", port), Port: port, TargetPort: intstr.FromInt32(port), Protocol: protocol, Would love to know what you think though. Do please tell me if I'm overlooking anything. |
||
var emptyDirVolumeSource = corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}} | ||
|
||
func (p *NginxProvisioner) buildNginxResourceObjects( | ||
|
@@ -136,9 +141,18 @@ func (p *NginxProvisioner) buildNginxResourceObjects( | |
openshiftObjs = p.buildOpenshiftObjects(objectMeta) | ||
} | ||
|
||
ports := make(map[int32]struct{}) | ||
ports := make(map[int32]PortInfo) | ||
for _, listener := range gateway.Spec.Listeners { | ||
ports[int32(listener.Port)] = struct{}{} | ||
var protocol corev1.Protocol | ||
switch listener.Protocol { | ||
case gatewayv1.TCPProtocolType: | ||
protocol = corev1.ProtocolTCP | ||
case gatewayv1.UDPProtocolType: | ||
protocol = corev1.ProtocolUDP | ||
default: | ||
protocol = corev1.ProtocolTCP | ||
} | ||
ports[int32(listener.Port)] = PortInfo{Port: int32(listener.Port), Protocol: protocol} | ||
} | ||
|
||
service, err := buildNginxService(objectMeta, nProxyCfg, ports, selectorLabels) | ||
|
@@ -434,7 +448,7 @@ func (p *NginxProvisioner) buildOpenshiftObjects(objectMeta metav1.ObjectMeta) [ | |
func buildNginxService( | ||
objectMeta metav1.ObjectMeta, | ||
nProxyCfg *graph.EffectiveNginxProxy, | ||
ports map[int32]struct{}, | ||
ports map[int32]PortInfo, | ||
selectorLabels map[string]string, | ||
) (*corev1.Service, error) { | ||
var serviceCfg ngfAPIv1alpha2.ServiceSpec | ||
|
@@ -456,16 +470,17 @@ func buildNginxService( | |
} | ||
|
||
servicePorts := make([]corev1.ServicePort, 0, len(ports)) | ||
for port := range ports { | ||
for _, portInfo := range ports { | ||
servicePort := corev1.ServicePort{ | ||
Name: fmt.Sprintf("port-%d", port), | ||
Port: port, | ||
TargetPort: intstr.FromInt32(port), | ||
Name: fmt.Sprintf("port-%d", portInfo.Port), | ||
Port: portInfo.Port, | ||
TargetPort: intstr.FromInt32(portInfo.Port), | ||
Protocol: portInfo.Protocol, | ||
} | ||
|
||
if serviceType != corev1.ServiceTypeClusterIP { | ||
for _, nodePort := range serviceCfg.NodePorts { | ||
if nodePort.ListenerPort == port { | ||
if nodePort.ListenerPort == portInfo.Port { | ||
servicePort.NodePort = nodePort.Port | ||
} | ||
} | ||
|
@@ -533,7 +548,7 @@ func (p *NginxProvisioner) buildNginxDeployment( | |
nProxyCfg *graph.EffectiveNginxProxy, | ||
ngxIncludesConfigMapName string, | ||
ngxAgentConfigMapName string, | ||
ports map[int32]struct{}, | ||
ports map[int32]PortInfo, | ||
selectorLabels map[string]string, | ||
agentTLSSecretName string, | ||
dockerSecretNames map[string]string, | ||
|
@@ -665,18 +680,19 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec( | |
nProxyCfg *graph.EffectiveNginxProxy, | ||
ngxIncludesConfigMapName string, | ||
ngxAgentConfigMapName string, | ||
ports map[int32]struct{}, | ||
ports map[int32]PortInfo, | ||
agentTLSSecretName string, | ||
dockerSecretNames map[string]string, | ||
jwtSecretName string, | ||
caSecretName string, | ||
clientSSLSecretName string, | ||
) corev1.PodTemplateSpec { | ||
containerPorts := make([]corev1.ContainerPort, 0, len(ports)) | ||
for port := range ports { | ||
for _, portInfo := range ports { | ||
containerPort := corev1.ContainerPort{ | ||
Name: fmt.Sprintf("port-%d", port), | ||
ContainerPort: port, | ||
Name: fmt.Sprintf("port-%d", portInfo.Port), | ||
ContainerPort: portInfo.Port, | ||
Protocol: portInfo.Protocol, | ||
} | ||
containerPorts = append(containerPorts, containerPort) | ||
} | ||
|