mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
bash_completions: annotate kubectl get with resources which can be 'gotten'
A user types: kubectl get $resource This will cause the bash completions to suggest the possible objects the user can ask for. The complete list right now is: endpoints event limitrange namespace node persistentvolume persistentvolumeclaim pod replicationcontroller resourcequota secret service status But this list should stay up2date as api objects are added or deleted
This commit is contained in:
parent
5b8a426d01
commit
c75ecbd8e3
@ -175,6 +175,19 @@ _kubectl_get()
|
||||
|
||||
must_have_one_flag=()
|
||||
must_have_one_noun=()
|
||||
must_have_one_noun+=("endpoints")
|
||||
must_have_one_noun+=("event")
|
||||
must_have_one_noun+=("limitrange")
|
||||
must_have_one_noun+=("namespace")
|
||||
must_have_one_noun+=("node")
|
||||
must_have_one_noun+=("persistentvolume")
|
||||
must_have_one_noun+=("persistentvolumeclaim")
|
||||
must_have_one_noun+=("pod")
|
||||
must_have_one_noun+=("replicationcontroller")
|
||||
must_have_one_noun+=("resourcequota")
|
||||
must_have_one_noun+=("secret")
|
||||
must_have_one_noun+=("service")
|
||||
must_have_one_noun+=("status")
|
||||
}
|
||||
|
||||
_kubectl_describe()
|
||||
|
@ -60,6 +60,9 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7`
|
||||
// NewCmdGet creates a command object for the generic "get" action, which
|
||||
// retrieves one or more resources from a server.
|
||||
func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
p := kubectl.NewHumanReadablePrinter(false)
|
||||
validArgs := p.HandledResources()
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...)",
|
||||
Short: "Display one or many resources",
|
||||
@ -69,6 +72,7 @@ func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
err := RunGet(f, out, cmd, args)
|
||||
cmdutil.CheckErr(err)
|
||||
},
|
||||
ValidArgs: validArgs,
|
||||
}
|
||||
cmdutil.AddPrinterFlags(cmd)
|
||||
cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on")
|
||||
|
@ -227,6 +227,22 @@ func (h *HumanReadablePrinter) validatePrintHandlerFunc(printFunc reflect.Value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *HumanReadablePrinter) HandledResources() []string {
|
||||
keys := make([]string, 0)
|
||||
|
||||
for k := range h.handlerMap {
|
||||
// k.String looks like "*api.PodList" and we want just "pod"
|
||||
api := strings.Split(k.String(), ".")
|
||||
resource := api[len(api)-1]
|
||||
if strings.HasSuffix(resource, "List") {
|
||||
continue
|
||||
}
|
||||
resource = strings.ToLower(resource)
|
||||
keys = append(keys, resource)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
var podColumns = []string{"POD", "IP", "CONTAINER(S)", "IMAGE(S)", "HOST", "LABELS", "STATUS", "CREATED"}
|
||||
var replicationControllerColumns = []string{"CONTROLLER", "CONTAINER(S)", "IMAGE(S)", "SELECTOR", "REPLICAS"}
|
||||
var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT(S)"}
|
||||
|
Loading…
Reference in New Issue
Block a user