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

kubectl plugin - reference to current directory #55708

Open
ae-dg opened this Issue Nov 14, 2017 · 14 comments

Comments

Projects
None yet
6 participants
@ae-dg

ae-dg commented Nov 14, 2017

Is this a BUG REPORT or FEATURE REQUEST?: feature request

/kind feature

When executing a plugin with a "kubectl plugin" command the current directory is changed to the directory of the plugin, but there is no reference to the directory the user was in before.

It would be nice to have a KUBECTL_PLUGIN variables set to the directory the user was in to be able to access files in there.

Environment:

  • Kubernetes version (use kubectl version): 1.8.0
  • Kubectl version: 1.8.2
  • Cloud provider or hardware configuration: minikube
  • OS (e.g. from /etc/os-release): macOS Sierra 10.12.6
@ae-dg

This comment has been minimized.

Show comment
Hide comment
@ae-dg

ae-dg Nov 14, 2017

/area kubectl

ae-dg commented Nov 14, 2017

/area kubectl

@ae-dg

This comment has been minimized.

Show comment
Hide comment
@ae-dg

ae-dg Nov 14, 2017

/sig cli

ae-dg commented Nov 14, 2017

/sig cli

@jordanwilson230

This comment has been minimized.

Show comment
Hide comment
@jordanwilson230

jordanwilson230 Nov 14, 2017

+1 ...I've run into the same issue. It seems to be an issue like subshell inheritance. Only when running a command directly from the plugin.yaml file (i.e., echo $PWD) does it return the user's directory. Once the plugin.yml launches the script/binary, then the user's current environment is lost.

Without access to this, the plugin feature becomes unsuitable for many (if not all) of our use cases.

jordanwilson230 commented Nov 14, 2017

+1 ...I've run into the same issue. It seems to be an issue like subshell inheritance. Only when running a command directly from the plugin.yaml file (i.e., echo $PWD) does it return the user's directory. Once the plugin.yml launches the script/binary, then the user's current environment is lost.

Without access to this, the plugin feature becomes unsuitable for many (if not all) of our use cases.

@ae-dg

This comment has been minimized.

Show comment
Hide comment
@ae-dg

ae-dg Nov 16, 2017

A quick experiment shows you can do something like command: "./run_plugin $PWD" and have the current directory on the command line to your plugin. 👍 for that.

(Unfortunately it splits the command line on spaces, regardless of quoting, so if your current path has a space in it you need to paste it back together again in the plugin, but it makes things possible until this is fixed.)

ae-dg commented Nov 16, 2017

A quick experiment shows you can do something like command: "./run_plugin $PWD" and have the current directory on the command line to your plugin. 👍 for that.

(Unfortunately it splits the command line on spaces, regardless of quoting, so if your current path has a space in it you need to paste it back together again in the plugin, but it makes things possible until this is fixed.)

@jordanwilson230

This comment has been minimized.

Show comment
Hide comment
@jordanwilson230

jordanwilson230 Nov 16, 2017

It's nasty, but one other workaround is to put a flag in your plugin and have your bashrc or bash_profile pass it the user's path. E.g.:

function kubectl() { case $* in "deploy"*) shift 1; command kubectl plugin deploy --path=$PWD "$@" ;; * ) command kubectl "$@" ;; esac }
' >> ~/.bash_profile

Thats a snippet of what I'm currently using. Using this method is a bad approach, but will have to use until a fix is found. I put that in an install.sh script, inside of tar archive of my plugins directory. Note that function makes it so you don't need to pass it the 'plugin' command when executing.

jordanwilson230 commented Nov 16, 2017

It's nasty, but one other workaround is to put a flag in your plugin and have your bashrc or bash_profile pass it the user's path. E.g.:

function kubectl() { case $* in "deploy"*) shift 1; command kubectl plugin deploy --path=$PWD "$@" ;; * ) command kubectl "$@" ;; esac }
' >> ~/.bash_profile

Thats a snippet of what I'm currently using. Using this method is a bad approach, but will have to use until a fix is found. I put that in an install.sh script, inside of tar archive of my plugins directory. Note that function makes it so you don't need to pass it the 'plugin' command when executing.

@jordanwilson230

This comment has been minimized.

Show comment
Hide comment
@jordanwilson230

jordanwilson230 Nov 16, 2017

@ae-dg regarding the spacing issue, you should be able to fix that by quoting the $PWD you're passing to your script, or changing the IFS variable to handle it.

jordanwilson230 commented Nov 16, 2017

@ae-dg regarding the spacing issue, you should be able to fix that by quoting the $PWD you're passing to your script, or changing the IFS variable to handle it.

@ae-dg

This comment has been minimized.

Show comment
Hide comment
@ae-dg

ae-dg Nov 17, 2017

@jordanwilson230 I tried quoting $PWD but my script ended up being called with $1 being '/tmp/a and $2 being dir'. I think it's line 51 of https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/plugins/runner.go that just does a simple split().

I also tried setting command to be CURDIR=$PWD ./myplugin to see if I could get a new variable into the plugin. But that wouldn't execute. At the moment it looks like it's very simplistic; take the command, split it on spaces, the first value is the command to execute and the rest are the arguments.

ae-dg commented Nov 17, 2017

@jordanwilson230 I tried quoting $PWD but my script ended up being called with $1 being '/tmp/a and $2 being dir'. I think it's line 51 of https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/plugins/runner.go that just does a simple split().

I also tried setting command to be CURDIR=$PWD ./myplugin to see if I could get a new variable into the plugin. But that wouldn't execute. At the moment it looks like it's very simplistic; take the command, split it on spaces, the first value is the command to execute and the rest are the arguments.

@fejta-bot

This comment has been minimized.

Show comment
Hide comment
@fejta-bot

fejta-bot Feb 15, 2018

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

fejta-bot commented Feb 15, 2018

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

fabiand added a commit to fabiand/kubectl-plugin-pvc that referenced this issue Mar 12, 2018

Add fix for kubectl plugin PWD
See kubernetes/kubernetes#55708

Signed-off-by: Fabian Deutsch <fabiand@fedoraproject.org>
@fejta-bot

This comment has been minimized.

Show comment
Hide comment
@fejta-bot

fejta-bot Mar 17, 2018

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
/remove-lifecycle stale

fejta-bot commented Mar 17, 2018

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
/remove-lifecycle stale

@fabiand

This comment has been minimized.

Show comment
Hide comment
@fabiand

fabiand Mar 18, 2018

Contributor

/remove-lifecycle rotten

Contributor

fabiand commented Mar 18, 2018

/remove-lifecycle rotten

@fejta-bot

This comment has been minimized.

Show comment
Hide comment
@fejta-bot

fejta-bot Jun 16, 2018

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

fejta-bot commented Jun 16, 2018

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@fabiand

This comment has been minimized.

Show comment
Hide comment
@fabiand

fabiand Jun 16, 2018

Contributor

/remove-lifecycle stale

Contributor

fabiand commented Jun 16, 2018

/remove-lifecycle stale

@soltysh soltysh referenced this issue Jul 24, 2018

Closed

add draft #1

@fejta-bot

This comment has been minimized.

Show comment
Hide comment
@fejta-bot

fejta-bot Sep 14, 2018

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

fejta-bot commented Sep 14, 2018

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@fabiand

This comment has been minimized.

Show comment
Hide comment
@fabiand

fabiand Sep 16, 2018

Contributor

/remove-lifecycle stale

Contributor

fabiand commented Sep 16, 2018

/remove-lifecycle stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment