Skip to content

Commit

Permalink
Use metav1.Object instead of Object
Browse files Browse the repository at this point in the history
In order to allow for a broader adoption of ContainsFinalizer, RemoveFinalizer and AddFinalizer and remove a BC break introduced to 0.5.x I switched the method back to the `metav1.Object`.

After reading kubernetes-sigs#959 and kubernetes-sigs#962 I'm unable to understand the benefit of requiring `runtime.Object` so I propose to revert the BC break and possible panic on line 285.
  • Loading branch information
boekkooi-fresh committed Jul 30, 2020
1 parent cea989b commit ebfd135
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/controller/controllerutil/controllerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func mutate(f MutateFn, key client.ObjectKey, obj runtime.Object) error {
type MutateFn func() error

// AddFinalizer accepts an Object and adds the provided finalizer if not present.
func AddFinalizer(o Object, finalizer string) {
func AddFinalizer(o metav1.Object, finalizer string) {
f := o.GetFinalizers()
for _, e := range f {
if e == finalizer {
Expand All @@ -257,12 +257,12 @@ func AddFinalizerWithError(o runtime.Object, finalizer string) error {
if err != nil {
return err
}
AddFinalizer(m.(Object), finalizer)
AddFinalizer(m, finalizer)
return nil
}

// RemoveFinalizer accepts an Object and removes the provided finalizer if present.
func RemoveFinalizer(o Object, finalizer string) {
func RemoveFinalizer(o metav1.Object, finalizer string) {
f := o.GetFinalizers()
for i := 0; i < len(f); i++ {
if f[i] == finalizer {
Expand All @@ -282,12 +282,12 @@ func RemoveFinalizerWithError(o runtime.Object, finalizer string) error {
if err != nil {
return err
}
RemoveFinalizer(m.(Object), finalizer)
RemoveFinalizer(m, finalizer)
return nil
}

// ContainsFinalizer checks an Object that the provided finalizer is present.
func ContainsFinalizer(o Object, finalizer string) bool {
func ContainsFinalizer(o metav1.Object, finalizer string) bool {
f := o.GetFinalizers()
for _, e := range f {
if e == finalizer {
Expand Down

0 comments on commit ebfd135

Please sign in to comment.