Skip to content

Commit

Permalink
Merge pull request #1125 from aryan9600/fix-finalizer-dupl
Browse files Browse the repository at this point in the history
Fix potential canary finalizer duplication
  • Loading branch information
stefanprodan authored Mar 8, 2022
2 parents 5d2a7ba + 84ae65c commit 519f343
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/controller/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func hasFinalizer(canary *flaggerv1.Canary) bool {
return false
}

// addFinalizer adds a provided finalizer to the specified canary resource.
// addFinalizer adds a provided finalizer (if it already doesn't exist) to the specified canary resource.
// If failures occur the error will be returned otherwise the action is deemed successful
// and error will be nil.
func (c *Controller) addFinalizer(canary *flaggerv1.Canary) error {
Expand All @@ -128,11 +128,14 @@ func (c *Controller) addFinalizer(canary *flaggerv1.Canary) error {
return fmt.Errorf("canary %s.%s get query failed: %w", name, ns, err)
}
}
firstTry = false

cCopy := canary.DeepCopy()
cCopy.ObjectMeta.Finalizers = append(cCopy.ObjectMeta.Finalizers, finalizer)
_, err = c.flaggerClient.FlaggerV1beta1().Canaries(canary.Namespace).Update(context.TODO(), cCopy, metav1.UpdateOptions{})
firstTry = false
if !hasFinalizer(cCopy) {
cCopy.ObjectMeta.Finalizers = append(cCopy.ObjectMeta.Finalizers, finalizer)
_, err = c.flaggerClient.FlaggerV1beta1().Canaries(canary.Namespace).Update(context.TODO(), cCopy, metav1.UpdateOptions{})
}

return
})

Expand Down

0 comments on commit 519f343

Please sign in to comment.