@@ -2343,6 +2343,73 @@ func TestRenderServiceUtil(t *testing.T) {
23432343 assert .Equal (t , 103 , p , "targetport 3" )
23442344 },
23452345 },
2346+ {
2347+ name : "lb service - service nodeport/targetport retained" ,
2348+ cls : []gwapiv1.GatewayClass {testutils .TestGwClass },
2349+ cfs : []stnrgwv1.GatewayConfig {testutils .TestGwConfig },
2350+ gws : []gwapiv1.Gateway {testutils .TestGw },
2351+ svcs : []corev1.Service {testutils .TestSvc },
2352+ prep : func (c * renderTestConfig ) {
2353+ // make sure UDP and TCP are both handled
2354+ gw := testutils .TestGw .DeepCopy ()
2355+ mixedProtoAnnotation := map [string ]string {
2356+ opdefault .MixedProtocolAnnotationKey : "true" ,
2357+ }
2358+ gw .ObjectMeta .SetAnnotations (mixedProtoAnnotation )
2359+ c .gws = []gwapiv1.Gateway {* gw }
2360+
2361+ s1 := testutils .TestSvc .DeepCopy ()
2362+ s1 .SetName ("gateway-1" )
2363+ s1 .SetNamespace ("testnamespace" )
2364+ s1 .Spec .Ports = []corev1.ServicePort {
2365+ {
2366+ Name : "gateway-1-listener-udp" ,
2367+ Protocol : corev1 .ProtocolUDP ,
2368+ Port : 1 ,
2369+ NodePort : 30001 ,
2370+ TargetPort : intstr .FromInt (1 ),
2371+ },
2372+ {
2373+ Name : "dummy" ,
2374+ Protocol : corev1 .ProtocolTCP ,
2375+ Port : 123 ,
2376+ NodePort : 31234 ,
2377+ TargetPort : intstr .FromString ("dummy" ),
2378+ },
2379+ }
2380+ s1 .SetOwnerReferences ([]metav1.OwnerReference {{
2381+ APIVersion : gwapiv1 .GroupVersion .String (),
2382+ Kind : "Gateway" ,
2383+ UID : testutils .TestGw .GetUID (),
2384+ Name : testutils .TestGw .GetName (),
2385+ }})
2386+ c .svcs = []corev1.Service {* s1 }
2387+ },
2388+ tester : func (t * testing.T , r * renderer ) {
2389+ gc , err := r .getGatewayClass ()
2390+ assert .NoError (t , err , "gw-class found" )
2391+ c := & RenderContext {gc : gc , log : log }
2392+ c .gwConf , err = r .getGatewayConfig4Class (c )
2393+ assert .NoError (t , err , "gw-conf found" )
2394+
2395+ gws := r .getGateways4Class (c )
2396+ assert .Len (t , gws , 1 , "gateways for class" )
2397+ gw := gws [0 ]
2398+
2399+ s , _ := r .createLbService4Gateway (c , gw )
2400+ assert .NotNil (t , s , "svc create" )
2401+ assert .Equal (t , c .gwConf .GetNamespace (), s .GetNamespace (), "namespace ok" )
2402+ assert .Equal (t , corev1 .ServiceTypeLoadBalancer , s .Spec .Type , "lb type" )
2403+ ports := s .Spec .Ports
2404+ assert .Len (t , ports , 2 , "service-port len" )
2405+ assert .Equal (t , "gateway-1-listener-udp" , ports [0 ].Name , "port 1 name" )
2406+ assert .Equal (t , int32 (30001 ), ports [0 ].NodePort , "port 1 np" ) // default
2407+ assert .Equal (t , intstr .FromInt (1 ), ports [0 ].TargetPort , "port 1 tp" ) // default
2408+ assert .Equal (t , "gateway-1-listener-tcp" , ports [1 ].Name , "port 1 name" )
2409+ assert .Equal (t , int32 (0 ), ports [1 ].NodePort , "port 2 np" )
2410+ assert .Equal (t , intstr.IntOrString {}, ports [1 ].TargetPort , "port 2 tp" )
2411+ },
2412+ },
23462413 {
23472414 name : "lb service - STUNner-specific annotation removed unless GW also sets it" ,
23482415 cls : []gwapiv1.GatewayClass {testutils .TestGwClass },
0 commit comments