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

No Auth Provider found for name "gcp" #242

Closed
ianlewis opened this issue Jul 12, 2017 · 10 comments · Fixed by aca/go-kubectx#1
Closed

No Auth Provider found for name "gcp" #242

ianlewis opened this issue Jul 12, 2017 · 10 comments · Fixed by aca/go-kubectx#1

Comments

@ianlewis
Copy link

ianlewis commented Jul 12, 2017

For the following code I get an error when trying to connect to a GKE API server with v3.0.0.

FWIW this worked in v3.0.0.beta.0

I have a version of apimachinery that's about 28 days old. Could it have to do with some library incompatibility?

F0712 12:20:52.391235   71066 main.go:73] Could not create Kubernetes ThirdPartyResource API client: No Auth Provider found for name "gcp"
package main

import (
	"flag"

	"github.com/golang/glog"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"k8s.io/apimachinery/pkg/runtime/serializer"
	"k8s.io/client-go/kubernetes/scheme"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/clientcmd"
)

type Thing struct {
	metav1.TypeMeta `json:",inline"`
	ObjectMeta      metav1.ObjectMeta `json:"metadata"`
}

// Required to satisfy ObjectMetaAccessor interface
func (m *Thing) GetObjectMeta() metav1.Object {
	return &m.ObjectMeta
}

type ThingList struct {
	metav1.TypeMeta `json:",inline"`
	ListMeta        metav1.ListMeta `json:"metadata"`
	Items           []Thing         `json:"items"`
}

// Required to satisfy ListMetaAccessor interface
func (m *ThingList) GetListMeta() metav1.List {
	return &m.ListMeta
}

func main() {
	kubeconfig := flag.String("kubeconfig", "", "The path to a kubeconfig. Default is in-cluster config.")

	flag.Parse()

	config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
	if err != nil {
		glog.Exitf("Could not read kubeconfig %s: %v", *kubeconfig, err)
	}

	groupVersion := schema.GroupVersion{
		Group:   "ianlewis.org",
		Version: "v1alpha1",
	}

	config.GroupVersion = &groupVersion
	config.APIPath = "/apis"
	config.ContentType = runtime.ContentTypeJSON
	config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}

	schemeBuilder := runtime.NewSchemeBuilder(
		func(scheme *runtime.Scheme) error {
			scheme.AddKnownTypes(
				groupVersion,
				&Thing{},
				&ThingList{},
			)
			return nil
		},
	)
	schemeBuilder.AddToScheme(scheme.Scheme)

	_, err = rest.RESTClientFor(config)

	if err != nil {
		glog.Exitf("Could not create Kubernetes ThirdPartyResource API client: %v", err)
	}

	glog.Infof("OK")
}
@ianlewis
Copy link
Author

$ go version
go version go1.8 darwin/amd64

@ianlewis
Copy link
Author

It seems you need import the auth plugin package

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
// or
_ "k8s.io/client-go/plugin/pkg/client/auth"

Is this working as intended? Is there any benefit to not loading auth plugins by default?

@ericchiang
Copy link
Contributor

Is this working as intended? Is there any benefit to not loading auth plugins by default?

Yes and this is documented in a couple places. The benefit is not overloading regular clients with unnecessary imports. E.g you don't have to import OpenID Connect and Azure packages.

Going to close since it looks like this is working as intended.

@ianlewis
Copy link
Author

@ericchiang Can you point me to where it's documented?
It wasn't here:
https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration
https://github.com/kubernetes/client-go/tree/master/examples/out-of-cluster-client-configuration

I just guessed based on reading the source code. It feels like that could be improved. Not that there are not really any "docs" to speak of yet.

While I understand the need to avoid importing packages that aren't needed I question the wisdom of this a bit. I can see folks creating apps and integrations that don't work w/ GKE/Azure/Openid because they don't import the plugins. It feels weird to drop this all of a sudden since it worked in v2.0.0 and v3.0.0.beta.0

@ericchiang
Copy link
Contributor

@ianlewis a few of the examples have lines like this

// Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).

The actual change was made here kubernetes/kubernetes#41532 during the 1.6 release. Are you sure this changed between v3.0.0.beta.0 and v3.0.0? I'm not seeing them imported by default in v3.0.0.beta.0

https://github.com/kubernetes/client-go/blob/v3.0.0-beta.0/kubernetes/clientset.go
https://github.com/kubernetes/client-go/blob/v2.0.0/kubernetes/clientset.go#L35-Lundefined

I can add a changelog item for the v3.0.0.beta.0

life1347 added a commit to fission/fission that referenced this issue Sep 24, 2017
life1347 added a commit to fission/fission that referenced this issue Sep 27, 2017
life1347 added a commit to fission/fission that referenced this issue Sep 28, 2017
@ianlewis
Copy link
Author

ianlewis commented Oct 5, 2017

@ericchiang I suppose you're right that it was removed between v2.0.0 and v3.0.0 but still the issue stands.

@ianlewis
Copy link
Author

ianlewis commented Oct 5, 2017

More folks noticing this on twitter: https://twitter.com/davecheney/status/915770572017037312

@G-Harmon
Copy link

FYI, I hit this error message, and the 2nd Google search result led me here. Glad this has the solution!
As for where to document, perhaps somewhere near the docs for "gcloud container clusters get-credentials"?

tamalsaha added a commit to stashed/stash that referenced this issue Feb 12, 2018
tamalsaha added a commit to stashed/stash that referenced this issue Feb 12, 2018
wrdls added a commit to wrdls/orca that referenced this issue Jan 16, 2019
philpep pushed a commit to philpep/imago that referenced this issue Oct 31, 2020
jimmykarily pushed a commit to epinio/epinio that referenced this issue Jan 26, 2021
When a gke cluster is targeted we get this error:

No Auth Provider found for name "gcp"

This commit fixes it.

See also: kubernetes/client-go#242
jimmykarily pushed a commit to epinio/epinio that referenced this issue Jan 27, 2021
When a gke cluster is targeted we get this error:

No Auth Provider found for name "gcp"

This commit fixes it.

See also: kubernetes/client-go#242
ndhanushkodi added a commit to hashicorp/consul-k8s that referenced this issue Mar 17, 2021
* they needed the auth plugin import: _ "k8s.io/client-go/plugin/pkg/client/auth"
* kubernetes/client-go#242
ndhanushkodi added a commit to hashicorp/consul-k8s that referenced this issue Mar 22, 2021
* they needed the auth plugin import: _ "k8s.io/client-go/plugin/pkg/client/auth"
* kubernetes/client-go#242
proelbtn pushed a commit to janog-netcon/netcon-problem-management-subsystem that referenced this issue Jan 12, 2023
MaxDaten added a commit to MaxDaten/autopilot-cost-calculator that referenced this issue Aug 21, 2024
MaxDaten added a commit to MaxDaten/autopilot-cost-calculator that referenced this issue Aug 21, 2024
Fixes No Auth Provider found for name "gcp"
For reference: kubernetes/client-go#242
MaxDaten added a commit to MaxDaten/autopilot-cost-calculator that referenced this issue Aug 21, 2024
Fixes No Auth Provider found for name "gcp"
For reference: kubernetes/client-go#242
MaxDaten added a commit to MaxDaten/autopilot-cost-calculator that referenced this issue Aug 21, 2024
Fixes No Auth Provider found for name "gcp"
For reference: kubernetes/client-go#242
This issue was closed.
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 a pull request may close this issue.

5 participants