mikelorant / kubectl-exec-user

Exec as a specified user into a Kubernetes container
57 stars 11 forks source link

Does this work with kubectl v1.12.0? #4

Open holmesb opened 6 years ago

holmesb commented 6 years ago

I'm on kubectl client version v1.12.0 and can't get this to work. I added the following to my path: ~/.kube/plugins ~/.kube/plugins/exec-user

But get:

user@host~/$ kubectl plugin list
error: unable to find any kubectl plugins in your PATH

If I rename ~/.kube/plugins/exec-user/exec-user.sh to ~/.kube/plugins/exec-user/kubectl-exec-user.sh I get:

> user@host ~/$ kubectl plugin list
> The following kubectl-compatible plugins are available:
> 
> ~/.kube/plugins/exec-user/kubectl-exec-user.sh
>   - warning: kubectl-exec-user.sh overwrites existing command: "kubectl exec"
> 
> error: one plugin warning was found

But when I try to use this plugin, I get: user@host~/$ kubectl plugin exec-user pod /bin/bash error: unknown command "exec-user test /bin/bash" See 'kubectl plugin -h' for help and examples.

Any ideas? Does this need to be brought in line with the latest documentation?

markx1916 commented 5 years ago

@holmesb , I get the same problem , Did you solve this ?

glensc commented 5 years ago

https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/

Discovering plugins

kubectl provides a command kubectl plugin list that searches your PATH for valid plugin executables. Executing this command causes a traversal of all files in your PATH. Any files that are executable, and begin with kubectl- will show up in the order in which they are present in your PATH in this command’s output. A warning will be included for any files beginning with kubectl- that are not executable. A warning will also be included for any valid plugin files that overlap each other’s name.

renaming necessary to avoid this warning:

  • warning: kubectl-exec-user overwrites existing command: "kubectl exec"
$ ln -s `pwd`/exec-user/exec-user.sh ~/.local/bin/kubectl-execuser

however, this is not sufficient, whole option parsing must be implemented by the standalone script

Note: Unlike previous versions of kubectl, the plugin mechanism will not create any custom, plugin-specific values or environment variables to a plugin process. This means that environment variables such as KUBECTL_PLUGINS_CURRENT_NAMESPACE are no longer provided to a plugin. Plugins must parse all of the arguments passed to them by a user, and handle flag validation as part of their own implementation. For plugins written in Go, a set of utilities has been provided under k8s.io/cli-runtime to assist with this.

ahmetb commented 4 years ago

We already have an exec-as plugin that pretty much does the same thing in Krew plugin manager: https://github.com/kubernetes-sigs/krew/

glensc commented 4 years ago

tested exec-as, works fine, so this repo can be considered obsolete for kubectl >= 1.12

mcandre commented 3 years ago

Both exec-user and exec-as fail for me.