Skip to content

Commit

Permalink
e2e: fix EnvoyGatewayBackend/TLSRouteBackendIP test not working on IP…
Browse files Browse the repository at this point in the history
…v6 first cluster (#4727)

* fix EnvoyGatewayBackend cluter IP test

Signed-off-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zirain authored Nov 15, 2024
1 parent 0f68219 commit 62f5df8
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 29 deletions.
12 changes: 0 additions & 12 deletions test/e2e/testdata/httproute-to-backend-ip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ metadata:
spec:
selector:
app: infra-backend-v1
clusterIP: 10.96.96.96
ports:
- protocol: TCP
port: 8080
Expand Down Expand Up @@ -34,14 +33,3 @@ spec:
- group: gateway.envoyproxy.io
kind: Backend
name: backend-ip
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: backend-ip
namespace: gateway-conformance-infra
spec:
endpoints:
- ip:
address: 10.96.96.96
port: 8080
14 changes: 1 addition & 13 deletions test/e2e/testdata/tlsroute-to-backend-ip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@ spec:
- backendRefs:
- group: gateway.envoyproxy.io
kind: Backend
name: backend-ip
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: backend-ip
namespace: gateway-conformance-infra
spec:
endpoints:
- ip:
address: 10.96.96.96
port: 443
name: backend-tls-ip
---
apiVersion: v1
kind: Service
Expand All @@ -34,7 +23,6 @@ metadata:
spec:
selector:
app: tls-backend-2
clusterIP: 10.96.96.96
ports:
- protocol: TCP
port: 443
Expand Down
24 changes: 22 additions & 2 deletions test/e2e/tests/httproute_with_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
}

var EnvoyGatewayBackendTest = suite.ConformanceTest{
ShortName: "EnvoyGatewayBackendTest",
ShortName: "EnvoyGatewayBackend",
Description: "Routes with a backend ref to a backend",
Manifests: []string{
"testdata/httproute-to-backend-fqdn.yaml",
Expand Down Expand Up @@ -51,11 +51,31 @@ var EnvoyGatewayBackendTest = suite.ConformanceTest{
})

t.Run("of type IP", func(t *testing.T) {
svcNN := types.NamespacedName{
Name: "infra-backend-v1-clusterip",
Namespace: "gateway-conformance-infra",
}
svc, err := GetService(suite.Client, svcNN)
if err != nil {
t.Fatalf("failed to get service %s: %v", svcNN, err)
}

backendIPName := "backend-ip"
ns := "gateway-conformance-infra"
err = CreateBackend(suite.Client, types.NamespacedName{Name: backendIPName, Namespace: ns}, svc.Spec.ClusterIP, 8080)
if err != nil {
t.Fatalf("failed to create backend %s: %v", backendIPName, err)
}
t.Cleanup(func() {
if err := DeleteBackend(suite.Client, types.NamespacedName{Name: backendIPName, Namespace: ns}); err != nil {
t.Fatalf("failed to delete backend %s: %v", backendIPName, err)
}
})

routeNN := types.NamespacedName{Name: "httproute-to-backend-ip", Namespace: ns}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
BackendMustBeAccepted(t, suite.Client, types.NamespacedName{Name: "backend-ip", Namespace: ns})
BackendMustBeAccepted(t, suite.Client, types.NamespacedName{Name: backendIPName, Namespace: ns})

expectedResponse := http.ExpectedResponse{
Request: http.Request{
Expand Down
24 changes: 22 additions & 2 deletions test/e2e/tests/tlsroute_with_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,34 @@ var TLSRouteBackendFQDNTest = suite.ConformanceTest{
}

var TLSRouteBackendIPTest = suite.ConformanceTest{
ShortName: "TLSRouteBackendIPTest",
ShortName: "TLSRouteBackendIP",
Description: "TLSRoutes with a backend ref to a Backend",
Manifests: []string{
"testdata/tlsroute-to-backend-ip.yaml",
},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
t.Run("TLSRoute with a IP type Backend", func(t *testing.T) {
testTLSRouteWithBackend(t, suite, "tlsroute-to-backend-ip", "backend-ip")
svcNN := types.NamespacedName{
Name: "tls-backend-2-clusterip",
Namespace: "gateway-conformance-infra",
}
svc, err := GetService(suite.Client, svcNN)
if err != nil {
t.Fatalf("failed to get service %s: %v", svcNN, err)
}

backendIPName := "backend-tls-ip"
ns := "gateway-conformance-infra"
err = CreateBackend(suite.Client, types.NamespacedName{Name: backendIPName, Namespace: ns}, svc.Spec.ClusterIP, 443)
if err != nil {
t.Fatalf("failed to create backend %s: %v", backendIPName, err)
}
t.Cleanup(func() {
if err := DeleteBackend(suite.Client, types.NamespacedName{Name: backendIPName, Namespace: ns}); err != nil {
t.Fatalf("failed to delete backend %s: %v", backendIPName, err)
}
})
testTLSRouteWithBackend(t, suite, "tlsroute-to-backend-ip", backendIPName)
})
},
}
Expand Down
36 changes: 36 additions & 0 deletions test/e2e/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,39 @@ func CollectAndDump(t *testing.T, rest *rest.Config) {
tlog.Logf(t, "\ndata: \n%s", data)
}
}

func GetService(c client.Client, nn types.NamespacedName) (*corev1.Service, error) {
svc := &corev1.Service{}
if err := c.Get(context.Background(), nn, svc); err != nil {
return nil, err
}
return svc, nil
}

func CreateBackend(c client.Client, nn types.NamespacedName, clusterIP string, port int32) error {
backend := &egv1a1.Backend{
ObjectMeta: metav1.ObjectMeta{
Namespace: nn.Namespace,
Name: nn.Name,
},
Spec: egv1a1.BackendSpec{
Endpoints: []egv1a1.BackendEndpoint{
{
IP: &egv1a1.IPEndpoint{
Address: clusterIP,
Port: port,
},
},
},
},
}
return c.Create(context.TODO(), backend)
}

func DeleteBackend(c client.Client, nn types.NamespacedName) error {
backend := &egv1a1.Backend{}
if err := c.Get(context.Background(), nn, backend); err != nil {
return err
}
return c.Delete(context.Background(), backend)
}

0 comments on commit 62f5df8

Please sign in to comment.