From 4e7c10a520c0c4f8feb8ca9185168e2496a2f56f Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Wed, 1 Mar 2017 18:33:08 -0500 Subject: [PATCH] Don't bypass filter on generic output It is inconsistent and confusing (filtering is orthogonal from output) and we don't want to regress behavior from 1.5. --- hack/lib/test.sh | 4 ++-- pkg/kubectl/cmd/get.go | 14 ++++---------- pkg/kubectl/cmd/get_test.go | 7 ++++--- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/hack/lib/test.sh b/hack/lib/test.sh index 1771a82160f..901777876d6 100644 --- a/hack/lib/test.sh +++ b/hack/lib/test.sh @@ -76,7 +76,7 @@ kube::test::object_assert() { local args=${5:-} for j in $(seq 1 ${tries}); do - res=$(eval kubectl get "${kube_flags[@]}" ${args} $object -o go-template=\"$request\") + res=$(eval kubectl get -a "${kube_flags[@]}" ${args} $object -o go-template=\"$request\") if [[ "$res" =~ ^$expected$ ]]; then echo -n ${green} echo "$(kube::test::get_caller 3): Successful get $object $request: $res" @@ -103,7 +103,7 @@ kube::test::get_object_jsonpath_assert() { local request=$2 local expected=$3 - res=$(eval kubectl get "${kube_flags[@]}" $object -o jsonpath=\"$request\") + res=$(eval kubectl get -a "${kube_flags[@]}" $object -o jsonpath=\"$request\") if [[ "$res" =~ ^$expected$ ]]; then echo -n ${green} diff --git a/pkg/kubectl/cmd/get.go b/pkg/kubectl/cmd/get.go index bde9402a396..6d8968aa8bc 100644 --- a/pkg/kubectl/cmd/get.go +++ b/pkg/kubectl/cmd/get.go @@ -54,11 +54,12 @@ var ( ` + valid_resources + ` - This command will hide resources that have completed. For instance, pods that are in the Succeeded or Failed phases. - You can see the full results for any resource by providing the '--show-all' flag. + This command will hide resources that have completed, such as pods that are + in the Succeeded or Failed phases. You can see the full results for any + resource by providing the '--show-all' flag. By specifying the output as 'template' and providing a Go template as the value - of the --template flag, you can filter the attributes of the fetched resource(s).`) + of the --template flag, you can filter the attributes of the fetched resources.`) get_example = templates.Examples(` # List all pods in ps output format. @@ -184,13 +185,6 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ return cmdutil.UsageError(cmd, usageString) } - // always show resources when getting by name or filename, or if the output - // is machine-consumable, or if multiple resource kinds were requested. - if cmdutil.OutputsRawFormat(cmd) { - if !cmd.Flag("show-all").Changed { - cmd.Flag("show-all").Value.Set("true") - } - } export := cmdutil.GetFlagBool(cmd, "export") filterFuncs := f.DefaultResourceFilterFunc() diff --git a/pkg/kubectl/cmd/get_test.go b/pkg/kubectl/cmd/get_test.go index 3b15124ae83..cdd67fe6b66 100644 --- a/pkg/kubectl/cmd/get_test.go +++ b/pkg/kubectl/cmd/get_test.go @@ -229,10 +229,11 @@ func TestGetObjectsFiltered(t *testing.T) { {args: []string{"pods", "foo"}, flags: map[string]string{"show-all": "false"}, resp: first, expect: []runtime.Object{first}}, {args: []string{"pods"}, flags: map[string]string{"show-all": "true"}, resp: pods, expect: []runtime.Object{first, second}}, {args: []string{"pods/foo"}, resp: first, expect: []runtime.Object{first}}, - {args: []string{"pods"}, flags: map[string]string{"output": "yaml"}, resp: pods, expect: []runtime.Object{first, second}}, + {args: []string{"pods"}, flags: map[string]string{"output": "yaml"}, resp: pods, expect: []runtime.Object{second}}, {args: []string{}, flags: map[string]string{"filename": "../../../examples/storage/cassandra/cassandra-controller.yaml"}, resp: pods, expect: []runtime.Object{first, second}}, {args: []string{"pods"}, resp: pods, expect: []runtime.Object{second}}, + {args: []string{"pods"}, flags: map[string]string{"show-all": "true", "output": "yaml"}, resp: pods, expect: []runtime.Object{first, second}}, {args: []string{"pods"}, flags: map[string]string{"show-all": "false"}, resp: pods, expect: []runtime.Object{second}}, } @@ -731,8 +732,8 @@ func TestGetByFormatForcesFlag(t *testing.T) { cmd.Run(cmd, []string{"pods"}) showAllFlag, _ := cmd.Flags().GetBool("show-all") - if !showAllFlag { - t.Errorf("expected showAll to be true when getting resource by name") + if showAllFlag { + t.Errorf("expected showAll to not be true when getting resource") } }