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

config: fix using the KUBECONFIG to build the client #84

Merged
merged 1 commit into from
Jul 24, 2018

Conversation

rphillips
Copy link
Contributor

@rphillips rphillips commented Jul 24, 2018

Fix passing the kubeconfig to the client factory.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 24, 2018
@sjenning
Copy link

/lgtm

@k8s-ci-robot
Copy link
Contributor

@sjenning: changing LGTM is restricted to assignees, and only kubernetes-sigs/controller-runtime repo collaborators may be assigned issues.

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@DirectXMan12
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 24, 2018
@DirectXMan12
Copy link
Contributor

approve bot might be borked right now, need to check.

@DirectXMan12
Copy link
Contributor

/approve

@DirectXMan12 DirectXMan12 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 24, 2018
@k8s-ci-robot k8s-ci-robot merged commit 85b0c6b into kubernetes-sigs:master Jul 24, 2018
justinsb pushed a commit to justinsb/controller-runtime that referenced this pull request Dec 7, 2018
…nfig

config: fix using the KUBECONFIG to build the client
DirectXMan12 pushed a commit that referenced this pull request Jan 31, 2020
disable git validation during release process
@migueleliasweb
Copy link

migueleliasweb commented Aug 3, 2023

There appears to be a regression error here. In the master branch the code seem to have been changed back to exactly what this PR fixed initially. Is that right?

Master branch: https://github.com/rphillips/controller-runtime/blob/master/pkg/client/config/config.go

func GetConfig() (*rest.Config, error) {
	if len(kubeconfig) > 0 {
		return clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
	}
	if len(os.Getenv("KUBECONFIG")) > 0 {
                 // HERE we have kubeconfig instead of os.Getenv("KUBECONFIG") again
		return clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
	}
	if c, err := rest.InClusterConfig(); err == nil {
		return c, nil
	}
	if usr, err := user.Current(); err == nil {
		if c, err := clientcmd.BuildConfigFromFlags(
			"", filepath.Join(usr.HomeDir, ".kube", "config")); err == nil {
			return c, nil
		}
	}

	return nil, fmt.Errorf("could not locate a kubeconfig")
}

Also, does it make sense to call rest.InClusterConfig() directly since clientcmd.BuildConfigFromFlags does it for us if the first and second params are set to empty string?

@sbueringer
Copy link
Member

sbueringer commented Aug 3, 2023

There is no master branch anymore on the upstream repository. And the code on the main branch looks different

(looks like what you linked is 5 years old)

@migueleliasweb
Copy link

Oh my god, I'm so sorry. I swear to god I was looking at the upstream kubernetes-sigs repo. My bad. Too many tabs open!

@sbueringer
Copy link
Member

No problem. IIRC GitHub also has some magic feature that sometimes redirects you to a fork if something doesn't exist on the main repo (I don't remember when exactly)

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants