Hi there,
I've been using client-go in combination with go modules and got it to work last week. However suddenly it fails with the following message:
go: finding k8s.io/api/admissionregistration/v1alpha1 latest
go: finding k8s.io/api/admissionregistration latest
go: finding k8s.io/api latest
/Users/simonbein/.gvm/pkgsets/go1.11.2/global/pkg/mod/k8s.io/[email protected]+incompatible/kubernetes/scheme/register.go:22:2: unknown import path "k8s.io/api/admissionregistration
/v1alpha1": cannot find module providing package k8s.io/api/admissionregistration/v1alpha1
Go modules seems to be correctly set-up in the project as I am able to resolve other dependencies (e.g. logrus) without any issues.
package main
import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/kubernetes"
"path/filepath"
"os"
"fmt"
)
func main() {
var config *rest.Config
kubecfgpath := filepath.Join(os.Getenv("HOME"), ".kube", "config")
config, err := clientcmd.BuildConfigFromFlags("", kubecfgpath)
clientset, err := kubernetes.NewForConfig(config)
// Please handle errors differently in your code ;)
if err != nil {
panic(err)
}
fmt.Println(clientset)
}
go.mod
module github.com/simontheleg/talks/k8s-client-package
require (
github.com/gogo/protobuf v1.2.0 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/json-iterator/go v1.1.5 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/sirupsen/logrus v1.3.0
github.com/spf13/pflag v1.0.3 // indirect
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 // indirect
golang.org/x/oauth2 v0.0.0-20190115181402-5dab4167f31c // indirect
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
k8s.io/api v0.0.0-20190126160303-ccdd560a045f // indirect
k8s.io/apimachinery v0.0.0-20190126155707-0e6dcdd1b5ce // indirect
k8s.io/client-go v10.0.0+incompatible
k8s.io/klog v0.1.0 // indirect
sigs.k8s.io/yaml v1.1.0 // indirect
)
go.sum
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gogo/protobuf v1.2.0 h1:xU6/SpYbvkNYiptHJYEDRseDLvYE7wSqhYYNy0QSUzI=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/googleapis/gnostic v0.2.0 h1:l6N3VoaVzTncYYW+9yOz2LJJammFZGBO13sqgEhpy9g=
github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f h1:ShTPMJQes6tubcjzGMODIVG5hlrCeImaBnZzKF2N8SM=
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 h1:ulvT7fqt0yHWzpJwI57MezWnYDVpCAYBVuYst/L+fAY=
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/oauth2 v0.0.0-20190115181402-5dab4167f31c h1:pcBdqVcrlT+A3i+tWsOROFONQyey9tisIQHI4xqVGLg=
golang.org/x/oauth2 v0.0.0-20190115181402-5dab4167f31c/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
k8s.io/api v0.0.0-20190126160303-ccdd560a045f h1:CgbcfvEnFr7J/BeUgOeg2c1FCdhMfv3MZkPGu/3e7GI=
k8s.io/api v0.0.0-20190126160303-ccdd560a045f/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
k8s.io/apimachinery v0.0.0-20190126155707-0e6dcdd1b5ce h1:CzCioXa348Dzt9UuYrvxRrLGpL1ZV50QpyBHt01SYj4=
k8s.io/apimachinery v0.0.0-20190126155707-0e6dcdd1b5ce/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
k8s.io/client-go v8.0.0+incompatible h1:tTI4hRmb1DRMl4fG6Vclfdi6nTM82oIrTT7HfitmxC4=
k8s.io/client-go v8.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/client-go v9.0.0+incompatible h1:2kqW3X2xQ9SbFvWZjGEHBLlWc1LG9JIJNXWkuqwdZ3A=
k8s.io/client-go v9.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/client-go v10.0.0+incompatible h1:F1IqCqw7oMBzDkqlcBymRq1450wD0eNqLE9jzUrIi34=
k8s.io/client-go v10.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/klog v0.1.0 h1:I5HMfc/DtuVaGR1KPwUrTc476K8NCqNBldC7H4dYEzk=
k8s.io/klog v0.1.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
k8s.io/api v0.0.0-20190126160303 indicates it is pulling from the master branch of k8s.io/api (and other k8s dependencies)
That alpha API was just recently removed in master in preparation for 1.14
you need to either pull from the master branch of client-go as well, or pin the dependencies to a release branch rather than master
/close
@liggitt: Closing this issue.
In response to this:
k8s.io/api v0.0.0-20190126160303 indicates it is pulling from the master branch of k8s.io/api (and other k8s dependencies)
That alpha API was just recently removed in master in preparation for 1.14
you need to either pull from the master branch of client-go as well, or pin the dependencies to a release branch rather than master
/close
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.
Thank you very much for the answer, it is exactly like you said :)
Quick addition for all fellow go beginners who might come across this thread, here's how I got it to work using dependency pinning:
Add the following to your _go.mod_ file
require (
k8s.io/api kubernetes-1.13.2
k8s.io/client-go v10.0.0
)
(You can find a list of all available tags for the api package here https://github.com/kubernetes/api/tags)
My build is also failing with this message, and the above fix is not working. Any further idea on how to fix this?
I manage to fix this issue by removing indirect dependency, change the version to:
require (
k8s.io/api kubernetes-1.13.2
k8s.io/client-go v10.0.0
)
and do go mod tidy
Is this still working for everyone? It is not working for me at all.
GOPATHgo.mod as in https://github.com/kubernetes/client-go/issues/551#issuecomment-462619473go build ./... blows up with imports k8s.io/api/admissionregistration/v1alpha1: unknown import path "k8s.io/api/admissionregistration/v1alpha1": cannot find module providing package k8s.io/api/admissionregistration/v1alpha1The master branch has no admissionregistration/v1alpha1 anymore (1.13 did have it). That suggests that you vendor the master branch.
Odd, so for some reason it's ignoring kubernetes-1.13.2 which I've specified in go.mod. I will keep digging, thanks.
edit: I was mistaken. I was using kubernetes-1.13.3 tag which breaks with the above error. Switching to kubernetes-1.13.2 seems to have the same problem (when starting from a clean gopath), so not sure what's going on.
update: Swapping k8s.io/api and k8s.io/client-go to kubernetes-1.12.5 seems to work. 1.13 seems broken, for me at least.
I have the same problem. I think this can be reproduced by just starting fresh right now. Something is probably pulling in the v1alpha1 dependency. I don't directly depend on it at least.
specify matching versions of all three k8s.io/... components in your go.mod file, for example:
require (
k8s.io/api kubernetes-1.14.1
k8s.io/apimachinery kubernetes-1.14.1
k8s.io/client-go kubernetes-1.14.1
)
if you want to be extra super sure that you are not using newer versions (even if some of your other dependencies want to), you can pin those versions in your top-level go.mod file:
replace (
k8s.io/api => k8s.io/api kubernetes-1.14.1
k8s.io/apimachinery => k8s.io/apimachinery kubernetes-1.14.1
k8s.io/client-go => k8s.io/client-go kubernetes-1.14.1
)
opened https://github.com/kubernetes/kubernetes/pull/75595/files to update client-go INSTALL.md instructions with go module details
It is working for me now on go 1.12.1 with the requirements @liggitt posted.
None of the steps above worked for me initially.
However, running go clean -modcache, _and then_ pinning the k8s.io/... components like @liggitt suggested, followed by go mod tidy fixed things for me.
None of this is working if I try to use the kubernetes-1.14.1 tag…
if I try to use the
kubernetes-1.14.1tag…
that requires client-go v11.0.0 (or you can use the kubernetes-1.14.1 tag for that as well)
if that doesn't work for you, can you provide your complete go.mod file?
D'oh! Thank you, @liggitt!
I'm running into an issue where even after pinning these versions, specifying the replaces, and running the go clean -modcache, go goes in and replaces with the versions from master despite pinning these versions.
go goes in and replaces with the versions from master despite pinning these versions.
go will update require statements to reflect the maximal version desired among all your dependencies. however, the replace directives will govern what is actually used in the build.
running GO111MODULE=on go mod graph | grep k8s.io might help narrow down what dependency is bumping your require directives back up to master
@liggitt I am running into the same issue. Even the versions in the replace directive are being replaced.
For posterity, I ran into the same issue. I was pinning all my k8s.io dependencies to kubernetes-1.15.0 and I was using the replace directive to be extra sure that it would use the appropriate tag. However, go was still complaining that the k8s.io/api/core/v1 package didn't exist. In the end, I was able to resolve my issue by pinning to kubernetes-1.14.6 tag. I also cleaned my cache i.e. go clean -modcache.
Is there something up with the 1.15.0 tag?
This is still happening . Trying to follow this example
$ go mod init sample
go: creating new go.mod: module sample
$ GOOS=linux go build -o ./app .
go: finding k8s.io/apimachinery/pkg/api/errors latest
go: finding k8s.io/apimachinery/pkg/apis/meta latest
go: finding k8s.io/client-go/rest latest
go: finding k8s.io/client-go/kubernetes latest
go: finding k8s.io/apimachinery/pkg/api latest
go: finding k8s.io/apimachinery/pkg/apis latest
go: finding k8s.io/apimachinery/pkg latest
go: finding k8s.io/api/extensions/v1beta1 latest
go: finding k8s.io/api/coordination/v1beta1 latest
go: finding k8s.io/api/storage/v1alpha1 latest
go: finding k8s.io/api/batch/v2alpha1 latest
go: finding k8s.io/api/apps/v1beta1 latest
go: finding k8s.io/api/core latest
go: finding k8s.io/api/networking latest
go: finding k8s.io/api/storage latest
go: finding k8s.io/api/autoscaling latest
go: finding k8s.io/api/scheduling latest
go: finding k8s.io/api/extensions latest
go: finding k8s.io/api/batch latest
go: finding k8s.io/api/coordination latest
go: finding k8s.io/api/apps latest
go: finding k8s.io/api v0.18.3
go: finding k8s.io/api/certificates/v1beta1 latest
go: finding k8s.io/api/admissionregistration/v1beta1 latest
go: finding k8s.io/api/authentication/v1beta1 latest
go: finding k8s.io/api/policy/v1beta1 latest
go: finding k8s.io/api/node/v1beta1 latest
go: finding k8s.io/api/apps/v1beta2 latest
go: finding k8s.io/api/scheduling/v1beta1 latest
go: finding k8s.io/api/certificates latest
go: finding k8s.io/api/admissionregistration latest
go: finding k8s.io/api/authentication latest
go: finding k8s.io/api/policy latest
go: finding k8s.io/api/node latest
go: finding k8s.io/api/authorization/v1beta1 latest
go: finding k8s.io/api/networking/v1beta1 latest
go: finding k8s.io/api/autoscaling/v2beta1 latest
go: finding k8s.io/api/rbac/v1alpha1 latest
go: finding k8s.io/api/rbac/v1beta1 latest
go: finding k8s.io/api/authorization latest
go: finding k8s.io/api/autoscaling/v2beta2 latest
go: finding k8s.io/api/node/v1alpha1 latest
go: finding k8s.io/api/auditregistration/v1alpha1 latest
go: finding k8s.io/api/rbac latest
go: finding k8s.io/api/batch/v1beta1 latest
go: finding k8s.io/api/scheduling/v1alpha1 latest
go: finding k8s.io/api/events/v1beta1 latest
go: finding k8s.io/api/auditregistration latest
go: finding k8s.io/api/storage/v1beta1 latest
go: finding k8s.io/api/settings/v1alpha1 latest
go: finding k8s.io/api/events latest
go: finding k8s.io/api/settings latest
go: finding k8s.io/utils/integer latest
go: finding k8s.io/utils latest
go: finding golang.org/x/time/rate latest
go: finding golang.org/x/time latest
go: finding golang.org/x/oauth2 latest
build sample: cannot load k8s.io/api/admissionregistration/v1beta1: cannot find module providing package k8s.io/api/admissionregistration/v1beta1
$ cat go.mod
module sample
go 1.12
require (
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect
k8s.io/apimachinery v0.18.3
k8s.io/client-go v11.0.0+incompatible
k8s.io/utils v0.0.0-20200601170155-a0dff01d8ea5 // indirect
)
copy from kubebuilder
k8s.io/api v0.17.2
k8s.io/apimachinery v0.17.2
k8s.io/client-go v0.17.2
For my case, I just need to keep client-go version the same as k8s.io/apimachinery
require (
k8s.io/apimachinery v0.19.1
k8s.io/client-go v10.0.0+incompatible
)
replace (
k8s.io/client-go => k8s.io/client-go v0.19.1
)
this will accomplish the same thing:
require (
k8s.io/apimachinery v0.19.1
k8s.io/client-go v0.19.1
)
@liggitt I tried that, but failed, I think that one is some transitive dep?
For anyone trying to use 1.19 client-go I found this was what I needed to use
go mod init
go mod vendor
go mod download
Running Go 1.15
// go.mod
require (
k8s.io/api v0.19.1
k8s.io/apimachinery v0.19.1
k8s.io/client-go v0.19.1
)
Took me a while to find this - adding the language above to help others looking for a solution here. Also important to note that I had to reset my cache from building was a previous version of the libraries as well.
Most helpful comment
Thank you very much for the answer, it is exactly like you said :)
Quick addition for all fellow go beginners who might come across this thread, here's how I got it to work using dependency pinning:
Add the following to your _go.mod_ file
(You can find a list of all available tags for the api package here https://github.com/kubernetes/api/tags)