@@ -44,6 +44,11 @@ const (
4444 defaultInitialDelaySeconds = int32 (3 )
4545)
4646
47+ type PortInfo struct {
48+ Port int32
49+ Protocol corev1.Protocol
50+ }
51+
4752var emptyDirVolumeSource = corev1.VolumeSource {EmptyDir : & corev1.EmptyDirVolumeSource {}}
4853
4954//nolint:gocyclo // will refactor at some point
@@ -147,9 +152,18 @@ func (p *NginxProvisioner) buildNginxResourceObjects(
147152 openshiftObjs = p .buildOpenshiftObjects (objectMeta )
148153 }
149154
150- ports := make (map [int32 ]struct {} )
155+ ports := make (map [int32 ]PortInfo )
151156 for _ , listener := range gateway .Spec .Listeners {
152- ports [int32 (listener .Port )] = struct {}{}
157+ var protocol corev1.Protocol
158+ switch listener .Protocol {
159+ case gatewayv1 .TCPProtocolType :
160+ protocol = corev1 .ProtocolTCP
161+ case gatewayv1 .UDPProtocolType :
162+ protocol = corev1 .ProtocolUDP
163+ default :
164+ protocol = corev1 .ProtocolTCP
165+ }
166+ ports [int32 (listener .Port )] = PortInfo {Port : int32 (listener .Port ), Protocol : protocol }
153167 }
154168
155169 // Create separate copies of objectMeta for service and deployment to avoid shared map references
@@ -515,7 +529,7 @@ func (p *NginxProvisioner) buildOpenshiftObjects(objectMeta metav1.ObjectMeta) [
515529func buildNginxService (
516530 objectMeta metav1.ObjectMeta ,
517531 nProxyCfg * graph.EffectiveNginxProxy ,
518- ports map [int32 ]struct {} ,
532+ ports map [int32 ]PortInfo ,
519533 selectorLabels map [string ]string ,
520534 addresses []gatewayv1.GatewaySpecAddress ,
521535) (* corev1.Service , error ) {
@@ -538,16 +552,17 @@ func buildNginxService(
538552 }
539553
540554 servicePorts := make ([]corev1.ServicePort , 0 , len (ports ))
541- for port := range ports {
555+ for _ , portInfo := range ports {
542556 servicePort := corev1.ServicePort {
543- Name : fmt .Sprintf ("port-%d" , port ),
544- Port : port ,
545- TargetPort : intstr .FromInt32 (port ),
557+ Name : fmt .Sprintf ("port-%d" , portInfo .Port ),
558+ Port : portInfo .Port ,
559+ TargetPort : intstr .FromInt32 (portInfo .Port ),
560+ Protocol : portInfo .Protocol ,
546561 }
547562
548563 if serviceType != corev1 .ServiceTypeClusterIP {
549564 for _ , nodePort := range serviceCfg .NodePorts {
550- if nodePort .ListenerPort == port {
565+ if nodePort .ListenerPort == portInfo . Port {
551566 servicePort .NodePort = nodePort .Port
552567 }
553568 }
@@ -625,7 +640,7 @@ func (p *NginxProvisioner) buildNginxDeployment(
625640 nProxyCfg * graph.EffectiveNginxProxy ,
626641 ngxIncludesConfigMapName string ,
627642 ngxAgentConfigMapName string ,
628- ports map [int32 ]struct {} ,
643+ ports map [int32 ]PortInfo ,
629644 selectorLabels map [string ]string ,
630645 agentTLSSecretName string ,
631646 dockerSecretNames map [string ]string ,
@@ -779,7 +794,7 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
779794 nProxyCfg * graph.EffectiveNginxProxy ,
780795 ngxIncludesConfigMapName string ,
781796 ngxAgentConfigMapName string ,
782- ports map [int32 ]struct {} ,
797+ ports map [int32 ]PortInfo ,
783798 agentTLSSecretName string ,
784799 dockerSecretNames map [string ]string ,
785800 jwtSecretName string ,
@@ -788,10 +803,11 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
788803 dataplaneKeySecretName string ,
789804) corev1.PodTemplateSpec {
790805 containerPorts := make ([]corev1.ContainerPort , 0 , len (ports ))
791- for port := range ports {
806+ for _ , portInfo := range ports {
792807 containerPort := corev1.ContainerPort {
793- Name : fmt .Sprintf ("port-%d" , port ),
794- ContainerPort : port ,
808+ Name : fmt .Sprintf ("port-%d" , portInfo .Port ),
809+ ContainerPort : portInfo .Port ,
810+ Protocol : portInfo .Protocol ,
795811 }
796812 containerPorts = append (containerPorts , containerPort )
797813 }
0 commit comments