carapace-sh / carapace-bin

multi-shell multi-command argument completer
https://carapace.sh
MIT License
827 stars 45 forks source link

kubectl: cluster namespace from command flag not used #2186

Closed petergarnaes closed 7 months ago

petergarnaes commented 7 months ago

Current Behavior

When autocompleting the name of a specific resource in a given namespace, for example when using kubectl describe, the command can not provide options when namespace is set through the command flag.

So when writing something like:

kubectl --namespace=the-namespace describe deployment # here i want autocomplete options

and then pressing tab for completion, the command does not know to use the provided namespace.

I tested with setting the namespace in the .kube/config file (and not providing the --namespace flag), an then it works flawlessly.

Expected Behavior

kubectl get ..., kubectl describe ..., kubectl delete ..., kubectl scale ..., kubectl label ... and all other commands working with kubernetes resources in the cluster should be able to autocomplete or provide options for resource names in the namespace provided through the --namespace flag, if provided.

This is how it works in the kubectl plugin for oh-my-zsh.

Steps To Reproduce

  1. deploy resource to a specific namespace in the cluster
  2. use a kubectl context that does not set a namespace, or sets another namespace than the one we just deployed a resource to
  3. try autocompleting that resource name while having the --namespace flag set to the namespace of the resource
  4. Resource will not show, or a kubectl error will occur if you do not have access to the default namespace

Version

0.29.7

OS

Shell

Anything else?

No response

rsteube commented 7 months ago

Thanks, should be fixed now. Not working with kubernetes myself at the moment which makes the completer a bit ambitious.

You can use the official completions as a workaround if you encounter issues like this:

# ~/.config/carapace/specs/kubectl.yaml
name: kubectl
description: kubectl controls the Kubernetes cluster manager
completion:
  positionalany: ["$carapace.bridge.Cobra([kubectl])"]
petergarnaes commented 7 months ago

Thanks for a quick response 😃 Workaround works like a charm 👍🏻 Thanks for a great project!