kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
8.78k stars 2.9k forks source link

go get upgrade broke compilation #1266

Closed regnaio closed 1 year ago

regnaio commented 1 year ago

Breaking change (migration from gnostic -> gnostic-models):


Updated packages using go get -u ./...

Then, I tried running a go file using go run <FILE>

Got the error message:

cannot use doc (variable of type *"github.com/google/gnostic/openapiv2".Document) as *"github.com/google/gnostic-models/openapiv2".Document

# k8s.io/client-go/applyconfigurations/meta/v1
/go/pkg/mod/k8s.io/client-go@v0.27.2/applyconfigurations/meta/v1/unstructured.go:64:38: cannot use doc (variable of type *"github.com/google/gnostic/openapiv2".Document) as *"github.com/google/gnostic-models/openapiv2".Document value in argument to proto.NewOpenAPIData

Workaround

go get -u ./...

go get k8s.io/kube-openapi@v0.0.0-20230530175149-33f04d5d6b58
huypq6 commented 1 year ago

it is because kubeopenapi changes from gnostic to gnostic-models. Check commit

regnaio commented 1 year ago

Yes, but I'm confused why. This breaks builds for projects with client-go

morlay commented 1 year ago

it could fixed with same k8s.io/kube-openapi version of v0.27.2 https://github.com/kubernetes/client-go/blob/v0.27.2/go.mod#L30

replace k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f
davidhay1969 commented 1 year ago

Thanks for this, I've had a go with a PR - Issue 1266: Revving k8s.io/kube-openapi version #118572 - hope it's of some use 🤞

Jefftree commented 1 year ago

I'm trying to understand the use case better, why are you trying to upgrade via go get -u? The solution pinned by @morlay should work as we pin dependencies for each release. v0.27.2 k8s client-go should stick to the kube-openapi version defined in the go mod.

The latest version of kube-openapi with the gnostic-models is compatible with v0.28 client go.

davidhay1969 commented 1 year ago

Just to check @Jefftree are you asking that question of the OP @regnaio ? TBH I followed @morlay sensible advice to update go.mod via : -

go mod edit --replace k8s.io/kube-openapi@v0.0.0-20230601164746-7562a1006961=k8s.io/kube-openapi@v0.0.0-20230606174411-725288a7abf1

and then ran go mod tidy before validating via go vet ./... etc.

Jefftree commented 1 year ago

Anyone with the problem can pitch in. We generally test new changes from library upgrades (go get -u) on the latest master branch (v0.28 at the moment) to look at compatibility and the pinned versions in go.mod are thoroughly tested with the client-go version. We cannot guarantee that everything works with library versions outside the pinned dependencies.

Is there a specific library that you wanted to upgrade via go get -u that was not reflected in the go.mod for your client-go version?

davidhay1969 commented 1 year ago

OK, so the reason that I ended up here was that we have a project that's using k8s.io/client-go amongst other k8s.io projects, which reports: -

# k8s.io/client-go/applyconfigurations/meta/v1
../../../../pkg/mod/k8s.io/client-go@v0.27.2/applyconfigurations/meta/v1/unstructured.go:64:38: cannot use doc (variable of type *"github.com/google/gnostic/openapiv2".Document) as *"github.com/google/gnostic-models/openapiv2".Document value in argument to proto.NewOpenAPIData

when we run go vet ./...

I've been tinkering with versions of client-go via go.mod within our own project, and am currently on : -

k8s.io/client-go v0.27.2

( using the tags page for inspiration )

but see the same behaviour with the very latest v0.28.0-alpha.1 : -

# k8s.io/client-go/applyconfigurations/meta/v1
../../../../pkg/mod/k8s.io/client-go@v0.28.0-alpha.1/applyconfigurations/meta/v1/unstructured.go:64:38: cannot use doc (variable of type *"github.com/google/gnostic/openapiv2".Document) as *"github.com/google/gnostic-models/openapiv2".Document value in argument to proto.NewOpenAPIData

We are also pulling in k8s.io/kube-openapi via an indirect reference in go.mod : -

    k8s.io/kube-openapi v0.0.0-20230601164746-7562a1006961 //indirect

Apologies if I'm being a complete n00b - I'd read the problem as being with k8s.io/client-go and saw this issue as providing the mitigation, hence my PR ...

davidhay1969 commented 1 year ago

Quick update, noting that the client-go page has been updated to include v0.28.0-alpha.2, I updated go.mod within our project, changing from: -

k8s.io/client-go v0.26.1

to: -

k8s.io/client-go v0.28.0-alpha.2

and then running go mod tidy, go vet ./... no longer throws up the cannot use doc (variable of type *"github.com/google/gnostic/openapiv2".Document) as *"github.com/google/gnostic-models/openapiv2".Document value in argument to proto.NewOpenAPIData warning.

I'm going to test our project more fully, waiting on Travis to build it, but .... 🤞

Jefftree commented 1 year ago

@davidhay1969 Thanks for the confirmation. Feel free to reopen if more problems are found but I'll mark this as fixed for now.

The solution will fully resolve itself once client-go v0.28 is released which is estimated to be in July. In the meantime, there are two workarounds:

  1. Pin kube-openapi to a version before the gnostic rename and stick with an older version of client-go (<0.28) go mod edit --replace k8s.io/kube-openapi@v0.0.0-20230601164746-7562a1006961=k8s.io/kube-openapi@v0.0.0-20230606174411-725288a7abf1 Unfortunately this will need to be done on every go get -u ./... if the latest version changes

  2. Upgrade client-go to k8s.io/client-go v0.28.0-alpha.2 (eg: replace in go.mod). I would encourage sticking to solution 1 in production environments since alpha is not guaranteed to be stable.

/close

k8s-ci-robot commented 1 year ago

@Jefftree: Closing this issue.

In response to [this](https://github.com/kubernetes/client-go/issues/1266#issuecomment-1585078271): >@davidhay1969 Thanks for the confirmation. Feel free to reopen if more problems are found but I'll mark this as fixed for now. > >The solution will fully resolve itself once client-go v0.28 is released which is estimated to be in July. In the meantime, there are two workarounds: > >1. Pin kube-openapi to a version before the gnostic rename and stick with an older version of client-go (<0.28) >```go mod edit --replace k8s.io/kube-openapi@v0.0.0-20230601164746-7562a1006961=k8s.io/kube-openapi@v0.0.0-20230606174411-725288a7abf1``` >Unfortunately this will need to be done on every `go get -u ./...` if the latest version changes > >2. Upgrade client-go to `k8s.io/client-go v0.28.0-alpha.2` (eg: replace in go.mod). I would encourage sticking to solution 1 in production environments since alpha is not guaranteed to be stable. > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.