Skip to content
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

Bug: kubectl create secret --from-file does not accept tilde ~ character in path #276

Closed
CalvinHartwell opened this issue Feb 12, 2018 · 7 comments
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.

Comments

@CalvinHartwell
Copy link

Kubernetes version (use kubectl version):
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.4", GitCommit:"9befc2b8928a9426501d3bf62f72849d5cbcd5a3", GitTreeState:"clean", BuildDate:"2017-11-20T05:28:34Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.2", GitCommit:"5fa2db2bd46ac79e5e00a4e6ed24191080aa463b", GitTreeState:"clean", BuildDate:"2018-01-18T09:42:01Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}

Environment: desktop/workstation and server/production/vm

  • Cloud provider or hardware configuration: k8s running on AWS but kubectl executed on x86 desktop machine.
  • OS (e.g. from /etc/os-release): Ubuntu 17.10
  • Kernel (e.g. uname -a): Linux ubuntu-ws 4.13.0-17-generic Mark deprecated commands in 'kubectl help' #20-Ubuntu SMP Mon Nov 6 10:04:08 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • Install tools: snap
  • Others:

What happened:
Attempt to create cluster secret from file using a relative path via tilde to refer to home directory. I.E: ~/somefile

But this does not work, it generates a file not found error.

What you expected to happen:

I expect to be able to use tilde ~ in paths to files.

How to reproduce it (as minimally and precisely as possible):

does not work, file not found.

kubectl create secret generic kubeconfig --from-file=~/somefile

works fine

kubectl create secret generic kubeconfig --from-file=/home//somefile

Anything else we need to know:

@shal
Copy link

shal commented Feb 27, 2018

+1

@mengqiy mengqiy added kind/bug Categorizes issue or PR as related to a bug. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Mar 5, 2018
@fejta-bot
Copy link

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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 3, 2018
@nikhita
Copy link
Member

nikhita commented Jun 3, 2018

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 3, 2018
@CalvinHartwell
Copy link
Author

CalvinHartwell commented Jun 5, 2018

@nikhita why was this marked at stale? Is it fixed?

I can work on this when I get a chance.

@nikhita
Copy link
Member

nikhita commented Jun 5, 2018

@nikhita why was this marked at stale?

We have a bot (@fejta-bot) which marks issues and PRs as "stale" if there has been no activity on it for 90 days. It is done to make sure that old issues are closed, if they are no longer relevant. If they are relevant, someone removes the stale label.

Is it fixed?

I haven't tested it but I don't think it is. If it were, I believe someone would have linked/referenced this issue on the PR.

I can work on this when I get a chance.

Please feel free to work on this. :)

@liggitt
Copy link
Member

liggitt commented Aug 15, 2018

This will work: kubectl create secret generic kubeconfig --from-file ~/somefile

Expansion of ~ paths to the home directory is done by the calling shell, and varies depending on whether the arg is quoted/unquoted, and is a flag or not. Bash chooses not to expand flag values containing ~. You can see this shell behavior in action with echo as well:

$ echo ~/test
/home/test

$ echo "~/test"
~/test

$ echo foo=~/test
foo=/home/test

$ echo "foo=~/test"
foo=~/test

$ echo --foo=~/test
--foo=~/test

$ echo "--foo=~/test"
--foo=~/test

I don't think it makes sense to add custom handling of every file-related flag value into every process to do this expansion.

/close

@JoshuaPostel
Copy link

For those who run into this issue when trying to set a specific key:

kubectl create secret generic registry-secret \
--from-file=.dockerconfigjson=~/.docker/config.json \
--type=kubernetes.io/dockerconfigjson

A possible work around (albeit a little ugly) is:

kubectl create secret generic registry-secret \
--from-file=.dockerconfigjson=$(readlink -f ~/.docker/config.json) \
--type=kubernetes.io/dockerconfigjson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

8 participants