From 8ec0b713a2407c41926be3295090a9d92cae6b63 Mon Sep 17 00:00:00 2001 From: sh2 Date: Wed, 24 Jul 2024 10:21:16 +0800 Subject: [PATCH] fix: flaky e2e gateway_with_conflicted_listener_cannot_be_merged (#3911) --- test/e2e/tests/merge_gateways.go | 75 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/test/e2e/tests/merge_gateways.go b/test/e2e/tests/merge_gateways.go index 900c305485e..fee4fd7180b 100644 --- a/test/e2e/tests/merge_gateways.go +++ b/test/e2e/tests/merge_gateways.go @@ -96,10 +96,11 @@ var MergeGatewaysTest = suite.ConformanceTest{ }) }) - t.Run("apply a gateway with conflicted listener", func(t *testing.T) { + t.Run("apply a gateway with conflicted listener and a httproute", func(t *testing.T) { // Manually create the conflicted Gateway and HTTPRoute resources, // in order to make sure the conflicted status will certainly surface for them. + // Create Gateway first to make sure there's no HTTPRoute attach to it. conflictedGateway := gwapiv1.Gateway{ TypeMeta: metav1.TypeMeta{ Kind: gatewayapi.KindGateway, @@ -126,6 +127,32 @@ var MergeGatewaysTest = suite.ConformanceTest{ }, } + if err := suite.Client.Create(ctx, &conflictedGateway); err != nil { + t.Errorf("failed to create conflicted gateway: %v", err) + } + + conflictedListenerStatus := []gwapiv1.ListenerStatus{{ + Name: gwapiv1.SectionName("http3"), + SupportedKinds: []gwapiv1.RouteGroupKind{ + { + Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Kind: gatewayapi.KindHTTPRoute, + }, + { + Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Kind: gatewayapi.KindGRPCRoute, + }, + }, + Conditions: []metav1.Condition{{ + Type: string(gwapiv1.ListenerConditionConflicted), + Status: metav1.ConditionTrue, + Reason: string(gwapiv1.ListenerReasonHostnameConflict), + }}, + AttachedRoutes: 0, + }} + kubernetes.GatewayStatusMustHaveListeners(t, suite.Client, suite.TimeoutConfig, gw4NN, conflictedListenerStatus) + + // Create HTTPRoute at last to make sure it will be referenced by the conflicted listener in Gateway. conflictedHTTPRoute := gwapiv1.HTTPRoute{ TypeMeta: metav1.TypeMeta{ Kind: gatewayapi.KindHTTPRoute, @@ -174,15 +201,20 @@ var MergeGatewaysTest = suite.ConformanceTest{ }, } - if err := suite.Client.Create(ctx, &conflictedGateway); err != nil { - t.Errorf("failed to create conflicted gateway: %v", err) - t.FailNow() - } - if err := suite.Client.Create(ctx, &conflictedHTTPRoute); err != nil { t.Errorf("failed to create conflicted httproute: %v", err) t.FailNow() } + + conflictedListenerStatus[0].AttachedRoutes = 1 + kubernetes.GatewayStatusMustHaveListeners(t, suite.Client, suite.TimeoutConfig, gw4NN, conflictedListenerStatus) + + expectedHTTPRouteCondition := metav1.Condition{ + Type: string(gwapiv1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: "NoReadyListeners", + } + kubernetes.HTTPRouteMustHaveCondition(t, suite.Client, suite.TimeoutConfig, route4NN, gw4NN, expectedHTTPRouteCondition) }) t.Run("gateway with conflicted listener cannot be merged", func(t *testing.T) { @@ -204,34 +236,6 @@ var MergeGatewaysTest = suite.ConformanceTest{ t.FailNow() } - conflictedListener := []gwapiv1.ListenerStatus{{ - Name: gwapiv1.SectionName("http3"), - SupportedKinds: []gwapiv1.RouteGroupKind{ - { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), - Kind: gatewayapi.KindHTTPRoute, - }, - { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), - Kind: gatewayapi.KindGRPCRoute, - }, - }, - Conditions: []metav1.Condition{{ - Type: string(gwapiv1.ListenerConditionConflicted), - Status: metav1.ConditionTrue, - Reason: string(gwapiv1.ListenerReasonHostnameConflict), - }}, - AttachedRoutes: 1, - }} - kubernetes.GatewayStatusMustHaveListeners(t, suite.Client, suite.TimeoutConfig, gw4NN, conflictedListener) - - expectedHTTPRouteCondition := metav1.Condition{ - Type: string(gwapiv1.RouteConditionAccepted), - Status: metav1.ConditionFalse, - Reason: "NoReadyListeners", - } - kubernetes.HTTPRouteMustHaveCondition(t, suite.Client, suite.TimeoutConfig, route4NN, gw4NN, expectedHTTPRouteCondition) - // Not merged gateway should not receive any traffic. http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gw4HostPort, http.ExpectedResponse{ Request: http.Request{Path: "/merge4", Host: "www.example4.com"}, @@ -242,6 +246,9 @@ var MergeGatewaysTest = suite.ConformanceTest{ // Clean-up the conflicted gateway and route resources. t.Cleanup(func() { + // Collect and dump every config before removing the created resource. + CollectAndDump(t, suite.RestConfig) + conflictedGateway := new(gwapiv1.Gateway) conflictedHTTPRoute := new(gwapiv1.HTTPRoute)