diff --git a/test/e2e/testdata/httproute-to-backend-ip.yaml b/test/e2e/testdata/httproute-to-backend-ip.yaml index de1116d3f8e..599cbd3b332 100644 --- a/test/e2e/testdata/httproute-to-backend-ip.yaml +++ b/test/e2e/testdata/httproute-to-backend-ip.yaml @@ -6,7 +6,6 @@ metadata: spec: selector: app: infra-backend-v1 - clusterIP: 10.96.96.96 ports: - protocol: TCP port: 8080 @@ -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 diff --git a/test/e2e/testdata/tlsroute-to-backend-ip.yaml b/test/e2e/testdata/tlsroute-to-backend-ip.yaml index 7206078e2b5..49a39d61f3f 100644 --- a/test/e2e/testdata/tlsroute-to-backend-ip.yaml +++ b/test/e2e/testdata/tlsroute-to-backend-ip.yaml @@ -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 @@ -34,7 +23,6 @@ metadata: spec: selector: app: tls-backend-2 - clusterIP: 10.96.96.96 ports: - protocol: TCP port: 443 diff --git a/test/e2e/tests/httproute_with_backend.go b/test/e2e/tests/httproute_with_backend.go index 7401e17c2f0..0bd7cc1ead1 100644 --- a/test/e2e/tests/httproute_with_backend.go +++ b/test/e2e/tests/httproute_with_backend.go @@ -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", @@ -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{ diff --git a/test/e2e/tests/tlsroute_with_backend.go b/test/e2e/tests/tlsroute_with_backend.go index c43162ee94f..34ed2896116 100644 --- a/test/e2e/tests/tlsroute_with_backend.go +++ b/test/e2e/tests/tlsroute_with_backend.go @@ -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) }) }, } diff --git a/test/e2e/tests/utils.go b/test/e2e/tests/utils.go index a7834fbaaa3..484e41922e1 100644 --- a/test/e2e/tests/utils.go +++ b/test/e2e/tests/utils.go @@ -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) +}