Skip to content

🐛 controllerutil.RemoveFinalizer can occurs slice bounds out of range exception #917

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

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions pkg/controller/controllerutil/controllerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,10 @@ func AddFinalizerWithError(o runtime.Object, finalizer string) error {
// RemoveFinalizer accepts a metav1 object and removes the provided finalizer if present.
func RemoveFinalizer(o metav1.Object, finalizer string) {
f := o.GetFinalizers()
for i, e := range f {
if e == finalizer {
for i := 0; i < len(f); i++ {
if f[i] == finalizer {
f = append(f[:i], f[i+1:]...)
i--
}
}
o.SetFinalizers(f)
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/controllerutil/controllerutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ var _ = Describe("Controllerutil", func() {
controllerutil.RemoveFinalizer(deploy, testFinalizer)
Expect(deploy.ObjectMeta.GetFinalizers()).To(Equal([]string{}))
})

It("should remove all equal finalizers if present", func() {
deploy.SetFinalizers(append(deploy.Finalizers, testFinalizer, testFinalizer))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexeldeib fixed there

controllerutil.RemoveFinalizer(deploy, testFinalizer)
Expect(deploy.ObjectMeta.GetFinalizers()).To(Equal([]string{}))
})
})
})
})
Expand Down