controller-runtime icon indicating copy to clipboard operation
controller-runtime copied to clipboard

Undefined SwitchMetric Error with client-go 0.30.0 in Go Vet

Open kkb0318 opened this issue 1 year ago • 8 comments

I recently updated to client-go version 0.30.0 while developing a Kubernetes controller using the Operator SDK. When running go vet ./... on my project, the following error occurred, suggesting an issue with the controller-runtime package:

❯ go vet ./...
# sigs.k8s.io/controller-runtime/pkg/metrics
/Users/kkb/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/metrics/leaderelection.go:26:71: undefined: leaderelection.SwitchMetric

Go Version

go version go1.22.2 darwin/amd64

OS

MacOS 14.4.1

kkb0318 avatar Apr 18 '24 13:04 kkb0318

Controller-runtime v0.17.3 is using client-go 0.29.

Sometimes it's impossible for us to be compatible with multiple client-go versions at the same time. IIRC this is such a case.

So I think the only options are:

  • to stay on client-go 0.29 (for now)
  • to switch to controller-runtime main branch + client-go 0.30 (and eventually upgrade to v0.18)

sbueringer avatar Apr 18 '24 13:04 sbueringer

Thank you for the quick response and the clarification.

I appreciate the guidance on compatible versions. I wasn't aware that client-go had updated so recently. I will wait to update until the controller-runtime is compatible with the newer client-go version.

Thanks again for your support!

kkb0318 avatar Apr 19 '24 12:04 kkb0318

You're welcome.

The general pattern at the moment is that we have a 1:1 mapping between controller-runtime and client-go (i.e. at least 1 controller-runtime release for every client-go release)

We try to stay as compatible as possible with other client-go versions but that is not always possible. It largely depends on if there are breaking changes in client-go and what these are (i.e. if they can be mitigated).

There is now also a PR in k/k: https://github.com/kubernetes/kubernetes/pull/124372. Depending on the outcome it could be that client-go v0.30.1+ will be compatible with CR v0.17 again.

sbueringer avatar Apr 19 '24 14:04 sbueringer

I have upgraded my operator code to adopt K8s v0.30 this week and seeing this issue. When are we planning to release v0.18 with this adoption ?

rahulsb avatar Apr 23 '24 12:04 rahulsb

Current plan was this week. Related Slack thread: https://kubernetes.slack.com/archives/C02MRBMN00Z/p1713510019996969

nit: I don't think this is a bug in controller-runtime, rather a breaking change in client-go

sbueringer avatar Apr 23 '24 13:04 sbueringer

Current plan was this week. Related Slack thread: https://kubernetes.slack.com/archives/C02MRBMN00Z/p1713510019996969

nit: I don't think this is a bug in controller-runtime, rather a breaking change in client-go

Thanks for actively working on this. Sorry, I have fixed my comments. Looking forward to the new release.

rahulsb avatar Apr 23 '24 14:04 rahulsb

Thank you for the quick fix and release.

rashedkvm avatar Apr 24 '24 23:04 rashedkvm

@alvaroaleman should we close this or wait if there's something that we should do after https://github.com/kubernetes/kubernetes/pull/124372 merges?

I lean towards there's probably nothing we can do. But we can wait a bit and see what happens to the k/k PR. I suspect it might make client-go 0.30.x compatible with CR v0.17. But given that we don't have any testing I wouldn't try to make CR v0.18 compatible with client-go 0.29

sbueringer avatar Apr 25 '24 05:04 sbueringer

I lean towards there's probably nothing we can do. But we can wait a bit and see what happens to the k/k PR. I suspect it might make client-go 0.30.x compatible with CR v0.17. But given that we don't have any testing I wouldn't try to make CR v0.18 compatible with client-go 0.29

Yeah, realistically we have a 1:1 mapping between the two, as there is no testing for skew, we can not promise that it will work anyways.

alvaroaleman avatar Jun 08 '24 16:06 alvaroaleman