|
| 1 | +package gateway |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + . "github.com/onsi/ginkgo/v2" |
| 7 | + . "github.com/onsi/gomega" |
| 8 | + elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1" |
| 9 | + "sigs.k8s.io/aws-load-balancer-controller/test/framework/http" |
| 10 | + "sigs.k8s.io/aws-load-balancer-controller/test/framework/utils" |
| 11 | + "sigs.k8s.io/aws-load-balancer-controller/test/framework/verifier" |
| 12 | +) |
| 13 | + |
| 14 | +var _ = Describe("test k8s alb gateway using ip targets reconciled by the aws load balancer controller", func() { |
| 15 | + var ( |
| 16 | + ctx context.Context |
| 17 | + stack ALBTestStack |
| 18 | + dnsName string |
| 19 | + lbARN string |
| 20 | + ) |
| 21 | + BeforeEach(func() { |
| 22 | + if !tf.Options.EnableGatewayTests { |
| 23 | + Skip("Skipping gateway tests") |
| 24 | + } |
| 25 | + ctx = context.Background() |
| 26 | + stack = ALBTestStack{} |
| 27 | + }) |
| 28 | + AfterEach(func() { |
| 29 | + stack.Cleanup(ctx, tf) |
| 30 | + }) |
| 31 | + Context("with ALB ip target configuration", func() { |
| 32 | + BeforeEach(func() {}) |
| 33 | + It("should provision internet-facing load balancer resources", func() { |
| 34 | + interf := elbv2gw.LoadBalancerSchemeInternetFacing |
| 35 | + lbcSpec := elbv2gw.LoadBalancerConfigurationSpec{ |
| 36 | + Scheme: &interf, |
| 37 | + } |
| 38 | + ipTargetType := elbv2gw.TargetTypeIP |
| 39 | + tgSpec := elbv2gw.TargetGroupConfigurationSpec{ |
| 40 | + DefaultConfiguration: elbv2gw.TargetGroupProps{ |
| 41 | + TargetType: &ipTargetType, |
| 42 | + }, |
| 43 | + } |
| 44 | + |
| 45 | + By("deploying stack", func() { |
| 46 | + err := stack.Deploy(ctx, tf, lbcSpec, tgSpec) |
| 47 | + Expect(err).NotTo(HaveOccurred()) |
| 48 | + }) |
| 49 | + |
| 50 | + By("checking gateway status for lb dns name", func() { |
| 51 | + dnsName = stack.GetLoadBalancerIngressHostName() |
| 52 | + Expect(dnsName).ToNot(BeEmpty()) |
| 53 | + }) |
| 54 | + |
| 55 | + By("querying AWS loadbalancer from the dns name", func() { |
| 56 | + var err error |
| 57 | + lbARN, err = tf.LBManager.FindLoadBalancerByDNSName(ctx, dnsName) |
| 58 | + Expect(err).NotTo(HaveOccurred()) |
| 59 | + Expect(lbARN).ToNot(BeEmpty()) |
| 60 | + }) |
| 61 | + |
| 62 | + tgMap := map[string]string{ |
| 63 | + "80": "HTTP", |
| 64 | + } |
| 65 | + |
| 66 | + targetNumber := int(*stack.albResourceStack.commonStack.dp.Spec.Replicas) |
| 67 | + |
| 68 | + By("verifying AWS loadbalancer resources", func() { |
| 69 | + err := verifier.VerifyAWSLoadBalancerResources(ctx, tf, lbARN, verifier.LoadBalancerExpectation{ |
| 70 | + Type: "application", |
| 71 | + Scheme: "internet-facing", |
| 72 | + TargetType: "ip", |
| 73 | + Listeners: stack.albResourceStack.getListenersPortMap(), |
| 74 | + TargetGroups: tgMap, |
| 75 | + NumTargets: targetNumber, |
| 76 | + TargetGroupHC: &verifier.TargetGroupHC{ |
| 77 | + Protocol: "HTTP", |
| 78 | + Port: "traffic-port", |
| 79 | + Path: "/", |
| 80 | + Interval: 15, |
| 81 | + Timeout: 5, |
| 82 | + HealthyThreshold: 3, |
| 83 | + UnhealthyThreshold: 3, |
| 84 | + }, |
| 85 | + }) |
| 86 | + Expect(err).NotTo(HaveOccurred()) |
| 87 | + }) |
| 88 | + By("waiting for target group targets to be healthy", func() { |
| 89 | + err := verifier.WaitUntilTargetsAreHealthy(ctx, tf, lbARN, targetNumber) |
| 90 | + Expect(err).NotTo(HaveOccurred()) |
| 91 | + }) |
| 92 | + By("waiting until DNS name is available", func() { |
| 93 | + err := utils.WaitUntilDNSNameAvailable(ctx, dnsName) |
| 94 | + Expect(err).NotTo(HaveOccurred()) |
| 95 | + }) |
| 96 | + By("sending http request to the lb", func() { |
| 97 | + url := fmt.Sprintf("http://%v/any-path", dnsName) |
| 98 | + err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(200)) |
| 99 | + Expect(err).NotTo(HaveOccurred()) |
| 100 | + }) |
| 101 | + }) |
| 102 | + }) |
| 103 | +}) |
0 commit comments