Skip to content

Commit 5e4eba8

Browse files
committed
Address flake with cluster object modified in e2e tests
1 parent 083fb58 commit 5e4eba8

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

test/e2e/shared/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type RuntimeEnvironment struct {
8989
func (c *E2EContext) DefaultControlPlaneWaiters() clusterctl.ControlPlaneWaiters {
9090
return clusterctl.ControlPlaneWaiters{
9191
WaitForControlPlaneInitialized: func(ctx context.Context, input clusterctl.ApplyCustomClusterTemplateAndWaitInput, result *clusterctl.ApplyCustomClusterTemplateAndWaitResult) {
92-
FixupWorkloadCluster(c, input.ClusterName, input.Namespace, true)
92+
FixupWorkloadCluster(c, input.ClusterName, input.Namespace)
9393

9494
result.ControlPlane = framework.DiscoveryAndWaitForControlPlaneInitialized(ctx, framework.DiscoveryAndWaitForControlPlaneInitializedInput{
9595
Lister: input.ClusterProxy.GetClient(),

test/e2e/shared/setup.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1313
addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1"
1414
"sigs.k8s.io/cluster-api/test/e2e"
15+
"sigs.k8s.io/cluster-api/test/framework"
1516
"sigs.k8s.io/controller-runtime/pkg/client"
1617

1718
. "github.com/onsi/gomega"
@@ -77,7 +78,7 @@ func FixupNamespace(e2eCtx *E2EContext, namespace string, enableCredentials bool
7778
}
7879

7980
// FixupWorkloadCluster patches the workload cluster object to install CNI.
80-
func FixupWorkloadCluster(e2eCtx *E2EContext, name string, namespace string, cni bool) {
81+
func FixupWorkloadCluster(e2eCtx *E2EContext, name string, namespace string) {
8182
clusterClient := e2eCtx.Environment.BootstrapClusterProxy.GetClient()
8283

8384
clusterName := types.NamespacedName{Name: name, Namespace: namespace}
@@ -86,16 +87,12 @@ func FixupWorkloadCluster(e2eCtx *E2EContext, name string, namespace string, cni
8687
e2e.Byf("Fetch workload cluster %v", clusterName)
8788
Expect(clusterClient.Get(context.TODO(), clusterName, cluster)).To(Succeed(), "Failed to retrieve workload cluster")
8889

89-
// Label cluster to match ClusterResourceSet that deploys the CNI
90-
if cni {
91-
e2e.Byf("Label workload cluster %v with cni=cni-resources", clusterName)
92-
93-
if cluster.Labels == nil {
94-
cluster.Labels = make(map[string]string, 1)
95-
}
96-
cluster.Labels["cni"] = "cni-resources"
97-
}
98-
9990
e2e.Byf("Patch workload cluster %v", clusterName)
100-
Expect(clusterClient.Update(context.TODO(), cluster)).To(Succeed(), "Failed to patch workload cluster with necessary labels and configs")
91+
framework.PatchClusterLabel(context.TODO(), framework.PatchClusterLabelInput{
92+
ClusterProxy: e2eCtx.Environment.BootstrapClusterProxy,
93+
Cluster: cluster,
94+
Labels: map[string]string{
95+
"cni": "cni-resources",
96+
},
97+
})
10198
}

0 commit comments

Comments
 (0)