From ec17e7611378ed970556ae92ae0a6b874ef9a31a Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Tue, 14 Nov 2023 21:28:50 +0000 Subject: [PATCH] e2e tests --- test/e2e/gateway_single_spoke_test.go | 40 +++++++++------------------ test/e2e/suite_test.go | 8 +++++- test/util/suite_config.go | 18 ++++++------ 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/test/e2e/gateway_single_spoke_test.go b/test/e2e/gateway_single_spoke_test.go index d098ccdd4..1b4ee487e 100644 --- a/test/e2e/gateway_single_spoke_test.go +++ b/test/e2e/gateway_single_spoke_test.go @@ -60,7 +60,7 @@ var _ = Describe("Gateway single target cluster", func() { Expect(err).ToNot(HaveOccurred()) By("creating a Gateway in the hub") - hostname = gatewayapi.Hostname(strings.Join([]string{testID, tconfig.ManagedZone()}, ".")) + hostname = gatewayapi.Hostname(strings.Join([]string{testID, managedZone.Spec.DomainName}, ".")) gw = NewGatewayBuilder(testID, GatewayClassName, tconfig.HubNamespace()).WithListener(gatewayapi.Listener{ Name: "https", Hostname: &hostname, @@ -238,26 +238,12 @@ var _ = Describe("Gateway single target cluster", func() { var dnsPolicy *mgcv1alpha1.DNSPolicy BeforeEach(func(ctx SpecContext) { - By("creating a DNSPolicy in the hub") - - dnsPolicy = &mgcv1alpha1.DNSPolicy{ - ObjectMeta: metav1.ObjectMeta{ - Name: testID, - Namespace: tconfig.HubNamespace(), - }, - Spec: mgcv1alpha1.DNSPolicySpec{ - TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ - Group: "gateway.networking.k8s.io", - Kind: "Gateway", - Name: gatewayapi.ObjectName(testID), - Namespace: Pointer(gatewayapi.Namespace(tconfig.HubNamespace())), - }, - RoutingStrategy: v1alpha1.LoadBalancedRoutingStrategy, - }, - } - err := tconfig.HubClient().Create(ctx, dnsPolicy) - Expect(err).ToNot(HaveOccurred()) + dnsPolicy := NewDNSPolicyBuilder(testID, tconfig.HubNamespace()). + WithProviderManagedZone(managedZone.Name). + WithTargetGateway(testID).WithRoutingStrategy(v1alpha1.LoadBalancedRoutingStrategy). + DNSPolicy + Expect(tconfig.HubClient().Create(ctx, dnsPolicy)).To(Succeed()) }) AfterEach(func(ctx SpecContext) { @@ -265,7 +251,7 @@ var _ = Describe("Gateway single target cluster", func() { Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: strings.Join([]string{testID, tconfig.ManagedZone()}, "."), + Name: strings.Join([]string{testID, managedZone.Spec.DomainName}, "."), Namespace: tconfig.HubNamespace(), }, } @@ -273,7 +259,7 @@ var _ = Describe("Gateway single target cluster", func() { Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) cert := &certmanv1.Certificate{ ObjectMeta: metav1.ObjectMeta{ - Name: strings.Join([]string{testID, tconfig.ManagedZone()}, "."), + Name: strings.Join([]string{testID, managedZone.Spec.DomainName}, "."), Namespace: tconfig.HubNamespace(), }, } @@ -311,7 +297,7 @@ var _ = Describe("Gateway single target cluster", func() { By("ensuring the authoritative nameserver resolves the hostname") // speed up things by using the authoritative nameserver - nameservers, err := net.LookupNS(tconfig.ManagedZone()) + nameservers, err := net.LookupNS(managedZone.Spec.DomainName) Expect(err).ToNot(HaveOccurred()) GinkgoWriter.Printf("[debug] authoritative nameserver used for DNS record resolution: %s\n", nameservers[0].Host) @@ -362,8 +348,8 @@ var _ = Describe("Gateway single target cluster", func() { if gw.Spec.Listeners == nil { gw.Spec.Listeners = []gatewayapi.Listener{} } - wildcardHostname = gatewayapi.Hostname(strings.Join([]string{"*", tconfig.ManagedZone()}, ".")) - secretName := gatewayapi.Hostname(strings.Join([]string{testID, tconfig.ManagedZone()}, ".")) + wildcardHostname = gatewayapi.Hostname(strings.Join([]string{"*", managedZone.Spec.DomainName}, ".")) + secretName := gatewayapi.Hostname(strings.Join([]string{testID, managedZone.Spec.DomainName}, ".")) AddListener("wildcard", wildcardHostname, gatewayapi.ObjectName(secretName), gw) err = tconfig.HubClient().Update(ctx, gw) Expect(err).ToNot(HaveOccurred()) @@ -422,7 +408,7 @@ var _ = Describe("Gateway single target cluster", func() { if gw.Spec.Listeners == nil { gw.Spec.Listeners = []gatewayapi.Listener{} } - otherHostname = gatewayapi.Hostname(strings.Join([]string{"other", tconfig.ManagedZone()}, ".")) + otherHostname = gatewayapi.Hostname(strings.Join([]string{"other", managedZone.Spec.DomainName}, ".")) AddListener("other", otherHostname, gatewayapi.ObjectName(otherHostname), gw) Eventually(func(g Gomega, ctx SpecContext) { err = tconfig.HubClient().Update(ctx, gw) @@ -471,7 +457,7 @@ var _ = Describe("Gateway single target cluster", func() { err := tconfig.HubClient().Delete(ctx, tlsPolicy, client.PropagationPolicy(metav1.DeletePropagationForeground)) Expect(err).ToNot(HaveOccurred()) - hostname = gatewayapi.Hostname(strings.Join([]string{testID, tconfig.ManagedZone()}, ".")) + hostname = gatewayapi.Hostname(strings.Join([]string{testID, managedZone.Spec.DomainName}, ".")) Eventually(func(g Gomega, ctx SpecContext) { secret := &corev1.Secret{} err = tconfig.HubClient().Get(ctx, client.ObjectKey{Name: string(hostname), Namespace: tconfig.HubNamespace()}, secret) diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index 6cd3feda2..97a42ec55 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -8,13 +8,18 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "sigs.k8s.io/controller-runtime/pkg/client" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" + "github.com/Kuadrant/multicluster-gateway-controller/pkg/apis/v1alpha1" . "github.com/Kuadrant/multicluster-gateway-controller/test/util" ) -var tconfig SuiteConfig +var ( + tconfig SuiteConfig + managedZone *v1alpha1.ManagedZone +) func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) @@ -31,6 +36,7 @@ var _ = BeforeSuite(func(ctx SpecContext) { err = tconfig.InstallPrerequisites(ctx) Expect(err).NotTo(HaveOccurred()) + Expect(tconfig.HubClient().Get(ctx, client.ObjectKey{Namespace: tconfig.HubNamespace(), Name: tconfig.ManagedZoneName()}, managedZone)).To(Succeed()) }) var _ = AfterSuite(func(ctx SpecContext) { diff --git a/test/util/suite_config.go b/test/util/suite_config.go index 3b8d1ce9c..01ac82cd9 100644 --- a/test/util/suite_config.go +++ b/test/util/suite_config.go @@ -35,7 +35,7 @@ const ( ClusterSetLabelValue = "true" // configuration environment variables - managedZoneEnvvar = "TEST_MANAGED_ZONE" + managedZoneNameEnvvar = "TEST_MANAGED_ZONE_NAME" hubNamespaceEnvvar = "TEST_HUB_NAMESPACE" hubKubeContextEnvvar = "TEST_HUB_KUBE_CONTEXT" spokeKubeContextPrefixEnvvar = "TEST_SPOKE_KUBE_CONTEXT_PREFIX" @@ -44,11 +44,11 @@ const ( ) type SuiteConfig struct { - cpClient client.Client - dpClients []client.Client - hubNamespace string - managedZone string - cleanupList []client.Object + cpClient client.Client + dpClients []client.Client + hubNamespace string + managedZoneName string + cleanupList []client.Object } func (cfg *SuiteConfig) Build() error { @@ -57,8 +57,8 @@ func (cfg *SuiteConfig) Build() error { if cfg.hubNamespace = os.Getenv(hubNamespaceEnvvar); cfg.hubNamespace == "" { return fmt.Errorf("env variable '%s' must be set", hubNamespaceEnvvar) } - if cfg.managedZone = os.Getenv(managedZoneEnvvar); cfg.managedZone == "" { - return fmt.Errorf("env variable '%s' must be set", managedZoneEnvvar) + if cfg.managedZoneName = os.Getenv(managedZoneNameEnvvar); cfg.managedZoneName == "" { + return fmt.Errorf("env variable '%s' must be set", managedZoneNameEnvvar) } var hubKubeContext string @@ -153,7 +153,7 @@ func (cfg *SuiteConfig) GenerateName() string { return namegenerator.NewNameGenerator(nBig.Int64()).Generate() } -func (cfg *SuiteConfig) ManagedZone() string { return cfg.managedZone } +func (cfg *SuiteConfig) ManagedZoneName() string { return cfg.managedZoneName } func (cfg *SuiteConfig) HubNamespace() string { return cfg.hubNamespace }