From 71a1970bf6848d33dd58a055aecfb57ae13f39ed Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Tue, 13 Mar 2018 15:24:24 +0800 Subject: [PATCH] --show-all is inert in v1.11 --- hack/make-rules/test-cmd-util.sh | 2 - pkg/kubectl/BUILD | 3 - pkg/kubectl/cmd/cmd_test.go | 36 +-------- pkg/kubectl/cmd/convert.go | 8 +- pkg/kubectl/cmd/resource/get.go | 79 +++++-------------- pkg/kubectl/cmd/resource/get_test.go | 72 ----------------- pkg/kubectl/cmd/util/factory.go | 3 - pkg/kubectl/cmd/util/factory_client_access.go | 4 - pkg/kubectl/cmd/util/helpers.go | 52 ------------ pkg/kubectl/resource_filter.go | 65 --------------- pkg/kubectl/resource_filter_test.go | 76 ------------------ pkg/printers/humanreadable.go | 3 - pkg/printers/internalversion/printers_test.go | 10 +-- 13 files changed, 28 insertions(+), 385 deletions(-) delete mode 100644 pkg/kubectl/resource_filter.go delete mode 100644 pkg/kubectl/resource_filter_test.go diff --git a/hack/make-rules/test-cmd-util.sh b/hack/make-rules/test-cmd-util.sh index 34fcbfefcc9..a0539096e27 100755 --- a/hack/make-rules/test-cmd-util.sh +++ b/hack/make-rules/test-cmd-util.sh @@ -5253,8 +5253,6 @@ run_initializer_tests() { output_message=$(kubectl get deployments web 2>&1 "${kube_flags[@]}") # Post-condition: I assume "web" is the deployment name kube::test::if_has_string "${output_message}" 'web' - # Command - output_message=$(kubectl get deployments --show-all 2>&1 "${kube_flags[@]}") # Post-condition: The text "No resources found" should be part of the output kube::test::if_has_string "${output_message}" 'No resources found' diff --git a/pkg/kubectl/BUILD b/pkg/kubectl/BUILD index 7fe68ccde17..c08677e00b3 100644 --- a/pkg/kubectl/BUILD +++ b/pkg/kubectl/BUILD @@ -21,7 +21,6 @@ go_test( "pdb_test.go", "priorityclass_test.go", "quota_test.go", - "resource_filter_test.go", "rolebinding_test.go", "rollback_test.go", "rolling_updater_test.go", @@ -52,7 +51,6 @@ go_test( "//pkg/client/clientset_generated/internalclientset/typed/core/internalversion:go_default_library", "//pkg/client/clientset_generated/internalclientset/typed/extensions/internalversion:go_default_library", "//pkg/kubectl/util:go_default_library", - "//pkg/printers:go_default_library", "//vendor/github.com/spf13/cobra:go_default_library", "//vendor/k8s.io/api/apps/v1beta1:go_default_library", "//vendor/k8s.io/api/apps/v1beta2:go_default_library", @@ -112,7 +110,6 @@ go_library( "pdb.go", "priorityclass.go", "quota.go", - "resource_filter.go", "rolebinding.go", "rollback.go", "rolling_updater.go", diff --git a/pkg/kubectl/cmd/cmd_test.go b/pkg/kubectl/cmd/cmd_test.go index b694aa640fb..5e020dc9b88 100644 --- a/pkg/kubectl/cmd/cmd_test.go +++ b/pkg/kubectl/cmd/cmd_test.go @@ -466,49 +466,17 @@ func Example_printPodShowTerminated() { } cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr) podList := newAllPhasePodList() - // filter pods - filterFuncs := tf.DefaultResourceFilterFunc() - filterOpts := cmdutil.ExtractCmdPrintOptions(cmd, false) - _, filteredPodList, errs := cmdutil.FilterResourceList(podList, filterFuncs, filterOpts) - if errs != nil { - fmt.Printf("Unexpected filter error: %v\n", errs) - } printer, err := cmdutil.PrinterForOptions(cmdutil.ExtractCmdPrintOptions(cmd, false)) if err != nil { - fmt.Printf("Unexpected printer get error: %v\n", errs) + fmt.Printf("Unexpected printer get error: %v\n", err) } - for _, pod := range filteredPodList { + for _, pod := range []runtime.Object{podList} { err := printer.PrintObj(pod, os.Stdout) if err != nil { fmt.Printf("Unexpected error: %v", err) } } // Output: - // NAME READY STATUS RESTARTS AGE - // test1 1/2 Pending 6 10y - // test2 1/2 Running 6 10y - // test3 1/2 Succeeded 6 10y - // test4 1/2 Failed 6 10y - // test5 1/2 Unknown 6 10y -} - -func Example_printPodShowAll() { - tf := cmdtesting.NewTestFactory() - defer tf.Cleanup() - - ns := legacyscheme.Codecs - - tf.Client = &fake.RESTClient{ - NegotiatedSerializer: ns, - Client: nil, - } - cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr) - podList := newAllPhasePodList() - err := cmdutil.PrintObject(cmd, podList, os.Stdout) - if err != nil { - fmt.Printf("Unexpected error: %v", err) - } - // Output: // NAME READY STATUS RESTARTS AGE // test1 1/2 Pending 6 10y // test2 1/2 Running 6 10y diff --git a/pkg/kubectl/cmd/convert.go b/pkg/kubectl/cmd/convert.go index 3a094b91787..1eff1056847 100644 --- a/pkg/kubectl/cmd/convert.go +++ b/pkg/kubectl/cmd/convert.go @@ -182,15 +182,11 @@ func (o *ConvertOptions) RunConvert() error { } if meta.IsListType(objects) { - _, items, err := cmdutil.FilterResourceList(objects, nil, nil) + obj, err := objectListToVersionedObject([]runtime.Object{objects}, o.specifiedOutputVersion) if err != nil { return err } - filteredObj, err := objectListToVersionedObject(items, o.specifiedOutputVersion) - if err != nil { - return err - } - return o.printer.PrintObj(filteredObj, o.out) + return o.printer.PrintObj(obj, o.out) } return o.printer.PrintObj(objects, o.out) diff --git a/pkg/kubectl/cmd/resource/get.go b/pkg/kubectl/cmd/resource/get.go index 4edb02a34d0..e7b7344a653 100644 --- a/pkg/kubectl/cmd/resource/get.go +++ b/pkg/kubectl/cmd/resource/get.go @@ -287,14 +287,8 @@ func (options *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []str return err } - filterOpts := cmdutil.ExtractCmdPrintOptions(cmd, options.AllNamespaces) - filterFuncs := f.DefaultResourceFilterFunc() - if r.TargetsSingleItems() { - filterFuncs = nil - } - if printer.IsGeneric() { - return options.printGeneric(printer, r, filterFuncs, filterOpts) + return options.printGeneric(printer, r) } allErrs := []error{} @@ -341,7 +335,6 @@ func (options *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []str showKind := options.ShowKind || resource.MultipleTypesRequested(args) || cmdutil.MustPrintWithKinds(objs, infos, sorter) - filteredResourceCount := 0 noHeaders := cmdutil.GetFlagBool(cmd, "no-headers") for ix := range objs { var mapping *meta.RESTMapping @@ -403,18 +396,6 @@ func (options *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []str typedObj := info.AsInternal() - // filter objects if filter has been defined for current object - if isFiltered, err := filterFuncs.Filter(typedObj, filterOpts); isFiltered { - if err == nil { - filteredResourceCount++ - continue - } - if !errs.Has(err.Error()) { - errs.Insert(err.Error()) - allErrs = append(allErrs, err) - } - } - if resourcePrinter, found := printer.(*printers.HumanReadablePrinter); found { resourceName := resourcePrinter.GetResourceKind() if mapping != nil { @@ -469,7 +450,9 @@ func (options *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []str nonEmptyObjCount++ } - cmdutil.PrintFilterCount(options.ErrOut, nonEmptyObjCount, filteredResourceCount, len(allErrs), filterOpts, options.IgnoreNotFound) + if nonEmptyObjCount == 0 && !options.IgnoreNotFound { + fmt.Fprintln(options.ErrOut, "No resources found.") + } return utilerrors.NewAggregate(allErrs) } @@ -538,12 +521,6 @@ func (options *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []s } } - filterOpts := cmdutil.ExtractCmdPrintOptions(cmd, options.AllNamespaces) - filterFuncs := f.DefaultResourceFilterFunc() - if r.TargetsSingleItems() { - filterFuncs = nil - } - info := infos[0] mapping := info.ResourceMapping() printOpts := cmdutil.ExtractCmdPrintOptions(cmd, options.AllNamespaces) @@ -582,18 +559,11 @@ func (options *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []s objsToPrint = append(objsToPrint, obj) } for _, objToPrint := range objsToPrint { - if isFiltered, err := filterFuncs.Filter(objToPrint, filterOpts); !isFiltered { - if err != nil { - glog.V(2).Infof("Unable to filter resource: %v", err) - continue - } - - // printing always takes the internal version, but the watch event uses externals - // TODO fix printing to use server-side or be version agnostic - internalGV := mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion() - if err := printer.PrintObj(attemptToConvertToInternal(objToPrint, mapping, internalGV), writer); err != nil { - return fmt.Errorf("unable to output the provided object: %v", err) - } + // printing always takes the internal version, but the watch event uses externals + // TODO fix printing to use server-side or be version agnostic + internalGV := mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion() + if err := printer.PrintObj(attemptToConvertToInternal(objToPrint, mapping, internalGV), writer); err != nil { + return fmt.Errorf("unable to output the provided object: %v", err) } } writer.Flush() @@ -615,18 +585,11 @@ func (options *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []s return false, nil } - if isFiltered, err := filterFuncs.Filter(e.Object, filterOpts); !isFiltered { - if err != nil { - glog.V(2).Infof("Unable to filter resource: %v", err) - return false, nil - } - - // printing always takes the internal version, but the watch event uses externals - // TODO fix printing to use server-side or be version agnostic - internalGV := mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion() - if err := printer.PrintObj(attemptToConvertToInternal(e.Object, mapping, internalGV), options.Out); err != nil { - return false, err - } + // printing always takes the internal version, but the watch event uses externals + // TODO fix printing to use server-side or be version agnostic + internalGV := mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion() + if err := printer.PrintObj(attemptToConvertToInternal(e.Object, mapping, internalGV), options.Out); err != nil { + return false, err } return false, nil }) @@ -664,7 +627,7 @@ func (options *GetOptions) decodeIntoTable(encoder runtime.Encoder, obj runtime. return table, nil } -func (options *GetOptions) printGeneric(printer printers.ResourcePrinter, r *resource.Result, filterFuncs kubectl.Filters, filterOpts *printers.PrintOptions) error { +func (options *GetOptions) printGeneric(printer printers.ResourcePrinter, r *resource.Result) error { // we flattened the data from the builder, so we have individual items, but now we'd like to either: // 1. if there is more than one item, combine them all into a single list // 2. if there is a single item and that item is a list, leave it as its specific list @@ -717,12 +680,12 @@ func (options *GetOptions) printGeneric(printer printers.ResourcePrinter, r *res isList := meta.IsListType(obj) if isList { - _, items, err := cmdutil.FilterResourceList(obj, filterFuncs, filterOpts) + items, err := meta.ExtractList(obj) if err != nil { return err } - // take the filtered items and create a new list for display + // take the items and create a new list for display list := &unstructured.UnstructuredList{ Object: map[string]interface{}{ "kind": "List", @@ -746,12 +709,8 @@ func (options *GetOptions) printGeneric(printer printers.ResourcePrinter, r *res return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs))) } - if isFiltered, err := filterFuncs.Filter(obj, filterOpts); !isFiltered { - if err != nil { - glog.V(2).Infof("Unable to filter resource: %v", err) - } else if err := printer.PrintObj(obj, options.Out); err != nil { - errs = append(errs, err) - } + if printErr := printer.PrintObj(obj, options.Out); printErr != nil { + errs = append(errs, printErr) } return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs))) diff --git a/pkg/kubectl/cmd/resource/get_test.go b/pkg/kubectl/cmd/resource/get_test.go index 162fa6392d8..897455e38eb 100644 --- a/pkg/kubectl/cmd/resource/get_test.go +++ b/pkg/kubectl/cmd/resource/get_test.go @@ -19,7 +19,6 @@ package resource import ( "bytes" encjson "encoding/json" - "fmt" "io" "io/ioutil" "net/http" @@ -377,77 +376,6 @@ foo 0/0 0 } } -func TestGetObjectsFiltered(t *testing.T) { - initTestErrorHandler(t) - - pods, _, _ := testData() - pods.Items[0].Status.Phase = api.PodFailed - first := &pods.Items[0] - - testCases := []struct { - args []string - resp runtime.Object - flags map[string]string - expect string - }{ - {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", "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": "../../../../test/e2e/testing-manifests/statefulset/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 { - t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { - tf := cmdtesting.NewTestFactory() - defer tf.Cleanup() - defer tf.Cleanup() - codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) - - tf.UnstructuredClient = &fake.RESTClient{ - GroupVersion: schema.GroupVersion{Version: "v1"}, - NegotiatedSerializer: unstructuredSerializer, - Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, test.resp)}, - } - tf.Namespace = "test" - buf := bytes.NewBuffer([]byte{}) - errBuf := bytes.NewBuffer([]byte{}) - - cmd := NewCmdGet(tf, buf, errBuf) - cmd.SetOutput(buf) - for k, v := range test.flags { - cmd.Flags().Lookup(k).Value.Set(v) - } - cmd.Run(cmd, test.args) - - if e, a := test.expect, buf.String(); e != a { - t.Errorf("expected %q, got %q", e, a) - } - }) - } -} - func TestGetObjectIgnoreNotFound(t *testing.T) { initTestErrorHandler(t) diff --git a/pkg/kubectl/cmd/util/factory.go b/pkg/kubectl/cmd/util/factory.go index 3cb44ab4db9..074af63e7f5 100644 --- a/pkg/kubectl/cmd/util/factory.go +++ b/pkg/kubectl/cmd/util/factory.go @@ -127,9 +127,6 @@ type ClientAccessFactory interface { // BindExternalFlags adds any flags defined by external projects (not part of pflags) BindExternalFlags(flags *pflag.FlagSet) - // DefaultResourceFilterFunc returns a collection of FilterFuncs suitable for filtering specific resource types. - DefaultResourceFilterFunc() kubectl.Filters - // SuggestedPodTemplateResources returns a list of resource types that declare a pod template SuggestedPodTemplateResources() []schema.GroupResource diff --git a/pkg/kubectl/cmd/util/factory_client_access.go b/pkg/kubectl/cmd/util/factory_client_access.go index 4ca24730962..831ec8b05a3 100644 --- a/pkg/kubectl/cmd/util/factory_client_access.go +++ b/pkg/kubectl/cmd/util/factory_client_access.go @@ -403,10 +403,6 @@ func (f *ring0Factory) BindExternalFlags(flags *pflag.FlagSet) { flags.AddGoFlagSet(flag.CommandLine) } -func (f *ring0Factory) DefaultResourceFilterFunc() kubectl.Filters { - return kubectl.NewResourceFilter() -} - func (f *ring0Factory) SuggestedPodTemplateResources() []schema.GroupResource { return []schema.GroupResource{ {Resource: "replicationcontroller"}, diff --git a/pkg/kubectl/cmd/util/helpers.go b/pkg/kubectl/cmd/util/helpers.go index 5a5409c5f57..a176e9e4c7f 100644 --- a/pkg/kubectl/cmd/util/helpers.go +++ b/pkg/kubectl/cmd/util/helpers.go @@ -43,10 +43,8 @@ import ( "k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/tools/clientcmd" - "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/kubectl" "k8s.io/kubernetes/pkg/kubectl/resource" - "k8s.io/kubernetes/pkg/printers" utilexec "k8s.io/utils/exec" ) @@ -689,56 +687,6 @@ func MustPrintWithKinds(objs []runtime.Object, infos []*resource.Info, sorter *k return false } -// FilterResourceList receives a list of runtime objects. -// If any objects are filtered, that number is returned along with a modified list. -func FilterResourceList(obj runtime.Object, filterFuncs kubectl.Filters, filterOpts *printers.PrintOptions) (int, []runtime.Object, error) { - items, err := meta.ExtractList(obj) - if err != nil { - return 0, []runtime.Object{obj}, utilerrors.NewAggregate([]error{err}) - } - if errs := runtime.DecodeList(items, legacyscheme.Codecs.UniversalDecoder(), unstructured.UnstructuredJSONScheme); len(errs) > 0 { - return 0, []runtime.Object{obj}, utilerrors.NewAggregate(errs) - } - - filterCount := 0 - list := make([]runtime.Object, 0, len(items)) - for _, obj := range items { - if isFiltered, err := filterFuncs.Filter(obj, filterOpts); !isFiltered { - if err != nil { - glog.V(2).Infof("Unable to filter resource: %v", err) - continue - } - list = append(list, obj) - } else if isFiltered { - filterCount++ - } - } - return filterCount, list, nil -} - -// PrintFilterCount displays informational messages based on the number of resources found, hidden, or -// config flags shown. -func PrintFilterCount(out io.Writer, found, hidden, errors int, options *printers.PrintOptions, ignoreNotFound bool) { - switch { - case errors > 0 || ignoreNotFound: - // print nothing - case found <= hidden: - if found == 0 { - fmt.Fprintln(out, "No resources found.") - } else { - fmt.Fprintln(out, "No resources found, use --show-all to see completed objects.") - } - case hidden > 0 && !options.ShowAll && !options.NoHeaders: - if glog.V(2) { - if hidden > 1 { - fmt.Fprintf(out, "info: %d objects not shown, use --show-all to see completed objects.\n", hidden) - } else { - fmt.Fprintf(out, "info: 1 object not shown, use --show-all to see completed objects.\n") - } - } - } -} - // IsSiblingCommandExists receives a pointer to a cobra command and a target string. // Returns true if the target string is found in the list of sibling commands. func IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool { diff --git a/pkg/kubectl/resource_filter.go b/pkg/kubectl/resource_filter.go deleted file mode 100644 index b873748f688..00000000000 --- a/pkg/kubectl/resource_filter.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package kubectl - -import ( - "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime" - api "k8s.io/kubernetes/pkg/apis/core" - "k8s.io/kubernetes/pkg/printers" -) - -// FilterFunc is a function that knows how to filter a specific resource kind. -// It receives a generic runtime.Object which must be type-checked by the function. -// Returns a boolean value true if a resource is filtered, or false otherwise. -type FilterFunc func(runtime.Object, printers.PrintOptions) bool - -// Filters is a collection of filter funcs -type Filters []FilterFunc - -func NewResourceFilter() Filters { - return []FilterFunc{ - filterPods, - } -} - -// filterPods returns true if a pod should be skipped. -// If show-all is true, the pod will be never be skipped (return false); -// otherwise, skip terminated pod. -func filterPods(obj runtime.Object, options printers.PrintOptions) bool { - if options.ShowAll { - return false - } - - switch p := obj.(type) { - case *v1.Pod: - 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 - } - return false -} - -// Filter loops through a collection of FilterFuncs until it finds one that can filter the given resource -func (f Filters) Filter(obj runtime.Object, opts *printers.PrintOptions) (bool, error) { - for _, filter := range f { - if ok := filter(obj, *opts); ok { - return true, nil - } - } - return false, nil -} diff --git a/pkg/kubectl/resource_filter_test.go b/pkg/kubectl/resource_filter_test.go deleted file mode 100644 index 7c3335bdf9a..00000000000 --- a/pkg/kubectl/resource_filter_test.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package kubectl - -import ( - "testing" - - "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime" - api "k8s.io/kubernetes/pkg/apis/core" - "k8s.io/kubernetes/pkg/printers" -) - -func TestResourceFilter(t *testing.T) { - tests := []struct { - name string - hide bool - object runtime.Object - }{ - {"v1.Pod pending", false, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodPending}}}, - {"v1.Pod running", false, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodRunning}}}, - {"v1.Pod succeeded", true, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodSucceeded}}}, - {"v1.Pod failed", true, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodFailed}}}, - {"v1.Pod evicted", true, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodFailed, Reason: "Evicted"}}}, - {"v1.Pod unknown", false, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodUnknown}}}, - - {"api.Pod pending", false, &api.Pod{Status: api.PodStatus{Phase: api.PodPending}}}, - {"api.Pod running", false, &api.Pod{Status: api.PodStatus{Phase: api.PodRunning}}}, - {"api.Pod succeeded", true, &api.Pod{Status: api.PodStatus{Phase: api.PodSucceeded}}}, - {"api.Pod failed", true, &api.Pod{Status: api.PodStatus{Phase: api.PodFailed}}}, - {"api.Pod evicted", true, &api.Pod{Status: api.PodStatus{Phase: api.PodFailed, Reason: "Evicted"}}}, - {"api.Pod unknown", false, &api.Pod{Status: api.PodStatus{Phase: api.PodUnknown}}}, - } - - filters := NewResourceFilter() - - options := &printers.PrintOptions{ - ShowAll: false, - } - for _, test := range tests { - got, err := filters.Filter(test.object, options) - if err != nil { - t.Errorf("%v: unexpected error: %v", test.name, err) - continue - } - if want := test.hide; got != want { - t.Errorf("%v: got %v, want %v", test.name, got, want) - } - } - - options.ShowAll = true - for _, test := range tests { - got, err := filters.Filter(test.object, options) - if err != nil { - t.Errorf("%v: unexpected error: %v", test.name, err) - continue - } - if want := false; got != want { - t.Errorf("%v (ShowAll): got %v, want %v", test.name, got, want) - } - } -} diff --git a/pkg/printers/humanreadable.go b/pkg/printers/humanreadable.go index 4e4b7c6543e..9a9be21469e 100644 --- a/pkg/printers/humanreadable.go +++ b/pkg/printers/humanreadable.go @@ -375,9 +375,6 @@ func PrintTable(table *metav1beta1.Table, output io.Writer, options PrintOptions fmt.Fprintln(output) } for _, row := range table.Rows { - if !options.ShowAll && hasCondition(row.Conditions, metav1beta1.RowCompleted) { - continue - } first := true for i, cell := range row.Cells { column := table.ColumnDefinitions[i] diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index 474e599a3ea..62c9c70799f 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -1542,7 +1542,7 @@ func TestPrintPodTable(t *testing.T) { expect: "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\tLABELS\ntest1\t1/2\tRunning\t6\t\ta=1,b=2\n", }, { - obj: &api.PodList{Items: []api.Pod{*runningPod, *failedPod}}, opts: printers.PrintOptions{ShowAll: true, ColumnLabels: []string{"a"}}, + obj: &api.PodList{Items: []api.Pod{*runningPod, *failedPod}}, opts: printers.PrintOptions{ColumnLabels: []string{"a"}}, expect: "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\tA\ntest1\t1/2\tRunning\t6\t\t1\ntest2\t1/2\tFailed\t6\t\t\n", }, { @@ -1551,11 +1551,11 @@ func TestPrintPodTable(t *testing.T) { }, { obj: failedPod, opts: printers.PrintOptions{}, - expect: "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\n", + expect: "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\ntest2\t1/2\tFailed\t6\t\n", ignoreLegacy: true, // filtering is not done by the printer in the legacy path }, { - obj: failedPod, opts: printers.PrintOptions{ShowAll: true}, + obj: failedPod, opts: printers.PrintOptions{}, expect: "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\ntest2\t1/2\tFailed\t6\t\n", }, } @@ -1671,7 +1671,7 @@ func TestPrintPod(t *testing.T) { } for i, test := range tests { - rows, err := printPod(&test.pod, printers.PrintOptions{ShowAll: true}) + rows, err := printPod(&test.pod, printers.PrintOptions{}) if err != nil { t.Fatal(err) } @@ -1781,7 +1781,7 @@ func TestPrintPodList(t *testing.T) { } for _, test := range tests { - rows, err := printPodList(&test.pods, printers.PrintOptions{ShowAll: true}) + rows, err := printPodList(&test.pods, printers.PrintOptions{}) if err != nil { t.Fatal(err)