From a1b7785e2e1bbb22bf356379083eedeac8602de6 Mon Sep 17 00:00:00 2001 From: David Eads Date: Wed, 21 Feb 2018 10:19:02 -0500 Subject: [PATCH 1/2] Revert "fix resource filter for generic printers on get" This reverts commit 799a0bf41023b02e84a5551a5030b34ffe410919. --- pkg/kubectl/resource_filter.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/pkg/kubectl/resource_filter.go b/pkg/kubectl/resource_filter.go index 67008db961f..b873748f688 100644 --- a/pkg/kubectl/resource_filter.go +++ b/pkg/kubectl/resource_filter.go @@ -18,9 +18,7 @@ package kubectl import ( "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/printers" ) @@ -52,27 +50,6 @@ func filterPods(obj runtime.Object, options printers.PrintOptions) bool { return p.Status.Phase == v1.PodSucceeded || p.Status.Phase == v1.PodFailed case *api.Pod: return p.Status.Phase == api.PodSucceeded || p.Status.Phase == api.PodFailed - case *unstructured.Unstructured: - if (p.GroupVersionKind().GroupKind() != schema.GroupKind{Kind: "Pod"}) { - return false - } - status, ok := p.Object["status"] - if !ok { - return false - } - statusMap, ok := status.(map[string]interface{}) - if !ok { - return false - } - phase, ok := statusMap["phase"] - if !ok { - return false - } - phaseString, ok := phase.(string) - if !ok { - return false - } - return phaseString == string(api.PodSucceeded) || phaseString == string(api.PodFailed) } return false } From f9a884d3f588b84262377d8560003264bc004ddd Mon Sep 17 00:00:00 2001 From: David Eads Date: Wed, 21 Feb 2018 10:25:23 -0500 Subject: [PATCH 2/2] adjust filtered object test to reflect old weird behavior --- pkg/kubectl/cmd/resource/get_test.go | 35 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/pkg/kubectl/cmd/resource/get_test.go b/pkg/kubectl/cmd/resource/get_test.go index 0e7f1adf2b9..8696ae1e340 100644 --- a/pkg/kubectl/cmd/resource/get_test.go +++ b/pkg/kubectl/cmd/resource/get_test.go @@ -386,16 +386,32 @@ func TestGetObjectsFiltered(t *testing.T) { flags map[string]string expect string }{ - {args: []string{"pods", "foo"}, flags: map[string]string{"show-all": "true"}, resp: first, expect: "pod/foo\n"}, - {args: []string{"pods", "foo"}, resp: first, expect: "pod/foo\n"}, - {args: []string{"pods"}, resp: pods, expect: "pod/foo\npod/bar\n"}, - {args: []string{"pods/foo"}, flags: map[string]string{"show-all": "false"}, resp: first, expect: "pod/foo\n"}, - {args: []string{"pods"}, flags: map[string]string{"show-all": "false", "output": "yaml"}, resp: pods, expect: "pod/bar\n"}, - {args: []string{}, flags: map[string]string{"show-all": "false", "filename": "../../../../examples/storage/cassandra/cassandra-controller.yaml"}, resp: pods, expect: "pod/foo\npod/bar\n"}, + {args: []string{"pods", "foo"}, resp: first, flags: map[string]string{"show-all": "true"}, + expect: "NAME READY STATUS RESTARTS AGE\nfoo 0/0 Failed 0 \n"}, - {args: []string{"pods"}, flags: map[string]string{"show-all": "false"}, resp: pods, expect: "pod/bar\n"}, - {args: []string{"pods"}, flags: map[string]string{"show-all": "true", "output": "yaml"}, resp: pods, expect: "pod/foo\npod/bar\n"}, - {args: []string{"pods"}, flags: map[string]string{"show-all": "false"}, resp: pods, expect: "pod/bar\n"}, + {args: []string{"pods", "foo"}, flags: map[string]string{"show-all": "false"}, resp: first, + expect: "NAME READY STATUS RESTARTS AGE\nfoo 0/0 Failed 0 \n"}, + + {args: []string{"pods"}, flags: map[string]string{"show-all": "true"}, resp: pods, + expect: "NAME READY STATUS RESTARTS AGE\nfoo 0/0 Failed 0 \nbar 0/0 0 \n"}, + + {args: []string{"pods/foo"}, resp: first, flags: map[string]string{"show-all": "false"}, + expect: "NAME READY STATUS RESTARTS AGE\nfoo 0/0 Failed 0 \n"}, + + {args: []string{"pods"}, flags: map[string]string{"show-all": "false", "output": "name"}, resp: pods, + expect: "pod/foo\npod/bar\n"}, + + {args: []string{}, flags: map[string]string{"show-all": "false", "filename": "../../../../examples/storage/cassandra/cassandra-controller.yaml"}, resp: pods, + expect: "NAME READY STATUS RESTARTS AGE\nfoo 0/0 Failed 0 \nbar 0/0 0 \n"}, + + {args: []string{"pods"}, resp: pods, flags: map[string]string{"show-all": "false"}, + expect: "NAME READY STATUS RESTARTS AGE\nbar 0/0 0 \n"}, + + {args: []string{"pods"}, flags: map[string]string{"show-all": "true", "output": "name"}, resp: pods, + expect: "pod/foo\npod/bar\n"}, + + {args: []string{"pods"}, flags: map[string]string{"show-all": "false"}, resp: pods, + expect: "NAME READY STATUS RESTARTS AGE\nbar 0/0 0 \n"}, } for i, test := range testCases { @@ -417,7 +433,6 @@ func TestGetObjectsFiltered(t *testing.T) { for k, v := range test.flags { cmd.Flags().Lookup(k).Value.Set(v) } - cmd.Flags().Set("output", "name") cmd.Run(cmd, test.args) if e, a := test.expect, buf.String(); e != a {