-
Notifications
You must be signed in to change notification settings - Fork 242
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
kubeconfig: remove default namespace from crc-developer context #4420
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,29 +160,40 @@ func Test_addContext(t *testing.T) { | |
username string | ||
context string | ||
token string | ||
namespace string | ||
} | ||
|
||
type expected struct { | ||
user string | ||
namespace string | ||
} | ||
|
||
tests := []struct { | ||
in input | ||
expected string | ||
expected expected | ||
}{ | ||
{ | ||
input{"https://abcdd.api.com", "foo", "foo@abcdd", "secretToken"}, | ||
"foo/abcdd-api-com", | ||
input{"https://abcdd.api.com", "foo", "foo@abcdd", "secretToken", "kube-system"}, | ||
expected{"foo/abcdd-api-com", "kube-system"}, | ||
}, | ||
{ | ||
input{"https://api.crc.testing:6443", "kubeadmin", "kubeadm", "secretToken", "default"}, | ||
expected{"kubeadmin/api-crc-testing:6443", "default"}, | ||
}, | ||
{ | ||
input{"https://api.crc.testing:6443", "kubeadmin", "kubeadm", "secretToken"}, | ||
"kubeadmin/api-crc-testing:6443", | ||
input{"https://api.crc.testing:6443", "kubeadmin", "kubeadm", "secretToken", ""}, | ||
expected{"kubeadmin/api-crc-testing:6443", ""}, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @anjannath we should add one more test case which have empty string as namespace which make sure the context is added to kubeconfig but without namespace. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated the test |
||
} | ||
|
||
cfg := api.NewConfig() | ||
|
||
for _, tt := range tests { | ||
err := addContext(cfg, tt.in.clusterAPI, tt.in.context, tt.in.username, tt.in.token) | ||
err := addContext(cfg, tt.in.clusterAPI, tt.in.context, tt.in.username, tt.in.token, tt.in.namespace) | ||
assert.NoError(t, err) | ||
assert.Contains(t, cfg.Contexts, tt.in.context, "Expected context not found") | ||
assert.Contains(t, cfg.AuthInfos, tt.expected, "Expected AuthInfo not found") | ||
assert.Contains(t, cfg.AuthInfos[tt.expected].Token, tt.in.token, "Expected token not found") | ||
assert.Equal(t, cfg.Contexts[tt.in.context].Namespace, tt.expected.namespace, "Expected namespace not found") | ||
assert.Contains(t, cfg.AuthInfos, tt.expected.user, "Expected AuthInfo not found") | ||
assert.Contains(t, cfg.AuthInfos[tt.expected.user].Token, tt.in.token, "Expected token not found") | ||
} | ||
} |
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.
what happens with the namespace set to
""
?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.
with an empty namespace in the context we still get the same error, but
oc config get-contexts
no longer shows a namespace for thecrc-developer
contextThere 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.
It is not only that but now when user try to check project switch to any project then it provide better error message instead forbidden error, we should have that as part of commit log.
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.
These are good reasons for the change, thanks for the explanations. Can this be added to the commit log?
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.
Thanks, i've updated the commit log to contain the error messages shown after the changes in this PR