Skip to content

Commit f0c92d4

Browse files
author
Arvind Thirumurugan
committed
address comments
Signed-off-by: Arvind Thirumurugan <[email protected]>
1 parent 391a689 commit f0c92d4

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

test/e2e/drain_tool_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package e2e
1919
import (
2020
"fmt"
2121
"os/exec"
22+
"time"
2223

2324
. "github.com/onsi/ginkgo/v2"
2425
. "github.com/onsi/gomega"
@@ -78,7 +79,7 @@ var _ = Describe("Drain cluster successfully", Ordered, Serial, func() {
7879

7980
It("should update drain cluster resource placement evictions status as expected", func() {
8081
var fetchError error
81-
drainEvictions, fetchError = fetchDrainEvictions()
82+
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster1EastProdName)
8283
Eventually(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
8384
for _, eviction := range drainEvictions {
8485
crpEvictionStatusUpdatedActual := testutilseviction.StatusUpdatedActual(
@@ -171,7 +172,7 @@ var _ = Describe("Drain cluster blocked - ClusterResourcePlacementDisruptionBudg
171172

172173
It("should update drain cluster resource placement evictions status as expected", func() {
173174
var fetchError error
174-
drainEvictions, fetchError = fetchDrainEvictions()
175+
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster1EastProdName)
175176
Eventually(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
176177
for _, eviction := range drainEvictions {
177178
crpEvictionStatusUpdatedActual := testutilseviction.StatusUpdatedActual(
@@ -258,7 +259,7 @@ var _ = Describe("Drain is allowed on one cluster, blocked on others - ClusterRe
258259

259260
It("should update drain cluster resource placement evictions status as expected", func() {
260261
var fetchError error
261-
drainEvictions, fetchError = fetchDrainEvictions()
262+
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster1EastProdName)
262263
Eventually(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
263264
for _, eviction := range drainEvictions {
264265
crpEvictionStatusUpdatedActual := testutilseviction.StatusUpdatedActual(
@@ -284,7 +285,7 @@ var _ = Describe("Drain is allowed on one cluster, blocked on others - ClusterRe
284285

285286
It("should update drain cluster resource placement evictions status as expected", func() {
286287
var fetchError error
287-
drainEvictions, fetchError = fetchDrainEvictions()
288+
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster2EastCanaryName)
288289
Eventually(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
289290
for _, eviction := range drainEvictions {
290291
crpEvictionStatusUpdatedActual := testutilseviction.StatusUpdatedActual(
@@ -348,12 +349,21 @@ func runUncordonClusterBinary(hubClusterName, memberClusterName string) {
348349
Expect(err).ToNot(HaveOccurred(), "Uncordon command failed with error: %v", err)
349350
}
350351

351-
func fetchDrainEvictions() ([]placementv1beta1.ClusterResourcePlacementEviction, error) {
352+
func fetchDrainEvictions(crpName, clusterName string) ([]placementv1beta1.ClusterResourcePlacementEviction, error) {
352353
var evictionList placementv1beta1.ClusterResourcePlacementEvictionList
353354
if err := hubClient.List(ctx, &evictionList); err != nil {
354355
return nil, err
355356
}
356-
return evictionList.Items, nil
357+
var filteredDrainEvictions []placementv1beta1.ClusterResourcePlacementEviction
358+
thirtySecondsAgo := time.Now().Add(-30 * time.Second)
359+
for _, eviction := range evictionList.Items {
360+
if eviction.CreationTimestamp.Time.After(thirtySecondsAgo) &&
361+
eviction.Spec.PlacementName == crpName &&
362+
eviction.Spec.ClusterName == clusterName {
363+
filteredDrainEvictions = append(filteredDrainEvictions, eviction)
364+
}
365+
}
366+
return filteredDrainEvictions, nil
357367
}
358368

359369
func memberClusterCordonTaintAddedActual(mcName string) func() error {

test/e2e/setup_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package e2e
1919
import (
2020
"context"
2121
"flag"
22+
"fmt"
2223
"log"
2324
"os"
2425
"path/filepath"
@@ -346,6 +347,12 @@ func beforeSuiteForAllProcesses() {
346347
for i := range allMemberClusters {
347348
allMemberClusterNames = append(allMemberClusterNames, allMemberClusters[i].ClusterName)
348349
}
350+
351+
// Check if drain cluster and uncordon cluster binaries exist.
352+
_, err := os.Stat(drainBinaryPath)
353+
Expect(os.IsNotExist(err)).To(BeFalse(), fmt.Sprintf("drain binary not found at %s", drainBinaryPath))
354+
_, err = os.Stat(uncordonBinaryPath)
355+
Expect(os.IsNotExist(err)).To(BeFalse(), fmt.Sprintf("uncordon binary not found at %s", uncordonBinaryPath))
349356
})
350357
}
351358

0 commit comments

Comments
 (0)