Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential canary finalizer duplication #1125

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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