Merge pull request #57211 from liggitt/gc-cluster-scoped

Automatic merge from submit-queue (batch tested with PRs 57211, 56150, 56368, 56271, 55957). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Process cluster-scoped owners correctly

Rework of https://github.com/kubernetes/kubernetes/pull/54943
Fixes #54940

Uses correct scope info from the restmapper at point of object lookup.

```release-note
Fixed a garbage collection race condition where objects with ownerRefs pointing to cluster-scoped objects could be deleted incorrectly.
```
This commit is contained in:
Kubernetes Submit Queue
2017-12-15 14:00:38 -08:00
committed by GitHub
5 changed files with 159 additions and 8 deletions

View File

@@ -297,7 +297,7 @@ func (gc *GarbageCollector) isDangling(reference metav1.OwnerReference, item *no
if err != nil {
return false, nil, err
}
resource, err := gc.apiResource(reference.APIVersion, reference.Kind, len(item.identity.Namespace) != 0)
resource, err := gc.apiResource(reference.APIVersion, reference.Kind)
if err != nil {
return false, nil, err
}

View File

@@ -32,7 +32,7 @@ import (
// apiResource consults the REST mapper to translate an <apiVersion, kind,
// namespace> tuple to a unversioned.APIResource struct.
func (gc *GarbageCollector) apiResource(apiVersion, kind string, namespaced bool) (*metav1.APIResource, error) {
func (gc *GarbageCollector) apiResource(apiVersion, kind string) (*metav1.APIResource, error) {
fqKind := schema.FromAPIVersionAndKind(apiVersion, kind)
mapping, err := gc.restMapper.RESTMapping(fqKind.GroupKind(), apiVersion)
if err != nil {
@@ -41,7 +41,7 @@ func (gc *GarbageCollector) apiResource(apiVersion, kind string, namespaced bool
glog.V(5).Infof("map kind %s, version %s to resource %s", kind, apiVersion, mapping.Resource)
resource := metav1.APIResource{
Name: mapping.Resource,
Namespaced: namespaced,
Namespaced: mapping.Scope == meta.RESTScopeNamespace,
Kind: kind,
}
return &resource, nil
@@ -53,7 +53,7 @@ func (gc *GarbageCollector) deleteObject(item objectReference, policy *metav1.De
if err != nil {
return err
}
resource, err := gc.apiResource(item.APIVersion, item.Kind, len(item.Namespace) != 0)
resource, err := gc.apiResource(item.APIVersion, item.Kind)
if err != nil {
return err
}
@@ -69,7 +69,7 @@ func (gc *GarbageCollector) getObject(item objectReference) (*unstructured.Unstr
if err != nil {
return nil, err
}
resource, err := gc.apiResource(item.APIVersion, item.Kind, len(item.Namespace) != 0)
resource, err := gc.apiResource(item.APIVersion, item.Kind)
if err != nil {
return nil, err
}
@@ -82,7 +82,7 @@ func (gc *GarbageCollector) updateObject(item objectReference, obj *unstructured
if err != nil {
return nil, err
}
resource, err := gc.apiResource(item.APIVersion, item.Kind, len(item.Namespace) != 0)
resource, err := gc.apiResource(item.APIVersion, item.Kind)
if err != nil {
return nil, err
}
@@ -95,7 +95,7 @@ func (gc *GarbageCollector) patchObject(item objectReference, patch []byte) (*un
if err != nil {
return nil, err
}
resource, err := gc.apiResource(item.APIVersion, item.Kind, len(item.Namespace) != 0)
resource, err := gc.apiResource(item.APIVersion, item.Kind)
if err != nil {
return nil, err
}