diff --git a/pkg/detector/detector.go b/pkg/detector/detector.go index 362bcbc5c..8c3fee708 100644 --- a/pkg/detector/detector.go +++ b/pkg/detector/detector.go @@ -980,16 +980,6 @@ func (d *ResourceDetector) ReconcilePropagationPolicy(key util.QueueKey) error { return nil } - // TODO(whitewindmills): In order to adapt to the upgrade scenario, we temporarily add finalizer here. - // Transplant it to karmada-webhook in the next release. More info: https://github.com/karmada-io/karmada/pull/4836#discussion_r1568186728. - if controllerutil.AddFinalizer(propagationObject, util.PropagationPolicyControllerFinalizer) { - if err = d.Client.Update(context.TODO(), propagationObject); err != nil { - klog.Errorf("Failed to add finalizer for PropagationPolicy(%s), err: %v", ckey.NamespaceKey(), err) - return err - } - return nil - } - klog.Infof("PropagationPolicy(%s) has been added or updated.", ckey.NamespaceKey()) return d.HandlePropagationPolicyCreationOrUpdate(propagationObject) } @@ -1092,16 +1082,6 @@ func (d *ResourceDetector) ReconcileClusterPropagationPolicy(key util.QueueKey) return nil } - // TODO(whitewindmills): In order to adapt to the upgrade scenario, we temporarily add finalizer here. - // Transplant it to karmada-webhook in the next release. More info: https://github.com/karmada-io/karmada/pull/4836#discussion_r1568186728. - if controllerutil.AddFinalizer(propagationObject, util.ClusterPropagationPolicyControllerFinalizer) { - if err = d.Client.Update(context.TODO(), propagationObject); err != nil { - klog.Errorf("Failed to add finalizer for ClusterPropagationPolicy(%s), err: %v", ckey.NamespaceKey(), err) - return err - } - return nil - } - klog.Infof("ClusterPropagationPolicy(%s) has been added or updated.", ckey.NamespaceKey()) return d.HandleClusterPropagationPolicyCreationOrUpdate(propagationObject) } diff --git a/pkg/webhook/clusterpropagationpolicy/mutating.go b/pkg/webhook/clusterpropagationpolicy/mutating.go index dc7141eef..cf76ba4c7 100644 --- a/pkg/webhook/clusterpropagationpolicy/mutating.go +++ b/pkg/webhook/clusterpropagationpolicy/mutating.go @@ -24,6 +24,7 @@ import ( "github.com/google/uuid" admissionv1 "k8s.io/api/admission/v1" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" @@ -85,6 +86,7 @@ func (a *MutatingAdmission) Handle(_ context.Context, req admission.Request) adm if req.Operation == admissionv1.Create { util.MergeLabel(policy, policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel, uuid.New().String()) + controllerutil.AddFinalizer(policy, util.ClusterPropagationPolicyControllerFinalizer) } marshaledBytes, err := json.Marshal(policy) diff --git a/pkg/webhook/propagationpolicy/mutating.go b/pkg/webhook/propagationpolicy/mutating.go index 01aa95185..298fba279 100644 --- a/pkg/webhook/propagationpolicy/mutating.go +++ b/pkg/webhook/propagationpolicy/mutating.go @@ -25,6 +25,7 @@ import ( "github.com/google/uuid" admissionv1 "k8s.io/api/admission/v1" "k8s.io/klog/v2" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" @@ -97,6 +98,7 @@ func (a *MutatingAdmission) Handle(_ context.Context, req admission.Request) adm if req.Operation == admissionv1.Create { util.MergeLabel(policy, policyv1alpha1.PropagationPolicyPermanentIDLabel, uuid.New().String()) + controllerutil.AddFinalizer(policy, util.PropagationPolicyControllerFinalizer) } marshaledBytes, err := json.Marshal(policy)