Fix kubectl describe for controllerRef
This commit is contained in:
@@ -1492,3 +1492,98 @@ func TestDescribeResourceQuota(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// boolPtr returns a pointer to a bool
|
||||
func boolPtr(b bool) *bool {
|
||||
o := b
|
||||
return &o
|
||||
}
|
||||
|
||||
func TestControllerRef(t *testing.T) {
|
||||
f := fake.NewSimpleClientset(
|
||||
&api.ReplicationController{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Namespace: "foo",
|
||||
UID: "123456",
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "ReplicationController",
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 1,
|
||||
Selector: map[string]string{"abc": "xyz"},
|
||||
Template: &api.PodTemplateSpec{
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Image: "mytest-image:latest"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&api.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "barpod",
|
||||
Namespace: "foo",
|
||||
Labels: map[string]string{"abc": "xyz"},
|
||||
OwnerReferences: []metav1.OwnerReference{{Name: "bar", UID: "123456", Controller: boolPtr(true)}},
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Pod",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Image: "mytest-image:latest"},
|
||||
},
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
},
|
||||
&api.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "orphan",
|
||||
Namespace: "foo",
|
||||
Labels: map[string]string{"abc": "xyz"},
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Pod",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Image: "mytest-image:latest"},
|
||||
},
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
},
|
||||
&api.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "buzpod",
|
||||
Namespace: "foo",
|
||||
Labels: map[string]string{"abc": "xyz"},
|
||||
OwnerReferences: []metav1.OwnerReference{{Name: "buz", UID: "654321", Controller: boolPtr(true)}},
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Pod",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Image: "mytest-image:latest"},
|
||||
},
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
},
|
||||
})
|
||||
d := ReplicationControllerDescriber{f}
|
||||
out, err := d.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: false})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !strings.Contains(out, "1 Running") {
|
||||
t.Errorf("unexpected out: %s", out)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user