From 0ccee81e31c593a17ec506cba3f1b537401f3a0a Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Tue, 7 Nov 2023 12:33:59 +0000 Subject: [PATCH] First pass at integration tests --- .../dnspolicy_controller_test.go | 1955 ++++++++--------- .../tlspolicy_controller_test.go | 8 +- test/util/test_dnspolicy_types.go | 105 + test/util/test_types.go | 4 +- 4 files changed, 1079 insertions(+), 993 deletions(-) create mode 100644 test/util/test_dnspolicy_types.go diff --git a/test/policy_integration/dnspolicy_controller_test.go b/test/policy_integration/dnspolicy_controller_test.go index 7e3a25b3e..6aefcab09 100644 --- a/test/policy_integration/dnspolicy_controller_test.go +++ b/test/policy_integration/dnspolicy_controller_test.go @@ -18,7 +18,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/Kuadrant/multicluster-gateway-controller/pkg/_internal/conditions" @@ -60,38 +59,11 @@ func testBuildGatewayClass(gwClassName, ns string) *gatewayv1beta1.GatewayClass } } -func testBuildGateway(gwName, gwClassName, hostname, ns, dnspolicy string) *gatewayv1beta1.Gateway { - typedHostname := gatewayv1beta1.Hostname(hostname) - wildcardHost := gatewayv1beta1.Hostname(TestWildCardListenerHost) - return &gatewayv1beta1.Gateway{ - ObjectMeta: metav1.ObjectMeta{ - Name: gwName, - Namespace: ns, - Annotations: map[string]string{ - DNSPoliciesBackRefAnnotation: fmt.Sprintf("[{\"Namespace\":\"%s\",\"Name\":\"%s\"}]", ns, dnspolicy), - }, - Labels: map[string]string{ - "cluster.open-cluster-management.io/placement": "GatewayControllerTest", - }, - }, - Spec: gatewayv1beta1.GatewaySpec{ - GatewayClassName: gatewayv1beta1.ObjectName(gwClassName), - Listeners: []gatewayv1beta1.Listener{ - { - Name: gatewayv1beta1.SectionName(hostname), - Hostname: &typedHostname, - Port: gatewayv1beta1.PortNumber(80), - Protocol: gatewayv1beta1.HTTPProtocolType, - }, - { - Name: TestWildCardListenerName, - Hostname: &wildcardHost, - Port: gatewayv1beta1.PortNumber(80), - Protocol: gatewayv1beta1.HTTPProtocolType, - }, - }, - }, - } +func testBuildGateway(gwName, gwClassName, hostname, ns string) *gatewayv1beta1.Gateway { + return testutil.NewTestGateway(gwName, gwClassName, ns). + WithHTTPListener(hostname, hostname). + WithHTTPListener(TestWildCardListenerName, TestWildCardListenerHost). + Gateway } func testBuildGatewayAddresses() []gatewayv1beta1.GatewayAddress { @@ -122,61 +94,45 @@ func testBuildGatewayListenerStatus(names []string, numRoutes []int32) []gateway return listeners } -func testBuildDNSPolicyWithHealthCheck(policyName, gwName, ns string, threshold *int) *v1alpha1.DNSPolicy { - typedNamespace := gatewayv1beta1.Namespace(ns) - protocol := v1alpha1.HttpProtocol - return &v1alpha1.DNSPolicy{ - ObjectMeta: metav1.ObjectMeta{ - Name: policyName, - Namespace: ns, - }, - Spec: v1alpha1.DNSPolicySpec{ - RoutingStrategy: v1alpha1.LoadBalancedRoutingStrategy, - TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ - Group: "gateway.networking.k8s.io", - Kind: "Gateway", - Name: gatewayv1beta1.ObjectName(gwName), - Namespace: &typedNamespace, - }, - HealthCheck: &v1alpha1.HealthCheckSpec{ - Endpoint: "/", - Protocol: &protocol, - FailureThreshold: threshold, - }, - LoadBalancing: &v1alpha1.LoadBalancingSpec{ - Weighted: &v1alpha1.LoadBalancingWeighted{ - DefaultWeight: 120, - }, - }, - }, +func testBuildGatewayStatus(gwAddresses []gatewayv1beta1.GatewayAddress, gwConditions []metav1.Condition, gwListeners []gatewayv1beta1.ListenerStatus) gatewayv1beta1.GatewayStatus { + return gatewayv1beta1.GatewayStatus{ + Addresses: gwAddresses, + Conditions: gwConditions, + Listeners: gwListeners, } } -func testBuildDNSPolicyWithGeo(policyName, gwName, ns string) *v1alpha1.DNSPolicy { - typedNamespace := gatewayv1beta1.Namespace(ns) - return &v1alpha1.DNSPolicy{ - ObjectMeta: metav1.ObjectMeta{ - Name: policyName, - Namespace: ns, - }, - Spec: v1alpha1.DNSPolicySpec{ - RoutingStrategy: v1alpha1.LoadBalancedRoutingStrategy, - TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ - Group: "gateway.networking.k8s.io", - Kind: "Gateway", - Name: gatewayv1beta1.ObjectName(gwName), - Namespace: &typedNamespace, - }, - LoadBalancing: &v1alpha1.LoadBalancingSpec{ - Weighted: &v1alpha1.LoadBalancingWeighted{ - DefaultWeight: 120, - }, - Geo: &v1alpha1.LoadBalancingGeo{ - DefaultGeo: "IE", - }, - }, - }, - } +func testBuildDNSPolicyLoadBalanced(policyName, gwName, ns string) *v1alpha1.DNSPolicy { + return testutil.NewTestDNSPolicy(policyName, ns). + WithTargetGateway(gwName). + WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). + DNSPolicy +} + +func testBuildDNSPolicyLoadBalancedWeighted(policyName, gwName, ns string, threshold *int) *v1alpha1.DNSPolicy { + return testutil.NewTestDNSPolicy(policyName, ns). + WithTargetGateway(gwName). + WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). + WithLoadBalancingWeightedFor(120, nil). + DNSPolicy +} + +func testBuildDNSPolicyLoadBalancedGeoWeighted(policyName, gwName, ns string) *v1alpha1.DNSPolicy { + return testutil.NewTestDNSPolicy(policyName, ns). + WithTargetGateway(gwName). + WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). + WithLoadBalancingWeightedFor(120, nil). + WithLoadBalancingGeoFor("IE"). + DNSPolicy +} + +func testBuildDNSPolicyLoadBalancedWeightedWithHealthCheck(policyName, gwName, ns string, threshold *int) *v1alpha1.DNSPolicy { + return testutil.NewTestDNSPolicy(policyName, ns). + WithTargetGateway(gwName). + WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). + WithHealthCheckFor("/", nil, v1alpha1.HttpProtocol, threshold). + WithLoadBalancingWeightedFor(120, nil). + DNSPolicy } var _ = Describe("DNSPolicy", Ordered, func() { @@ -233,7 +189,7 @@ var _ = Describe("DNSPolicy", Ordered, func() { gwClassName := "istio" BeforeEach(func() { - dnsPolicy = testBuildDNSPolicyWithHealthCheck("test-dns-policy", "test-gateway", testNamespace, nil) + dnsPolicy = testBuildDNSPolicyLoadBalanced("test-dns-policy", "test-gateway", testNamespace) Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil()) Eventually(func() error { //dns policy exists return k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy) @@ -271,7 +227,7 @@ var _ = Describe("DNSPolicy", Ordered, func() { By("creating a valid Gateway") gateway = testutil.NewTestGateway("test-gateway", gwClassName, testNamespace). - WithHTTPListener("test.example.com").Gateway + WithHTTPListener("test-listener", "test.example.com").Gateway Expect(k8sClient.Create(ctx, gateway)).To(BeNil()) Eventually(func() error { //gateway exists return k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway) @@ -325,12 +281,108 @@ var _ = Describe("DNSPolicy", Ordered, func() { }) - Context("gateway placed", func() { + Context("valid target with no gateway status", func() { + var gateway *gatewayv1beta1.Gateway + var dnsPolicy *v1alpha1.DNSPolicy + testGatewayName := "test-not-status-gateway" + + BeforeEach(func() { + gateway = testBuildGateway(testGatewayName, testutil.DummyCRName, TestAttachedRouteName, testNamespace) + dnsPolicy = testBuildDNSPolicyLoadBalanced("test-dns-policy", testGatewayName, testNamespace) + + Expect(k8sClient.Create(ctx, gateway)).To(BeNil()) + Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil()) + + Eventually(func() error { + return k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy) + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + + Eventually(func() error { //gateway exists + return k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway) + }, TestTimeoutMedium, TestRetryIntervalMedium).ShouldNot(HaveOccurred()) + + Eventually(func() error { //dns policy exists + return k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy) + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + }) + + AfterEach(func() { + err := k8sClient.Delete(ctx, gateway) + Expect(err).ToNot(HaveOccurred()) + }) + + It("should not create a dns record", func() { + Consistently(func() []v1alpha1.DNSRecord { // DNS record exists + dnsRecords := v1alpha1.DNSRecordList{} + err := k8sClient.List(ctx, &dnsRecords, client.InNamespace(dnsPolicy.GetNamespace())) + Expect(err).ToNot(HaveOccurred()) + return dnsRecords.Items + }, time.Second*15, time.Second).Should(BeEmpty()) + }) + + It("should have ready status", func() { + Eventually(func() error { + if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy); err != nil { + return err + } + if !meta.IsStatusConditionTrue(dnsPolicy.Status.Conditions, string(conditions.ConditionTypeReady)) { + return fmt.Errorf("expected DNSPolicy status condition to be %s", string(conditions.ConditionTypeReady)) + } + return nil + }, time.Second*15, time.Second).Should(BeNil()) + }) + + It("should set gateway back reference", func() { + existingGateway := &gatewayv1beta1.Gateway{} + policyBackRefValue := testNamespace + "/" + dnsPolicy.Name + refs, _ := json.Marshal([]client.ObjectKey{{Name: dnsPolicy.Name, Namespace: testNamespace}}) + policiesBackRefValue := string(refs) + Eventually(func() error { + // Check gateway back references + err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) + if err != nil { + return err + } + annotations := existingGateway.GetAnnotations() + if annotations == nil { + return fmt.Errorf("existingGateway annotations should not be nil") + } + if _, ok := annotations[DNSPolicyBackRefAnnotation]; !ok { + return fmt.Errorf("existingGateway annotations do not have annotation %s", DNSPolicyBackRefAnnotation) + } + if annotations[DNSPolicyBackRefAnnotation] != policyBackRefValue { + return fmt.Errorf("existingGateway annotations[%s] does not have expected value", DNSPolicyBackRefAnnotation) + } + return nil + }, time.Second*5, time.Second).Should(BeNil()) + Eventually(func() error { + // Check gateway back references + err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) + if err != nil { + return err + } + annotations := existingGateway.GetAnnotations() + if annotations == nil { + return fmt.Errorf("existingGateway annotations should not be nil") + } + if _, ok := annotations[DNSPoliciesBackRefAnnotation]; !ok { + return fmt.Errorf("existingGateway annotations do not have annotation %s", DNSPoliciesBackRefAnnotation) + } + if annotations[DNSPoliciesBackRefAnnotation] != policiesBackRefValue { + return fmt.Errorf("existingGateway annotations[%s] does not have expected value", DNSPoliciesBackRefAnnotation) + } + return nil + }, time.Second*5, time.Second).Should(BeNil()) + }) + }) + + Context("multi cluster gateway status", func() { var gateway *gatewayv1beta1.Gateway var lbHash, dnsRecordName, wildcardDNSRecordName string BeforeEach(func() { - gateway = testBuildGateway(TestPlacedGatewayName, testutil.DummyCRName, TestAttachedRouteName, testNamespace, "test-dns-policy") + gateway = testBuildGateway(TestPlacedGatewayName, testutil.DummyCRName, TestAttachedRouteName, testNamespace) + lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) dnsRecordName = fmt.Sprintf("%s-%s", TestPlacedGatewayName, TestAttachedRouteName) wildcardDNSRecordName = fmt.Sprintf("%s-%s", TestPlacedGatewayName, TestWildCardListenerName) @@ -383,634 +435,387 @@ var _ = Describe("DNSPolicy", Ordered, func() { } }) - Context("weighted dnspolicy", func() { - var dnsPolicy *v1alpha1.DNSPolicy + Context("simple routing strategy", func() { + //ToDo Add simple routing strategy tests + }) - BeforeEach(func() { - dnsPolicy = testBuildDNSPolicyWithHealthCheck("test-dns-policy", TestPlacedGatewayName, testNamespace, nil) - Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil()) - Eventually(func() error { //dns policy exists - return k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy) - }, TestTimeoutMedium, TestRetryIntervalMedium).ShouldNot(HaveOccurred()) - }) + Context("loadbalanced routing strategy", func() { - It("should create a dns record", func() { - createdDNSRecord := &v1alpha1.DNSRecord{} - expectedEndpoints := []*v1alpha1.Endpoint{ - { - DNSName: "test.example.com", - Targets: []string{ - "lb-" + lbHash + ".test.example.com", - }, - RecordType: "CNAME", - SetIdentifier: "", - RecordTTL: 300, - }, - { - DNSName: "lb-" + lbHash + ".test.example.com", - Targets: []string{ - "default.lb-" + lbHash + ".test.example.com", - }, - RecordType: "CNAME", - SetIdentifier: "default", - RecordTTL: 300, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "geo-code", - Value: "*", + Context("weighted", func() { + var dnsPolicy *v1alpha1.DNSPolicy + + BeforeEach(func() { + dnsPolicy = testBuildDNSPolicyLoadBalancedWeightedWithHealthCheck("test-dns-policy", TestPlacedGatewayName, testNamespace, nil) + Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil()) + Eventually(func() error { //dns policy exists + return k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy) + }, TestTimeoutMedium, TestRetryIntervalMedium).ShouldNot(HaveOccurred()) + }) + + It("should create a dns record", func() { + createdDNSRecord := &v1alpha1.DNSRecord{} + expectedEndpoints := []*v1alpha1.Endpoint{ + { + DNSName: "test.example.com", + Targets: []string{ + "lb-" + lbHash + ".test.example.com", }, + RecordType: "CNAME", + SetIdentifier: "", + RecordTTL: 300, }, - }, - { - DNSName: "s07c46.lb-" + lbHash + ".test.example.com", - Targets: []string{ - TestAttachedRouteAddressOne, - }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - { - DNSName: "default.lb-" + lbHash + ".test.example.com", - Targets: []string{ - "s07c46.lb-" + lbHash + ".test.example.com", + { + DNSName: "lb-" + lbHash + ".test.example.com", + Targets: []string{ + "default.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "default", + RecordTTL: 300, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "geo-code", + Value: "*", + }, + }, }, - RecordType: "CNAME", - SetIdentifier: "s07c46.lb-" + lbHash + ".test.example.com", - RecordTTL: 60, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", + { + DNSName: "s07c46.lb-" + lbHash + ".test.example.com", + Targets: []string{ + TestAttachedRouteAddressOne, }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, }, - }, - { - DNSName: "default.lb-" + lbHash + ".test.example.com", - Targets: []string{ - "2w705o.lb-" + lbHash + ".test.example.com", + { + DNSName: "default.lb-" + lbHash + ".test.example.com", + Targets: []string{ + "s07c46.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "s07c46.lb-" + lbHash + ".test.example.com", + RecordTTL: 60, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, + }, }, - RecordType: "CNAME", - SetIdentifier: "2w705o.lb-" + lbHash + ".test.example.com", - RecordTTL: 60, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", + { + DNSName: "default.lb-" + lbHash + ".test.example.com", + Targets: []string{ + "2w705o.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "2w705o.lb-" + lbHash + ".test.example.com", + RecordTTL: 60, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, }, }, - }, - { - DNSName: "2w705o.lb-" + lbHash + ".test.example.com", - Targets: []string{ - TestAttachedRouteAddressTwo, + { + DNSName: "2w705o.lb-" + lbHash + ".test.example.com", + Targets: []string{ + TestAttachedRouteAddressTwo, + }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - } - Eventually(func() error { // DNS record exists - if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord); err != nil { - return err } - if len(createdDNSRecord.Spec.Endpoints) != len(expectedEndpoints) { - return fmt.Errorf("expected %v endpoints in DNSRecord, got %v", len(expectedEndpoints), len(createdDNSRecord.Spec.Endpoints)) - } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - Expect(createdDNSRecord.Spec.ManagedZoneRef.Name).To(Equal("example.com")) - Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) - Expect(createdDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) - }) - It("should create a wildcard dns record", func() { - wildcardDNSRecord := &v1alpha1.DNSRecord{} - expectedEndpoints := []*v1alpha1.Endpoint{ - { - DNSName: TestWildCardListenerHost, - Targets: []string{ - "lb-" + lbHash + ".example.com", - }, - RecordType: "CNAME", - SetIdentifier: "", - RecordTTL: 300, - }, - { - DNSName: "lb-" + lbHash + ".example.com", - Targets: []string{ - "default.lb-" + lbHash + ".example.com", - }, - RecordType: "CNAME", - SetIdentifier: "default", - RecordTTL: 300, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "geo-code", - Value: "*", + Eventually(func() error { // DNS record exists + if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord); err != nil { + return err + } + if len(createdDNSRecord.Spec.Endpoints) != len(expectedEndpoints) { + return fmt.Errorf("expected %v endpoints in DNSRecord, got %v", len(expectedEndpoints), len(createdDNSRecord.Spec.Endpoints)) + } + return nil + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + Expect(createdDNSRecord.Spec.ManagedZoneRef.Name).To(Equal("example.com")) + Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) + Expect(createdDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) + }) + It("should create a wildcard dns record", func() { + wildcardDNSRecord := &v1alpha1.DNSRecord{} + expectedEndpoints := []*v1alpha1.Endpoint{ + { + DNSName: TestWildCardListenerHost, + Targets: []string{ + "lb-" + lbHash + ".example.com", }, + RecordType: "CNAME", + SetIdentifier: "", + RecordTTL: 300, }, - }, - { - DNSName: "s07c46.lb-" + lbHash + ".example.com", - Targets: []string{ - TestAttachedRouteAddressOne, - }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - { - DNSName: "default.lb-" + lbHash + ".example.com", - Targets: []string{ - "s07c46.lb-" + lbHash + ".example.com", - }, - RecordType: "CNAME", - SetIdentifier: "s07c46.lb-" + lbHash + ".example.com", - RecordTTL: 60, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", + { + DNSName: "lb-" + lbHash + ".example.com", + Targets: []string{ + "default.lb-" + lbHash + ".example.com", }, - }, - }, - { - DNSName: "2w705o.lb-" + lbHash + ".example.com", - Targets: []string{ - TestAttachedRouteAddressTwo, - }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - { - DNSName: "default.lb-" + lbHash + ".example.com", - Targets: []string{ - "2w705o.lb-" + lbHash + ".example.com", - }, - RecordType: "CNAME", - SetIdentifier: "2w705o.lb-" + lbHash + ".example.com", - RecordTTL: 60, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", + RecordType: "CNAME", + SetIdentifier: "default", + RecordTTL: 300, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "geo-code", + Value: "*", + }, + }, + }, + { + DNSName: "s07c46.lb-" + lbHash + ".example.com", + Targets: []string{ + TestAttachedRouteAddressOne, + }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, + }, + { + DNSName: "default.lb-" + lbHash + ".example.com", + Targets: []string{ + "s07c46.lb-" + lbHash + ".example.com", + }, + RecordType: "CNAME", + SetIdentifier: "s07c46.lb-" + lbHash + ".example.com", + RecordTTL: 60, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, + }, + }, + { + DNSName: "2w705o.lb-" + lbHash + ".example.com", + Targets: []string{ + TestAttachedRouteAddressTwo, + }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, + }, + { + DNSName: "default.lb-" + lbHash + ".example.com", + Targets: []string{ + "2w705o.lb-" + lbHash + ".example.com", + }, + RecordType: "CNAME", + SetIdentifier: "2w705o.lb-" + lbHash + ".example.com", + RecordTTL: 60, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, }, }, - }, - } - Eventually(func() error { // DNS record exists - if err := k8sClient.Get(ctx, client.ObjectKey{Name: wildcardDNSRecordName, Namespace: testNamespace}, wildcardDNSRecord); err != nil { - return err - } - if len(wildcardDNSRecord.Spec.Endpoints) != len(expectedEndpoints) { - return fmt.Errorf("expected %v wildcard endpoints in DNSRecord, got %v", len(expectedEndpoints), len(wildcardDNSRecord.Spec.Endpoints)) - } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - Expect(wildcardDNSRecord.Spec.ManagedZoneRef.Name).To(Equal("example.com")) - Expect(wildcardDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) - Expect(wildcardDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) - Expect(expectedEndpoints).Should(ContainElements(wildcardDNSRecord.Spec.Endpoints)) - }) - - It("should have correct status", func() { - Eventually(func() error { - if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy); err != nil { - return err - } - if !meta.IsStatusConditionTrue(dnsPolicy.Status.Conditions, string(conditions.ConditionTypeReady)) { - return fmt.Errorf("expected status condition %s to be True", conditions.ConditionTypeReady) - } - if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(gateway), gateway); err != nil { - return err - } - - policyAffectedCond := meta.FindStatusCondition(gateway.Status.Conditions, string(DNSPolicyAffected)) - if policyAffectedCond == nil { - return fmt.Errorf("policy affected conditon expected but not found") - } - if policyAffectedCond.ObservedGeneration != gateway.Generation { - return fmt.Errorf("expected policy affected cond generation to be %d but got %d", gateway.Generation, policyAffectedCond.ObservedGeneration) - } - if !meta.IsStatusConditionTrue(gateway.Status.Conditions, string(DNSPolicyAffected)) { - return fmt.Errorf("expected gateway status condition %s to be True", DNSPolicyAffected) } + Eventually(func() error { // DNS record exists + if err := k8sClient.Get(ctx, client.ObjectKey{Name: wildcardDNSRecordName, Namespace: testNamespace}, wildcardDNSRecord); err != nil { + return err + } + if len(wildcardDNSRecord.Spec.Endpoints) != len(expectedEndpoints) { + return fmt.Errorf("expected %v wildcard endpoints in DNSRecord, got %v", len(expectedEndpoints), len(wildcardDNSRecord.Spec.Endpoints)) + } + return nil + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + Expect(wildcardDNSRecord.Spec.ManagedZoneRef.Name).To(Equal("example.com")) + Expect(wildcardDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) + Expect(wildcardDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) + Expect(expectedEndpoints).Should(ContainElements(wildcardDNSRecord.Spec.Endpoints)) + }) - return nil - }, time.Second*15, time.Second).Should(BeNil()) - }) + It("should have correct status", func() { + Eventually(func() error { + if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy); err != nil { + return err + } + if !meta.IsStatusConditionTrue(dnsPolicy.Status.Conditions, string(conditions.ConditionTypeReady)) { + return fmt.Errorf("expected status condition %s to be True", conditions.ConditionTypeReady) + } + if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(gateway), gateway); err != nil { + return err + } - It("should set gateway back reference", func() { - existingGateway := &gatewayv1beta1.Gateway{} - policyBackRefValue := testNamespace + "/" + dnsPolicy.Name - refs, _ := json.Marshal([]client.ObjectKey{{Name: dnsPolicy.Name, Namespace: testNamespace}}) - policiesBackRefValue := string(refs) - - Eventually(func() map[string]string { - // Check gateway back references - err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) - // must exist - Expect(err).ToNot(HaveOccurred()) - return existingGateway.GetAnnotations() - }, time.Second*5, time.Second).Should(HaveKeyWithValue(DNSPolicyBackRefAnnotation, policyBackRefValue)) - Eventually(func() map[string]string { - // Check gateway back references - err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) - // must exist - Expect(err).ToNot(HaveOccurred()) - return existingGateway.GetAnnotations() - }, time.Second*5, time.Second).Should(HaveKeyWithValue(DNSPoliciesBackRefAnnotation, policiesBackRefValue)) - }) + policyAffectedCond := meta.FindStatusCondition(gateway.Status.Conditions, string(DNSPolicyAffected)) + if policyAffectedCond == nil { + return fmt.Errorf("policy affected conditon expected but not found") + } + if policyAffectedCond.ObservedGeneration != gateway.Generation { + return fmt.Errorf("expected policy affected cond generation to be %d but got %d", gateway.Generation, policyAffectedCond.ObservedGeneration) + } + if !meta.IsStatusConditionTrue(gateway.Status.Conditions, string(DNSPolicyAffected)) { + return fmt.Errorf("expected gateway status condition %s to be True", DNSPolicyAffected) + } - It("should remove dns records when listener removed", func() { - //get the gateway and remove the listeners + return nil + }, time.Second*15, time.Second).Should(BeNil()) + }) - Eventually(func() error { + It("should set gateway back reference", func() { existingGateway := &gatewayv1beta1.Gateway{} - if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(gateway), existingGateway); err != nil { - return err - } - newListeners := []gatewayv1beta1.Listener{} - for _, existing := range existingGateway.Spec.Listeners { - if existing.Name == TestWildCardListenerName { - newListeners = append(newListeners, existing) - } - } - - patch := client.MergeFrom(existingGateway.DeepCopy()) - existingGateway.Spec.Listeners = newListeners - rec := &v1alpha1.DNSRecord{} - if err := k8sClient.Patch(ctx, existingGateway, patch); err != nil { - return err - } - //dns record should be removed for non wildcard - if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, rec); err != nil && !k8serrors.IsNotFound(err) { - return err - } - return k8sClient.Get(ctx, client.ObjectKey{Name: wildcardDNSRecordName, Namespace: testNamespace}, rec) - }, time.Second*10, time.Second).Should(BeNil()) - }) + policyBackRefValue := testNamespace + "/" + dnsPolicy.Name + refs, _ := json.Marshal([]client.ObjectKey{{Name: dnsPolicy.Name, Namespace: testNamespace}}) + policiesBackRefValue := string(refs) + + Eventually(func() map[string]string { + // Check gateway back references + err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) + // must exist + Expect(err).ToNot(HaveOccurred()) + return existingGateway.GetAnnotations() + }, time.Second*5, time.Second).Should(HaveKeyWithValue(DNSPolicyBackRefAnnotation, policyBackRefValue)) + Eventually(func() map[string]string { + // Check gateway back references + err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) + // must exist + Expect(err).ToNot(HaveOccurred()) + return existingGateway.GetAnnotations() + }, time.Second*5, time.Second).Should(HaveKeyWithValue(DNSPoliciesBackRefAnnotation, policiesBackRefValue)) + }) - It("should remove gateway back reference on policy deletion", func() { - existingGateway := &gatewayv1beta1.Gateway{} - policyBackRefValue := testNamespace + "/" + dnsPolicy.Name - refs, _ := json.Marshal([]client.ObjectKey{{Name: dnsPolicy.Name, Namespace: testNamespace}}) - policiesBackRefValue := string(refs) - - Eventually(func() map[string]string { - // Check gateway back references - err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) - // must exist - Expect(err).ToNot(HaveOccurred()) - return existingGateway.GetAnnotations() - }, time.Second*5, time.Second).Should(HaveKeyWithValue(DNSPolicyBackRefAnnotation, policyBackRefValue)) - Eventually(func() map[string]string { - // Check gateway back references - err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) - // must exist - Expect(err).ToNot(HaveOccurred()) - return existingGateway.GetAnnotations() - }, time.Second*5, time.Second).Should(HaveKeyWithValue(DNSPoliciesBackRefAnnotation, policiesBackRefValue)) - - //finalizer should exist - Eventually(func() bool { - existingDNSPolicy := &v1alpha1.DNSPolicy{} - err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: testNamespace}, existingDNSPolicy) - // must exist - Expect(err).ToNot(HaveOccurred()) - return metadata.HasFinalizer(existingDNSPolicy, DNSPolicyFinalizer) - }, time.Second*5, time.Second).Should(BeTrue()) - - Expect(k8sClient.Delete(ctx, dnsPolicy)).To(BeNil()) - - Eventually(func() map[string]string { - // Check gateway back references - err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, existingGateway) - // must exist - Expect(err).ToNot(HaveOccurred()) - return existingGateway.GetAnnotations() - }, time.Second*5, time.Second).ShouldNot(HaveKey(DNSPolicyBackRefAnnotation)) - - Eventually(func() map[string]string { - // Check gateway back references - err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) - // must exist - Expect(err).ToNot(HaveOccurred()) - return existingGateway.GetAnnotations() - }, time.Second*5, time.Second).ShouldNot(HaveKeyWithValue(DNSPoliciesBackRefAnnotation, policiesBackRefValue)) - - Eventually(func() error { - // Check gateway back references - if err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway); err != nil { - return err - } - cond := meta.FindStatusCondition(existingGateway.Status.Conditions, string(DNSPolicyAffected)) - if cond != nil { - return fmt.Errorf("expected the condition %s to be gone", DNSPolicyAffected) - } - return nil - }, time.Second*5, time.Second).Should(BeNil()) - }) + It("should remove dns records when listener removed", func() { + //get the gateway and remove the listeners - It("should remove dns record reference on policy deletion even if gateway is removed", func() { - createdDNSRecord := &v1alpha1.DNSRecord{} - Eventually(func() error { // DNS record exists - if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord); err != nil { - return err - } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + Eventually(func() error { + existingGateway := &gatewayv1beta1.Gateway{} + if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(gateway), existingGateway); err != nil { + return err + } + newListeners := []gatewayv1beta1.Listener{} + for _, existing := range existingGateway.Spec.Listeners { + if existing.Name == TestWildCardListenerName { + newListeners = append(newListeners, existing) + } + } - err := k8sClient.Delete(ctx, gateway) - Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) + patch := client.MergeFrom(existingGateway.DeepCopy()) + existingGateway.Spec.Listeners = newListeners + rec := &v1alpha1.DNSRecord{} + if err := k8sClient.Patch(ctx, existingGateway, patch); err != nil { + return err + } + //dns record should be removed for non wildcard + if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, rec); err != nil && !k8serrors.IsNotFound(err) { + return err + } + return k8sClient.Get(ctx, client.ObjectKey{Name: wildcardDNSRecordName, Namespace: testNamespace}, rec) + }, time.Second*10, time.Second).Should(BeNil()) + }) - dnsPolicy = testBuildDNSPolicyWithHealthCheck("test-dns-policy", TestPlacedGatewayName, testNamespace, nil) - err = k8sClient.Delete(ctx, dnsPolicy) - Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) + It("should remove gateway back reference on policy deletion", func() { + existingGateway := &gatewayv1beta1.Gateway{} + policyBackRefValue := testNamespace + "/" + dnsPolicy.Name + refs, _ := json.Marshal([]client.ObjectKey{{Name: dnsPolicy.Name, Namespace: testNamespace}}) + policiesBackRefValue := string(refs) + + Eventually(func() map[string]string { + // Check gateway back references + err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) + // must exist + Expect(err).ToNot(HaveOccurred()) + return existingGateway.GetAnnotations() + }, time.Second*5, time.Second).Should(HaveKeyWithValue(DNSPolicyBackRefAnnotation, policyBackRefValue)) + Eventually(func() map[string]string { + // Check gateway back references + err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) + // must exist + Expect(err).ToNot(HaveOccurred()) + return existingGateway.GetAnnotations() + }, time.Second*5, time.Second).Should(HaveKeyWithValue(DNSPoliciesBackRefAnnotation, policiesBackRefValue)) + + //finalizer should exist + Eventually(func() bool { + existingDNSPolicy := &v1alpha1.DNSPolicy{} + err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: testNamespace}, existingDNSPolicy) + // must exist + Expect(err).ToNot(HaveOccurred()) + return metadata.HasFinalizer(existingDNSPolicy, DNSPolicyFinalizer) + }, time.Second*5, time.Second).Should(BeTrue()) + + Expect(k8sClient.Delete(ctx, dnsPolicy)).To(BeNil()) + + Eventually(func() map[string]string { + // Check gateway back references + err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, existingGateway) + // must exist + Expect(err).ToNot(HaveOccurred()) + return existingGateway.GetAnnotations() + }, time.Second*5, time.Second).ShouldNot(HaveKey(DNSPolicyBackRefAnnotation)) + + Eventually(func() map[string]string { + // Check gateway back references + err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) + // must exist + Expect(err).ToNot(HaveOccurred()) + return existingGateway.GetAnnotations() + }, time.Second*5, time.Second).ShouldNot(HaveKeyWithValue(DNSPoliciesBackRefAnnotation, policiesBackRefValue)) - Eventually(func() error { // DNS record removed - if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord); err != nil { - if k8serrors.IsNotFound(err) { - return nil + Eventually(func() error { + // Check gateway back references + if err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway); err != nil { + return err } - return err - } - return errors.New("found dnsrecord when it should be deleted") - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - }) - - }) + cond := meta.FindStatusCondition(existingGateway.Status.Conditions, string(DNSPolicyAffected)) + if cond != nil { + return fmt.Errorf("expected the condition %s to be gone", DNSPolicyAffected) + } + return nil + }, time.Second*5, time.Second).Should(BeNil()) + }) - Context("geo dnspolicy", func() { - var dnsPolicy *v1alpha1.DNSPolicy + It("should remove dns record reference on policy deletion even if gateway is removed", func() { + createdDNSRecord := &v1alpha1.DNSRecord{} + Eventually(func() error { // DNS record exists + if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord); err != nil { + return err + } + return nil + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - BeforeEach(func() { - dnsPolicy = testBuildDNSPolicyWithGeo("test-dns-policy", TestPlacedGatewayName, testNamespace) - Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil()) - Eventually(func() error { //dns policy exists - if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy); err != nil { - return err - } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - }) + err := k8sClient.Delete(ctx, gateway) + Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) - It("should create a dns record", func() { - createdDNSRecord := &v1alpha1.DNSRecord{} - expectedEndpoints := []*v1alpha1.Endpoint{ - { - DNSName: "2w705o.lb-" + lbHash + ".test.example.com", - Targets: []string{ - TestAttachedRouteAddressTwo, - }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - { - DNSName: "ie.lb-" + lbHash + ".test.example.com", - Targets: []string{ - "2w705o.lb-" + lbHash + ".test.example.com", - }, - RecordType: "CNAME", - SetIdentifier: "2w705o.lb-" + lbHash + ".test.example.com", - RecordTTL: 60, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", - }, - }, - }, - { - DNSName: "ie.lb-" + lbHash + ".test.example.com", - Targets: []string{ - "s07c46.lb-" + lbHash + ".test.example.com", - }, - RecordType: "CNAME", - SetIdentifier: "s07c46.lb-" + lbHash + ".test.example.com", - RecordTTL: 60, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", - }, - }, - }, - { - DNSName: "lb-" + lbHash + ".test.example.com", - Targets: []string{ - "ie.lb-" + lbHash + ".test.example.com", - }, - RecordType: "CNAME", - SetIdentifier: "IE", - RecordTTL: 300, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "geo-code", - Value: "IE", - }, - }, - }, - { - DNSName: "lb-" + lbHash + ".test.example.com", - Targets: []string{ - "ie.lb-" + lbHash + ".test.example.com", - }, - RecordType: "CNAME", - SetIdentifier: "default", - RecordTTL: 300, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "geo-code", - Value: "*", - }, - }, - }, - { - DNSName: "s07c46.lb-" + lbHash + ".test.example.com", - Targets: []string{ - TestAttachedRouteAddressOne, - }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - { - DNSName: "test.example.com", - Targets: []string{ - "lb-" + lbHash + ".test.example.com", - }, - RecordType: "CNAME", - SetIdentifier: "", - RecordTTL: 300, - }, - } - Eventually(func() error { // DNS record exists - if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: dnsPolicy.Namespace}, createdDNSRecord); err != nil { - return err - } - if len(createdDNSRecord.Spec.Endpoints) != len(expectedEndpoints) { - return fmt.Errorf("expected %v endpoints in DNSRecord, got %v", len(expectedEndpoints), len(createdDNSRecord.Spec.Endpoints)) - } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - Expect(createdDNSRecord.Spec.ManagedZoneRef.Name).To(Equal("example.com")) - Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) - Expect(createdDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) - Expect(expectedEndpoints).Should(ContainElements(createdDNSRecord.Spec.Endpoints)) + dnsPolicy = testBuildDNSPolicyLoadBalancedWeightedWithHealthCheck("test-dns-policy", TestPlacedGatewayName, testNamespace, nil) + err = k8sClient.Delete(ctx, dnsPolicy) + Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) - }) + Eventually(func() error { // DNS record removed + if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord); err != nil { + if k8serrors.IsNotFound(err) { + return nil + } + return err + } + return errors.New("found dnsrecord when it should be deleted") + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + }) - It("should create a wildcard dns record", func() { - wildcardDNSRecord := &v1alpha1.DNSRecord{} - expectedEndpoints := []*v1alpha1.Endpoint{ - { - DNSName: "*.example.com", - Targets: []string{ - "lb-" + lbHash + ".example.com", - }, - RecordType: "CNAME", - SetIdentifier: "", - RecordTTL: 300, - }, - { - DNSName: "2w705o.lb-" + lbHash + ".example.com", - Targets: []string{ - TestAttachedRouteAddressTwo, - }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - { - DNSName: "ie.lb-" + lbHash + ".example.com", - Targets: []string{ - "2w705o.lb-" + lbHash + ".example.com", - }, - RecordType: "CNAME", - SetIdentifier: "2w705o.lb-" + lbHash + ".example.com", - RecordTTL: 60, - Labels: nil, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", - }, - }, - }, - { - DNSName: "ie.lb-" + lbHash + ".example.com", - Targets: []string{ - "s07c46.lb-" + lbHash + ".example.com", - }, - RecordType: "CNAME", - SetIdentifier: "s07c46.lb-" + lbHash + ".example.com", - RecordTTL: 60, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", - }, - }, - }, - { - DNSName: "lb-" + lbHash + ".example.com", - Targets: []string{ - "ie.lb-" + lbHash + ".example.com", - }, - RecordType: "CNAME", - SetIdentifier: "IE", - RecordTTL: 300, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "geo-code", - Value: "IE", - }, - }, - }, - { - DNSName: "lb-" + lbHash + ".example.com", - Targets: []string{ - "ie.lb-" + lbHash + ".example.com", - }, - RecordType: "CNAME", - SetIdentifier: "default", - RecordTTL: 300, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "geo-code", - Value: "*", - }, - }, - }, - { - DNSName: "s07c46.lb-" + lbHash + ".example.com", - Targets: []string{ - TestAttachedRouteAddressOne, - }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - } - Eventually(func() error { // DNS record exists - if err := k8sClient.Get(ctx, client.ObjectKey{Name: wildcardDNSRecordName, Namespace: dnsPolicy.Namespace}, wildcardDNSRecord); err != nil { - return err - } - if len(wildcardDNSRecord.Spec.Endpoints) != len(expectedEndpoints) { - return fmt.Errorf("expected %v endpoints in DNSRecord, got %v", len(expectedEndpoints), len(wildcardDNSRecord.Spec.Endpoints)) - } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - Expect(wildcardDNSRecord.Spec.ManagedZoneRef.Name).To(Equal("example.com")) - Expect(wildcardDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) - Expect(wildcardDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) - Expect(expectedEndpoints).Should(ContainElements(wildcardDNSRecord.Spec.Endpoints)) - }) - }) - Context("probes status impact DNS records", func() { - var dnsPolicy *v1alpha1.DNSPolicy - var unhealthy bool - - BeforeEach(func() { - dnsPolicy = testBuildDNSPolicyWithHealthCheck("test-dns-policy", TestPlacedGatewayName, testNamespace, testutil.Pointer(4)) - Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil()) - Eventually(func() error { //dns policy exists - return k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy) - }, TestTimeoutMedium, TestRetryIntervalMedium).ShouldNot(HaveOccurred()) }) - It("should create a dns record", func() { - createdDNSRecord := &v1alpha1.DNSRecord{} - Eventually(func() error { // DNS record exists - if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord); err != nil { - return err - } - if len(createdDNSRecord.Spec.Endpoints) != 6 { - return fmt.Errorf("expected %v endpoints in DNSRecord, got %v", 6, len(createdDNSRecord.Spec.Endpoints)) - } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(6)) - }) - It("should have probes that are healthy", func() { - probeList := &v1alpha1.DNSHealthCheckProbeList{} - Eventually(func() error { - Expect(k8sClient.List(ctx, probeList, &client.ListOptions{Namespace: testNamespace})).To(BeNil()) - if len(probeList.Items) != 2 { - return fmt.Errorf("expected %v probes, got %v", 2, len(probeList.Items)) - } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - Expect(len(probeList.Items)).To(Equal(2)) - }) + Context("geo+weighted", func() { + var dnsPolicy *v1alpha1.DNSPolicy - Context("all unhealthy probes", func() { - It("should publish all dns records endpoints", func() { - lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) + BeforeEach(func() { + dnsPolicy = testBuildDNSPolicyLoadBalancedGeoWeighted("test-dns-policy", TestPlacedGatewayName, testNamespace) + Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil()) + Eventually(func() error { //dns policy exists + if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy); err != nil { + return err + } + return nil + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + }) + It("should create a dns record", func() { + createdDNSRecord := &v1alpha1.DNSRecord{} expectedEndpoints := []*v1alpha1.Endpoint{ { DNSName: "2w705o.lb-" + lbHash + ".test.example.com", @@ -1022,16 +827,7 @@ var _ = Describe("DNSPolicy", Ordered, func() { RecordTTL: 60, }, { - DNSName: "s07c46.lb-" + lbHash + ".test.example.com", - Targets: []string{ - TestAttachedRouteAddressOne, - }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - { - DNSName: "default.lb-" + lbHash + ".test.example.com", + DNSName: "ie.lb-" + lbHash + ".test.example.com", Targets: []string{ "2w705o.lb-" + lbHash + ".test.example.com", }, @@ -1046,14 +842,13 @@ var _ = Describe("DNSPolicy", Ordered, func() { }, }, { - DNSName: "default.lb-" + lbHash + ".test.example.com", + DNSName: "ie.lb-" + lbHash + ".test.example.com", Targets: []string{ "s07c46.lb-" + lbHash + ".test.example.com", }, RecordType: "CNAME", SetIdentifier: "s07c46.lb-" + lbHash + ".test.example.com", RecordTTL: 60, - Labels: nil, ProviderSpecific: v1alpha1.ProviderSpecific{ { Name: "weight", @@ -1064,7 +859,22 @@ var _ = Describe("DNSPolicy", Ordered, func() { { DNSName: "lb-" + lbHash + ".test.example.com", Targets: []string{ - "default.lb-" + lbHash + ".test.example.com", + "ie.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "IE", + RecordTTL: 300, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "geo-code", + Value: "IE", + }, + }, + }, + { + DNSName: "lb-" + lbHash + ".test.example.com", + Targets: []string{ + "ie.lb-" + lbHash + ".test.example.com", }, RecordType: "CNAME", SetIdentifier: "default", @@ -1076,6 +886,15 @@ var _ = Describe("DNSPolicy", Ordered, func() { }, }, }, + { + DNSName: "s07c46.lb-" + lbHash + ".test.example.com", + Targets: []string{ + TestAttachedRouteAddressOne, + }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, + }, { DNSName: "test.example.com", Targets: []string{ @@ -1086,87 +905,52 @@ var _ = Describe("DNSPolicy", Ordered, func() { RecordTTL: 300, }, } - - probeList := &v1alpha1.DNSHealthCheckProbeList{} - Eventually(func() error { - Expect(k8sClient.List(ctx, probeList, &client.ListOptions{Namespace: testNamespace})).To(BeNil()) - if len(probeList.Items) != 2 { - return fmt.Errorf("expected %v probes, got %v", 2, len(probeList.Items)) - } - return nil - }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) - - for _, probe := range probeList.Items { - Eventually(func() error { - if probe.Name == fmt.Sprintf("%s-%s-%s", TestAttachedRouteAddressTwo, TestPlacedGatewayName, TestAttachedRouteName) || - probe.Name == fmt.Sprintf("%s-%s-%s", TestAttachedRouteAddressOne, TestPlacedGatewayName, TestAttachedRouteName) { - getProbe := &v1alpha1.DNSHealthCheckProbe{} - if err := k8sClient.Get(ctx, client.ObjectKey{Name: probe.Name, Namespace: probe.Namespace}, getProbe); err != nil { - return err - } - patch := client.MergeFrom(getProbe.DeepCopy()) - unhealthy = false - getProbe.Status = v1alpha1.DNSHealthCheckProbeStatus{ - LastCheckedAt: metav1.NewTime(time.Now()), - ConsecutiveFailures: *getProbe.Spec.FailureThreshold + 1, - Healthy: &unhealthy, - } - if err := k8sClient.Status().Patch(ctx, getProbe, patch); err != nil { - return err - } - } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - } - createdDNSRecord := &v1alpha1.DNSRecord{} - Eventually(func() error { - - err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord) - if err != nil && k8serrors.IsNotFound(err) { + Eventually(func() error { // DNS record exists + if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: dnsPolicy.Namespace}, createdDNSRecord); err != nil { return err } if len(createdDNSRecord.Spec.Endpoints) != len(expectedEndpoints) { return fmt.Errorf("expected %v endpoints in DNSRecord, got %v", len(expectedEndpoints), len(createdDNSRecord.Spec.Endpoints)) } return nil - }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + Expect(createdDNSRecord.Spec.ManagedZoneRef.Name).To(Equal("example.com")) Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) Expect(createdDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) Expect(expectedEndpoints).Should(ContainElements(createdDNSRecord.Spec.Endpoints)) }) - }) - Context("some unhealthy probes", func() { - It("should publish expected endpoints", func() { - lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) + It("should create a wildcard dns record", func() { + wildcardDNSRecord := &v1alpha1.DNSRecord{} expectedEndpoints := []*v1alpha1.Endpoint{ { - DNSName: "2w705o.lb-" + lbHash + ".test.example.com", + DNSName: "*.example.com", Targets: []string{ - TestAttachedRouteAddressTwo, + "lb-" + lbHash + ".example.com", }, - RecordType: "A", + RecordType: "CNAME", SetIdentifier: "", - RecordTTL: 60, + RecordTTL: 300, }, { - DNSName: "s07c46.lb-" + lbHash + ".test.example.com", + DNSName: "2w705o.lb-" + lbHash + ".example.com", Targets: []string{ - TestAttachedRouteAddressOne, + TestAttachedRouteAddressTwo, }, RecordType: "A", SetIdentifier: "", RecordTTL: 60, }, { - DNSName: "default.lb-" + lbHash + ".test.example.com", + DNSName: "ie.lb-" + lbHash + ".example.com", Targets: []string{ - "2w705o.lb-" + lbHash + ".test.example.com", + "2w705o.lb-" + lbHash + ".example.com", }, RecordType: "CNAME", - SetIdentifier: "2w705o.lb-" + lbHash + ".test.example.com", + SetIdentifier: "2w705o.lb-" + lbHash + ".example.com", RecordTTL: 60, + Labels: nil, ProviderSpecific: v1alpha1.ProviderSpecific{ { Name: "weight", @@ -1175,14 +959,13 @@ var _ = Describe("DNSPolicy", Ordered, func() { }, }, { - DNSName: "default.lb-" + lbHash + ".test.example.com", + DNSName: "ie.lb-" + lbHash + ".example.com", Targets: []string{ - "s07c46.lb-" + lbHash + ".test.example.com", + "s07c46.lb-" + lbHash + ".example.com", }, RecordType: "CNAME", - SetIdentifier: "s07c46.lb-" + lbHash + ".test.example.com", + SetIdentifier: "s07c46.lb-" + lbHash + ".example.com", RecordTTL: 60, - Labels: nil, ProviderSpecific: v1alpha1.ProviderSpecific{ { Name: "weight", @@ -1191,9 +974,24 @@ var _ = Describe("DNSPolicy", Ordered, func() { }, }, { - DNSName: "lb-" + lbHash + ".test.example.com", + DNSName: "lb-" + lbHash + ".example.com", Targets: []string{ - "default.lb-" + lbHash + ".test.example.com", + "ie.lb-" + lbHash + ".example.com", + }, + RecordType: "CNAME", + SetIdentifier: "IE", + RecordTTL: 300, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "geo-code", + Value: "IE", + }, + }, + }, + { + DNSName: "lb-" + lbHash + ".example.com", + Targets: []string{ + "ie.lb-" + lbHash + ".example.com", }, RecordType: "CNAME", SetIdentifier: "default", @@ -1206,292 +1004,475 @@ var _ = Describe("DNSPolicy", Ordered, func() { }, }, { - DNSName: "test.example.com", + DNSName: "s07c46.lb-" + lbHash + ".example.com", Targets: []string{ - "lb-" + lbHash + ".test.example.com", + TestAttachedRouteAddressOne, }, - RecordType: "CNAME", + RecordType: "A", SetIdentifier: "", - RecordTTL: 300, + RecordTTL: 60, }, } - - probeList := &v1alpha1.DNSHealthCheckProbeList{} - Eventually(func() error { - Expect(k8sClient.List(ctx, probeList, &client.ListOptions{Namespace: testNamespace})).To(BeNil()) - if len(probeList.Items) != 2 { - return fmt.Errorf("expected %v probes, got %v", 2, len(probeList.Items)) + Eventually(func() error { // DNS record exists + if err := k8sClient.Get(ctx, client.ObjectKey{Name: wildcardDNSRecordName, Namespace: dnsPolicy.Namespace}, wildcardDNSRecord); err != nil { + return err + } + if len(wildcardDNSRecord.Spec.Endpoints) != len(expectedEndpoints) { + return fmt.Errorf("expected %v endpoints in DNSRecord, got %v", len(expectedEndpoints), len(wildcardDNSRecord.Spec.Endpoints)) } return nil - }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) - Expect(probeList.Items).To(HaveLen(2)) + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + Expect(wildcardDNSRecord.Spec.ManagedZoneRef.Name).To(Equal("example.com")) + Expect(wildcardDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) + Expect(wildcardDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) + Expect(expectedEndpoints).Should(ContainElements(wildcardDNSRecord.Spec.Endpoints)) + }) + }) - Eventually(func() error { - getProbe := &v1alpha1.DNSHealthCheckProbe{} - if err := k8sClient.Get(ctx, client.ObjectKey{Name: fmt.Sprintf("%s-%s-%s", TestAttachedRouteAddressOne, TestPlacedGatewayName, TestAttachedRouteName), Namespace: testNamespace}, getProbe); err != nil { + Context("with health checks", func() { + var dnsPolicy *v1alpha1.DNSPolicy + var unhealthy bool + + BeforeEach(func() { + dnsPolicy = testBuildDNSPolicyLoadBalancedWeightedWithHealthCheck("test-dns-policy", TestPlacedGatewayName, testNamespace, testutil.Pointer(4)) + Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil()) + Eventually(func() error { //dns policy exists + return k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy) + }, TestTimeoutMedium, TestRetryIntervalMedium).ShouldNot(HaveOccurred()) + }) + + It("should create a dns record", func() { + createdDNSRecord := &v1alpha1.DNSRecord{} + Eventually(func() error { // DNS record exists + if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord); err != nil { return err } - patch := client.MergeFrom(getProbe.DeepCopy()) - unhealthy = false - getProbe.Status = v1alpha1.DNSHealthCheckProbeStatus{ - LastCheckedAt: metav1.NewTime(time.Now()), - ConsecutiveFailures: *getProbe.Spec.FailureThreshold + 1, - Healthy: &unhealthy, - } - if err := k8sClient.Status().Patch(ctx, getProbe, patch); err != nil { - return err + if len(createdDNSRecord.Spec.Endpoints) != 6 { + return fmt.Errorf("expected %v endpoints in DNSRecord, got %v", 6, len(createdDNSRecord.Spec.Endpoints)) } return nil - }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) - - // after that verify that in time the endpoints are 5 in the dnsrecord - createdDNSRecord := &v1alpha1.DNSRecord{} + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(6)) + }) + It("should have probes that are healthy", func() { + probeList := &v1alpha1.DNSHealthCheckProbeList{} Eventually(func() error { - err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord) - if err != nil && k8serrors.IsNotFound(err) { - return err + Expect(k8sClient.List(ctx, probeList, &client.ListOptions{Namespace: testNamespace})).To(BeNil()) + if len(probeList.Items) != 2 { + return fmt.Errorf("expected %v probes, got %v", 2, len(probeList.Items)) } return nil }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) - Expect(createdDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) - Expect(expectedEndpoints).Should(ContainElements(createdDNSRecord.Spec.Endpoints)) + Expect(len(probeList.Items)).To(Equal(2)) }) - }) - Context("some unhealthy endpoints for other listener", func() { - It("should publish expected endpoints", func() { - lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) - expectedEndpoints := []*v1alpha1.Endpoint{ - { - DNSName: "2w705o.lb-" + lbHash + ".test.example.com", - Targets: []string{ - TestAttachedRouteAddressTwo, + Context("all unhealthy probes", func() { + It("should publish all dns records endpoints", func() { + lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) + + expectedEndpoints := []*v1alpha1.Endpoint{ + { + DNSName: "2w705o.lb-" + lbHash + ".test.example.com", + Targets: []string{ + TestAttachedRouteAddressTwo, + }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - { - DNSName: "s07c46.lb-" + lbHash + ".test.example.com", - Targets: []string{ - TestAttachedRouteAddressOne, + { + DNSName: "s07c46.lb-" + lbHash + ".test.example.com", + Targets: []string{ + TestAttachedRouteAddressOne, + }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, }, - RecordType: "A", - SetIdentifier: "", - RecordTTL: 60, - }, - { - DNSName: "default.lb-" + lbHash + ".test.example.com", - Targets: []string{ - "2w705o.lb-" + lbHash + ".test.example.com", + { + DNSName: "default.lb-" + lbHash + ".test.example.com", + Targets: []string{ + "2w705o.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "2w705o.lb-" + lbHash + ".test.example.com", + RecordTTL: 60, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, + }, }, - RecordType: "CNAME", - SetIdentifier: "2w705o.lb-" + lbHash + ".test.example.com", - RecordTTL: 60, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", + { + DNSName: "default.lb-" + lbHash + ".test.example.com", + Targets: []string{ + "s07c46.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "s07c46.lb-" + lbHash + ".test.example.com", + RecordTTL: 60, + Labels: nil, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, }, }, - }, - { - DNSName: "default.lb-" + lbHash + ".test.example.com", - Targets: []string{ - "s07c46.lb-" + lbHash + ".test.example.com", + { + DNSName: "lb-" + lbHash + ".test.example.com", + Targets: []string{ + "default.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "default", + RecordTTL: 300, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "geo-code", + Value: "*", + }, + }, }, - RecordType: "CNAME", - SetIdentifier: "s07c46.lb-" + lbHash + ".test.example.com", - RecordTTL: 60, - Labels: nil, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "weight", - Value: "120", + { + DNSName: "test.example.com", + Targets: []string{ + "lb-" + lbHash + ".test.example.com", }, + RecordType: "CNAME", + SetIdentifier: "", + RecordTTL: 300, }, - }, - { - DNSName: "lb-" + lbHash + ".test.example.com", - Targets: []string{ - "default.lb-" + lbHash + ".test.example.com", + } + + probeList := &v1alpha1.DNSHealthCheckProbeList{} + Eventually(func() error { + Expect(k8sClient.List(ctx, probeList, &client.ListOptions{Namespace: testNamespace})).To(BeNil()) + if len(probeList.Items) != 2 { + return fmt.Errorf("expected %v probes, got %v", 2, len(probeList.Items)) + } + return nil + }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) + + for _, probe := range probeList.Items { + Eventually(func() error { + if probe.Name == fmt.Sprintf("%s-%s-%s", TestAttachedRouteAddressTwo, TestPlacedGatewayName, TestAttachedRouteName) || + probe.Name == fmt.Sprintf("%s-%s-%s", TestAttachedRouteAddressOne, TestPlacedGatewayName, TestAttachedRouteName) { + getProbe := &v1alpha1.DNSHealthCheckProbe{} + if err := k8sClient.Get(ctx, client.ObjectKey{Name: probe.Name, Namespace: probe.Namespace}, getProbe); err != nil { + return err + } + patch := client.MergeFrom(getProbe.DeepCopy()) + unhealthy = false + getProbe.Status = v1alpha1.DNSHealthCheckProbeStatus{ + LastCheckedAt: metav1.NewTime(time.Now()), + ConsecutiveFailures: *getProbe.Spec.FailureThreshold + 1, + Healthy: &unhealthy, + } + if err := k8sClient.Status().Patch(ctx, getProbe, patch); err != nil { + return err + } + } + return nil + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + } + createdDNSRecord := &v1alpha1.DNSRecord{} + Eventually(func() error { + + err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord) + if err != nil && k8serrors.IsNotFound(err) { + return err + } + if len(createdDNSRecord.Spec.Endpoints) != len(expectedEndpoints) { + return fmt.Errorf("expected %v endpoints in DNSRecord, got %v", len(expectedEndpoints), len(createdDNSRecord.Spec.Endpoints)) + } + return nil + }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) + Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) + Expect(createdDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) + Expect(expectedEndpoints).Should(ContainElements(createdDNSRecord.Spec.Endpoints)) + + }) + }) + Context("some unhealthy probes", func() { + It("should publish expected endpoints", func() { + lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) + + expectedEndpoints := []*v1alpha1.Endpoint{ + { + DNSName: "2w705o.lb-" + lbHash + ".test.example.com", + Targets: []string{ + TestAttachedRouteAddressTwo, + }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, }, - RecordType: "CNAME", - SetIdentifier: "default", - RecordTTL: 300, - ProviderSpecific: v1alpha1.ProviderSpecific{ - { - Name: "geo-code", - Value: "*", + { + DNSName: "s07c46.lb-" + lbHash + ".test.example.com", + Targets: []string{ + TestAttachedRouteAddressOne, }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, }, - }, - { - DNSName: "test.example.com", - Targets: []string{ - "lb-" + lbHash + ".test.example.com", + { + DNSName: "default.lb-" + lbHash + ".test.example.com", + Targets: []string{ + "2w705o.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "2w705o.lb-" + lbHash + ".test.example.com", + RecordTTL: 60, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, + }, }, - RecordType: "CNAME", - SetIdentifier: "", - RecordTTL: 300, - }, - } + { + DNSName: "default.lb-" + lbHash + ".test.example.com", + Targets: []string{ + "s07c46.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "s07c46.lb-" + lbHash + ".test.example.com", + RecordTTL: 60, + Labels: nil, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, + }, + }, + { + DNSName: "lb-" + lbHash + ".test.example.com", + Targets: []string{ + "default.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "default", + RecordTTL: 300, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "geo-code", + Value: "*", + }, + }, + }, + { + DNSName: "test.example.com", + Targets: []string{ + "lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "", + RecordTTL: 300, + }, + } - err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway) - Expect(err).NotTo(HaveOccurred()) - Expect(gateway.Spec.Listeners).NotTo(BeNil()) - // add another listener, should result in 4 probes - typedHostname := gatewayv1beta1.Hostname(OtherAttachedRouteName) - otherListener := gatewayv1beta1.Listener{ - Name: gatewayv1beta1.SectionName(OtherAttachedRouteName), - Hostname: &typedHostname, - Port: gatewayv1beta1.PortNumber(80), - Protocol: gatewayv1beta1.HTTPProtocolType, - } + probeList := &v1alpha1.DNSHealthCheckProbeList{} + Eventually(func() error { + Expect(k8sClient.List(ctx, probeList, &client.ListOptions{Namespace: testNamespace})).To(BeNil()) + if len(probeList.Items) != 2 { + return fmt.Errorf("expected %v probes, got %v", 2, len(probeList.Items)) + } + return nil + }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) + Expect(probeList.Items).To(HaveLen(2)) - patch := client.MergeFrom(gateway.DeepCopy()) - gateway.Spec.Listeners = append(gateway.Spec.Listeners, otherListener) - Expect(k8sClient.Patch(ctx, gateway, patch)).To(BeNil()) + Eventually(func() error { + getProbe := &v1alpha1.DNSHealthCheckProbe{} + if err := k8sClient.Get(ctx, client.ObjectKey{Name: fmt.Sprintf("%s-%s-%s", TestAttachedRouteAddressOne, TestPlacedGatewayName, TestAttachedRouteName), Namespace: testNamespace}, getProbe); err != nil { + return err + } + patch := client.MergeFrom(getProbe.DeepCopy()) + unhealthy = false + getProbe.Status = v1alpha1.DNSHealthCheckProbeStatus{ + LastCheckedAt: metav1.NewTime(time.Now()), + ConsecutiveFailures: *getProbe.Spec.FailureThreshold + 1, + Healthy: &unhealthy, + } + if err := k8sClient.Status().Patch(ctx, getProbe, patch); err != nil { + return err + } + return nil + }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) - probeList := &v1alpha1.DNSHealthCheckProbeList{} - Eventually(func() error { - Expect(k8sClient.List(ctx, probeList, &client.ListOptions{Namespace: testNamespace})).To(BeNil()) - if len(probeList.Items) != 4 { - return fmt.Errorf("expected %v probes, got %v", 4, len(probeList.Items)) - } - return nil - }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) - Expect(len(probeList.Items)).To(Equal(4)) + // after that verify that in time the endpoints are 5 in the dnsrecord + createdDNSRecord := &v1alpha1.DNSRecord{} + Eventually(func() error { + err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord) + if err != nil && k8serrors.IsNotFound(err) { + return err + } + return nil + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) + Expect(createdDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) + Expect(expectedEndpoints).Should(ContainElements(createdDNSRecord.Spec.Endpoints)) + }) + }) + Context("some unhealthy endpoints for other listener", func() { + It("should publish expected endpoints", func() { + lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) - // - Eventually(func() error { - getProbe := &v1alpha1.DNSHealthCheckProbe{} - if err = k8sClient.Get(ctx, client.ObjectKey{Name: fmt.Sprintf("%s-%s-%s", TestAttachedRouteAddressOne, TestPlacedGatewayName, OtherAttachedRouteName), Namespace: testNamespace}, getProbe); err != nil { - return err - } - patch := client.MergeFrom(getProbe.DeepCopy()) - unhealthy = false - getProbe.Status = v1alpha1.DNSHealthCheckProbeStatus{ - LastCheckedAt: metav1.NewTime(time.Now()), - ConsecutiveFailures: *getProbe.Spec.FailureThreshold + 1, - Healthy: &unhealthy, - } - if err = k8sClient.Status().Patch(ctx, getProbe, patch); err != nil { - return err + expectedEndpoints := []*v1alpha1.Endpoint{ + { + DNSName: "2w705o.lb-" + lbHash + ".test.example.com", + Targets: []string{ + TestAttachedRouteAddressTwo, + }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, + }, + { + DNSName: "s07c46.lb-" + lbHash + ".test.example.com", + Targets: []string{ + TestAttachedRouteAddressOne, + }, + RecordType: "A", + SetIdentifier: "", + RecordTTL: 60, + }, + { + DNSName: "default.lb-" + lbHash + ".test.example.com", + Targets: []string{ + "2w705o.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "2w705o.lb-" + lbHash + ".test.example.com", + RecordTTL: 60, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, + }, + }, + { + DNSName: "default.lb-" + lbHash + ".test.example.com", + Targets: []string{ + "s07c46.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "s07c46.lb-" + lbHash + ".test.example.com", + RecordTTL: 60, + Labels: nil, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "weight", + Value: "120", + }, + }, + }, + { + DNSName: "lb-" + lbHash + ".test.example.com", + Targets: []string{ + "default.lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "default", + RecordTTL: 300, + ProviderSpecific: v1alpha1.ProviderSpecific{ + { + Name: "geo-code", + Value: "*", + }, + }, + }, + { + DNSName: "test.example.com", + Targets: []string{ + "lb-" + lbHash + ".test.example.com", + }, + RecordType: "CNAME", + SetIdentifier: "", + RecordTTL: 300, + }, } - return nil - }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) - // after that verify that in time the endpoints are 5 in the dnsrecord - createdDNSRecord := &v1alpha1.DNSRecord{} - Eventually(func() error { - err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord) - if err != nil && k8serrors.IsNotFound(err) { - return err + err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway) + Expect(err).NotTo(HaveOccurred()) + Expect(gateway.Spec.Listeners).NotTo(BeNil()) + // add another listener, should result in 4 probes + typedHostname := gatewayv1beta1.Hostname(OtherAttachedRouteName) + otherListener := gatewayv1beta1.Listener{ + Name: gatewayv1beta1.SectionName(OtherAttachedRouteName), + Hostname: &typedHostname, + Port: gatewayv1beta1.PortNumber(80), + Protocol: gatewayv1beta1.HTTPProtocolType, } - return nil - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) - Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) - Expect(createdDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) - Expect(expectedEndpoints).Should(ContainElements(createdDNSRecord.Spec.Endpoints)) - }) - }) - }) - }) - - Context("gateway not placed", func() { - var gateway *gatewayv1beta1.Gateway - var dnsPolicy *v1alpha1.DNSPolicy - testGatewayName := "test-not-placed-gateway" - BeforeEach(func() { - gateway = testBuildGateway(testGatewayName, testutil.DummyCRName, TestAttachedRouteName, testNamespace, "test-dns-policy") - dnsPolicy = testBuildDNSPolicyWithHealthCheck("test-dns-policy", testGatewayName, testNamespace, nil) + patch := client.MergeFrom(gateway.DeepCopy()) + gateway.Spec.Listeners = append(gateway.Spec.Listeners, otherListener) + Expect(k8sClient.Patch(ctx, gateway, patch)).To(BeNil()) - Expect(k8sClient.Create(ctx, gateway)).To(BeNil()) - Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil()) + probeList := &v1alpha1.DNSHealthCheckProbeList{} + Eventually(func() error { + Expect(k8sClient.List(ctx, probeList, &client.ListOptions{Namespace: testNamespace})).To(BeNil()) + if len(probeList.Items) != 4 { + return fmt.Errorf("expected %v probes, got %v", 4, len(probeList.Items)) + } + return nil + }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) + Expect(len(probeList.Items)).To(Equal(4)) - Eventually(func() error { - return k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy) - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + // + Eventually(func() error { + getProbe := &v1alpha1.DNSHealthCheckProbe{} + if err = k8sClient.Get(ctx, client.ObjectKey{Name: fmt.Sprintf("%s-%s-%s", TestAttachedRouteAddressOne, TestPlacedGatewayName, OtherAttachedRouteName), Namespace: testNamespace}, getProbe); err != nil { + return err + } + patch := client.MergeFrom(getProbe.DeepCopy()) + unhealthy = false + getProbe.Status = v1alpha1.DNSHealthCheckProbeStatus{ + LastCheckedAt: metav1.NewTime(time.Now()), + ConsecutiveFailures: *getProbe.Spec.FailureThreshold + 1, + Healthy: &unhealthy, + } + if err = k8sClient.Status().Patch(ctx, getProbe, patch); err != nil { + return err + } + return nil + }, TestTimeoutLong, TestRetryIntervalMedium).Should(BeNil()) - Eventually(func() error { //gateway exists - return k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway) - }, TestTimeoutMedium, TestRetryIntervalMedium).ShouldNot(HaveOccurred()) + // after that verify that in time the endpoints are 5 in the dnsrecord + createdDNSRecord := &v1alpha1.DNSRecord{} + Eventually(func() error { + err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord) + if err != nil && k8serrors.IsNotFound(err) { + return err + } + return nil + }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) + Expect(createdDNSRecord.Spec.Endpoints).To(HaveLen(len(expectedEndpoints))) + Expect(createdDNSRecord.Spec.Endpoints).Should(ContainElements(expectedEndpoints)) + Expect(expectedEndpoints).Should(ContainElements(createdDNSRecord.Spec.Endpoints)) + }) + }) + }) - Eventually(func() error { //dns policy exists - return k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy) - }, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeNil()) }) - AfterEach(func() { - err := k8sClient.Delete(ctx, gateway) - Expect(err).ToNot(HaveOccurred()) - }) + }) - It("should not create a dns record", func() { - Consistently(func() []v1alpha1.DNSRecord { // DNS record exists - dnsRecords := v1alpha1.DNSRecordList{} - err := k8sClient.List(ctx, &dnsRecords, client.InNamespace(dnsPolicy.GetNamespace())) - Expect(err).ToNot(HaveOccurred()) - return dnsRecords.Items - }, time.Second*15, time.Second).Should(BeEmpty()) - }) + Context("single cluster gateway status", func() { + //ToDo add single cluster tests here - It("should have ready status", func() { - Eventually(func() error { - if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsPolicy.Name, Namespace: dnsPolicy.Namespace}, dnsPolicy); err != nil { - return err - } - if !meta.IsStatusConditionTrue(dnsPolicy.Status.Conditions, string(conditions.ConditionTypeReady)) { - return fmt.Errorf("expected DNSPolicy status condition to be %s", string(conditions.ConditionTypeReady)) - } - return nil - }, time.Second*15, time.Second).Should(BeNil()) + Context("simple routing strategy", func() { + //ToDo Add simple routing strategy tests }) - It("should set gateway back reference", func() { - existingGateway := &gatewayv1beta1.Gateway{} - policyBackRefValue := testNamespace + "/" + dnsPolicy.Name - refs, _ := json.Marshal([]client.ObjectKey{{Name: dnsPolicy.Name, Namespace: testNamespace}}) - policiesBackRefValue := string(refs) - Eventually(func() error { - // Check gateway back references - err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) - if err != nil { - return err - } - annotations := existingGateway.GetAnnotations() - if annotations == nil { - return fmt.Errorf("existingGateway annotations should not be nil") - } - if _, ok := annotations[DNSPolicyBackRefAnnotation]; !ok { - return fmt.Errorf("existingGateway annotations do not have annotation %s", DNSPolicyBackRefAnnotation) - } - if annotations[DNSPolicyBackRefAnnotation] != policyBackRefValue { - return fmt.Errorf("existingGateway annotations[%s] does not have expected value", DNSPolicyBackRefAnnotation) - } - return nil - }, time.Second*5, time.Second).Should(BeNil()) - Eventually(func() error { - // Check gateway back references - err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: testNamespace}, existingGateway) - if err != nil { - return err - } - annotations := existingGateway.GetAnnotations() - if annotations == nil { - return fmt.Errorf("existingGateway annotations should not be nil") - } - if _, ok := annotations[DNSPoliciesBackRefAnnotation]; !ok { - return fmt.Errorf("existingGateway annotations do not have annotation %s", DNSPoliciesBackRefAnnotation) - } - if annotations[DNSPoliciesBackRefAnnotation] != policiesBackRefValue { - return fmt.Errorf("existingGateway annotations[%s] does not have expected value", DNSPoliciesBackRefAnnotation) - } - return nil - }, time.Second*5, time.Second).Should(BeNil()) + Context("loadbalanced routing strategy", func() { + //ToDo Add loadbalanced routing strategy tests }) + }) + }) diff --git a/test/policy_integration/tlspolicy_controller_test.go b/test/policy_integration/tlspolicy_controller_test.go index 243a99c11..65d888521 100644 --- a/test/policy_integration/tlspolicy_controller_test.go +++ b/test/policy_integration/tlspolicy_controller_test.go @@ -125,7 +125,7 @@ var _ = Describe("TLSPolicy", Ordered, func() { By("creating a valid Gateway") gateway = NewTestGateway("test-gateway", gwClassName, testNamespace). - WithHTTPListener("test.example.com").Gateway + WithHTTPListener("test-listener", "test.example.com").Gateway Expect(k8sClient.Create(ctx, gateway)).To(BeNil()) Eventually(func() error { //gateway exists return k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway) @@ -200,7 +200,7 @@ var _ = Describe("TLSPolicy", Ordered, func() { Context("valid target, issuer and policy", func() { BeforeEach(func() { gateway = NewTestGateway("test-gateway", gwClassName, testNamespace). - WithHTTPListener("test.example.com").Gateway + WithHTTPListener("test-listener", "test.example.com").Gateway Expect(k8sClient.Create(ctx, gateway)).To(BeNil()) Eventually(func() error { //gateway exists return k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway) @@ -293,7 +293,7 @@ var _ = Describe("TLSPolicy", Ordered, func() { BeforeEach(func() { gateway = NewTestGateway("test-gateway", gwClassName, testNamespace). - WithHTTPListener("test.example.com").Gateway + WithHTTPListener("test-listener", "test.example.com").Gateway Expect(k8sClient.Create(ctx, gateway)).To(BeNil()) Eventually(func() error { //gateway exists return k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway) @@ -329,7 +329,7 @@ var _ = Describe("TLSPolicy", Ordered, func() { BeforeEach(func() { gateway = NewTestGateway("test-gateway", gwClassName, testNamespace). - WithHTTPListener("test.example.com").Gateway + WithHTTPListener("test-listener", "test.example.com").Gateway Expect(k8sClient.Create(ctx, gateway)).To(BeNil()) Eventually(func() error { //gateway exists return k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway) diff --git a/test/util/test_dnspolicy_types.go b/test/util/test_dnspolicy_types.go new file mode 100644 index 000000000..623e309ab --- /dev/null +++ b/test/util/test_dnspolicy_types.go @@ -0,0 +1,105 @@ +//go:build unit || integration || e2e + +package testutil + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" + + "github.com/Kuadrant/multicluster-gateway-controller/pkg/apis/v1alpha1" +) + +type TestDNSPolicy struct { + *v1alpha1.DNSPolicy +} + +func NewTestDNSPolicy(name, ns string) *TestDNSPolicy { + return &TestDNSPolicy{ + &v1alpha1.DNSPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: ns, + }, + Spec: v1alpha1.DNSPolicySpec{}, + }, + } +} + +func (t *TestDNSPolicy) WithTargetRef(targetRef gatewayapiv1alpha2.PolicyTargetReference) *TestDNSPolicy { + t.Spec.TargetRef = targetRef + return t +} + +func (t *TestDNSPolicy) WithHealthCheck(healthCheck v1alpha1.HealthCheckSpec) *TestDNSPolicy { + t.Spec.HealthCheck = &healthCheck + return t +} + +func (t *TestDNSPolicy) WithLoadBalancing(loadBalancing v1alpha1.LoadBalancingSpec) *TestDNSPolicy { + t.Spec.LoadBalancing = &loadBalancing + return t +} + +func (t *TestDNSPolicy) WithRoutingStrategy(strategy v1alpha1.RoutingStrategy) *TestDNSPolicy { + t.Spec.RoutingStrategy = strategy + return t +} + +//TargetRef + +func (t *TestDNSPolicy) WithTargetGateway(gwName string) *TestDNSPolicy { + typedNamespace := gatewayv1beta1.Namespace(t.GetNamespace()) + return t.WithTargetRef(gatewayapiv1alpha2.PolicyTargetReference{ + Group: "gateway.networking.k8s.io", + Kind: "Gateway", + Name: gatewayv1beta1.ObjectName(gwName), + Namespace: &typedNamespace, + }) +} + +//HealthCheck + +func (t *TestDNSPolicy) WithHealthCheckFor(endpoint string, port *int, protocol v1alpha1.HealthProtocol, failureThreshold *int) *TestDNSPolicy { + return t.WithHealthCheck(v1alpha1.HealthCheckSpec{ + Endpoint: endpoint, + Port: port, + Protocol: &protocol, + FailureThreshold: failureThreshold, + AdditionalHeadersRef: nil, + ExpectedResponses: nil, + AllowInsecureCertificates: false, + Interval: nil, + }) +} + +//LoadBalancing + +func (t *TestDNSPolicy) WithLoadBalancingWeighted(lbWeighted v1alpha1.LoadBalancingWeighted) *TestDNSPolicy { + if t.Spec.LoadBalancing == nil { + t.Spec.LoadBalancing = &v1alpha1.LoadBalancingSpec{} + } + t.Spec.LoadBalancing.Weighted = &lbWeighted + return t +} + +func (t *TestDNSPolicy) WithLoadBalancingGeo(lbGeo v1alpha1.LoadBalancingGeo) *TestDNSPolicy { + if t.Spec.LoadBalancing == nil { + t.Spec.LoadBalancing = &v1alpha1.LoadBalancingSpec{} + } + t.Spec.LoadBalancing.Geo = &lbGeo + return t +} + +func (t *TestDNSPolicy) WithLoadBalancingWeightedFor(defaultWeight v1alpha1.Weight, custom []*v1alpha1.CustomWeight) *TestDNSPolicy { + return t.WithLoadBalancingWeighted(v1alpha1.LoadBalancingWeighted{ + DefaultWeight: defaultWeight, + Custom: custom, + }) +} + +func (t *TestDNSPolicy) WithLoadBalancingGeoFor(defaultGeo string) *TestDNSPolicy { + return t.WithLoadBalancingGeo(v1alpha1.LoadBalancingGeo{ + DefaultGeo: defaultGeo, + }) +} diff --git a/test/util/test_types.go b/test/util/test_types.go index 96134c7ec..cf40fc8c0 100644 --- a/test/util/test_types.go +++ b/test/util/test_types.go @@ -92,10 +92,10 @@ func (t *TestGateway) WithLabels(labels map[string]string) *TestGateway { return t } -func (t *TestGateway) WithHTTPListener(hostname string) *TestGateway { +func (t *TestGateway) WithHTTPListener(name, hostname string) *TestGateway { typedHostname := gatewayv1beta1.Hostname(hostname) t.WithListener(gatewayv1beta1.Listener{ - Name: gatewayv1beta1.SectionName(hostname), + Name: gatewayv1beta1.SectionName(name), Hostname: &typedHostname, Port: gatewayv1beta1.PortNumber(80), Protocol: gatewayv1beta1.HTTPProtocolType,