Skip to content

Commit

Permalink
Try three times to remove finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Apr 2, 2018
1 parent d20a37a commit 5c92744
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions lifecycle/object.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lifecycle

import (
"fmt"
"reflect"

"github.com/rancher/norman/clientbase"
Expand Down Expand Up @@ -92,15 +93,10 @@ func (o *objectLifecycleAdapter) finalize(metadata metav1.Object, obj runtime.Ob
copyObj = newObj
}

if err := removeFinalizer(o.constructFinalizerKey(), copyObj); err != nil {
return false, err
}

_, err := o.objectClient.Update(metadata.GetName(), copyObj)
return false, err
return false, o.removeFinalizer(o.constructFinalizerKey(), copyObj)
}

func removeFinalizer(name string, obj runtime.Object) error {
func (o *objectLifecycleAdapter) removeFinalizer(name string, obj runtime.Object) error {
metadata, err := meta.Accessor(obj)
if err != nil {
return err
Expand All @@ -115,7 +111,26 @@ func removeFinalizer(name string, obj runtime.Object) error {
}
metadata.SetFinalizers(finalizers)

return nil
for i := 0; i < 3; i++ {
_, err := o.objectClient.Update(metadata.GetName(), obj)
if err == nil {
return nil
}

obj, err = o.objectClient.GetNamespaced(metadata.GetNamespace(), metadata.GetName(), metav1.GetOptions{})
if err != nil {
return err
}

metadata, err := meta.Accessor(obj)
if err != nil {
return err
}

metadata.SetFinalizers(finalizers)
}

return fmt.Errorf("failed to remove finalizer on %s:%s", metadata.GetNamespace(), metadata.GetName())
}

func (o *objectLifecycleAdapter) createKey() string {
Expand Down

0 comments on commit 5c92744

Please sign in to comment.