Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flaky e2e gateway_with_conflicted_listener_cannot_be_merged #3911

Merged
merged 7 commits into from
Jul 24, 2024
72 changes: 38 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 Down
Loading