-
Notifications
You must be signed in to change notification settings - Fork 4.7k
make oc login kubeconfig permission error clearer #9968
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
make oc login kubeconfig permission error clearer #9968
Conversation
ec5b7eb
to
4510817
Compare
[test] |
@fabianofranz Could you please take a look? Thanks! |
@@ -394,7 +394,11 @@ func (o *LoginOptions) SaveConfig() (bool, error) { | |||
} | |||
|
|||
if err := kclientcmd.ModifyConfig(o.PathOptions, *configToWrite, true); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the only error that could come back from this a file permission error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liggitt hm, I could parse the error string to make sure it is a "permission denied" error before returning this message, and then otherwise return just the original error message. But I am not sure that the only error that comes back is file permission error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing error strings is a code smell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, what if I type the errors in loader.go#WriteToFile and then return a message accordingly in loginoptions.go?
EDIT: turns out os.IsPermission works :p 0a85f23#diff-f260fb37cbe8b4d20167cc6bc6d4e51aR397
4510817
to
0a85f23
Compare
[test] |
Check with @csrwng, he implemented a similar feature in |
I added a check and error message in case your config is not writeable: |
@csrwng @fabianofranz I think @csrwng's error message for kubeconfig not being writable definitely would work for |
@juanvallejo importing works for me. |
I would move it if we intend to reuse it. I don't want login depending on docker bootstrap packages. |
@juanvallejo so in the cluster up code I check for the interfaces implemented by the error so I can print out additional details, solution, etc. In this case, it seems that would all make sense to be part of the error message, since that's what would get printed out, no? |
@@ -275,6 +275,11 @@ os::cmd::expect_success_and_not_text 'oc get is' 'is/test1' | |||
echo "resource printer: ok" | |||
os::test::junit::declare_suite_end | |||
|
|||
os::test::junit::declare_suite_start "cmd/basicresources/login" | |||
os::cmd::expect_failure_and_text "oc login ${KUBERNETES_MASTER} -u test -p test --config=/src --insecure-skip-tls-verify" 'Failed to create kubeconfig under' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote your vars
os::cmd::expect_failure_and_text "oc login '${KUBERNETES_MASTER}' -u test ...
^ ^
2e003dd
to
ac74302
Compare
Thanks for pointing this out! I went ahead and added that in the |
@juanvallejo you can implement FormatError by calling PrintError on a buffer and returning the buffer string. One concern is that we don't usually display errors like this for other CLI commands. |
ac74302
to
ea204df
Compare
Sounds good
I went ahead and changed the format so that it resembles more a standard error msg:
|
ea204df
to
c9f443d
Compare
re[test] |
Looks like parts of this new errors structure (the interface, printer, |
I agree with this, I'll go ahead and update the PR |
aac0667
to
2e709a5
Compare
os::test::junit::declare_suite_start "cmd/authentication" | ||
|
||
os::test::junit::declare_suite_start "cmd/authentication/scopedtokens" | ||
os::cmd::expect_success 'oadm policy add-role-to-user admin scoped-user' | ||
|
||
# make sure we handle invalid config file destination | ||
os::cmd::expect_failure_and_text "oc login '${KUBERNETES_MASTER}' -u test -p test --config=/src --insecure-skip-tls-verify" 'KUBECONFIG is set to a file that cannot be created or modified' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this belongs to the suite you started in line 13 (which is doing nothing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of our tests for oc login
are in the main body of hack/test-cmd.sh
.
Although I have a PR in flight to move that location, I think it makes the most sense to colocate this test and those others. Whichever of us merges first will rebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I will update the PR with these changes
Sounds good, since |
@juanvallejo good to go? |
@fabianofranz Yeah, everything looks good to me |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/7026/) (Image: devenv-rhel7_4690) |
@juanvallejo could use a squash |
f3354e7
to
ce8595f
Compare
Done! |
[merge] |
Evaluated for origin test up to ce8595f |
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/7001/) |
Evaluated for origin merge up to ce8595f |
Related BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1332131
When logging in with a
$KUBECONFIG
variable, or--config
flag pointing to a location that denies write access,oc login
prints a non-specific error at the bottom of its output:export KUBECONFIG=/src
oc login --token=<my_token> --insecure-skip-tls-verify
This updates the error to be more clear as to what has happened:
oc login -u test -p test --insecure-skip-tls-verify
Same output, but using a
--config
flag:oc login -u test -p test --insecure-skip-tls-verify --config=/src