Skip to content

Commit

Permalink
fix: flaky e2e gateway_with_conflicted_listener_cannot_be_merged (env…
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnh2 authored Jul 24, 2024
1 parent f29c1d6 commit 8ec0b71
Showing 1 changed file with 41 additions and 34 deletions.
75 changes: 41 additions & 34 deletions test/e2e/tests/merge_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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"},
Expand All @@ -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)

Expand Down

0 comments on commit 8ec0b71

Please sign in to comment.