Skip to content

Commit

Permalink
chore: optimize function
Browse files Browse the repository at this point in the history
Signed-off-by: 0xff-dev <stevenshuang521@gmail.com>
  • Loading branch information
0xff-dev committed Jun 12, 2023
1 parent 30eae58 commit 8e0001c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/controller/controllerutil/controllerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,18 @@ func AddFinalizer(o client.Object, finalizer string) (finalizersUpdated bool) {
// It returns an indication of whether it updated the object's list of finalizers.
func RemoveFinalizer(o client.Object, finalizer string) (finalizersUpdated bool) {
f := o.GetFinalizers()
for i := 0; i < len(f); i++ {
length := len(f)

index := 0
for i := 0; i < length; i++ {
if f[i] == finalizer {
f = append(f[:i], f[i+1:]...)
i--
finalizersUpdated = true
continue
}
f[index] = f[i]
index++
}
o.SetFinalizers(f)
return
o.SetFinalizers(f[:index])
return length != index
}

// ContainsFinalizer checks an Object that the provided finalizer is present.
Expand Down

0 comments on commit 8e0001c

Please sign in to comment.