-
Notifications
You must be signed in to change notification settings - Fork 936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
role missing in kubectl get command line completion #357
Comments
cc: @superbrothers |
I will look this ;) |
The reason why "clusterrole" and "role" are not completed is that they are not included in handled resources of human readable printer.
Fundamentally, we should replace So we have the following two choices:
I feel "2" is better because of simple. @mengqiy What do you think? |
2 is simpler, but I feel it treats
@juanvallejo @soltysh Any idea how we can fix this? |
I agree this step is the most straightforward out of the two, however I'm still thinking of a cleaner implementation. With regards to replacing If we could find a way to patch completions so that they use a discovery-based list of resources, without having to touch the |
I've seen a PR fixing that bit of code with data from discovery. Let's revisit this issue after kubernetes/kubernetes#61691 is merged. |
@soltysh yes, as kubernetes/kubernetes#61691 looks like as it would fill the gap |
Looks like that the way of kubernetes/kubernetes#61691 is not better for this issue. Since # the generated completion script with `kubectl completion bash`
must_have_one_flag=()
must_have_one_noun=()
must_have_one_noun+=("certificatesigningrequest")
must_have_one_noun+=("clusterrolebinding")
must_have_one_noun+=("componentstatus")
must_have_one_noun+=("configmap")
must_have_one_noun+=("controllerrevision")
must_have_one_noun+=("cronjob")
must_have_one_noun+=("daemonset")
must_have_one_noun+=("deployment")
must_have_one_noun+=("endpoints")
must_have_one_noun+=("event")
must_have_one_noun+=("horizontalpodautoscaler")
must_have_one_noun+=("ingress")
must_have_one_noun+=("job")
must_have_one_noun+=("namespace") This is not appropriate when using multiple clusters. In this case, we need to obtain the resource list dynamically from the discovery service every time we complete it. One idea is to use commit b8f1b5e3aeb8b200ba3ab1afa300ebd322557592
Author: Kazuki Suda <[email protected]>
Date: Sat Mar 31 12:09:53 2018 +0900
Complete resource types from the discovery service
diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go
index c6fdab1..e6d542d 100644
--- a/pkg/kubectl/cmd/cmd.go
+++ b/pkg/kubectl/cmd/cmd.go
@@ -106,7 +106,14 @@ __kubectl_parse_get()
__kubectl_get_resource()
{
if [[ ${#nouns[@]} -eq 0 ]]; then
- return 1
+ local kubectl_out
+ if kubectl_out=$(kubectl api-resources $(__kubectl_override_flags) --no-headers 2>/dev/null | awk '{print $1}'); then
+ COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
+ fi
+ if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
+ # TODO: To complete shortnames
+ fi
+ return 0
fi
__kubectl_parse_get "${nouns[${#nouns[@]} -1]}"
}
diff --git a/pkg/kubectl/cmd/resource/get.go b/pkg/kubectl/cmd/resource/get.go
index e4b4256..2457ff9 100644
--- a/pkg/kubectl/cmd/resource/get.go
+++ b/pkg/kubectl/cmd/resource/get.go
@@ -138,7 +138,6 @@ func NewGetOptions(out io.Writer, errOut io.Writer) *GetOptions {
// retrieves one or more resources from a server.
func NewCmdGet(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
options := NewGetOptions(out, errOut)
- validArgs := cmdutil.ValidArgList(f)
cmd := &cobra.Command{
Use: "get [(-o|--output=)json|yaml|wide|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...] (TYPE [NAME | -l label] | TYPE/NAME ...) [flags]",
@@ -152,8 +151,6 @@ func NewCmdGet(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Comman
cmdutil.CheckErr(options.Run(f, cmd, args))
},
SuggestFor: []string{"list", "ps"},
- ValidArgs: validArgs,
- ArgAliases: kubectl.ResourceAliases(validArgs),
}
cmd.Flags().StringVar(&options.Raw, "raw", options.Raw, "Raw URI to request from the server. Uses the transport specified by the kubeconfig file.") This works well.
However there is a problem that
https://github.com/superbrothers/kubernetes/tree/kubectl-357-3 is an implementation of this idea. You can try this with the following steps:
|
kubernetes/kubernetes#63421 implements lookup at completion-time using |
@liggitt Great work! |
@liggitt Thanks! |
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Cache preferred resources, use in kubectl resource name autocomplete Fixes #63145 Fixes kubernetes/kubectl#357 Alternative to #61928 * starts to unify preferred resource logic on top of ServerGroups()/ServerResourcesForGroupVersion() methods * allows indicating a cached list of resources is acceptable when calling `kubectl api-resources` (default is still to rediscover) * uses `kubectl api-resources` in bash completion ```sh $ kubectl get [TAB][TAB] apiservices.apiregistration.k8s.io networkpolicies.extensions certificatesigningrequests.certificates.k8s.io networkpolicies.networking.k8s.io clusterrolebindings.rbac.authorization.k8s.io nodes clusterroles.rbac.authorization.k8s.io persistentvolumeclaims componentstatuses persistentvolumes configmaps poddisruptionbudgets.policy controllerrevisions.apps pods cronjobs.batch podsecuritypolicies.extensions customresourcedefinitions.apiextensions.k8s.io podsecuritypolicies.policy daemonsets.apps podtemplates daemonsets.extensions replicasets.apps deployments.apps replicasets.extensions deployments.extensions replicationcontrollers endpoints resourcequotas events rolebindings.rbac.authorization.k8s.io events.events.k8s.io roles.rbac.authorization.k8s.io horizontalpodautoscalers.autoscaling secrets ingresses.extensions serviceaccounts initializerconfigurations.admissionregistration.k8s.io services jobs.batch statefulsets.apps limitranges storageclasses.storage.k8s.io mutatingwebhookconfigurations.admissionregistration.k8s.io validatingwebhookconfigurations.admissionregistration.k8s.io namespaces volumeattachments.storage.k8s.io ``` ```release-note NONE ```
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Cache preferred resources, use in kubectl resource name autocomplete Fixes #63145 Fixes kubernetes/kubectl#357 Alternative to #61928 * starts to unify preferred resource logic on top of ServerGroups()/ServerResourcesForGroupVersion() methods * allows indicating a cached list of resources is acceptable when calling `kubectl api-resources` (default is still to rediscover) * uses `kubectl api-resources` in bash completion ```sh $ kubectl get [TAB][TAB] apiservices.apiregistration.k8s.io networkpolicies.extensions certificatesigningrequests.certificates.k8s.io networkpolicies.networking.k8s.io clusterrolebindings.rbac.authorization.k8s.io nodes clusterroles.rbac.authorization.k8s.io persistentvolumeclaims componentstatuses persistentvolumes configmaps poddisruptionbudgets.policy controllerrevisions.apps pods cronjobs.batch podsecuritypolicies.extensions customresourcedefinitions.apiextensions.k8s.io podsecuritypolicies.policy daemonsets.apps podtemplates daemonsets.extensions replicasets.apps deployments.apps replicasets.extensions deployments.extensions replicationcontrollers endpoints resourcequotas events rolebindings.rbac.authorization.k8s.io events.events.k8s.io roles.rbac.authorization.k8s.io horizontalpodautoscalers.autoscaling secrets ingresses.extensions serviceaccounts initializerconfigurations.admissionregistration.k8s.io services jobs.batch statefulsets.apps limitranges storageclasses.storage.k8s.io mutatingwebhookconfigurations.admissionregistration.k8s.io validatingwebhookconfigurations.admissionregistration.k8s.io namespaces volumeattachments.storage.k8s.io ``` ```release-note NONE ``` Kubernetes-commit: 068b7befa926d376634c79cbba3d210c1dc596fe
What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.): completion
Kubernetes version (use
kubectl version
):Environment:
uname -a
):What happened:
The command line completion of
kubectl get
does not showrole
. It shows onlyrolebinding
.What you expected to happen:
kubectl get
command line completion should also showrole
becausegetting
a role is possible:How to reproduce it (as minimally and precisely as possible):
kubectl get [tab,tab]
The text was updated successfully, but these errors were encountered: