From 547f18810068b7b3b30672b7b10a86bb3fc337df Mon Sep 17 00:00:00 2001 From: chenpu <1102509144@163.com> Date: Tue, 2 Apr 2024 00:28:53 +0800 Subject: [PATCH] Fix clone controller shallow copy bug --- pkg/controller/clone_controller.go | 5 +++-- pkg/controller/controller.go | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/controller/clone_controller.go b/pkg/controller/clone_controller.go index d7113f807d..4dc7b70120 100644 --- a/pkg/controller/clone_controller.go +++ b/pkg/controller/clone_controller.go @@ -199,9 +199,10 @@ func (p *CloningProtectionController) syncClaim(ctx context.Context, claim *v1.P finalizers = append(finalizers, finalizer) } } - claim.ObjectMeta.Finalizers = finalizers - if _, err = p.client.CoreV1().PersistentVolumeClaims(claim.Namespace).Update(ctx, claim, metav1.UpdateOptions{}); err != nil { + clone := claim.DeepCopy() + clone.Finalizers = finalizers + if _, err = p.client.CoreV1().PersistentVolumeClaims(clone.Namespace).Update(ctx, clone, metav1.UpdateOptions{}); err != nil { if !apierrs.IsNotFound(err) { // Couldn't remove finalizer and the object still exists, the controller may // try to remove the finalizer again on the next update diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 9113474d1e..ecc1c12a7f 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -983,9 +983,10 @@ func (p *csiProvisioner) setCloneFinalizer(ctx context.Context, pvc *v1.Persiste return err } - if !checkFinalizer(claim, pvcCloneFinalizer) { - claim.Finalizers = append(claim.Finalizers, pvcCloneFinalizer) - _, err := p.client.CoreV1().PersistentVolumeClaims(claim.Namespace).Update(ctx, claim, metav1.UpdateOptions{}) + clone := claim.DeepCopy() + if !checkFinalizer(clone, pvcCloneFinalizer) { + clone.Finalizers = append(clone.Finalizers, pvcCloneFinalizer) + _, err := p.client.CoreV1().PersistentVolumeClaims(clone.Namespace).Update(ctx, clone, metav1.UpdateOptions{}) return err }