kubernetes-sigs / controller-runtime

Repo for the controller-runtime subproject of kubebuilder (sig-apimachinery)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined SwitchMetric Error with client-go 0.30.0 in Go Vet

kkb0318 opened this issue · comments

commented

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/controller-runtime@v0.17.3/pkg/metrics/leaderelection.go:26:71: undefined: leaderelection.SwitchMetric

Go Version

go version go1.22.2 darwin/amd64

OS

MacOS 14.4.1

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)
commented

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!

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: kubernetes/kubernetes#124372. Depending on the outcome it could be that client-go v0.30.1+ will be compatible with CR v0.17 again.

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 ?

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

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.

Thank you for the quick fix and release.

@alvaroaleman should we close this or wait if there's something that we should do after kubernetes/kubernetes#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

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.