Skip to content

Commit

Permalink
e2e: fix flaky merge-gateways test (#3331)
Browse files Browse the repository at this point in the history
* manually create conflicted gateways for merge-gateways e2e test

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* keep skipTest field

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

---------

Signed-off-by: shawnh2 <shawnhxh@outlook.com>
  • Loading branch information
shawnh2 committed May 6, 2024
1 parent ce0d8b5 commit decefcc
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 43 deletions.
4 changes: 1 addition & 3 deletions test/e2e/merge_gateways/merge_gateways_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ func TestMergeGateways(t *testing.T) {
Debug: *flags.ShowDebug,
CleanupBaseResources: *flags.CleanupBaseResources,
RunTest: *flags.RunTest,
SkipTests: []string{
tests.MergeGatewaysTest.ShortName, // https://github.com/envoyproxy/gateway/issues/3290
},
SkipTests: []string{},
})

// Setting up the necessary arguments for the suite instead of calling Suite.Setup method again,
Expand Down
37 changes: 0 additions & 37 deletions test/e2e/testdata/basic-merge-gateways.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@ spec:
protocol: HTTP
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: merged-gateway-4
namespace: gateway-conformance-infra
spec:
gatewayClassName: merge-gateways
listeners:
- allowedRoutes:
namespaces:
from: Same
name: http3
port: 8082
protocol: HTTP
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: merged-gateway-route-1
Expand Down Expand Up @@ -123,25 +108,3 @@ spec:
- path:
type: PathPrefix
value: /merge3
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: merged-gateway-route-4
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: merged-gateway-4
hostnames:
- "www.example4.com"
rules:
- backendRefs:
- group: ""
kind: Service
name: infra-backend-v3
port: 8080
weight: 1
matches:
- path:
type: PathPrefix
value: /merge4
120 changes: 117 additions & 3 deletions test/e2e/tests/merge_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
package tests

import (
"context"
"net"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
Expand All @@ -31,6 +33,7 @@ var MergeGatewaysTest = suite.ConformanceTest{
Description: "Basic test for MergeGateways feature",
Manifests: []string{"testdata/basic-merge-gateways.yaml"},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
ctx := context.Background()
ns := "gateway-conformance-infra"

route1NN := types.NamespacedName{Name: "merged-gateway-route-1", Namespace: ns}
Expand All @@ -45,6 +48,10 @@ var MergeGatewaysTest = suite.ConformanceTest{
gw3NN := types.NamespacedName{Name: "merged-gateway-3", Namespace: ns}
gw3HostPort := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gw3NN), route3NN)

// Conflicted Gateway and HTTPRoute name
route4NN := types.NamespacedName{Name: "merged-gateway-route-4", Namespace: ns}
gw4NN := types.NamespacedName{Name: "merged-gateway-4", Namespace: ns}

gw1Addr, _, err := net.SplitHostPort(gw1HostPort)
if err != nil {
t.Errorf("failed to split hostport %s of gateway %s: %v", gw1HostPort, gw1NN.String(), err)
Expand Down Expand Up @@ -89,10 +96,96 @@ var MergeGatewaysTest = suite.ConformanceTest{
})
})

t.Run("gateway with conflicted listener cannot be merged", func(t *testing.T) {
route4NN := types.NamespacedName{Name: "merged-gateway-route-4", Namespace: ns}
gw4NN := types.NamespacedName{Name: "merged-gateway-4", Namespace: ns}
t.Run("apply a gateway with conflicted listener", 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.

conflictedGateway := gwapiv1.Gateway{
TypeMeta: metav1.TypeMeta{
Kind: gatewayapi.KindGateway,
APIVersion: gwapiv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: gw4NN.Name,
Namespace: gw4NN.Namespace,
},
Spec: gwapiv1.GatewaySpec{
GatewayClassName: gwapiv1.ObjectName(suite.GatewayClassName),
Listeners: []gwapiv1.Listener{
{
AllowedRoutes: &gwapiv1.AllowedRoutes{
Namespaces: &gwapiv1.RouteNamespaces{
From: gatewayapi.FromNamespacesPtr(gwapiv1.NamespacesFromSame),
},
},
Name: "http3",
Port: 8082,
Protocol: gwapiv1.HTTPProtocolType,
},
},
},
}

conflictedHTTPRoute := gwapiv1.HTTPRoute{
TypeMeta: metav1.TypeMeta{
Kind: gatewayapi.KindHTTPRoute,
APIVersion: gwapiv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: route4NN.Name,
Namespace: route4NN.Namespace,
},
Spec: gwapiv1.HTTPRouteSpec{
CommonRouteSpec: gwapiv1.CommonRouteSpec{
ParentRefs: []gwapiv1.ParentReference{
{
Name: gwapiv1.ObjectName(gw4NN.Name),
},
},
},
Hostnames: []gwapiv1.Hostname{
"www.example4.com",
},
Rules: []gwapiv1.HTTPRouteRule{
{
BackendRefs: []gwapiv1.HTTPBackendRef{
{
BackendRef: gwapiv1.BackendRef{
BackendObjectReference: gwapiv1.BackendObjectReference{
Group: gatewayapi.GroupPtr(""),
Kind: gatewayapi.KindPtr(gatewayapi.KindService),
Name: "infra-backend-v3",
Port: gatewayapi.PortNumPtr(8080),
},
Weight: ptr.To[int32](1),
},
},
},
Matches: []gwapiv1.HTTPRouteMatch{
{
Path: &gwapiv1.HTTPPathMatch{
Type: ptr.To(gwapiv1.PathMatchPathPrefix),
Value: ptr.To("/merge4"),
},
},
},
},
},
},
}

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()
}
})

t.Run("gateway with conflicted listener cannot be merged", func(t *testing.T) {
gw4HostPort, err := kubernetes.WaitForGatewayAddress(t, suite.Client, suite.TimeoutConfig, gw4NN)
if err != nil {
t.Errorf("failed to get the address of gateway %s", gw4NN.String())
Expand Down Expand Up @@ -146,5 +239,26 @@ var MergeGatewaysTest = suite.ConformanceTest{
Namespace: ns,
})
})

t.Run("clean-up conflicted gateway", func(t *testing.T) {
conflictedGateway := new(gwapiv1.Gateway)
conflictedHTTPRoute := new(gwapiv1.HTTPRoute)

if err := suite.Client.Get(ctx, gw4NN, conflictedGateway); err != nil {
t.Errorf("failed to get conflicted gateway: %v", err)
t.FailNow()
}
if err := suite.Client.Delete(ctx, conflictedGateway); err != nil {
t.Errorf("failed to delete conflicted gateway: %v", err)
}

if err := suite.Client.Get(ctx, route4NN, conflictedHTTPRoute); err != nil {
t.Errorf("failed to get conflicted httproute: %v", err)
t.FailNow()
}
if err := suite.Client.Delete(ctx, conflictedHTTPRoute); err != nil {
t.Errorf("failed to delete conflicted httproute: %v", err)
}
})
},
}

0 comments on commit decefcc

Please sign in to comment.