kubectl: Use v1.5-compatible ownership logic when listing dependents.

In particular, we should not assume ControllerRefs are necessarily set.
However, we can still use ControllerRefs that do exist to avoid
interfering with controllers that do use it.
This commit is contained in:
Anthony Yeh
2017-03-16 11:43:09 -07:00
parent 725ec0cc5e
commit fa23729a6d
7 changed files with 159 additions and 40 deletions

View File

@@ -476,6 +476,7 @@ func TestDeploymentStop(t *testing.T) {
&deployment, // GET
&extensions.ReplicaSetList{ // LIST
Items: []extensions.ReplicaSet{
// ReplicaSet owned by this Deployment.
{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@@ -484,7 +485,7 @@ func TestDeploymentStop(t *testing.T) {
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: extensions.SchemeGroupVersion.String(),
Kind: "ReplicaSet",
Kind: "Deployment",
Name: deployment.Name,
UID: deployment.UID,
Controller: &trueVar,
@@ -495,6 +496,72 @@ func TestDeploymentStop(t *testing.T) {
Template: template,
},
},
// ReplicaSet owned by something else (should be ignored).
{
ObjectMeta: metav1.ObjectMeta{
Name: "rs2",
Namespace: ns,
Labels: map[string]string{"k1": "v1"},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: extensions.SchemeGroupVersion.String(),
Kind: "Deployment",
Name: "somethingelse",
UID: uuid.NewUUID(),
Controller: &trueVar,
},
},
},
Spec: extensions.ReplicaSetSpec{
Template: template,
},
},
},
},
},
StopError: nil,
ExpectedActions: []string{"get:deployments", "update:deployments",
"get:deployments", "list:replicasets", "get:replicasets",
"get:replicasets", "update:replicasets", "get:replicasets",
"get:replicasets", "delete:replicasets", "delete:deployments"},
},
{
Name: "Deployment with single replicaset, no ControllerRef (old cluster)",
Objs: []runtime.Object{
&deployment, // GET
&extensions.ReplicaSetList{ // LIST
Items: []extensions.ReplicaSet{
// ReplicaSet that matches but with no ControllerRef.
{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
Labels: map[string]string{"k1": "v1"},
},
Spec: extensions.ReplicaSetSpec{
Template: template,
},
},
// ReplicaSet owned by something else (should be ignored).
{
ObjectMeta: metav1.ObjectMeta{
Name: "rs2",
Namespace: ns,
Labels: map[string]string{"k1": "v1"},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: extensions.SchemeGroupVersion.String(),
Kind: "Deployment",
Name: "somethingelse",
UID: uuid.NewUUID(),
Controller: &trueVar,
},
},
},
Spec: extensions.ReplicaSetSpec{
Template: template,
},
},
},
},
},