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

Support KUBECONF env variable #1076

Merged
merged 2 commits into from
Nov 25, 2019

Conversation

bouskaJ
Copy link
Contributor

@bouskaJ bouskaJ commented Nov 22, 2019

No description provided.

Copy link
Member

@nicolaferraro nicolaferraro left a comment

Choose a reason for hiding this comment

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

I'm not sure this solves the issue, because I see in the codebase that every time the getDefaultKubeConfigFile is called, the code previously check that the KubeConfigEnvVar is empty. If this is the case, this change should not have effect.

Are you running the operator or the CLI inside the container?

@bouskaJ
Copy link
Contributor Author

bouskaJ commented Nov 22, 2019

I can't agree. Let's see following functions read my comments:

func shouldUseContainerMode() (bool, error) {
	// When kube config is set, container mode is not used
	if os.Getenv(k8sutil.KubeConfigEnvVar) != "" {
		return false, nil                             --- My case - return false
	}

func initialize(kubeconfig string) {
	if kubeconfig == "" { 
		// skip out-of-cluster initialization if inside the container
		if kc, err := shouldUseContainerMode(); kc && err == nil {       --- kc == false -> continue
			return
		} else if err != nil {
			logrus.Errorf("could not determine if running in a container: %v", err)
		}
		var err error
		kubeconfig, err = getDefaultKubeConfigFile()      --- Load kubernetes config from HOME dir (not from KUBECONF)
		if err != nil {
			panic(err)
		}
	}
	os.Setenv(k8sutil.KubeConfigEnvVar, kubeconfig)           --- Override my KUBECONF property
}

Source:

func shouldUseContainerMode() (bool, error) {
// When kube config is set, container mode is not used
if os.Getenv(k8sutil.KubeConfigEnvVar) != "" {
return false, nil
}

https://github.com/apache/camel-k/blob/master/pkg/client/client.go#L136-L150

@nicolaferraro
Copy link
Member

The problem is that the code should even not enter that if branch, because the kubeconfig variable should have been populated with the KUBECONF env var or with the value passed via --config flag.

I'd like to understand why it isn't and fix that.

@bouskaJ
Copy link
Contributor Author

bouskaJ commented Nov 22, 2019

Ok, I am trying to run e2e tests. I forget to mention it. Test client is initialized with empty string.

func newTestClient() (client.Client, error) {
	return client.NewOutOfClusterClient("")
}

https://github.com/apache/camel-k/blob/master/e2e/test_support.go#L82

@nicolaferraro
Copy link
Member

To avoid inconsistencies between --config and KUBECONF, what do you think about moving all references to os.getEnv outside the pkg/client package and rely on the kubeconfig variable only.

Then we change the tests to pick values from the KUBECONF env (cobra commands already initializes it from env or from the --config flag).

@bouskaJ
Copy link
Contributor Author

bouskaJ commented Nov 22, 2019

Sounds reasonable. I will update my PR on Monday.

@bouskaJ
Copy link
Contributor Author

bouskaJ commented Nov 25, 2019

@nicolaferraro you are right. https://github.com/apache/camel-k/blob/master/pkg/cmd/root.go#L54 should be enough. Please check my test-fix.

@nicolaferraro nicolaferraro merged commit 7ff682f into apache:master Nov 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants