-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Allow in-cluster config for oc #5722
Allow in-cluster config for oc #5722
Conversation
[test] |
I'm going to also fix the stupid message "error in default cluster" |
03a8358
to
72e4e06
Compare
@@ -33,24 +35,62 @@ import ( | |||
routegen "github.com/openshift/origin/pkg/route/generator" | |||
) | |||
|
|||
// defaultClusterConfigURL is a local name that is used to identify when the client config | |||
// is unspecified. | |||
const defaultClusterConfigURL = "https://origin-server.local:8443" |
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.
O_o
How does this fix in cluster config? |
In cluster config doesn't work if the default cluster host value is empty. |
1a12da7
to
41215b8
Compare
Yeah, I remember someone's pull being rejected as "ugly". I look forward to seeing the beautiful version. :) |
if err != nil { | ||
return nil, err | ||
} | ||
if isDefaultConfig(cfg) { |
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.
So if we actually want to solve it this way, why not try to do it upstream? I can't say that I'm really a fan of this.
41215b8
to
6896447
Compare
I tested this and it now works without having to include the --token. However, I would also expect 'oc' to default to the pod's namespace, instead it defaults to 'default' and you have to specify '-n namespace'. |
@@ -143,6 +157,10 @@ func ConfirmUsable(config clientcmdapi.Config, passedContextName string) error { | |||
func validateClusterInfo(clusterName string, clusterInfo clientcmdapi.Cluster) []error { | |||
validationErrors := make([]error, 0) | |||
|
|||
if reflect.DeepEqual(clientcmdapi.Cluster{}, clusterInfo) { |
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 would expect you have to have problems with nil maps versus empty maps. If you don't have an issue now, be sure to add a test that goes through the load method. I remember a pull upstream that was looking at having empty maps instead of nil ones.
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.
A nil map would still be someone setup the config. I will add a test.
On Thu, Nov 5, 2015 at 11:00 AM, David Eads [email protected]
wrote:
In
Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/clientcmd/validation.go
#5722 (comment):@@ -143,6 +157,10 @@ func ConfirmUsable(config clientcmdapi.Config, passedContextName string) error {
func validateClusterInfo(clusterName string, clusterInfo clientcmdapi.Cluster) []error {
validationErrors := make([]error, 0)
- if reflect.DeepEqual(clientcmdapi.Cluster{}, clusterInfo) {
I would expect you have to have problems with nil maps versus empty maps.
If you don't have an issue now, be sure to add a test that goes through the
load method. I remember a pull upstream that was looking at having empty
maps instead of nil ones.—
Reply to this email directly or view it on GitHub
https://github.com/openshift/origin/pull/5722/files#r44028845.
At first glance, this looks like it simply changes the message. How is this changing behavior? |
func (c defaultingClientConfig) ClientConfig() (*kclient.Config, error) { | ||
cfg, err := c.nested.ClientConfig() | ||
if err != nil { | ||
if kclientcmd.IsEmptyCluster(err) { |
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.
Why would I be inspecting and transforming the error here instead of CheckErr
?
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.
More invasive change, also it would result in a because Kube would
have different messages than us.
On Thu, Nov 5, 2015 at 11:07 AM, David Eads [email protected]
wrote:
In pkg/cmd/util/clientcmd/factory.go
#5722 (comment):
+// RawConfig calls the nested method
+func (c defaultingClientConfig) RawConfig() (kclientcmdapi.Config, error) {
- return c.nested.RawConfig()
+}
+// Namespace calls the nested method
+func (c defaultingClientConfig) Namespace() (string, bool, error) {
- return c.nested.Namespace()
+}
+// ClientConfig returns a complete client config
+func (c defaultingClientConfig) ClientConfig() (*kclient.Config, error) {
- cfg, err := c.nested.ClientConfig()
- if err != nil {
if kclientcmd.IsEmptyCluster(err) {
Why would I be inspecting and transforming the error here instead of
CheckErr?—
Reply to this email directly or view it on GitHub
https://github.com/openshift/origin/pull/5722/files#r44029872.
6896447
to
db665a7
Compare
Now with upstream tests, a cleaner core story, and comments addressed |
I think we'll want different messages at some point. We should probably add a |
I'm still not seeing where this is changing the client you get for an empty config, but it does give a prettier message. lgetm |
It does not any more - Jordan's feedback convinced me not to do that. On Thu, Nov 5, 2015 at 12:59 PM, David Eads [email protected]
|
@@ -31,6 +31,14 @@ func init() { | |||
redactedBytes = []byte(string(sDec)) | |||
} | |||
|
|||
// IsConfigEmpty returns true if the config is empty. | |||
func IsConfigEmpty(config *Config) bool { | |||
return len(config.AuthInfos) == 0 && len(config.Clusters) == 0 && len(config.Contexts) == 0 && |
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.
does api.Semantic.DeepEqual(config, &Config{})
not work? That treats nil==map[]{}
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 can't require it from here because of circular dependencies.
@csrwng do you have KUBECONFIG set to a real file or KUBERNETES_MASTER set? |
[test] |
neither:
|
@@ -49,6 +55,16 @@ func IsContextNotFound(err error) bool { | |||
return strings.Contains(err.Error(), "context was not found for specified context") | |||
} | |||
|
|||
// IsEmptyConfig returns true if the provided error indicates the provided configuration | |||
// is empty. | |||
func IsEmptyConfig(err error) bool { |
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.
IsEmptyConfigError
, to keep us sane, since we also have IsConfigEmpty
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.
just saw we have other similarly named functions, nm for now I guess
a420428
to
0d57c59
Compare
Now uses POD_NAMESPACE iff EmptyConfig is returned. |
ab12593
to
b96c13c
Compare
verified that setting POD_NAMESPACE works |
Working on the e2e test now. On Fri, Nov 6, 2015 at 9:02 AM, Cesar Wong [email protected] wrote:
|
b96c13c
to
a5f322e
Compare
Should go green, can I get a final sign off on this? |
return nil, err | ||
} | ||
|
||
if icc, err := kclient.InClusterConfig(); 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.
I think we should switch to client/unversionted/clientcmd/inClusterClientConfig
, but we can do that later.
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.
Yeah it would need to be public and other things have to change (it doesn't implement ClientConfig)
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 think we should switch to client/unversionted/clientcmd/inClusterClientConfig, but we can do that later.
Yeah, the .Possible
method makes the behavior more obvious. Can we get a TODO?
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.
Added todo, waiting to see if this goes green before pushing (then i'll stick merge on it unless you find more things)
one request for a comment. lgtm, otherwise. |
working for me |
[merge] - last jenkins wedged |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/6960/) (Image: devenv-rhel7_2649) |
Because we set the default env value to empty, we can't use the default in cluster config for 'oc' (when you run inside a container, oc works). It's really important for container integration scenarios that oc uses the service account token by default, just like kubeconfig.
a5f322e
to
13cc7c6
Compare
Temporarily disabling e2e tests so this can merge (cesar has manually validated), but ca.crt generated into the running containers under hack/test-end-to-end-docker.sh has newlines, and ca.crt generated into hack/test-end-to-end.sh does not. |
Evaluated for origin test up to 13cc7c6 |
Evaluated for origin merge up to 13cc7c6 |
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/6960/) |
Because we set the default env value to empty, we can't use the default
in cluster config for 'oc' (when you run inside a container, oc works).
It's really important for container integration scenarios that oc uses
the service account token by default, just like kubeconfig.
Regression from upstream kubectl behavior, blocks a significant amount of
real integrations inside containers.