diff --git a/test/e2e/framework/workload_manager.go b/test/e2e/framework/workload_manager.go index 96211ac0..156ea732 100644 --- a/test/e2e/framework/workload_manager.go +++ b/test/e2e/framework/workload_manager.go @@ -203,7 +203,7 @@ func (wm *WorkloadManager) DeployWorkload(ctx context.Context) error { } // AddServiceDNSLabel adds a DNS label to the service in member cluster. -func (wm *WorkloadManager) AddServiceDNSLabel(ctx context.Context, cluster *Cluster) error { +func (wm *WorkloadManager) AddServiceDNSLabel(ctx context.Context, cluster *Cluster, dns string) error { var service corev1.Service if err := cluster.kubeClient.Get(ctx, types.NamespacedName{Namespace: wm.namespace, Name: wm.service.Name}, &service); err != nil { return fmt.Errorf("failed to get service %s in cluster %s: %w", wm.service.Name, cluster.Name(), err) @@ -211,7 +211,7 @@ func (wm *WorkloadManager) AddServiceDNSLabel(ctx context.Context, cluster *Clus if service.Annotations == nil { service.Annotations = make(map[string]string) } - service.Annotations[objectmeta.ServiceAnnotationAzureDNSLabelName] = wm.BuildServiceDNSLabelName(cluster) + service.Annotations[objectmeta.ServiceAnnotationAzureDNSLabelName] = dns if err := cluster.kubeClient.Update(ctx, &service); err != nil { return fmt.Errorf("failed to update service %s in cluster %s: %w", service.Name, cluster.Name(), err) } @@ -220,7 +220,7 @@ func (wm *WorkloadManager) AddServiceDNSLabel(ctx context.Context, cluster *Clus // BuildServiceDNSLabelName builds the DNS label name for the service. func (wm *WorkloadManager) BuildServiceDNSLabelName(cluster *Cluster) string { - return fmt.Sprintf("%s-%s-%s", wm.namespace, wm.service.Name, cluster.Name()) + return fmt.Sprintf("%s-%s-%s-%s", wm.namespace, wm.service.Name, cluster.Name(), uniquename.RandomLowerCaseAlphabeticString(5)) } // UpdateServiceType updates the service type in the member cluster. diff --git a/test/e2e/traffic_manager_test.go b/test/e2e/traffic_manager_test.go index 8930d4b4..2fce0920 100644 --- a/test/e2e/traffic_manager_test.go +++ b/test/e2e/traffic_manager_test.go @@ -100,7 +100,7 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu By("Validating the Azure traffic manager profile") atmProfile = buildDesiredATMProfile(profile, nil) - // Controller does not set the trafficViewEnrollmentStatus. + // The Controller does not set the trafficViewEnrollmentStatus. atmProfile.Properties.TrafficViewEnrollmentStatus = ptr.To(armtrafficmanager.TrafficViewEnrollmentStatusEnabled) atmValidator.ValidateProfile(ctx, atmProfileName, atmProfile) }) @@ -109,6 +109,8 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu Context("Test invalid trafficManagerBackend (invalid serviceImport)", Ordered, func() { var backend fleetnetv1alpha1.TrafficManagerBackend var name types.NamespacedName + var membersDNSLabel []string + BeforeAll(func() { By("Creating trafficManagerBackend") backend = wm.TrafficManagerBackend() @@ -146,8 +148,8 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu By("Validating the trafficManagerBackend status") wantEndpoints := []fleetnetv1alpha1.TrafficManagerEndpointStatus{ { - Weight: ptr.To(int64(100)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[0]), clusterLocation)), + Weight: ptr.To(int64(100)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, membersDNSLabel[0], clusterLocation)), From: &fleetnetv1alpha1.FromCluster{ ClusterStatus: fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[0].Name()}, }, @@ -161,22 +163,23 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu atmValidator.ValidateProfile(ctx, atmProfileName, atmProfile) By("Adding DNS label to the service on member-2") + membersDNSLabel[1] = wm.BuildServiceDNSLabelName(memberClusters[1]) Eventually(func() error { - return wm.AddServiceDNSLabel(ctx, memberClusters[1]) + return wm.AddServiceDNSLabel(ctx, memberClusters[1], membersDNSLabel[1]) }, framework.PollTimeout, framework.PollInterval).Should(Succeed(), "Failed to add DNS label to the service") By("Validating the trafficManagerBackend status") wantEndpoints = []fleetnetv1alpha1.TrafficManagerEndpointStatus{ { - Weight: ptr.To(int64(50)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[0]), clusterLocation)), + Weight: ptr.To(int64(50)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, membersDNSLabel[0], clusterLocation)), From: &fleetnetv1alpha1.FromCluster{ ClusterStatus: fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[0].Name()}, }, }, { - Weight: ptr.To(int64(50)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[1]), clusterLocation)), + Weight: ptr.To(int64(50)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, membersDNSLabel[1], clusterLocation)), From: &fleetnetv1alpha1.FromCluster{ ClusterStatus: fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[1].Name()}, }, @@ -194,12 +197,14 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu Context("Test invalid trafficManagerBackend (invalid profile)", Ordered, func() { var backend fleetnetv1alpha1.TrafficManagerBackend var backendName types.NamespacedName + var memberDNSLabels []string BeforeEach(func() { // create valid serviceImport By("Adding DNS label to the service on member-1 & member-2") for i := range memberClusters { + memberDNSLabels[i] = wm.BuildServiceDNSLabelName(memberClusters[i]) Eventually(func() error { - return wm.AddServiceDNSLabel(ctx, memberClusters[i]) + return wm.AddServiceDNSLabel(ctx, memberClusters[i], memberDNSLabels[i]) }, framework.PollTimeout, framework.PollInterval).Should(Succeed(), "Failed to add DNS label to the service") } @@ -238,12 +243,12 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu wantEndpoints := []fleetnetv1alpha1.TrafficManagerEndpointStatus{ { Weight: ptr.To(int64(50)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[0]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[0], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[0].Name()}, }, { Weight: ptr.To(int64(50)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[1]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[1], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[1].Name()}, }, } @@ -280,14 +285,16 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu Context("Test valid trafficManagerBackend", Ordered, func() { var backend fleetnetv1alpha1.TrafficManagerBackend var backendName types.NamespacedName + var memberDNSLabels []string var extraTrafficManagerEndpoint *armtrafficmanager.Endpoint BeforeEach(func() { // create valid serviceImport By("Adding DNS label to the service on member-1 & member-2") for i := range memberClusters { + memberDNSLabels[i] = wm.BuildServiceDNSLabelName(memberClusters[i]) Eventually(func() error { - return wm.AddServiceDNSLabel(ctx, memberClusters[i]) + return wm.AddServiceDNSLabel(ctx, memberClusters[i], memberDNSLabels[i]) }, framework.PollTimeout, framework.PollInterval).Should(Succeed(), "Failed to add DNS label to the service") } @@ -303,12 +310,12 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu wantEndpoints := []fleetnetv1alpha1.TrafficManagerEndpointStatus{ { Weight: ptr.To(int64(50)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[0]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[0], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[0].Name()}, }, { Weight: ptr.To(int64(50)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[1]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[1], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[1].Name()}, }, } @@ -383,12 +390,12 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu wantEndpoints := []fleetnetv1alpha1.TrafficManagerEndpointStatus{ { Weight: ptr.To(int64(5)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[0]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[0], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[0].Name()}, }, { Weight: ptr.To(int64(5)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[1]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[1], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[1].Name()}, }, } @@ -432,12 +439,12 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu wantEndpoints := []fleetnetv1alpha1.TrafficManagerEndpointStatus{ { Weight: ptr.To(int64(5)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[0]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[0], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[0].Name()}, }, { Weight: ptr.To(int64(5)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[1]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[1], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[1].Name()}, }, } @@ -469,12 +476,12 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu wantEndpoints := []fleetnetv1alpha1.TrafficManagerEndpointStatus{ { Weight: ptr.To(int64(5)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[0]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[0], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[0].Name()}, }, { Weight: ptr.To(int64(5)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[1]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[1], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[1].Name()}, }, } @@ -497,7 +504,7 @@ var _ = Describe("Test exporting service via Azure traffic manager", Ordered, fu wantEndpoints := []fleetnetv1alpha1.TrafficManagerEndpointStatus{ { Weight: ptr.To(int64(100)), - Target: ptr.To(fmt.Sprintf(azureDNSFormat, wm.BuildServiceDNSLabelName(memberClusters[1]), clusterLocation)), + Target: ptr.To(fmt.Sprintf(azureDNSFormat, memberDNSLabels[1], clusterLocation)), Cluster: &fleetnetv1alpha1.ClusterStatus{Cluster: memberClusters[1].Name()}, }, }