Commit 19364c2d authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #32222 from juanvallejo/jvallejo_bugfix/single-resource-prefix-kubectl-get-all

Automatic merge from submit-queue print resource kind prefix when `kubectl get all` has single type to display **Release note**: ```release-note NONE ``` This patch forces the HumanReadablePrinter to display resource kind prefixes when there is only one type of resource to show and a specific resource type has not been specified as an argument to kubectl get `$ kubectl get all` ``` NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes 172.30.0.1 <none> 443/TCP,53/UDP,53/TCP 2m ``` `$ kubectl get all` ``` NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/kubernetes 172.30.0.1 <none> 443/TCP,53/UDP,53/TCP 2m ```
parents 3414a374 59ba00f8
......@@ -156,6 +156,7 @@ 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))
printAll := false
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil {
......@@ -171,6 +172,14 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
return cmdutil.UsageError(cmd, "Required resource not specified.")
}
// determine if args contains "all"
for _, a := range args {
if a == "all" {
printAll = true
break
}
}
// always show resources when getting by name or filename
argsHasNames, err := resource.HasNames(args)
if err != nil {
......@@ -365,7 +374,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
var lastMapping *meta.RESTMapping
w := kubectl.GetNewTabWriter(out)
if mustPrintWithKinds(objs, infos, sorter) {
if mustPrintWithKinds(objs, infos, sorter, printAll) {
showKind = true
}
......@@ -431,9 +440,13 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
// 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 {
func mustPrintWithKinds(objs []runtime.Object, infos []*resource.Info, sorter *kubectl.RuntimeSort, printAll bool) bool {
var lastMap *meta.RESTMapping
if len(infos) == 1 && printAll {
return true
}
for ix := range objs {
var mapping *meta.RESTMapping
if sorter != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment