Skip to content

Commit

Permalink
Merge pull request #1190 from 1978629634/shallow-copy-fix
Browse files Browse the repository at this point in the history
Fix clone controller shallow copy bug
  • Loading branch information
k8s-ci-robot authored Apr 8, 2024
2 parents 4dd7180 + 547f188 commit 91e80e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pkg/controller/clone_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 91e80e5

Please sign in to comment.