From 6ecfc62ccc3a775d929acf8ea3f3751254ecbd14 Mon Sep 17 00:00:00 2001 From: Olivia Song Date: Fri, 27 Oct 2023 13:32:05 -0700 Subject: [PATCH] enable ingress instance e2e test for ipv6 (#3416) * enable ingress instance e2e test for ipv6 * add coverage for ingress instance e2e test --- scripts/run-e2e-test.sh | 5 +- test/e2e/ingress/multi_path_backend_test.go | 22 ------ test/e2e/ingress/vanilla_ingress_test.go | 88 ++++++++++++++++++++- 3 files changed, 85 insertions(+), 30 deletions(-) diff --git a/scripts/run-e2e-test.sh b/scripts/run-e2e-test.sh index b0475551f..92031733a 100755 --- a/scripts/run-e2e-test.sh +++ b/scripts/run-e2e-test.sh @@ -200,12 +200,9 @@ function run_ginkgo_test() { TEST_RESULT=success local focus=$1 echo "Starting the ginkgo tests from generated ginkgo test binaries with focus: $focus" - if [ "$IP_FAMILY" == "IPv4" ]; then + if [ "$IP_FAMILY" == "IPv4" ] || [ "$IP_FAMILY" == "IPv6" ]; then (CGO_ENABLED=0 GOOS=$OS_OVERRIDE ginkgo --no-color $EXTRA_GINKGO_FLAGS --focus="$focus" -v --timeout 2h --fail-on-pending $GINKGO_TEST_BUILD/ingress.test -- --kubeconfig=$KUBE_CONFIG_PATH --cluster-name=$CLUSTER_NAME --aws-region=$REGION --aws-vpc-id=$VPC_ID --test-image-registry=$TEST_IMAGE_REGISTRY --ip-family=$IP_FAMILY || TEST_RESULT=fail) (CGO_ENABLED=0 GOOS=$OS_OVERRIDE ginkgo --no-color $EXTRA_GINKGO_FLAGS --focus="$focus" -v --timeout 2h --fail-on-pending $GINKGO_TEST_BUILD/service.test -- --kubeconfig=$KUBE_CONFIG_PATH --cluster-name=$CLUSTER_NAME --aws-region=$REGION --aws-vpc-id=$VPC_ID --test-image-registry=$TEST_IMAGE_REGISTRY --ip-family=$IP_FAMILY || TEST_RESULT=fail) - elif [ "$IP_FAMILY" == "IPv6" ]; then - (CGO_ENABLED=0 GOOS=$OS_OVERRIDE ginkgo --no-color $EXTRA_GINKGO_FLAGS --focus="$focus" --skip="instance" -v --timeout 2h --fail-on-pending $GINKGO_TEST_BUILD/ingress.test -- --kubeconfig=$KUBE_CONFIG_PATH --cluster-name=$CLUSTER_NAME --aws-region=$REGION --aws-vpc-id=$VPC_ID --test-image-registry=$TEST_IMAGE_REGISTRY --ip-family=$IP_FAMILY || TEST_RESULT=fail) - (CGO_ENABLED=0 GOOS=$OS_OVERRIDE ginkgo --no-color $EXTRA_GINKGO_FLAGS --focus="$focus" --skip="instance" -v --timeout 2h --fail-on-pending $GINKGO_TEST_BUILD/service.test -- --kubeconfig=$KUBE_CONFIG_PATH --cluster-name=$CLUSTER_NAME --aws-region=$REGION --aws-vpc-id=$VPC_ID --test-image-registry=$TEST_IMAGE_REGISTRY --ip-family=$IP_FAMILY || TEST_RESULT=fail) else echo "Invalid IP_FAMILY input, choose from IPv4 or IPv6 only" fi diff --git a/test/e2e/ingress/multi_path_backend_test.go b/test/e2e/ingress/multi_path_backend_test.go index 74053de4c..ff41e6879 100644 --- a/test/e2e/ingress/multi_path_backend_test.go +++ b/test/e2e/ingress/multi_path_backend_test.go @@ -38,19 +38,11 @@ var _ = Describe("test ingresses with multiple path and backends", func() { Context("with podReadinessGate enabled", func() { It("standalone Ingress should behaves correctly", func() { - // TODO: Once instance mode is supported in IPv6, the backendConfigA can be removed and reverted backendConfigA := BackendConfig{ Replicas: 3, TargetType: elbv2model.TargetTypeInstance, HTTPBody: "backend-a", } - if tf.Options.IPFamily == "IPv6" { - backendConfigA = BackendConfig{ - Replicas: 3, - TargetType: elbv2model.TargetTypeIP, - HTTPBody: "backend-a", - } - } stack := NewMultiPathBackendStack(map[string]NamespacedResourcesConfig{ "ns-1": { IngCFGs: map[string]MultiPathIngressConfig{ @@ -106,9 +98,7 @@ var _ = Describe("test ingresses with multiple path and backends", func() { err = stack.Cleanup(ctx, tf) Expect(err).NotTo(HaveOccurred()) }) - It("IngressGroup across namespaces should behaves correctly", func() { - // TODO: Once instance mode is supported in IPv6, the backendConfigA and backendConfigD can be removed and reverted backendConfigA := BackendConfig{ Replicas: 3, TargetType: elbv2model.TargetTypeInstance, @@ -119,18 +109,6 @@ var _ = Describe("test ingresses with multiple path and backends", func() { TargetType: elbv2model.TargetTypeInstance, HTTPBody: "backend-d", } - if tf.Options.IPFamily == "IPv6" { - backendConfigA = BackendConfig{ - Replicas: 3, - TargetType: elbv2model.TargetTypeIP, - HTTPBody: "backend-a", - } - backendConfigD = BackendConfig{ - Replicas: 3, - TargetType: elbv2model.TargetTypeIP, - HTTPBody: "backend-d", - } - } groupName := fmt.Sprintf("e2e-group.%v", utils.RandomDNS1123Label(8)) stack := NewMultiPathBackendStack(map[string]NamespacedResourcesConfig{ "ns-1": { diff --git a/test/e2e/ingress/vanilla_ingress_test.go b/test/e2e/ingress/vanilla_ingress_test.go index be9e08c34..8337728cb 100644 --- a/test/e2e/ingress/vanilla_ingress_test.go +++ b/test/e2e/ingress/vanilla_ingress_test.go @@ -70,7 +70,52 @@ var _ = Describe("vanilla ingress tests", func() { }) Context("with basic settings", func() { - It("[ingress-class] with IngressClass configured with 'ingress.k8s.aws/alb' controller, one ALB shall be created and functional", func() { + It("[ingress-class] in IP mode, with IngressClass configured with 'ingress.k8s.aws/alb' controller, one ALB shall be created and functional", func() { + appBuilder := manifest.NewFixedResponseServiceBuilder() + ingBuilder := manifest.NewIngressBuilder() + dp, svc := appBuilder.Build(sandboxNS.Name, "app", tf.Options.TestImageRegistry) + ingBackend := networking.IngressBackend{ + Service: &networking.IngressServiceBackend{ + Name: svc.Name, + Port: networking.ServiceBackendPort{ + Number: 80, + }, + }, + } + ingClass := &networking.IngressClass{ + ObjectMeta: metav1.ObjectMeta{ + Name: sandboxNS.Name, + }, + Spec: networking.IngressClassSpec{ + Controller: "ingress.k8s.aws/alb", + }, + } + annotation := map[string]string{ + "alb.ingress.kubernetes.io/scheme": "internet-facing", + "alb.ingress.kubernetes.io/target-type": "ip", + } + if tf.Options.IPFamily == "IPv6" { + annotation["alb.ingress.kubernetes.io/ip-address-type"] = "dualstack" + } + ing := ingBuilder. + AddHTTPRoute("", networking.HTTPIngressPath{Path: "/path", PathType: &exact, Backend: ingBackend}). + WithIngressClassName(ingClass.Name). + WithAnnotations(annotation).Build(sandboxNS.Name, "ing") + resStack := fixture.NewK8SResourceStack(tf, dp, svc, ingClass, ing) + err := resStack.Setup(ctx) + Expect(err).NotTo(HaveOccurred()) + + defer resStack.TearDown(ctx) + + lbARN, lbDNS := ExpectOneLBProvisionedForIngress(ctx, tf, ing) + // test traffic + ExpectLBDNSBeAvailable(ctx, tf, lbARN, lbDNS) + httpExp := httpexpect.New(tf.LoggerReporter, fmt.Sprintf("http://%v", lbDNS)) + httpExp.GET("/path").Expect(). + Status(http.StatusOK). + Body().Equal("Hello World!") + }) + It("[ingress-class] in Instance mode, with IngressClass configured with 'ingress.k8s.aws/alb' controller, one ALB shall be created and functional", func() { appBuilder := manifest.NewFixedResponseServiceBuilder() ingBuilder := manifest.NewIngressBuilder() dp, svc := appBuilder.Build(sandboxNS.Name, "app", tf.Options.TestImageRegistry) @@ -95,7 +140,6 @@ var _ = Describe("vanilla ingress tests", func() { } if tf.Options.IPFamily == "IPv6" { annotation["alb.ingress.kubernetes.io/ip-address-type"] = "dualstack" - annotation["alb.ingress.kubernetes.io/target-type"] = "ip" } ing := ingBuilder. AddHTTPRoute("", networking.HTTPIngressPath{Path: "/path", PathType: &exact, Backend: ingBackend}). @@ -116,7 +160,44 @@ var _ = Describe("vanilla ingress tests", func() { Body().Equal("Hello World!") }) - It("with 'kubernetes.io/ingress.class' annotation set to 'alb', one ALB shall be created and functional", func() { + It("ingress in IP mode, with 'kubernetes.io/ingress.class' annotation set to 'alb', one ALB shall be created and functional", func() { + appBuilder := manifest.NewFixedResponseServiceBuilder() + ingBuilder := manifest.NewIngressBuilder() + dp, svc := appBuilder.Build(sandboxNS.Name, "app", tf.Options.TestImageRegistry) + ingBackend := networking.IngressBackend{ + Service: &networking.IngressServiceBackend{ + Name: svc.Name, + Port: networking.ServiceBackendPort{ + Number: 80, + }, + }, + } + annotation := map[string]string{ + "kubernetes.io/ingress.class": "alb", + "alb.ingress.kubernetes.io/scheme": "internet-facing", + "alb.ingress.kubernetes.io/target-type": "ip", + } + if tf.Options.IPFamily == "IPv6" { + annotation["alb.ingress.kubernetes.io/ip-address-type"] = "dualstack" + } + ing := ingBuilder. + AddHTTPRoute("", networking.HTTPIngressPath{Path: "/path", PathType: &exact, Backend: ingBackend}). + WithAnnotations(annotation).Build(sandboxNS.Name, "ing") + resStack := fixture.NewK8SResourceStack(tf, dp, svc, ing) + err := resStack.Setup(ctx) + Expect(err).NotTo(HaveOccurred()) + + defer resStack.TearDown(ctx) + + lbARN, lbDNS := ExpectOneLBProvisionedForIngress(ctx, tf, ing) + // test traffic + ExpectLBDNSBeAvailable(ctx, tf, lbARN, lbDNS) + httpExp := httpexpect.New(tf.LoggerReporter, fmt.Sprintf("http://%v", lbDNS)) + httpExp.GET("/path").Expect(). + Status(http.StatusOK). + Body().Equal("Hello World!") + }) + It("ingress in Instance mode, with 'kubernetes.io/ingress.class' annotation set to 'alb', one ALB shall be created and functional", func() { appBuilder := manifest.NewFixedResponseServiceBuilder() ingBuilder := manifest.NewIngressBuilder() dp, svc := appBuilder.Build(sandboxNS.Name, "app", tf.Options.TestImageRegistry) @@ -134,7 +215,6 @@ var _ = Describe("vanilla ingress tests", func() { } if tf.Options.IPFamily == "IPv6" { annotation["alb.ingress.kubernetes.io/ip-address-type"] = "dualstack" - annotation["alb.ingress.kubernetes.io/target-type"] = "ip" } ing := ingBuilder. AddHTTPRoute("", networking.HTTPIngressPath{Path: "/path", PathType: &exact, Backend: ingBackend}).