mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #32524 from derekwaynecarr/ns-controller-finalizer
Automatic merge from submit-queue Namespace Controller handles items with finalizers gracefully This PR does the following: 1. ensures the "orphan" finalizer is not added to items during DELETE COLLECTION calls 2. does not treat presence of a finalizer as an unexpected error condition. The 15s wait should only happen when finalizers not added by GC are used. I am aware of any finalizer like that at this time. Fixes https://github.com/kubernetes/kubernetes/issues/32519
This commit is contained in:
commit
c1f47581fa
@ -48,6 +48,8 @@ type operation string
|
|||||||
const (
|
const (
|
||||||
operationDeleteCollection operation = "deleteCollection"
|
operationDeleteCollection operation = "deleteCollection"
|
||||||
operationList operation = "list"
|
operationList operation = "list"
|
||||||
|
// assume a default estimate for finalizers to complete when found on items pending deletion.
|
||||||
|
finalizerEstimateSeconds int64 = int64(15)
|
||||||
)
|
)
|
||||||
|
|
||||||
// operationKey is an entry in a cache.
|
// operationKey is an entry in a cache.
|
||||||
@ -154,7 +156,12 @@ func deleteCollection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
apiResource := unversioned.APIResource{Name: gvr.Resource, Namespaced: true}
|
apiResource := unversioned.APIResource{Name: gvr.Resource, Namespaced: true}
|
||||||
err := dynamicClient.Resource(&apiResource, namespace).DeleteCollection(nil, &v1.ListOptions{})
|
|
||||||
|
// namespace controller does not want the garbage collector to insert the orphan finalizer since it calls
|
||||||
|
// resource deletions generically. it will ensure all resources in the namespace are purged prior to releasing
|
||||||
|
// namespace itself.
|
||||||
|
orphanDependents := false
|
||||||
|
err := dynamicClient.Resource(&apiResource, namespace).DeleteCollection(&v1.DeleteOptions{OrphanDependents: &orphanDependents}, &v1.ListOptions{})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -300,6 +307,14 @@ func deleteAllContentForGroupVersionResource(
|
|||||||
}
|
}
|
||||||
glog.V(5).Infof("namespace controller - deleteAllContentForGroupVersionResource - items remaining - namespace: %s, gvr: %v, items: %v", namespace, gvr, len(unstructuredList.Items))
|
glog.V(5).Infof("namespace controller - deleteAllContentForGroupVersionResource - items remaining - namespace: %s, gvr: %v, items: %v", namespace, gvr, len(unstructuredList.Items))
|
||||||
if len(unstructuredList.Items) != 0 && estimate == int64(0) {
|
if len(unstructuredList.Items) != 0 && estimate == int64(0) {
|
||||||
|
// if any item has a finalizer, we treat that as a normal condition, and use a default estimation to allow for GC to complete.
|
||||||
|
for _, item := range unstructuredList.Items {
|
||||||
|
if len(item.GetFinalizers()) > 0 {
|
||||||
|
glog.V(5).Infof("namespace controller - deleteAllContentForGroupVersionResource - items remaining with finalizers - namespace: %s, gvr: %v, finalizers: %v", namespace, gvr, item.GetFinalizers())
|
||||||
|
return finalizerEstimateSeconds, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// nothing reported a finalizer, so something was unexpected as it should have been deleted.
|
||||||
return estimate, fmt.Errorf("unexpected items still remain in namespace: %s for gvr: %v", namespace, gvr)
|
return estimate, fmt.Errorf("unexpected items still remain in namespace: %s for gvr: %v", namespace, gvr)
|
||||||
}
|
}
|
||||||
return estimate, nil
|
return estimate, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user