@@ -254,6 +254,106 @@ func testGatewayScheduledStatus(ctx context.Context, t *testing.T, provider *Pro
254254 assert .Equal (t , gw .Spec , gws .Spec )
255255}
256256
257+ // Test that even when resources such as the Service/Deployment get hashed names (because of a gateway with a very long name)
258+ func testLongNameHashedResources (ctx context.Context , t * testing.T , provider * Provider , resources * message.ProviderResources ) {
259+ cli := provider .manager .GetClient ()
260+
261+ gc := getGatewayClass ("envoy-gateway-class" )
262+ require .NoError (t , cli .Create (ctx , gc ))
263+
264+ // Ensure the GatewayClass reports "Ready".
265+ require .Eventually (t , func () bool {
266+ if err := cli .Get (ctx , types.NamespacedName {Name : gc .Name }, gc ); err != nil {
267+ return false
268+ }
269+
270+ for _ , cond := range gc .Status .Conditions {
271+ if cond .Type == string (gwapiv1b1 .GatewayClassConditionStatusAccepted ) && cond .Status == metav1 .ConditionTrue {
272+ return true
273+ }
274+ }
275+
276+ return false
277+ }, defaultWait , defaultTick )
278+
279+ defer func () {
280+ require .NoError (t , cli .Delete (ctx , gc ))
281+ }()
282+
283+ // Create the namespace for the Gateway under test.
284+ ns := & corev1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : "envoy-gateway" }}
285+ require .NoError (t , cli .Create (ctx , ns ))
286+
287+ gw := & gwapiv1b1.Gateway {
288+ ObjectMeta : metav1.ObjectMeta {
289+ Name : "gatewaywithaverylongnamethatwillresultinhashedresources" ,
290+ Namespace : ns .Name ,
291+ },
292+ Spec : gwapiv1b1.GatewaySpec {
293+ GatewayClassName : gwapiv1b1 .ObjectName (gc .Name ),
294+ Listeners : []gwapiv1b1.Listener {
295+ {
296+ Name : "test" ,
297+ Port : gwapiv1b1 .PortNumber (int32 (8080 )),
298+ Protocol : gwapiv1b1 .HTTPProtocolType ,
299+ },
300+ },
301+ },
302+ }
303+ require .NoError (t , cli .Create (ctx , gw ))
304+
305+ // Ensure the Gateway is ready and gets an address.
306+ ready := false
307+ hasAddress := false
308+ require .Eventually (t , func () bool {
309+ if err := cli .Get (ctx , types.NamespacedName {Namespace : gw .Namespace , Name : gw .Name }, gw ); err != nil {
310+ return false
311+ }
312+
313+ for _ , cond := range gw .Status .Conditions {
314+ fmt .Printf ("Condition: %v" , cond )
315+ if cond .Type == string (gwapiv1b1 .GatewayConditionReady ) && cond .Status == metav1 .ConditionTrue {
316+ ready = true
317+ }
318+ }
319+
320+ if gw .Status .Addresses != nil {
321+ hasAddress = len (gw .Status .Addresses ) >= 1
322+ }
323+
324+ return ready && hasAddress
325+ }, defaultWait , defaultTick )
326+
327+ defer func () {
328+ require .NoError (t , cli .Delete (ctx , gw ))
329+ }()
330+
331+ // Ensure the gatewayclass has been finalized.
332+ require .NoError (t , cli .Get (ctx , types.NamespacedName {Name : gc .Name }, gc ))
333+ require .Contains (t , gc .Finalizers , gatewayClassFinalizer )
334+
335+ // Ensure the number of Gateways in the Gateway resource table is as expected.
336+ require .Eventually (t , func () bool {
337+ return resources .Gateways .Len () == 1
338+ }, defaultWait , defaultTick )
339+
340+ // Ensure the test Gateway in the Gateway resources is as expected.
341+ key := types.NamespacedName {
342+ Namespace : gw .Namespace ,
343+ Name : gw .Name ,
344+ }
345+ require .Eventually (t , func () bool {
346+ return cli .Get (ctx , key , gw ) == nil
347+ }, defaultWait , defaultTick )
348+ gws , _ := resources .Gateways .Load (key )
349+ // Only check if the spec is equal
350+ // The watchable map will not store a resource
351+ // with an updated status if the spec has not changed
352+ // to eliminate this endless loop:
353+ // reconcile->store->translate->update-status->reconcile
354+ assert .Equal (t , gw .Spec , gws .Spec )
355+ }
356+
257357func testHTTPRoute (ctx context.Context , t * testing.T , provider * Provider , resources * message.ProviderResources ) {
258358 cli := provider .manager .GetClient ()
259359
0 commit comments