@@ -44,6 +44,11 @@ const (
44
44
defaultInitialDelaySeconds = int32 (3 )
45
45
)
46
46
47
+ type PortInfo struct {
48
+ Port int32
49
+ Protocol corev1.Protocol
50
+ }
51
+
47
52
var emptyDirVolumeSource = corev1.VolumeSource {EmptyDir : & corev1.EmptyDirVolumeSource {}}
48
53
49
54
//nolint:gocyclo // will refactor at some point
@@ -147,9 +152,18 @@ func (p *NginxProvisioner) buildNginxResourceObjects(
147
152
openshiftObjs = p .buildOpenshiftObjects (objectMeta )
148
153
}
149
154
150
- ports := make (map [int32 ]struct {} )
155
+ ports := make (map [int32 ]PortInfo )
151
156
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 }
153
167
}
154
168
155
169
// 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) [
515
529
func buildNginxService (
516
530
objectMeta metav1.ObjectMeta ,
517
531
nProxyCfg * graph.EffectiveNginxProxy ,
518
- ports map [int32 ]struct {} ,
532
+ ports map [int32 ]PortInfo ,
519
533
selectorLabels map [string ]string ,
520
534
addresses []gatewayv1.GatewaySpecAddress ,
521
535
) (* corev1.Service , error ) {
@@ -538,16 +552,17 @@ func buildNginxService(
538
552
}
539
553
540
554
servicePorts := make ([]corev1.ServicePort , 0 , len (ports ))
541
- for port := range ports {
555
+ for _ , portInfo := range ports {
542
556
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 ,
546
561
}
547
562
548
563
if serviceType != corev1 .ServiceTypeClusterIP {
549
564
for _ , nodePort := range serviceCfg .NodePorts {
550
- if nodePort .ListenerPort == port {
565
+ if nodePort .ListenerPort == portInfo . Port {
551
566
servicePort .NodePort = nodePort .Port
552
567
}
553
568
}
@@ -625,7 +640,7 @@ func (p *NginxProvisioner) buildNginxDeployment(
625
640
nProxyCfg * graph.EffectiveNginxProxy ,
626
641
ngxIncludesConfigMapName string ,
627
642
ngxAgentConfigMapName string ,
628
- ports map [int32 ]struct {} ,
643
+ ports map [int32 ]PortInfo ,
629
644
selectorLabels map [string ]string ,
630
645
agentTLSSecretName string ,
631
646
dockerSecretNames map [string ]string ,
@@ -779,7 +794,7 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
779
794
nProxyCfg * graph.EffectiveNginxProxy ,
780
795
ngxIncludesConfigMapName string ,
781
796
ngxAgentConfigMapName string ,
782
- ports map [int32 ]struct {} ,
797
+ ports map [int32 ]PortInfo ,
783
798
agentTLSSecretName string ,
784
799
dockerSecretNames map [string ]string ,
785
800
jwtSecretName string ,
@@ -788,10 +803,11 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
788
803
dataplaneKeySecretName string ,
789
804
) corev1.PodTemplateSpec {
790
805
containerPorts := make ([]corev1.ContainerPort , 0 , len (ports ))
791
- for port := range ports {
806
+ for _ , portInfo := range ports {
792
807
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 ,
795
811
}
796
812
containerPorts = append (containerPorts , containerPort )
797
813
}
0 commit comments