|
7 | 7 | "strings" |
8 | 8 | "time" |
9 | 9 |
|
| 10 | + "k8s.io/apimachinery/pkg/types" |
10 | 11 | gwv1 "sigs.k8s.io/gateway-api/apis/v1" |
11 | 12 |
|
12 | 13 | awssdk "github.com/aws/aws-sdk-go-v2/aws" |
@@ -788,4 +789,138 @@ var _ = Describe("test nlb gateway using instance targets reconciled by the aws |
788 | 789 | }) |
789 | 790 | }) |
790 | 791 | }) |
| 792 | + |
| 793 | + Context("with NLB instance target and gateway-level default TGC via LBC", func() { |
| 794 | + It("should apply default TGC from LBC and merge with service-level TGC", func() { |
| 795 | + ipTargetType := elbv2gw.TargetTypeIP |
| 796 | + hcProtocol := elbv2gw.TargetGroupHealthCheckProtocolHTTP |
| 797 | + gwHCPath := "/gw-default-health" |
| 798 | + svcHCPath := "/svc-override-health" |
| 799 | + |
| 800 | + interf := elbv2gw.LoadBalancerSchemeInternetFacing |
| 801 | + lbcSpec := elbv2gw.LoadBalancerConfigurationSpec{ |
| 802 | + Scheme: &interf, |
| 803 | + DefaultTargetGroupConfiguration: &elbv2gw.DefaultTargetGroupConfigurationReference{ |
| 804 | + Name: "gw-default-tgc", |
| 805 | + }, |
| 806 | + } |
| 807 | + |
| 808 | + defaultTGC := buildDefaultTargetGroupConfig("gw-default-tgc", elbv2gw.TargetGroupProps{ |
| 809 | + TargetType: &ipTargetType, |
| 810 | + HealthCheckConfig: &elbv2gw.HealthCheckConfiguration{ |
| 811 | + HealthCheckPath: &gwHCPath, |
| 812 | + HealthCheckProtocol: &hcProtocol, |
| 813 | + }, |
| 814 | + }) |
| 815 | + |
| 816 | + svcTgSpec := elbv2gw.TargetGroupConfigurationSpec{ |
| 817 | + DefaultConfiguration: elbv2gw.TargetGroupProps{ |
| 818 | + HealthCheckConfig: &elbv2gw.HealthCheckConfiguration{ |
| 819 | + HealthCheckPath: &svcHCPath, |
| 820 | + HealthCheckProtocol: &hcProtocol, |
| 821 | + }, |
| 822 | + }, |
| 823 | + } |
| 824 | + |
| 825 | + By("deploying stack", func() { |
| 826 | + err := stack.DeployWithDefaultTGC(ctx, tf, lbcSpec, defaultTGC, svcTgSpec, true) |
| 827 | + Expect(err).NotTo(HaveOccurred()) |
| 828 | + }) |
| 829 | + |
| 830 | + By("checking gateway status for lb dns name", func() { |
| 831 | + dnsName = stack.GetLoadBalancerIngressHostName() |
| 832 | + Expect(dnsName).ToNot(BeEmpty()) |
| 833 | + }) |
| 834 | + |
| 835 | + By("querying AWS loadbalancer from the dns name", func() { |
| 836 | + var err error |
| 837 | + lbARN, err = tf.LBManager.FindLoadBalancerByDNSName(ctx, dnsName) |
| 838 | + Expect(err).NotTo(HaveOccurred()) |
| 839 | + Expect(lbARN).ToNot(BeEmpty()) |
| 840 | + }) |
| 841 | + |
| 842 | + By("verifying AWS loadbalancer resources with two ip target groups", func() { |
| 843 | + expectedTargetGroups := []verifier.ExpectedTargetGroup{ |
| 844 | + { |
| 845 | + Protocol: "TCP", |
| 846 | + Port: 80, |
| 847 | + TargetType: "ip", |
| 848 | + NumTargets: int(*stack.nlbResourceStack.commonStack.dps[0].Spec.Replicas), |
| 849 | + }, |
| 850 | + { |
| 851 | + Protocol: "TCP", |
| 852 | + Port: 80, |
| 853 | + TargetType: "ip", |
| 854 | + NumTargets: int(*stack.nlbResourceStack.commonStack.dps[0].Spec.Replicas), |
| 855 | + }, |
| 856 | + } |
| 857 | + err := verifier.VerifyAWSLoadBalancerResources(ctx, tf, lbARN, verifier.LoadBalancerExpectation{ |
| 858 | + Type: "network", |
| 859 | + Scheme: "internet-facing", |
| 860 | + Listeners: stack.nlbResourceStack.getListenersPortMap(), |
| 861 | + TargetGroups: expectedTargetGroups, |
| 862 | + }) |
| 863 | + Expect(err).NotTo(HaveOccurred()) |
| 864 | + }) |
| 865 | + |
| 866 | + By("verifying svc1 inherits gateway TGC and svc2 uses service-level TGC health check path", func() { |
| 867 | + targetGroups, err := tf.TGManager.GetTargetGroupsForLoadBalancer(ctx, lbARN) |
| 868 | + Expect(err).NotTo(HaveOccurred()) |
| 869 | + Expect(len(targetGroups)).To(Equal(2)) |
| 870 | + |
| 871 | + hcPaths := []string{} |
| 872 | + for _, tg := range targetGroups { |
| 873 | + Expect(string(tg.TargetType)).To(Equal("ip")) |
| 874 | + hcPaths = append(hcPaths, awssdk.ToString(tg.HealthCheckPath)) |
| 875 | + } |
| 876 | + Expect(hcPaths).To(ContainElements("/gw-default-health", "/svc-override-health")) |
| 877 | + }) |
| 878 | + |
| 879 | + By("waiting for target group targets to be healthy", func() { |
| 880 | + err := verifier.WaitUntilAllTargetsAreHealthy(ctx, tf, lbARN, int(*stack.nlbResourceStack.commonStack.dps[0].Spec.Replicas)*2) |
| 881 | + Expect(err).NotTo(HaveOccurred()) |
| 882 | + }) |
| 883 | + |
| 884 | + By("waiting until DNS name is available", func() { |
| 885 | + err := utils.WaitUntilDNSNameAvailable(ctx, dnsName) |
| 886 | + Expect(err).NotTo(HaveOccurred()) |
| 887 | + }) |
| 888 | + |
| 889 | + By("sending http request to the lb", func() { |
| 890 | + url := fmt.Sprintf("http://%v/any-path", dnsName) |
| 891 | + err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(200)) |
| 892 | + Expect(err).NotTo(HaveOccurred()) |
| 893 | + }) |
| 894 | + |
| 895 | + By("updating default TGC health check path and verifying propagation", func() { |
| 896 | + tgcKey := types.NamespacedName{ |
| 897 | + Name: "gw-default-tgc", |
| 898 | + Namespace: stack.nlbResourceStack.commonStack.ns.Name, |
| 899 | + } |
| 900 | + tgc := &elbv2gw.TargetGroupConfiguration{} |
| 901 | + err := tf.K8sClient.Get(ctx, tgcKey, tgc) |
| 902 | + Expect(err).NotTo(HaveOccurred()) |
| 903 | + |
| 904 | + updatedHCPath := "/updated-default-health" |
| 905 | + tgc.Spec.DefaultConfiguration.HealthCheckConfig.HealthCheckPath = &updatedHCPath |
| 906 | + err = tf.K8sClient.Update(ctx, tgc) |
| 907 | + Expect(err).NotTo(HaveOccurred()) |
| 908 | + }) |
| 909 | + |
| 910 | + By("verifying AWS target group health check path updated after TGC change", func() { |
| 911 | + Eventually(func() bool { |
| 912 | + targetGroups, err := tf.TGManager.GetTargetGroupsForLoadBalancer(ctx, lbARN) |
| 913 | + if err != nil || len(targetGroups) == 0 { |
| 914 | + return false |
| 915 | + } |
| 916 | + for _, tg := range targetGroups { |
| 917 | + if awssdk.ToString(tg.HealthCheckPath) == "/updated-default-health" { |
| 918 | + return true |
| 919 | + } |
| 920 | + } |
| 921 | + return false |
| 922 | + }, utils.PollTimeoutLong, utils.PollIntervalMedium).Should(BeTrue()) |
| 923 | + }) |
| 924 | + }) |
| 925 | + }) |
791 | 926 | }) |
0 commit comments