Merge pull request #44084 from nikhiljindal/removeFinalizers

Automatic merge from submit-queue (batch tested with PRs 44084, 42964)

Removing both finalizers in federation controllers in a single update

Fixes https://github.com/kubernetes/kubernetes/issues/43828

There is a bug right now where the controller fails to delete the object if one finalizer is removed and the second isnt.
This updates the code so that both the finalizers are removed in a single API call. Kept the code changes minimum to enable cherrypick in 1.6.x

cc @csbell @kubernetes/sig-federation-bugs
This commit is contained in:
Kubernetes Submit Queue
2017-04-05 20:45:18 -07:00
committed by GitHub
11 changed files with 68 additions and 40 deletions

View File

@@ -210,14 +210,14 @@ func (nc *NamespaceController) hasFinalizerFunc(obj runtime.Object, finalizer st
return false
}
// Removes the finalizer from the given objects ObjectMeta.
// Removes the finalizers from the given objects ObjectMeta.
// Assumes that the given object is a namespace.
func (nc *NamespaceController) removeFinalizerFunc(obj runtime.Object, finalizer string) (runtime.Object, error) {
func (nc *NamespaceController) removeFinalizerFunc(obj runtime.Object, finalizers []string) (runtime.Object, error) {
namespace := obj.(*apiv1.Namespace)
newFinalizers := []string{}
hasFinalizer := false
for i := range namespace.ObjectMeta.Finalizers {
if string(namespace.ObjectMeta.Finalizers[i]) != finalizer {
if !deletionhelper.ContainsString(finalizers, namespace.ObjectMeta.Finalizers[i]) {
newFinalizers = append(newFinalizers, namespace.ObjectMeta.Finalizers[i])
} else {
hasFinalizer = true
@@ -230,7 +230,7 @@ func (nc *NamespaceController) removeFinalizerFunc(obj runtime.Object, finalizer
namespace.ObjectMeta.Finalizers = newFinalizers
namespace, err := nc.federatedApiClient.Core().Namespaces().Update(namespace)
if err != nil {
return nil, fmt.Errorf("failed to remove finalizer %s from namespace %s: %v", finalizer, namespace.Name, err)
return nil, fmt.Errorf("failed to remove finalizers %v from namespace %s: %v", finalizers, namespace.Name, err)
}
return namespace, nil
}