Skip to content

Commit 382e812

Browse files
authored
Merge pull request #542 from fluxcd/patch-finalizers
Use patch instead of update when adding finalizers
2 parents 29816d5 + 5be3377 commit 382e812

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

controllers/bucket_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
9797

9898
// Add our finalizer if it does not exist
9999
if !controllerutil.ContainsFinalizer(&bucket, sourcev1.SourceFinalizer) {
100+
patch := client.MergeFrom(bucket.DeepCopy())
100101
controllerutil.AddFinalizer(&bucket, sourcev1.SourceFinalizer)
101-
if err := r.Update(ctx, &bucket); err != nil {
102+
if err := r.Patch(ctx, &bucket, patch); err != nil {
102103
log.Error(err, "unable to register finalizer")
103104
return ctrl.Result{}, err
104105
}

controllers/gitrepository_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reques
100100

101101
// Add our finalizer if it does not exist
102102
if !controllerutil.ContainsFinalizer(&repository, sourcev1.SourceFinalizer) {
103+
patch := client.MergeFrom(repository.DeepCopy())
103104
controllerutil.AddFinalizer(&repository, sourcev1.SourceFinalizer)
104-
if err := r.Update(ctx, &repository); err != nil {
105+
if err := r.Patch(ctx, &repository, patch); err != nil {
105106
log.Error(err, "unable to register finalizer")
106107
return ctrl.Result{}, err
107108
}

controllers/helmchart_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
126126

127127
// Add our finalizer if it does not exist
128128
if !controllerutil.ContainsFinalizer(&chart, sourcev1.SourceFinalizer) {
129+
patch := client.MergeFrom(chart.DeepCopy())
129130
controllerutil.AddFinalizer(&chart, sourcev1.SourceFinalizer)
130-
if err := r.Update(ctx, &chart); err != nil {
131+
if err := r.Patch(ctx, &chart, patch); err != nil {
131132
log.Error(err, "unable to register finalizer")
132133
return ctrl.Result{}, err
133134
}

controllers/helmrepository_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque
9393

9494
// Add our finalizer if it does not exist
9595
if !controllerutil.ContainsFinalizer(&repository, sourcev1.SourceFinalizer) {
96+
patch := client.MergeFrom(repository.DeepCopy())
9697
controllerutil.AddFinalizer(&repository, sourcev1.SourceFinalizer)
97-
if err := r.Update(ctx, &repository); err != nil {
98+
if err := r.Patch(ctx, &repository, patch); err != nil {
9899
log.Error(err, "unable to register finalizer")
99100
return ctrl.Result{}, err
100101
}

0 commit comments

Comments
 (0)