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

Problems building Go application with client-go #749

Closed
jpedro1992 opened this issue Feb 12, 2020 · 22 comments
Closed

Problems building Go application with client-go #749

jpedro1992 opened this issue Feb 12, 2020 · 22 comments

Comments

@jpedro1992
Copy link

jpedro1992 commented Feb 12, 2020

Problem Description

I am not being able to compile my application due to client-go.
I am working on a different scheduler for Kubernetes. These are my main dependencies:

Dependencies

k8sApi "k8s.io/api/core/v1"
k8sSchedulerApi "k8s.io/kubernetes/pkg/scheduler/apis/extender/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

Compilation Error

k8s.io/client-go/transport
..\k8s.io\client-go\transport\round_trippers.go:70:11: cannot convert klog.V(9) (type klog.Verbose) >to type bool
..\k8s.io\client-go\transport\round_trippers.go:72:11: cannot convert klog.V(8) (type klog.Verbose) >to type bool
..\k8s.io\client-go\transport\round_trippers.go:74:11: cannot convert klog.V(7) (type klog.Verbose) >to type bool
..\k8s.io\client-go\transport\round_trippers.go:76:11: cannot convert klog.V(6) (type klog.Verbose) >to type bool

I tried to use go.mod but I had no success, unable to sync packages:

go: finding k8s.io/kubernetes/pkg latest
go: finding k8s.io/kubernetes/pkg/scheduler/apis latest
go: finding k8s.io/kubernetes/pkg/scheduler/apis/extender latest
go: finding k8s.io/kubernetes/pkg/scheduler latest
go: k8s.io/kubernetes@v1.17.3 requires
  k8s.io/api@v0.0.0: reading k8s.io/api/go.mod at revision v0.0.0: unknown revision v0.0.0

go.mod:

go 1.13

require (
  golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
  golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
  k8s.io/api v0.17.3
  k8s.io/apimachinery v0.17.3
  k8s.io/client-go v11.0.0+incompatible
  k8s.io/utils v0.0.0-20200124190032-861946025e34 // indirect
)


Any way to make it work with or without go.mod? How it is supposed to write the Dockerfile?

@sbhardwaj-mt
Copy link

I found the similar issue building the repo's master example for
vendor/k8s.io/client-go/rest/request.go:598:31: not enough arguments in call to watch.NewStreamWatcher have (*versioned.Decoder) want (watch.Decoder, watch.Reporter)

@StiviiK
Copy link

StiviiK commented Feb 27, 2020

I found the similar issue building the repo's master example for
vendor/k8s.io/client-go/rest/request.go:598:31: not enough arguments in call to watch.NewStreamWatcher have (*versioned.Decoder) want (watch.Decoder, watch.Reporter)

I also receive the same error.

@StiviiK
Copy link

StiviiK commented Feb 28, 2020

Fixed @sbhardwaj-mt's and mine error by using the following go.mod:

go 1.14

require (
	k8s.io/api v0.0.0-20200214081623-ecbd4af0fc33
	k8s.io/apimachinery v0.0.0-20200214081019-7490b3ed6e92
	k8s.io/client-go v0.0.0-20200214082307-e38a84523341
	k8s.io/code-generator v0.0.0-20200214080538-dc8f3adce97c
	k8s.io/klog v1.0.0
)

replace (
	golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
	golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
	k8s.io/api => k8s.io/api v0.0.0-20200214081623-ecbd4af0fc33
	k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200214081019-7490b3ed6e92
	k8s.io/client-go => k8s.io/client-go v0.0.0-20200214082307-e38a84523341
	k8s.io/code-generator => k8s.io/code-generator v0.0.0-20200214080538-dc8f3adce97c
)

@mstrYoda
Copy link

mstrYoda commented Mar 3, 2020

It might not resolve your issue but can you try to replace k8s.io/client-go v11.0.0+incompatible with k8s.io/client-go v0.17.0 in your go.mod file?

@EwanValentine
Copy link

I'm having similar issues with dependencies unfortunately:

build github.com/EwanValentine/hypermap/api: cannot load github.com/googleapis/gnostic/OpenAPIv2: module github.com/googleapis/gnostic@latest found (v0.4.1), but does not contain package github.com/googleapis/gnostic/OpenAPIv2

Here's my go.mod file:

module github.com/EwanValentine/hypermap/api

go 1.13

replace (
	golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
	golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
	k8s.io/api => k8s.io/api v0.0.0-20200214081623-ecbd4af0fc33
	k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200214081019-7490b3ed6e92
	k8s.io/client-go => k8s.io/client-go v0.17.0
	k8s.io/code-generator => k8s.io/code-generator v0.0.0-20200214080538-dc8f3adce97c
)

require (
	github.com/99designs/gqlgen v0.11.3
	github.com/googleapis/gnostic v0.4.1 // indirect
	github.com/imdario/mergo v0.3.8 // indirect
	github.com/json-iterator/go v1.1.9 // indirect
	github.com/rs/cors v1.7.0
	github.com/stripe/stripe-go v70.5.0+incompatible
	github.com/vektah/gqlparser/v2 v2.0.1
	golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
	golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
	k8s.io/api v0.17.0
	k8s.io/apimachinery v0.17.0
	k8s.io/client-go v0.17.0
)

@EwanValentine
Copy link

Sorry for the noise but I've just resolved this by doing:

replace (
	github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.3.1
        ...
)

@lwabish
Copy link

lwabish commented Mar 25, 2020

It might not resolve your issue but can you try to replace k8s.io/client-go v11.0.0+incompatible with k8s.io/client-go v0.17.0 in your go.mod file?

yes, works for me.
I wonder why go mod uses v11.0.0 version at first when initiating?

@lossanarch
Copy link

This is still a problem, and being forced to use replace is not a good solution.
I would guess that the proxy is selecting the highest semver available to it, which means since the valid major version is now v0, it's always going to prefer to select v12.

@gosoon
Copy link

gosoon commented Apr 3, 2020

I have the same problem.

@lozenko
Copy link

lozenko commented Apr 29, 2020

same problem

@carnott-snap
Copy link

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?

@liggitt
Copy link
Member

liggitt commented May 12, 2020

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)

@carnott-snap
Copy link

carnott-snap commented May 12, 2020

This is really painful for upgrades, and the selected version scheme conflicts with minimum version selection in nuanced and complex ways. Is there any plan to improve things, or are you indicating that it is not yet painful enough to justify investment?

Spitballing alternatives:

  • Move to semver such that compatibility guarantees are provided:
    • from: v0.18.2
    • to: v18.2.0
    • This was initially one of the proposed versioning schemes, but was turned down.
    • This could conflict with old releases like v11.0.0, but since nothing lower than v0.15.8 has been released this year, it seems moot.
  • Move to a new import path prefix, either a new domain or a new folder:
    • from: k8s.io/api
    • to: k8s.dev/api
    • or: k8s.io/v/api
  • Move to a prohibitively large major, and keep rolling:
    • from: v0.18.2
    • to: v99.18.2
    • This has the same effect of a new folder, since k8s.io/api/v99 is the import path.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 11, 2020
@carnott-snap
Copy link

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 11, 2020
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 9, 2020
@carnott-snap
Copy link

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 19, 2020
@albertmenglongli
Copy link

same problem

@ebilling
Copy link

ebilling commented Mar 3, 2021

This module has a major issue with its version tags that confuse Golang:

Latest version tag is supposed to be v0.20.4, but there are also tags of v1.. through v12.0.0 (dated Jun 20, 2019)

This breaks basic module versioning as of GO 1.11. If you don't select a version for v2 or greater that it will only pull the highest major of 0 or 1. Which as of today is v1.5.2 which contains a go.mod that retracts all previous module versions including v1.5.2. I have no idea if that works or not, but since I'm still having trouble just using the module without an explicit replace directive in my go.mod, I suspect it's not.

I created a similar issue in one of my repos and the only way to deal with it was to delete the version tags for the higher versions. Otherwise, everyone has to manually run the replace, and they won't pick up changes on an update. That's a major pain and makes it difficult to stay current for security fixes.

I appreciate that some people may have hard coded those old version tags, but IMHO, they need to be removed. They have been causing problems for over a year.

@liggitt
Copy link
Member

liggitt commented Mar 3, 2021

using go1.16 (which honors the retract directives we just added), go get k8s.io/client-go@latest will resolve to the latest unretracted version, and works as expected:

go version
go version go1.16 darwin/amd64

go mod init myexample
go: creating new go.mod: module myexample

go get k8s.io/client-go
go get: added k8s.io/client-go v0.20.4

Deleting the old tags has all the downsides of disrupting builds of older clients, and wouldn't remove cached versions of those versions held by things like the module proxy.

Explicitly specifying the version you want with go get k8s.io/client-go@$version or using go1.16+ to go get k8s.io/client-go@latest is the current recommendation.

@liggitt
Copy link
Member

liggitt commented Mar 4, 2021

The reporter of this issue in particular is encountering problems because it is trying to depend on k8s.io/kubernetes as a library, which is not recommended or supported.

For more general go get issues, https://github.com/kubernetes/client-go/blob/master/INSTALL.md has been updated to give more specific guidance for using a particular version, and for resolving the most common issues encountered.

@lboix
Copy link

lboix commented Mar 25, 2021

Here is a workaround that could help, especially if you are using Kubernetes 1.14 : #741 (comment)

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

No branches or pull requests