mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 05:36:12 +00:00
print resource kind prefix when kubectl get all
has single type to display
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 ```
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user