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

Allow in-cluster config for oc #5722

Merged

Conversation

smarterclayton
Copy link
Contributor

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.

@smarterclayton smarterclayton added priority/P1 approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 5, 2015
@smarterclayton
Copy link
Contributor Author

@liggitt @deads2k @csrwng this unblocks running oc from within a container under the service account token, which means we can use oc inside our containers automatically.

@smarterclayton
Copy link
Contributor Author

[test]

@smarterclayton smarterclayton self-assigned this Nov 5, 2015
@smarterclayton smarterclayton modified the milestone: 1.1.0 Nov 5, 2015
@smarterclayton
Copy link
Contributor Author

I'm going to also fix the stupid message "error in default cluster"

@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O_o

@liggitt
Copy link
Contributor

liggitt commented Nov 5, 2015

How does this fix in cluster config?

@smarterclayton
Copy link
Contributor Author

In cluster config doesn't work if the default cluster host value is empty.

@smarterclayton smarterclayton force-pushed the allow_incluster_config branch 2 times, most recently from 1a12da7 to 41215b8 Compare November 5, 2015 05:21
@deads2k
Copy link
Contributor

deads2k commented Nov 5, 2015

I'm going to also fix the stupid message "error in default cluster"

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) {
Copy link
Contributor

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.

@csrwng
Copy link
Contributor

csrwng commented Nov 5, 2015

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@csrwng
Copy link
Contributor

csrwng commented Nov 5, 2015

@deads2k
Copy link
Contributor

deads2k commented Nov 5, 2015

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@smarterclayton
Copy link
Contributor Author

Now with upstream tests, a cleaner core story, and comments addressed

@deads2k
Copy link
Contributor

deads2k commented Nov 5, 2015

More invasive change, also it would result in a because Kube would
have different messages than us.

I think we'll want different messages at some point. We should probably add a ErrorInterpretter or some such to kube.

@deads2k
Copy link
Contributor

deads2k commented Nov 5, 2015

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

@smarterclayton
Copy link
Contributor Author

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]
wrote:

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


Reply to this email directly or view it on GitHub
#5722 (comment).

@@ -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 &&
Copy link
Contributor

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[]{}

Copy link
Contributor Author

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.

@smarterclayton
Copy link
Contributor Author

@csrwng do you have KUBECONFIG set to a real file or KUBERNETES_MASTER set?

@smarterclayton
Copy link
Contributor Author

[test]

@csrwng
Copy link
Contributor

csrwng commented Nov 5, 2015

neither:

bash-4.2$ env | grep KUBECONFIG
bash-4.2$ env | grep KUBERNETES_MASTER

@@ -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 {
Copy link
Contributor

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

Copy link
Contributor

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

@smarterclayton
Copy link
Contributor Author

Now uses POD_NAMESPACE iff EmptyConfig is returned.

@smarterclayton smarterclayton force-pushed the allow_incluster_config branch 2 times, most recently from ab12593 to b96c13c Compare November 6, 2015 01:55
@csrwng
Copy link
Contributor

csrwng commented Nov 6, 2015

verified that setting POD_NAMESPACE works

@smarterclayton
Copy link
Contributor Author

Working on the e2e test now.

On Fri, Nov 6, 2015 at 9:02 AM, Cesar Wong [email protected] wrote:

verified that setting POD_NAMESPACE works


Reply to this email directly or view it on GitHub
#5722 (comment).

@smarterclayton
Copy link
Contributor Author

Should go green, can I get a final sign off on this?

return nil, err
}

if icc, err := kclient.InClusterConfig(); err == nil {
Copy link
Contributor

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.

Copy link
Contributor Author

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)

Copy link
Contributor

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?

Copy link
Contributor Author

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)

@deads2k
Copy link
Contributor

deads2k commented Nov 6, 2015

one request for a comment.

lgtm, otherwise.

@csrwng
Copy link
Contributor

csrwng commented Nov 6, 2015

working for me

@smarterclayton
Copy link
Contributor Author

[merge] - last jenkins wedged

@openshift-bot
Copy link
Contributor

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.
@smarterclayton
Copy link
Contributor Author

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.

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 13cc7c6

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 13cc7c6

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/6960/)

openshift-bot pushed a commit that referenced this pull request Nov 6, 2015
@openshift-bot openshift-bot merged commit 49be0e9 into openshift:master Nov 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. priority/P1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants