From e4a3e8b4d0e64d877a657e404e1e336275e301fc Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Mon, 19 Sep 2016 17:07:30 -0400 Subject: [PATCH] UPSTREAM: 31163: add resource filter handling UPSTREAM: https://github.com/kubernetes/kubernetes/pull/31163 Fixes https://github.com/openshift/origin/issues/9901 Resources are currently filtered (in order to prevent printing) at print time in their HumanReadablePrinter handlers. This design makes it not possible to filter objects when they are printed using any other printer, such as YAML, JSON, or the NamePrinter. This patch removes any filters previously added at the printer level for pods and adds a way to define resource-specific filters before they are sent to a printer handler. A woking filter handler for pods has also been implemented. Filters affect resources being printed through the HumanReadablePrinter, YAML, JSON, and `--template` printers. --- .../kubernetes/pkg/kubectl/cmd/cmd_test.go | 22 +++-- .../k8s.io/kubernetes/pkg/kubectl/cmd/get.go | 88 ++++++++++++------- .../pkg/kubectl/cmd/util/factory.go | 23 +++++ .../pkg/kubectl/cmd/util/helpers.go | 76 +++++++++++++++- .../kubernetes/pkg/kubectl/resource/result.go | 8 +- .../kubernetes/pkg/kubectl/resource_filter.go | 67 ++++++++++++++ .../pkg/kubectl/resource_printer.go | 24 +---- .../pkg/kubectl/resource_printer_test.go | 20 +---- 8 files changed, 245 insertions(+), 83 deletions(-) create mode 100644 vendor/k8s.io/kubernetes/pkg/kubectl/resource_filter.go diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/cmd_test.go b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/cmd_test.go index cf7d1af64883..185d31b713ee 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/cmd_test.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/cmd_test.go @@ -723,16 +723,26 @@ func Example_printPodHideTerminated() { } cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) podList := newAllPhasePodList() - mapper, _ := f.Object(false) - err := f.PrintObject(cmd, mapper, podList, os.Stdout) - if err != nil { - fmt.Printf("Unexpected error: %v", err) + + // filter pods + filterFuncs := f.DefaultResourceFilterFunc() + filterOpts := f.DefaultResourceFilterOptions(cmd, false) + _, filteredPodList, errs := cmdutil.FilterResourceList(podList, filterFuncs, filterOpts) + if errs != nil { + fmt.Printf("Unexpected filter error: %v\n", errs) + } + for _, pod := range filteredPodList { + mapper, _ := f.Object(false) + err := f.PrintObject(cmd, mapper, 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 - // test5 1/2 Unknown 6 10y + // test2 1/2 Running 6 10y + // test5 1/2 Unknown 6 10y } func Example_printPodShowAll() { diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get.go b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get.go index 6551226ca6bf..99d78387dd47 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get.go @@ -20,6 +20,7 @@ import ( "fmt" "io" + "github.com/golang/glog" "github.com/renstrom/dedent" "github.com/spf13/cobra" "k8s.io/kubernetes/pkg/api/meta" @@ -156,6 +157,8 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm allNamespaces := cmdutil.GetFlagBool(cmd, "all-namespaces") showKind := cmdutil.GetFlagBool(cmd, "show-kind") mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd)) + filterFuncs := f.DefaultResourceFilterFunc() + filterOpts := f.DefaultResourceFilterOptions(cmd, allNamespaces) cmdNamespace, enforceNamespace, err := f.DefaultNamespace() if err != nil { @@ -231,11 +234,13 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm } // print the current object + filteredResourceCount := 0 if !isWatchOnly { if err := printer.PrintObj(obj, out); err != nil { return fmt.Errorf("unable to output the provided object: %v", err) } - printer.FinishPrint(errOut, mapping.Resource) + filteredResourceCount++ + cmdutil.PrintFilterCount(filteredResourceCount, mapping.Resource, errOut, filterOpts) } // print watched changes @@ -245,6 +250,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm } first := true + filteredResourceCount = 0 kubectl.WatchLoop(w, func(e watch.Event) error { if !isList && first { // drop the initial watch event in the single resource case @@ -253,7 +259,8 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm } err := printer.PrintObj(e.Object, out) if err == nil { - printer.FinishPrint(errOut, mapping.Resource) + filteredResourceCount++ + cmdutil.PrintFilterCount(filteredResourceCount, mapping.Resource, errOut, filterOpts) } return err }) @@ -312,9 +319,36 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm return err } - err = printer.PrintObj(obj, out) - printer.FinishPrint(errOut, res) - return err + isList := meta.IsListType(obj) + if isList { + filteredResourceCount, items, errs := cmdutil.FilterResourceList(obj, filterFuncs, filterOpts) + if errs != nil { + return errs + } + filteredObj, err := cmdutil.ObjectListToVersionedObject(items, version) + if err != nil { + return err + } + if err := printer.PrintObj(filteredObj, out); err != nil { + allErrs = append(allErrs, err) + } + + cmdutil.PrintFilterCount(filteredResourceCount, res, errOut, filterOpts) + return utilerrors.NewAggregate(allErrs) + } + + filteredResourceCount := 0 + 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, out); err != nil { + allErrs = append(allErrs, err) + } + } else if isFiltered { + filteredResourceCount++ + } + cmdutil.PrintFilterCount(filteredResourceCount, res, errOut, filterOpts) + return utilerrors.NewAggregate(allErrs) } allErrs := []error{} @@ -362,8 +396,9 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm printer = nil var lastMapping *meta.RESTMapping w := kubectl.GetNewTabWriter(out) + filteredResourceCount := 0 - if mustPrintWithKinds(objs, infos, sorter) { + if cmdutil.MustPrintWithKinds(objs, infos, sorter) { showKind = true } @@ -380,7 +415,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm if printer == nil || lastMapping == nil || mapping == nil || mapping.Resource != lastMapping.Resource { if printer != nil { w.Flush() - printer.FinishPrint(errOut, lastMapping.Resource) + cmdutil.PrintFilterCount(filteredResourceCount, lastMapping.Resource, errOut, filterOpts) } printer, err = f.PrinterForMapping(cmd, mapping, allNamespaces) if err != nil { @@ -389,6 +424,16 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm } lastMapping = mapping } + + // filter objects if filter has been defined for current object + if isFiltered, err := filterFuncs.Filter(original, filterOpts); isFiltered { + if err == nil { + filteredResourceCount++ + continue + } + allErrs = append(allErrs, err) + } + if resourcePrinter, found := printer.(*kubectl.HumanReadablePrinter); found { resourceName := resourcePrinter.GetResourceKind() if mapping != nil { @@ -419,33 +464,8 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm } } w.Flush() - if printer != nil { - printer.FinishPrint(errOut, lastMapping.Resource) + if printer != nil && lastMapping != nil { + cmdutil.PrintFilterCount(filteredResourceCount, lastMapping.Resource, errOut, filterOpts) } return utilerrors.NewAggregate(allErrs) } - -// mustPrintWithKinds determines if printer is dealing -// with multiple resource kinds, in which case it will -// return true, indicating resource kind will be -// included as part of printer output -func mustPrintWithKinds(objs []runtime.Object, infos []*resource.Info, sorter *kubectl.RuntimeSort) bool { - var lastMap *meta.RESTMapping - - for ix := range objs { - var mapping *meta.RESTMapping - if sorter != nil { - mapping = infos[sorter.OriginalPosition(ix)].Mapping - } else { - mapping = infos[ix].Mapping - } - - // display "kind" only if we have mixed resources - if lastMap != nil && mapping.Resource != lastMap.Resource { - return true - } - lastMap = mapping - } - - return false -} diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/factory.go b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/factory.go index 49ffb4d953ee..72d6c0fc3977 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/factory.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/factory.go @@ -1239,6 +1239,29 @@ func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig { return clientConfig } +func (f *Factory) DefaultResourceFilterOptions(cmd *cobra.Command, withNamespace bool) *kubectl.PrintOptions { + columnLabel, err := cmd.Flags().GetStringSlice("label-columns") + if err != nil { + columnLabel = []string{} + } + opts := &kubectl.PrintOptions{ + NoHeaders: GetFlagBool(cmd, "no-headers"), + WithNamespace: withNamespace, + Wide: GetWideFlag(cmd), + ShowAll: GetFlagBool(cmd, "show-all"), + ShowLabels: GetFlagBool(cmd, "show-labels"), + AbsoluteTimestamps: isWatch(cmd), + ColumnLabels: columnLabel, + } + + return opts +} + +// DefaultResourceFilterFunc returns a collection of FilterFuncs suitable for filtering specific resource types. +func (f *Factory) DefaultResourceFilterFunc() kubectl.Filters { + return kubectl.NewResourceFilter() +} + // PrintObject prints an api object given command line flags to modify the output format func (f *Factory) PrintObject(cmd *cobra.Command, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error { gvks, _, err := api.Scheme.ObjectKinds(obj) diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/helpers.go b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/helpers.go index adc82b6b227a..e42e81997571 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/helpers.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/helpers.go @@ -28,6 +28,7 @@ import ( "strings" "time" + "k8s.io/kubernetes/pkg/api" kerrors "k8s.io/kubernetes/pkg/api/errors" "k8s.io/kubernetes/pkg/api/meta" "k8s.io/kubernetes/pkg/api/unversioned" @@ -43,7 +44,7 @@ import ( "k8s.io/kubernetes/pkg/util/sets" "k8s.io/kubernetes/pkg/util/strategicpatch" - "github.com/evanphx/json-patch" + jsonpatch "github.com/evanphx/json-patch" "github.com/golang/glog" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -60,7 +61,7 @@ type debugError interface { // AddSourceToErr adds handleResourcePrefix and source string to error message. // verb is the string like "creating", "deleting" etc. -// souce is the filename or URL to the template file(*.json or *.yaml), or stdin to use to handle the resource. +// source is the filename or URL to the template file(*.json or *.yaml), or stdin to use to handle the resource. func AddSourceToErr(verb string, source string, err error) error { if source != "" { if statusError, ok := err.(kerrors.APIStatus); ok { @@ -636,3 +637,74 @@ func MaybeConvertObject(obj runtime.Object, gv unversioned.GroupVersion, convert return converter.ConvertToVersion(obj, gv) } } + +// MustPrintWithKinds determines if printer is dealing +// with multiple resource kinds, in which case it will +// return true, indicating resource kind will be +// included as part of printer output +func MustPrintWithKinds(objs []runtime.Object, infos []*resource.Info, sorter *kubectl.RuntimeSort) bool { + var lastMap *meta.RESTMapping + + for ix := range objs { + var mapping *meta.RESTMapping + if sorter != nil { + mapping = infos[sorter.OriginalPosition(ix)].Mapping + } else { + mapping = infos[ix].Mapping + } + + // display "kind" only if we have mixed resources + if lastMap != nil && mapping.Resource != lastMap.Resource { + return true + } + lastMap = mapping + } + + 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 *kubectl.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, api.Codecs.UniversalDecoder(), runtime.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 +} + +func PrintFilterCount(hiddenObjNum int, resource string, out io.Writer, options *kubectl.PrintOptions) error { + if !options.NoHeaders && !options.ShowAll && hiddenObjNum > 0 { + _, err := fmt.Fprintf(out, " info: %d completed object(s) was(were) not shown in %s list. Pass --show-all to see all objects.\n\n", hiddenObjNum, resource) + return err + } + return nil +} + +// ObjectListToVersionedObject receives a list of api objects and a group version +// and squashes the list's items into a single versioned runtime.Object. +func ObjectListToVersionedObject(objects []runtime.Object, version unversioned.GroupVersion) (runtime.Object, error) { + objectList := &api.List{Items: objects} + converted, err := resource.TryConvert(api.Scheme, objectList, version, registered.GroupOrDie(api.GroupName).GroupVersion) + if err != nil { + return nil, err + } + return converted, nil +} diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/resource/result.go b/vendor/k8s.io/kubernetes/pkg/kubectl/resource/result.go index 892b30e947a1..78f11e4a533b 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/resource/result.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/resource/result.go @@ -222,7 +222,7 @@ func AsVersionedObject(infos []*Info, forceList bool, version unversioned.GroupV object = objects[0] } else { object = &api.List{Items: objects} - converted, err := tryConvert(api.Scheme, object, version, registered.GroupOrDie(api.GroupName).GroupVersion) + converted, err := TryConvert(api.Scheme, object, version, registered.GroupOrDie(api.GroupName).GroupVersion) if err != nil { return nil, err } @@ -263,7 +263,7 @@ func AsVersionedObjects(infos []*Info, version unversioned.GroupVersion, encoder } } - converted, err := tryConvert(info.Mapping.ObjectConvertor, info.Object, version, info.Mapping.GroupVersionKind.GroupVersion()) + converted, err := TryConvert(info.Mapping.ObjectConvertor, info.Object, version, info.Mapping.GroupVersionKind.GroupVersion()) if err != nil { return nil, err } @@ -272,9 +272,9 @@ func AsVersionedObjects(infos []*Info, version unversioned.GroupVersion, encoder return objects, nil } -// tryConvert attempts to convert the given object to the provided versions in order. This function assumes +// TryConvert attempts to convert the given object to the provided versions in order. This function assumes // the object is in internal version. -func tryConvert(converter runtime.ObjectConvertor, object runtime.Object, versions ...unversioned.GroupVersion) (runtime.Object, error) { +func TryConvert(converter runtime.ObjectConvertor, object runtime.Object, versions ...unversioned.GroupVersion) (runtime.Object, error) { var last error for _, version := range versions { if version.Empty() { diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/resource_filter.go b/vendor/k8s.io/kubernetes/pkg/kubectl/resource_filter.go new file mode 100644 index 000000000000..8ca31d83ac30 --- /dev/null +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/resource_filter.go @@ -0,0 +1,67 @@ +/* +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/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/v1" + "k8s.io/kubernetes/pkg/runtime" +) + +// 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, 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. +// defaults to true for terminated pods +func filterPods(obj runtime.Object, options PrintOptions) bool { + switch p := obj.(type) { + case *v1.Pod: + reason := string(p.Status.Phase) + if p.Status.Reason != "" { + reason = p.Status.Reason + } + return !options.ShowAll && (reason == string(v1.PodSucceeded) || reason == string(v1.PodFailed)) + case *api.Pod: + reason := string(p.Status.Phase) + if p.Status.Reason != "" { + reason = p.Status.Reason + } + return !options.ShowAll && (reason == string(api.PodSucceeded) || reason == string(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 *PrintOptions) (bool, error) { + for _, filter := range f { + if ok := filter(obj, *opts); ok { + return true, nil + } + } + return false, nil +} diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/resource_printer.go b/vendor/k8s.io/kubernetes/pkg/kubectl/resource_printer.go index 5af291ed69e9..0b076106e31a 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/resource_printer.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/resource_printer.go @@ -352,10 +352,9 @@ type PrintOptions struct { // will only be printed if the object type changes. This makes it useful for printing items // received from watches. type HumanReadablePrinter struct { - handlerMap map[reflect.Type]*handlerEntry - options PrintOptions - lastType reflect.Type - hiddenObjNum int + handlerMap map[reflect.Type]*handlerEntry + options PrintOptions + lastType reflect.Type } // NewHumanReadablePrinter creates a HumanReadablePrinter. @@ -448,10 +447,6 @@ func (h *HumanReadablePrinter) HandledResources() []string { } func (h *HumanReadablePrinter) FinishPrint(output io.Writer, res string) error { - if !h.options.NoHeaders && !h.options.ShowAll && h.hiddenObjNum > 0 { - _, err := fmt.Fprintf(output, " info: %d completed object(s) was(were) not shown in %s list. Pass --show-all to see all objects.\n\n", h.hiddenObjNum, res) - return err - } return nil } @@ -498,12 +493,6 @@ var certificateSigningRequestColumns = []string{"NAME", "AGE", "REQUESTOR", "CON var securityContextConstraintsColumns = []string{"NAME", "PRIV", "CAPS", "SELINUX", "RUNASUSER", "FSGROUP", "SUPGROUP", "PRIORITY", "READONLYROOTFS", "VOLUMES"} func (h *HumanReadablePrinter) printPod(pod *api.Pod, w io.Writer, options PrintOptions) error { - reason := string(pod.Status.Phase) - // if not printing all pods, skip terminated pods (default) - if !options.ShowAll && (reason == string(api.PodSucceeded) || reason == string(api.PodFailed)) { - h.hiddenObjNum++ - return nil - } if err := printPodBase(pod, w, options); err != nil { return err } @@ -513,13 +502,6 @@ func (h *HumanReadablePrinter) printPod(pod *api.Pod, w io.Writer, options Print func (h *HumanReadablePrinter) printPodList(podList *api.PodList, w io.Writer, options PrintOptions) error { for _, pod := range podList.Items { - reason := string(pod.Status.Phase) - // if not printing all pods, skip terminated pods (default) - if !options.ShowAll && (reason == string(api.PodSucceeded) || reason == string(api.PodFailed)) { - h.hiddenObjNum++ - continue - } - if err := printPodBase(&pod, w, options); err != nil { return err } diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/resource_printer_test.go b/vendor/k8s.io/kubernetes/pkg/kubectl/resource_printer_test.go index 2f341acfaf9f..cc04248570f0 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/resource_printer_test.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/resource_printer_test.go @@ -1148,7 +1148,7 @@ func TestPrintPod(t *testing.T) { } buf := bytes.NewBuffer([]byte{}) - printer := HumanReadablePrinter{hiddenObjNum: 0} + printer := HumanReadablePrinter{} for _, test := range tests { printer.printPod(&test.pod, buf, PrintOptions{false, false, false, false, true, false, false, "", []string{}}) // We ignore time @@ -1157,9 +1157,6 @@ func TestPrintPod(t *testing.T) { } buf.Reset() } - if printer.hiddenObjNum > 0 { - t.Fatalf("Expected hidden pods: 0, got: %d", printer.hiddenObjNum) - } } func TestPrintNonTerminatedPod(t *testing.T) { @@ -1245,7 +1242,7 @@ func TestPrintNonTerminatedPod(t *testing.T) { } buf := bytes.NewBuffer([]byte{}) - printer := HumanReadablePrinter{hiddenObjNum: 0} + printer := HumanReadablePrinter{} for _, test := range tests { printer.printPod(&test.pod, buf, PrintOptions{false, false, false, false, false, false, false, "", []string{}}) // We ignore time @@ -1254,9 +1251,6 @@ func TestPrintNonTerminatedPod(t *testing.T) { } buf.Reset() } - if printer.hiddenObjNum != 2 { - t.Fatalf("Expected hidden pods: 2, got: %d", printer.hiddenObjNum) - } } func TestPrintPodWithLabels(t *testing.T) { @@ -1309,7 +1303,7 @@ func TestPrintPodWithLabels(t *testing.T) { } buf := bytes.NewBuffer([]byte{}) - printer := HumanReadablePrinter{hiddenObjNum: 0} + printer := HumanReadablePrinter{} for _, test := range tests { printer.printPod(&test.pod, buf, PrintOptions{false, false, false, false, false, false, false, "", test.labelColumns}) // We ignore time @@ -1318,9 +1312,6 @@ func TestPrintPodWithLabels(t *testing.T) { } buf.Reset() } - if printer.hiddenObjNum > 0 { - t.Fatalf("Expected hidden pods: 0, got: %d", printer.hiddenObjNum) - } } type stringTestList []struct { @@ -1519,7 +1510,7 @@ func TestPrintPodShowLabels(t *testing.T) { } buf := bytes.NewBuffer([]byte{}) - printer := HumanReadablePrinter{hiddenObjNum: 0} + printer := HumanReadablePrinter{} for _, test := range tests { printer.printPod(&test.pod, buf, PrintOptions{false, false, false, false, false, test.showLabels, false, "", []string{}}) @@ -1529,7 +1520,4 @@ func TestPrintPodShowLabels(t *testing.T) { } buf.Reset() } - if printer.hiddenObjNum > 0 { - t.Fatalf("Expected hidden pods: 0, got: %d", printer.hiddenObjNum) - } }