初次使用kubenetes client-go来学习遇到的问题。
代码使用github 练习:examples/out-of-cluster-client-configuration/main.go
使用go build -o app . 出现以下错误
# k8s.io/client-go/tools/clientcmd/api/v1
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\tools\clientcmd\api\v1\conversion.go:29:15: scheme.AddConversionFuncs undefined (type *runtime.Scheme has no field or method AddConversionFuncs)
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\tools\clientcmd\api\v1\conversion.go:31:12: s.DefaultConvert undefined (type conversion.Scope has no field or method DefaultConvert)
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\tools\clientcmd\api\v1\conversion.go:34:12: s.DefaultConvert undefined (type conversion.Scope has no field or method DefaultConvert)
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\tools\clientcmd\api\v1\conversion.go:37:12: s.DefaultConvert undefined (type conversion.Scope has no field or method DefaultConvert)
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\tools\clientcmd\api\v1\conversion.go:40:12: s.DefaultConvert undefined (type conversion.Scope has no field or method DefaultConvert)
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\tools\clientcmd\api\v1\conversion.go:43:12: s.DefaultConvert undefined (type conversion.Scope has no field or method DefaultConvert)
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\tools\clientcmd\api\v1\conversion.go:46:12: s.DefaultConvert undefined (type conversion.Scope has no field or method DefaultConvert)
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\tools\clientcmd\api\v1\conversion.go:49:12: s.DefaultConvert undefined (type conversion.Scope has no field or method DefaultConvert)
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\tools\clientcmd\api\v1\conversion.go:52:12: s.DefaultConvert undefined (type conversion.Scope has no field or method DefaultConvert)
# k8s.io/client-go/rest
D:\software\gotest\pkg\mod\k8s.io\client-go@v11.0.0+incompatible\rest\request.go:598:31: not enough arguments in call to watch.NewStreamWatcher
golang version:1.14
client-go version: 1.18
修改go.mod 文件,替换k8s.io\client-go@v11.0.0+incompatible为k8s.io/client-go v0.18.2,然后在go build就可以了,github issue中解释如下:
Related issue is that go get k8s.io/client-go@latest resolves to v11.0.0+incompatible not v0.18.2. Should I break this off as a separate discussion?
Unfortunately, that is not possible to resolve. k8s.io/client-go had major versions tagged prior to the introduction of go modules. go modules require any major version X >= 2 rename the module to k8s.io/client-go/v<X>.
Go considers tags >= 2.x.x which contain a go.mod file with a module name that doesn't end with /v<X> invalid and won't include them when resolving @latest, so until the k8s.io/client-go module is renamed with version suffixes, go get must indicate specific versions (e.g. go get k8s.io/client-go@v0.18.2)
有疑问加站长微信联系(非本文作者)