|
| 1 | +package integration |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1" |
| 7 | + "github.com/aws/aws-application-networking-k8s/test/pkg/test" |
| 8 | + "github.com/aws/aws-sdk-go/aws" |
| 9 | + "github.com/aws/aws-sdk-go/service/vpclattice" |
| 10 | + . "github.com/onsi/ginkgo/v2" |
| 11 | + . "github.com/onsi/gomega" |
| 12 | + appsv1 "k8s.io/api/apps/v1" |
| 13 | + corev1 "k8s.io/api/core/v1" |
| 14 | + gwv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" |
| 15 | +) |
| 16 | + |
| 17 | +var _ = Describe("Target Group Policy Tests", Ordered, func() { |
| 18 | + var ( |
| 19 | + deployment *appsv1.Deployment |
| 20 | + service *corev1.Service |
| 21 | + httpRoute *gwv1beta1.HTTPRoute |
| 22 | + policy *v1alpha1.TargetGroupPolicy |
| 23 | + ) |
| 24 | + |
| 25 | + BeforeAll(func() { |
| 26 | + deployment, service = testFramework.NewNginxApp(test.ElasticSearchOptions{ |
| 27 | + Name: "target-group-policy-test", |
| 28 | + Namespace: k8snamespace, |
| 29 | + }) |
| 30 | + |
| 31 | + httpRoute = testFramework.NewHttpRoute(testGateway, service, service.Kind) |
| 32 | + |
| 33 | + testFramework.ExpectCreated(ctx, deployment, service, httpRoute) |
| 34 | + }) |
| 35 | + |
| 36 | + It("Update Protocol creates new Target Group", func() { |
| 37 | + policy = testFramework.CreateTargetGroupPolicy(service, &test.TargetGroupPolicyConfig{ |
| 38 | + PolicyName: "test-policy", |
| 39 | + Protocol: aws.String(vpclattice.TargetGroupProtocolHttp), |
| 40 | + }) |
| 41 | + |
| 42 | + testFramework.ExpectCreated(ctx, policy) |
| 43 | + |
| 44 | + tg := testFramework.GetTargetGroup(ctx, service) |
| 45 | + |
| 46 | + Expect(*tg.Protocol).To(Equal(vpclattice.TargetGroupProtocolHttp)) |
| 47 | + |
| 48 | + testFramework.UpdateTargetGroupPolicy(policy, &test.TargetGroupPolicyConfig{ |
| 49 | + Protocol: aws.String(vpclattice.TargetGroupProtocolHttps), |
| 50 | + }) |
| 51 | + |
| 52 | + testFramework.ExpectUpdated(ctx, policy) |
| 53 | + |
| 54 | + httpsTG := testFramework.GetTargetGroupWithProtocol(ctx, service, "https", "http1") |
| 55 | + |
| 56 | + Expect(*httpsTG.Protocol).To(Equal(vpclattice.TargetGroupProtocolHttps)) |
| 57 | + }) |
| 58 | + |
| 59 | + It("Delete Target Group Policy reset health check config for HTTP and HTTP1 Target Group", func() { |
| 60 | + policy = testFramework.CreateTargetGroupPolicy(service, &test.TargetGroupPolicyConfig{ |
| 61 | + PolicyName: "test-policy", |
| 62 | + Protocol: aws.String(vpclattice.TargetGroupProtocolHttp), |
| 63 | + ProtocolVersion: aws.String(vpclattice.TargetGroupProtocolVersionHttp1), |
| 64 | + HealthCheck: &v1alpha1.HealthCheckConfig{ |
| 65 | + IntervalSeconds: aws.Int64(7), |
| 66 | + StatusMatch: aws.String("200,204"), |
| 67 | + }, |
| 68 | + }) |
| 69 | + |
| 70 | + testFramework.ExpectCreated(ctx, policy) |
| 71 | + |
| 72 | + // time.Sleep(10 * time.Second) |
| 73 | + |
| 74 | + Eventually(func(g Gomega) { |
| 75 | + tgSummary := testFramework.GetTargetGroup(ctx, service) |
| 76 | + |
| 77 | + tg := testFramework.GetFullTargetGroupFromSummary(ctx, tgSummary) |
| 78 | + |
| 79 | + g.Expect(*tg.Config.HealthCheck.ProtocolVersion).To(Equal(vpclattice.TargetGroupProtocolVersionHttp1)) |
| 80 | + g.Expect(*tg.Config.HealthCheck.Protocol).To(Equal(vpclattice.TargetGroupProtocolHttp)) |
| 81 | + g.Expect(*tg.Config.HealthCheck.HealthCheckIntervalSeconds).To(BeEquivalentTo(7)) |
| 82 | + g.Expect(*tg.Config.HealthCheck.Matcher.HttpCode).To(Equal("200,204")) |
| 83 | + }).Within(10 * time.Second).WithPolling(1 * time.Second).Should(Succeed()) |
| 84 | + |
| 85 | + testFramework.ExpectDeletedThenNotFound(ctx, policy) |
| 86 | + |
| 87 | + Eventually(func(g Gomega) { |
| 88 | + tgSummary := testFramework.GetTargetGroup(ctx, service) |
| 89 | + |
| 90 | + tg := testFramework.GetFullTargetGroupFromSummary(ctx, tgSummary) |
| 91 | + |
| 92 | + g.Expect(*tg.Config.HealthCheck).To(Equal(vpclattice.HealthCheckConfig{ |
| 93 | + Enabled: aws.Bool(true), |
| 94 | + Path: aws.String("/"), |
| 95 | + HealthCheckIntervalSeconds: aws.Int64(30), |
| 96 | + HealthCheckTimeoutSeconds: aws.Int64(5), |
| 97 | + HealthyThresholdCount: aws.Int64(5), |
| 98 | + UnhealthyThresholdCount: aws.Int64(2), |
| 99 | + Protocol: aws.String(vpclattice.TargetGroupProtocolHttp), |
| 100 | + ProtocolVersion: aws.String(vpclattice.TargetGroupProtocolVersionHttp1), |
| 101 | + Port: nil, |
| 102 | + Matcher: &vpclattice.Matcher{ |
| 103 | + HttpCode: aws.String("200"), |
| 104 | + }, |
| 105 | + })) |
| 106 | + }).Within(10 * time.Second).WithPolling(1 * time.Second).Should(Succeed()) |
| 107 | + }) |
| 108 | + |
| 109 | + It("Delete Target Group Policy create HTTP and HTTP1 Target Group", func() { |
| 110 | + policy = testFramework.CreateTargetGroupPolicy(service, &test.TargetGroupPolicyConfig{ |
| 111 | + PolicyName: "test-policy", |
| 112 | + Protocol: aws.String(vpclattice.TargetGroupProtocolHttps), |
| 113 | + ProtocolVersion: aws.String(vpclattice.TargetGroupProtocolVersionHttp2), |
| 114 | + }) |
| 115 | + |
| 116 | + testFramework.ExpectCreated(ctx, policy) |
| 117 | + |
| 118 | + tg := testFramework.GetTargetGroupWithProtocol(ctx, service, "https", "http2") |
| 119 | + |
| 120 | + Expect(*tg.Protocol).To(Equal(vpclattice.TargetGroupProtocolHttps)) |
| 121 | + |
| 122 | + testFramework.ExpectDeleted(ctx, policy) |
| 123 | + |
| 124 | + httpTG := testFramework.GetTargetGroup(ctx, service) |
| 125 | + |
| 126 | + Expect(*httpTG.Protocol).To(Equal(vpclattice.TargetGroupProtocolHttp)) |
| 127 | + }) |
| 128 | + |
| 129 | + AfterEach(func() { |
| 130 | + testFramework.ExpectDeleted( |
| 131 | + ctx, |
| 132 | + policy, |
| 133 | + ) |
| 134 | + }) |
| 135 | + |
| 136 | + AfterAll(func() { |
| 137 | + testFramework.ExpectDeleted( |
| 138 | + ctx, |
| 139 | + deployment, |
| 140 | + service, |
| 141 | + httpRoute, |
| 142 | + ) |
| 143 | + }) |
| 144 | +}) |
0 commit comments