@@ -70,6 +70,23 @@ func gwRouteStatus(refs ...v1.ParentReference) v1.RouteStatus {
70
70
return v
71
71
}
72
72
73
+ func omWithGeneration (meta metav1.ObjectMeta , generation int64 ) metav1.ObjectMeta {
74
+ meta .Generation = generation
75
+ return meta
76
+ }
77
+
78
+ func rsWithGeneration (routeStatus v1.HTTPRouteStatus , generation ... int64 ) v1.HTTPRouteStatus {
79
+ for i , parent := range routeStatus .Parents {
80
+ if len (generation ) <= i {
81
+ break
82
+ }
83
+
84
+ parent .Conditions [0 ].ObservedGeneration = generation [i ]
85
+ }
86
+
87
+ return routeStatus
88
+ }
89
+
73
90
func gwParentRef (namespace , name string , options ... gwParentRefOption ) v1.ParentReference {
74
91
group := v1 .Group ("gateway.networking.k8s.io" )
75
92
kind := v1 .Kind ("Gateway" )
@@ -192,6 +209,46 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
192
209
"level=debug msg=\" Gateway gateway-namespace/not-gateway-name does not match gateway-name route-namespace/test\" " ,
193
210
},
194
211
},
212
+ {
213
+ title : "GatewayNameOldGeneration" ,
214
+ config : Config {
215
+ GatewayName : "gateway-name" ,
216
+ },
217
+ namespaces : namespaces ("gateway-namespace" , "route-namespace" ),
218
+ gateways : []* v1beta1.Gateway {
219
+ {
220
+ ObjectMeta : omWithGeneration (objectMeta ("gateway-namespace" , "gateway-name" ), 2 ),
221
+ Spec : v1.GatewaySpec {
222
+ Listeners : []v1.Listener {{
223
+ Protocol : v1 .HTTPProtocolType ,
224
+ AllowedRoutes : allowAllNamespaces ,
225
+ }},
226
+ },
227
+ Status : gatewayStatus ("1.2.3.4" ),
228
+ },
229
+ },
230
+ routes : []* v1beta1.HTTPRoute {{
231
+ ObjectMeta : omWithGeneration (objectMeta ("route-namespace" , "old-test" ), 5 ),
232
+ Spec : v1.HTTPRouteSpec {
233
+ Hostnames : hostnames ("test.example.internal" ),
234
+ CommonRouteSpec : v1.CommonRouteSpec {
235
+ ParentRefs : []v1.ParentReference {
236
+ gwParentRef ("gateway-namespace" , "gateway-name" ),
237
+ },
238
+ },
239
+ },
240
+ Status : rsWithGeneration (httpRouteStatus ( // The route was previously attached to a different gateway
241
+ gwParentRef ("gateway-namespace" , "gateway-name" ),
242
+ gwParentRef ("gateway-namespace" , "gateway-name" ),
243
+ ), 5 , 4 ),
244
+ }},
245
+ endpoints : []* endpoint.Endpoint {
246
+ newTestEndpoint ("test.example.internal" , "A" , "1.2.3.4" ),
247
+ },
248
+ logExpectations : []string {
249
+ "level=debug msg=\" Ignoring parent gateway-namespace/gateway-name of route-namespace/old-test as generation 4 does not match current generation 5\" " ,
250
+ },
251
+ },
195
252
{
196
253
title : "GatewayNamespace" ,
197
254
config : Config {
0 commit comments