From 25867c45ba582cd5c9ea8c3a62297a8e1d735228 Mon Sep 17 00:00:00 2001 From: changzhen Date: Mon, 25 Nov 2024 14:48:55 +0800 Subject: [PATCH] update taint-manager to config eviction task with purgeMode Signed-off-by: changzhen --- pkg/controllers/cluster/taint_manager.go | 21 +++++++++++++++---- pkg/controllers/cluster/taint_manager_test.go | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/controllers/cluster/taint_manager.go b/pkg/controllers/cluster/taint_manager.go index b1f3f459426c..285643c13af9 100644 --- a/pkg/controllers/cluster/taint_manager.go +++ b/pkg/controllers/cluster/taint_manager.go @@ -32,6 +32,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1" + policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" "github.com/karmada-io/karmada/pkg/features" "github.com/karmada-io/karmada/pkg/util" @@ -172,9 +173,15 @@ func (tc *NoExecuteTaintManager) syncBindingEviction(key util.QueueKey) error { if needEviction || tolerationTime == 0 { // update final result to evict the target cluster if features.FeatureGate.Enabled(features.GracefulEviction) { - binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager), workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated))) + binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions( + workv1alpha2.WithPurgeMode(policyv1alpha1.Graciously), + workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager), + workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated))) } else { - binding.Spec.RemoveCluster(cluster) + binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions( + workv1alpha2.WithPurgeMode(policyv1alpha1.Immediately), + workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager), + workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated))) } if err = tc.Update(context.TODO(), binding); err != nil { helper.EmitClusterEvictionEventForResourceBinding(binding, cluster, tc.EventRecorder, err) @@ -228,9 +235,15 @@ func (tc *NoExecuteTaintManager) syncClusterBindingEviction(key util.QueueKey) e if needEviction || tolerationTime == 0 { // update final result to evict the target cluster if features.FeatureGate.Enabled(features.GracefulEviction) { - binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager), workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated))) + binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions( + workv1alpha2.WithPurgeMode(policyv1alpha1.Graciously), + workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager), + workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated))) } else { - binding.Spec.RemoveCluster(cluster) + binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions( + workv1alpha2.WithPurgeMode(policyv1alpha1.Immediately), + workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager), + workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated))) } if err = tc.Update(context.TODO(), binding); err != nil { helper.EmitClusterEvictionEventForClusterResourceBinding(binding, cluster, tc.EventRecorder, err) diff --git a/pkg/controllers/cluster/taint_manager_test.go b/pkg/controllers/cluster/taint_manager_test.go index efac5255ef0a..b3a53d0c4b64 100644 --- a/pkg/controllers/cluster/taint_manager_test.go +++ b/pkg/controllers/cluster/taint_manager_test.go @@ -29,6 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1" + policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" "github.com/karmada-io/karmada/pkg/util" "github.com/karmada-io/karmada/pkg/util/fedinformer/keys" @@ -237,6 +238,7 @@ func TestNoExecuteTaintManager_syncBindingEviction(t *testing.T) { GracefulEvictionTasks: []workv1alpha2.GracefulEvictionTask{ { FromCluster: "test-cluster", + PurgeMode: policyv1alpha1.Graciously, Replicas: &replica, Reason: workv1alpha2.EvictionReasonTaintUntolerated, Producer: workv1alpha2.EvictionProducerTaintManager, @@ -403,6 +405,7 @@ func TestNoExecuteTaintManager_syncClusterBindingEviction(t *testing.T) { GracefulEvictionTasks: []workv1alpha2.GracefulEvictionTask{ { FromCluster: "test-cluster", + PurgeMode: policyv1alpha1.Graciously, Replicas: &replica, Reason: workv1alpha2.EvictionReasonTaintUntolerated, Producer: workv1alpha2.EvictionProducerTaintManager,