From 082fe7cff9def214f21e1f2de4bf7a418d96f35f Mon Sep 17 00:00:00 2001 From: mszacillo Date: Wed, 27 Nov 2024 23:37:01 -0500 Subject: [PATCH] Cleanup works from cluster if purgemode is immediately Signed-off-by: mszacillo --- pkg/util/helper/binding.go | 6 +++++- pkg/util/helper/binding_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/pkg/util/helper/binding.go b/pkg/util/helper/binding.go index 04e2a02b5de1..d3a605186974 100644 --- a/pkg/util/helper/binding.go +++ b/pkg/util/helper/binding.go @@ -186,7 +186,11 @@ func ObtainBindingSpecExistingClusters(bindingSpec workv1alpha2.ResourceBindingS } for _, task := range bindingSpec.GracefulEvictionTasks { - clusterNames.Insert(task.FromCluster) + // EvictionTasks with Immediately PurgeMode should not be treated as existing clusters + // Work on those clusters should be removed immediately and treated as orphans + if task.PurgeMode != policyv1alpha1.Immediately { + clusterNames.Insert(task.FromCluster) + } } return clusterNames diff --git a/pkg/util/helper/binding_test.go b/pkg/util/helper/binding_test.go index 3db7f62de5eb..a657684ac4e5 100644 --- a/pkg/util/helper/binding_test.go +++ b/pkg/util/helper/binding_test.go @@ -35,6 +35,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" + policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1" workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" "github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager" @@ -335,6 +336,36 @@ func TestObtainBindingSpecExistingClusters(t *testing.T) { }, want: sets.New("member1", "member2", "member3"), }, + { + name: "unique cluster names with GracefulEvictionTasks with PurgeMode Immediately", + bindingSpec: workv1alpha2.ResourceBindingSpec{ + Clusters: []workv1alpha2.TargetCluster{ + { + Name: "member1", + Replicas: 2, + }, + { + Name: "member2", + Replicas: 3, + }, + }, + GracefulEvictionTasks: []workv1alpha2.GracefulEvictionTask{ + { + FromCluster: "member3", + PurgeMode: policyv1alpha1.Immediately, + }, + { + FromCluster: "member4", + PurgeMode: policyv1alpha1.Graciously, + }, + { + FromCluster: "member5", + PurgeMode: policyv1alpha1.Never, + }, + }, + }, + want: sets.New("member1", "member2", "member4", "member5"), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {