mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Don't print the "filtered" message on generic output
Unify the various output displays and make them simpler. Don't write to glog, but only output the info when `-v 2` to stderr.
This commit is contained in:
parent
4e7c10a520
commit
34e4337e57
@ -1106,6 +1106,10 @@ run_kubectl_get_tests() {
|
|||||||
# Post-condition: The text "No resources found" should be part of the output
|
# Post-condition: The text "No resources found" should be part of the output
|
||||||
kube::test::if_has_string "${output_message}" 'No resources found'
|
kube::test::if_has_string "${output_message}" 'No resources found'
|
||||||
# Command
|
# Command
|
||||||
|
output_message=$(kubectl get pods --ignore-not-found 2>&1 "${kube_flags[@]}")
|
||||||
|
# Post-condition: The text "No resources found" should not be part of the output
|
||||||
|
kube::test::if_has_not_string "${output_message}" 'No resources found'
|
||||||
|
# Command
|
||||||
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}" -o wide)
|
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}" -o wide)
|
||||||
# Post-condition: The text "No resources found" should be part of the output
|
# Post-condition: The text "No resources found" should be part of the output
|
||||||
kube::test::if_has_string "${output_message}" 'No resources found'
|
kube::test::if_has_string "${output_message}" 'No resources found'
|
||||||
|
@ -243,13 +243,10 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
}
|
}
|
||||||
|
|
||||||
// print the current object
|
// print the current object
|
||||||
filteredResourceCount := 0
|
|
||||||
if !isWatchOnly {
|
if !isWatchOnly {
|
||||||
if err := printer.PrintObj(obj, out); err != nil {
|
if err := printer.PrintObj(obj, out); err != nil {
|
||||||
return fmt.Errorf("unable to output the provided object: %v", err)
|
return fmt.Errorf("unable to output the provided object: %v", err)
|
||||||
}
|
}
|
||||||
filteredResourceCount++
|
|
||||||
cmdutil.PrintFilterCount(filteredResourceCount, mapping.Resource, filterOpts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print watched changes
|
// print watched changes
|
||||||
@ -259,7 +256,6 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
}
|
}
|
||||||
|
|
||||||
first := true
|
first := true
|
||||||
filteredResourceCount = 0
|
|
||||||
intr := interrupt.New(nil, w.Stop)
|
intr := interrupt.New(nil, w.Stop)
|
||||||
intr.Run(func() error {
|
intr.Run(func() error {
|
||||||
_, err := watch.Until(0, w, func(e watch.Event) (bool, error) {
|
_, err := watch.Until(0, w, func(e watch.Event) (bool, error) {
|
||||||
@ -272,8 +268,6 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
filteredResourceCount++
|
|
||||||
cmdutil.PrintFilterCount(filteredResourceCount, mapping.Resource, filterOpts)
|
|
||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
@ -326,11 +320,6 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
|
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
|
||||||
}
|
}
|
||||||
|
|
||||||
res := ""
|
|
||||||
if len(infos) > 0 {
|
|
||||||
res = infos[0].ResourceMapping().Resource
|
|
||||||
}
|
|
||||||
|
|
||||||
var obj runtime.Object
|
var obj runtime.Object
|
||||||
if !singleItemImplied || len(infos) > 1 {
|
if !singleItemImplied || len(infos) > 1 {
|
||||||
// we have more than one item, so coerce all items into a list
|
// we have more than one item, so coerce all items into a list
|
||||||
@ -351,7 +340,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
|
|
||||||
isList := meta.IsListType(obj)
|
isList := meta.IsListType(obj)
|
||||||
if isList {
|
if isList {
|
||||||
filteredResourceCount, items, err := cmdutil.FilterResourceList(obj, filterFuncs, filterOpts)
|
_, items, err := cmdutil.FilterResourceList(obj, filterFuncs, filterOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -375,23 +364,17 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
if err := printer.PrintObj(list, out); err != nil {
|
if err := printer.PrintObj(list, out); err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdutil.PrintFilterCount(filteredResourceCount, res, filterOpts)
|
|
||||||
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
|
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
|
||||||
}
|
}
|
||||||
|
|
||||||
filteredResourceCount := 0
|
|
||||||
if isFiltered, err := filterFuncs.Filter(obj, filterOpts); !isFiltered {
|
if isFiltered, err := filterFuncs.Filter(obj, filterOpts); !isFiltered {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(2).Infof("Unable to filter resource: %v", err)
|
glog.V(2).Infof("Unable to filter resource: %v", err)
|
||||||
} else if err := printer.PrintObj(obj, out); err != nil {
|
} else if err := printer.PrintObj(obj, out); err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
} else if isFiltered {
|
|
||||||
filteredResourceCount++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdutil.PrintFilterCount(filteredResourceCount, res, filterOpts)
|
|
||||||
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
|
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,9 +384,6 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
allErrs = append(allErrs, err)
|
allErrs = append(allErrs, err)
|
||||||
}
|
}
|
||||||
if len(infos) == 0 && len(allErrs) == 0 && !options.IgnoreNotFound {
|
|
||||||
outputEmptyListWarning(errOut)
|
|
||||||
}
|
|
||||||
|
|
||||||
objs := make([]runtime.Object, len(infos))
|
objs := make([]runtime.Object, len(infos))
|
||||||
for ix := range infos {
|
for ix := range infos {
|
||||||
@ -426,12 +406,12 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
printer = nil
|
printer = nil
|
||||||
var lastMapping *meta.RESTMapping
|
var lastMapping *meta.RESTMapping
|
||||||
w := printers.GetNewTabWriter(out)
|
w := printers.GetNewTabWriter(out)
|
||||||
filteredResourceCount := 0
|
|
||||||
|
|
||||||
if resource.MultipleTypesRequested(args) || cmdutil.MustPrintWithKinds(objs, infos, sorter) {
|
if resource.MultipleTypesRequested(args) || cmdutil.MustPrintWithKinds(objs, infos, sorter) {
|
||||||
showKind = true
|
showKind = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filteredResourceCount := 0
|
||||||
for ix := range objs {
|
for ix := range objs {
|
||||||
var mapping *meta.RESTMapping
|
var mapping *meta.RESTMapping
|
||||||
var original runtime.Object
|
var original runtime.Object
|
||||||
@ -445,7 +425,6 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
if printer == nil || lastMapping == nil || mapping == nil || mapping.Resource != lastMapping.Resource {
|
if printer == nil || lastMapping == nil || mapping == nil || mapping.Resource != lastMapping.Resource {
|
||||||
if printer != nil {
|
if printer != nil {
|
||||||
w.Flush()
|
w.Flush()
|
||||||
cmdutil.PrintFilterCount(filteredResourceCount, lastMapping.Resource, filterOpts)
|
|
||||||
}
|
}
|
||||||
printer, err = f.PrinterForMapping(cmd, mapping, allNamespaces)
|
printer, err = f.PrinterForMapping(cmd, mapping, allNamespaces)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -517,14 +496,6 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
if printer != nil && lastMapping != nil {
|
cmdutil.PrintFilterCount(errOut, len(objs), filteredResourceCount, len(allErrs), "", filterOpts, options.IgnoreNotFound)
|
||||||
cmdutil.PrintFilterCount(filteredResourceCount, lastMapping.Resource, filterOpts)
|
|
||||||
}
|
|
||||||
return utilerrors.NewAggregate(allErrs)
|
return utilerrors.NewAggregate(allErrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// outputEmptyListWarning outputs a warning indicating that no items are available to display
|
|
||||||
func outputEmptyListWarning(out io.Writer) error {
|
|
||||||
_, err := fmt.Fprintf(out, "%s\n", "No resources found.")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
@ -698,9 +698,26 @@ func FilterResourceList(obj runtime.Object, filterFuncs kubectl.Filters, filterO
|
|||||||
return filterCount, list, nil
|
return filterCount, list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintFilterCount(hiddenObjNum int, resource string, options *printers.PrintOptions) {
|
// PrintFilterCount displays informational messages based on the number of resources found, hidden, or
|
||||||
if !options.NoHeaders && !options.ShowAll && hiddenObjNum > 0 {
|
// config flags shown.
|
||||||
glog.V(2).Infof(" info: %d completed object(s) was(were) not shown in %s list. Pass --show-all to see all objects.\n\n", hiddenObjNum, resource)
|
func PrintFilterCount(out io.Writer, found, hidden, errors int, resource string, 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user