Skip to content

Commit bbb380e

Browse files
author
Arvind Thirumurugan
committed
fix E2E
1 parent 65eb45b commit bbb380e

File tree

4 files changed

+83
-44
lines changed

4 files changed

+83
-44
lines changed

test/e2e/placement_eviction_test.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ import (
1717
placementv1alpha1 "go.goms.io/fleet/apis/placement/v1alpha1"
1818
placementv1beta1 "go.goms.io/fleet/apis/placement/v1beta1"
1919
"go.goms.io/fleet/pkg/utils/condition"
20-
"go.goms.io/fleet/test/e2e/framework"
2120
testutilseviction "go.goms.io/fleet/test/utils/eviction"
2221
)
2322

2423
var _ = Describe("ClusterResourcePlacement eviction of bound binding, taint cluster before eviction - No PDB specified", Ordered, Serial, func() {
2524
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
2625
crpEvictionName := fmt.Sprintf(crpEvictionNameTemplate, GinkgoParallelProcess())
27-
taintClusterNames := []string{memberCluster1EastProdName}
26+
var taintClusterNames, noTaintClusterNames []string
2827

2928
BeforeAll(func() {
29+
taintClusterNames = []string{memberCluster1EastProdName}
30+
noTaintClusterNames = buildClusterNamesWithoutTaints(taintClusterNames)
31+
3032
By("creating work resources")
3133
createWorkResources()
3234

@@ -74,22 +76,20 @@ var _ = Describe("ClusterResourcePlacement eviction of bound binding, taint clus
7476
})
7577

7678
It("should ensure no resources exist on evicted member cluster with taint", func() {
77-
unSelectedClusters := []*framework.Cluster{memberCluster1EastProd}
78-
for _, cluster := range unSelectedClusters {
79+
taintClusters := buildClustersFromNames(taintClusterNames)
80+
for _, cluster := range taintClusters {
7981
resourceRemovedActual := workNamespaceRemovedFromClusterActual(cluster)
8082
Eventually(resourceRemovedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to check if resources doesn't exist on member cluster")
8183
}
8284
})
8385

8486
It("should update cluster resource placement status as expected", func() {
85-
// allMemberClusterNames - taintClusterNames
86-
noTaintClusterNames := []string{memberCluster2EastCanaryName, memberCluster3WestProdName}
8787
crpStatusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), noTaintClusterNames, nil, "0")
8888
Eventually(crpStatusUpdatedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update cluster resource placement status as expected")
8989
})
9090

9191
It("should place resources on the selected clusters with no taint", func() {
92-
noTaintClusters := []*framework.Cluster{memberCluster2EastCanary, memberCluster3WestProd}
92+
noTaintClusters := buildClustersFromNames(noTaintClusterNames)
9393
for _, cluster := range noTaintClusters {
9494
resourcePlacedActual := workNamespaceAndConfigMapPlacedOnClusterActual(cluster)
9595
Eventually(resourcePlacedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place resources on the selected clusters")
@@ -222,9 +222,12 @@ var _ = Describe("ClusterResourcePlacement eviction of bound binding - PickAll C
222222
var _ = Describe("ClusterResourcePlacement eviction of bound binding - PickAll CRP, PDB specified to protect resources in all but one cluster, eviction allowed", Ordered, Serial, func() {
223223
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
224224
crpEvictionName := fmt.Sprintf(crpEvictionNameTemplate, GinkgoParallelProcess())
225-
taintClusterNames := []string{memberCluster1EastProdName}
225+
var taintClusterNames, noTaintClusterNames []string
226226

227227
BeforeAll(func() {
228+
taintClusterNames = []string{memberCluster1EastProdName}
229+
noTaintClusterNames = buildClusterNamesWithoutTaints(taintClusterNames)
230+
228231
By("creating work resources")
229232
createWorkResources()
230233

@@ -287,22 +290,20 @@ var _ = Describe("ClusterResourcePlacement eviction of bound binding - PickAll C
287290
})
288291

289292
It("should ensure no resources exist on evicted member cluster with taint", func() {
290-
unSelectedClusters := []*framework.Cluster{memberCluster1EastProd}
291-
for _, cluster := range unSelectedClusters {
293+
taintClusters := buildClustersFromNames(taintClusterNames)
294+
for _, cluster := range taintClusters {
292295
resourceRemovedActual := workNamespaceRemovedFromClusterActual(cluster)
293296
Eventually(resourceRemovedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to check if resources doesn't exist on member cluster")
294297
}
295298
})
296299

297300
It("should update cluster resource placement status as expected", func() {
298-
// allMemberClusterNames - taintClusterNames
299-
noTaintClusterNames := []string{memberCluster2EastCanaryName, memberCluster3WestProdName}
300301
crpStatusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), noTaintClusterNames, nil, "0")
301302
Eventually(crpStatusUpdatedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update cluster resource placement status as expected")
302303
})
303304

304305
It("should place resources on the selected clusters with no taint", func() {
305-
noTaintClusters := []*framework.Cluster{memberCluster2EastCanary, memberCluster3WestProd}
306+
noTaintClusters := buildClustersFromNames(noTaintClusterNames)
306307
for _, cluster := range noTaintClusters {
307308
resourcePlacedActual := workNamespaceAndConfigMapPlacedOnClusterActual(cluster)
308309
Eventually(resourcePlacedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place resources on the selected clusters")
@@ -397,9 +398,12 @@ var _ = Describe("ClusterResourcePlacement eviction of bound binding - PickN CRP
397398
var _ = Describe("ClusterResourcePlacement eviction of bound binding - PickN CRP, PDB with MaxUnavailable specified as percentage to protect all clusters but one, eviction allowed", Ordered, Serial, func() {
398399
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
399400
crpEvictionName := fmt.Sprintf(crpEvictionNameTemplate, GinkgoParallelProcess())
400-
taintClusterNames := []string{memberCluster1EastProdName}
401+
var taintClusterNames, noTaintClusterNames []string
401402

402403
BeforeAll(func() {
404+
taintClusterNames = []string{memberCluster1EastProdName}
405+
noTaintClusterNames = buildClusterNamesWithoutTaints(taintClusterNames)
406+
403407
By("creating work resources")
404408
createWorkResources()
405409

@@ -477,22 +481,20 @@ var _ = Describe("ClusterResourcePlacement eviction of bound binding - PickN CRP
477481
})
478482

479483
It("should ensure no resources exist on evicted member cluster with taint", func() {
480-
unSelectedClusters := []*framework.Cluster{memberCluster1EastProd}
481-
for _, cluster := range unSelectedClusters {
484+
taintClusters := buildClustersFromNames(taintClusterNames)
485+
for _, cluster := range taintClusters {
482486
resourceRemovedActual := workNamespaceRemovedFromClusterActual(cluster)
483487
Eventually(resourceRemovedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to check if resources doesn't exist on member cluster")
484488
}
485489
})
486490

487491
It("should update cluster resource placement status as expected", func() {
488-
// allMemberClusterNames - taintClusterNames
489-
noTaintClusterNames := []string{memberCluster2EastCanaryName, memberCluster3WestProdName}
490-
crpStatusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), noTaintClusterNames, nil, "0")
492+
crpStatusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), noTaintClusterNames, taintClusterNames, "0")
491493
Eventually(crpStatusUpdatedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update cluster resource placement status as expected")
492494
})
493495

494496
It("should place resources on the selected clusters with no taint", func() {
495-
noTaintClusters := []*framework.Cluster{memberCluster2EastCanary, memberCluster3WestProd}
497+
noTaintClusters := buildClustersFromNames(noTaintClusterNames)
496498
for _, cluster := range noTaintClusters {
497499
resourcePlacedActual := workNamespaceAndConfigMapPlacedOnClusterActual(cluster)
498500
Eventually(resourcePlacedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place resources on the selected clusters")

test/e2e/setup_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ var (
9595

9696
allMemberClusters []*framework.Cluster
9797
allMemberClusterNames = []string{}
98+
allMemberClustersMap = map[string]*framework.Cluster{}
9899
)
99100

100101
var (
@@ -308,8 +309,9 @@ func beforeSuiteForAllProcesses() {
308309
once.Do(func() {
309310
// Set these arrays only once; this is necessary as for the first spawned Ginkgo process,
310311
// the `beforeSuiteForAllProcesses` function is called twice.
311-
for _, cluster := range allMemberClusters {
312-
allMemberClusterNames = append(allMemberClusterNames, cluster.ClusterName)
312+
for i := range allMemberClusters {
313+
allMemberClusterNames = append(allMemberClusterNames, allMemberClusters[i].ClusterName)
314+
allMemberClustersMap[allMemberClusters[i].ClusterName] = allMemberClusters[i]
313315
}
314316
})
315317
}

test/e2e/taint_toleration_test.go

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"k8s.io/utils/ptr"
1515

1616
placementv1beta1 "go.goms.io/fleet/apis/placement/v1beta1"
17-
"go.goms.io/fleet/test/e2e/framework"
1817
)
1918

2019
var _ = Describe("placing resource using a cluster resource placement with pickFixed placement policy specified, taint clusters, pick all specified clusters", Serial, Ordered, func() {
@@ -61,10 +60,12 @@ var _ = Describe("placing resource using a cluster resource placement with pickF
6160

6261
var _ = Describe("placing resources using a cluster resource placement with no placement policy specified, taint clusters, update cluster resource placement with tolerations", Serial, Ordered, func() {
6362
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
64-
taintClusterNames := []string{memberCluster1EastProdName, memberCluster2EastCanaryName}
65-
selectedClusterNames := []string{memberCluster3WestProdName}
63+
var taintClusterNames, noTaintClusterNames []string
6664

6765
BeforeAll(func() {
66+
taintClusterNames = []string{memberCluster1EastProdName, memberCluster2EastCanaryName}
67+
noTaintClusterNames = buildClusterNamesWithoutTaints(taintClusterNames)
68+
6869
// Create the resources.
6970
createWorkResources()
7071
// Add taint to member clusters 1, 2.
@@ -92,21 +93,24 @@ var _ = Describe("placing resources using a cluster resource placement with no p
9293
})
9394

9495
It("should update cluster resource placement status as expected", func() {
95-
crpStatusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), selectedClusterNames, nil, "0")
96+
crpStatusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), noTaintClusterNames, nil, "0")
9697
Eventually(crpStatusUpdatedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update cluster resource placement status as expected")
9798
})
9899

99100
It("should ensure no resources exist on member clusters with taint", func() {
100-
unSelectedClusters := []*framework.Cluster{memberCluster1EastProd, memberCluster2EastCanary}
101-
for _, cluster := range unSelectedClusters {
101+
taintClusters := buildClustersFromNames(taintClusterNames)
102+
for _, cluster := range taintClusters {
102103
resourceRemovedActual := workNamespaceRemovedFromClusterActual(cluster)
103104
Eventually(resourceRemovedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to check if resources doesn't exist on member cluster")
104105
}
105106
})
106107

107108
It("should place resources on the selected cluster without taint", func() {
108-
resourcePlacedActual := workNamespaceAndConfigMapPlacedOnClusterActual(memberCluster3WestProd)
109-
Eventually(resourcePlacedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place resources on selected cluster")
109+
noTaintClusters := buildClustersFromNames(noTaintClusterNames)
110+
for _, cluster := range noTaintClusters {
111+
resourcePlacedActual := workNamespaceAndConfigMapPlacedOnClusterActual(cluster)
112+
Eventually(resourcePlacedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place resources on selected cluster")
113+
}
110114
})
111115

112116
It("should update cluster resource placement spec with tolerations for tainted cluster", func() {
@@ -130,10 +134,12 @@ var _ = Describe("placing resources using a cluster resource placement with no p
130134

131135
var _ = Describe("placing resources using a cluster resource placement with no placement policy specified, taint clusters, remove taints from cluster, all cluster should be picked", Serial, Ordered, func() {
132136
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
133-
taintClusterNames := []string{memberCluster1EastProdName, memberCluster2EastCanaryName}
134-
selectedClusterNames := []string{memberCluster3WestProdName}
137+
var taintClusterNames, noTaintClusterNames []string
135138

136139
BeforeAll(func() {
140+
taintClusterNames = []string{memberCluster1EastProdName, memberCluster2EastCanaryName}
141+
noTaintClusterNames = buildClusterNamesWithoutTaints(taintClusterNames)
142+
137143
// Create the resources.
138144
createWorkResources()
139145
// Add taint to member clusters 1, 2.
@@ -161,21 +167,24 @@ var _ = Describe("placing resources using a cluster resource placement with no p
161167
})
162168

163169
It("should update cluster resource placement status as expected", func() {
164-
crpStatusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), selectedClusterNames, nil, "0")
170+
crpStatusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), noTaintClusterNames, nil, "0")
165171
Eventually(crpStatusUpdatedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update cluster resource placement status as expected")
166172
})
167173

168174
It("should ensure no resources exist on member clusters with taint", func() {
169-
unSelectedClusters := []*framework.Cluster{memberCluster1EastProd, memberCluster2EastCanary}
170-
for _, cluster := range unSelectedClusters {
175+
taintClusters := buildClustersFromNames(taintClusterNames)
176+
for _, cluster := range taintClusters {
171177
resourceRemovedActual := workNamespaceRemovedFromClusterActual(cluster)
172178
Eventually(resourceRemovedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to check if resources doesn't exist on member cluster")
173179
}
174180
})
175181

176182
It("should place resources on the selected cluster without taint", func() {
177-
resourcePlacedActual := workNamespaceAndConfigMapPlacedOnClusterActual(memberCluster3WestProd)
178-
Eventually(resourcePlacedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place resources on selected cluster")
183+
noTaintClusters := buildClustersFromNames(noTaintClusterNames)
184+
for _, cluster := range noTaintClusters {
185+
resourcePlacedActual := workNamespaceAndConfigMapPlacedOnClusterActual(cluster)
186+
Eventually(resourcePlacedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place resources on selected cluster")
187+
}
179188
})
180189

181190
It("should remove taints from member clusters", func() {
@@ -197,10 +206,13 @@ var _ = Describe("placing resources using a cluster resource placement with no p
197206

198207
var _ = Describe("picking N clusters with affinities and topology spread constraints, taint clusters, create cluster resource placement with toleration for one cluster", Serial, Ordered, func() {
199208
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
200-
taintClusterNames := []string{memberCluster1EastProdName, memberCluster2EastCanaryName}
201-
tolerateClusterNames := []string{memberCluster1EastProdName}
209+
var taintClusterNames, tolerateClusterNames, unSelectedClusterNames []string
202210

203211
BeforeAll(func() {
212+
taintClusterNames = []string{memberCluster1EastProdName, memberCluster2EastCanaryName}
213+
tolerateClusterNames = []string{memberCluster1EastProdName}
214+
unSelectedClusterNames = []string{memberCluster2EastCanaryName}
215+
204216
// Create the resources.
205217
createWorkResources()
206218
// Add taint to member cluster 1, 2.
@@ -261,20 +273,21 @@ var _ = Describe("picking N clusters with affinities and topology spread constra
261273
})
262274

263275
It("should update cluster resource placement status as expected", func() {
264-
statusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), []string{memberCluster1EastProdName}, []string{memberCluster2EastCanaryName}, "0")
276+
// we choose two clusters using a label.
277+
statusUpdatedActual := crpStatusUpdatedActual(workResourceIdentifiers(), tolerateClusterNames, unSelectedClusterNames, "0")
265278
Eventually(statusUpdatedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update cluster resource placement status as expected")
266279
})
267280

268281
It("should place resources on the selected clusters with tolerated taint", func() {
269-
targetClusters := []*framework.Cluster{memberCluster1EastProd}
270-
for _, cluster := range targetClusters {
282+
tolerateClusters := buildClustersFromNames(tolerateClusterNames)
283+
for _, cluster := range tolerateClusters {
271284
resourcePlacedActual := workNamespaceAndConfigMapPlacedOnClusterActual(cluster)
272285
Eventually(resourcePlacedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place resources on the selected clusters")
273286
}
274287
})
275288

276289
It("should ensure no resources exist on member clusters with untolerated taint", func() {
277-
unSelectedClusters := []*framework.Cluster{memberCluster2EastCanary}
290+
unSelectedClusters := buildClustersFromNames(unSelectedClusterNames)
278291
for _, cluster := range unSelectedClusters {
279292
resourceRemovedActual := workNamespaceRemovedFromClusterActual(cluster)
280293
Eventually(resourceRemovedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to check if resources doesn't exist on member cluster")
@@ -284,7 +297,7 @@ var _ = Describe("picking N clusters with affinities and topology spread constra
284297
AfterAll(func() {
285298
// Remove taint from member cluster 1, 2.
286299
removeTaintsFromMemberClusters(taintClusterNames)
287-
ensureCRPAndRelatedResourcesDeleted(crpName, []*framework.Cluster{memberCluster1EastProd})
300+
ensureCRPAndRelatedResourcesDeleted(crpName, buildClustersFromNames(tolerateClusterNames))
288301
})
289302
})
290303

test/e2e/utils_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,28 @@ func updateCRPWithTolerations(tolerations []placementv1beta1.Toleration) {
11121112
}, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update cluster resource placement with tolerations %s", crpName)
11131113
}
11141114

1115+
func buildClusterNamesWithoutTaints(taintClusterNames []string) []string {
1116+
taintClusterNameMap := make(map[string]bool)
1117+
for i := range taintClusterNames {
1118+
taintClusterNameMap[taintClusterNames[i]] = true
1119+
}
1120+
var noTaintClustersNames []string
1121+
for i := range allMemberClusterNames {
1122+
if !taintClusterNameMap[allMemberClusterNames[i]] {
1123+
noTaintClustersNames = append(noTaintClustersNames, allMemberClusterNames[i])
1124+
}
1125+
}
1126+
return noTaintClustersNames
1127+
}
1128+
1129+
func buildClustersFromNames(clusterNames []string) []*framework.Cluster {
1130+
clusters := make([]*framework.Cluster, len(clusterNames))
1131+
for i := range clusterNames {
1132+
clusters[i] = allMemberClustersMap[clusterNames[i]]
1133+
}
1134+
return clusters
1135+
}
1136+
11151137
func cleanupClusterResourceOverride(name string) {
11161138
cro := &placementv1alpha1.ClusterResourceOverride{
11171139
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)