Skip to content

Commit

Permalink
fix flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiying-lin committed Jan 6, 2025
1 parent 956689a commit 030b015
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
6 changes: 3 additions & 3 deletions test/e2e/framework/workload_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ 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)
}
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)
}
Expand All @@ -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.
Expand Down
49 changes: 28 additions & 21 deletions test/e2e/traffic_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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()
Expand Down Expand Up @@ -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()},
},
Expand All @@ -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()},
},
Expand All @@ -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")
}

Expand Down Expand Up @@ -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()},
},
}
Expand Down Expand Up @@ -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")
}

Expand All @@ -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()},
},
}
Expand Down Expand Up @@ -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()},
},
}
Expand Down Expand Up @@ -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()},
},
}
Expand Down Expand Up @@ -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()},
},
}
Expand All @@ -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()},
},
}
Expand Down

0 comments on commit 030b015

Please sign in to comment.