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

AddEventHandler return type error #2302

Closed
VincentYuan-hub opened this issue May 5, 2023 · 10 comments
Closed

AddEventHandler return type error #2302

VincentYuan-hub opened this issue May 5, 2023 · 10 comments

Comments

@VincentYuan-hub
Copy link

root/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.6/pkg/cache/multi_namespace_cache.go:308:9: cannot use handles (variable of type map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration) as type "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration in return statement:
        map[string]"k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration does not implement "k8s.io/client-go/tools/cache".ResourceEventHandlerRegistration (missing HasSynced method)

I check the code , It feels like a mistake

func (i *multiNamespaceInformer) AddEventHandler(handler toolscache.ResourceEventHandler) (toolscache.ResourceEventHandlerRegistration, error) {
	handles := make(map[string]toolscache.ResourceEventHandlerRegistration, len(i.namespaceToInformer))
	for ns, informer := range i.namespaceToInformer {
		registration, err := informer.AddEventHandler(handler)
		if err != nil {
			return nil, err
		}
		handles[ns] = registration
	}
	return handles, nil
}
@sbueringer
Copy link
Member

Which versions of controller-runtime and client-go are you using?

@VincentYuan-hub
Copy link
Author

您使用的是哪个版本的 controller-runtime 和 client-go?

k8s.io/client-go v0.26.3
sigs.k8s.io/controller-runtime v0.14.6

I feel this error is reasonable. it declare to return toolscache.ResourceEventHandlerRegistration, but return map[string]toolscache.ResourceEventHandlerRegistration

@sbueringer
Copy link
Member

ResourceEventHandlerRegistration doesn't have a HasSynced func in client-go v0.26.3

https://github.com/kubernetes/client-go/blob/v0.26.3/tools/cache/shared_informer.go#L213-L216

This was introduced in v0.27.x

https://github.com/kubernetes/client-go/blob/v0.27.1/tools/cache/shared_informer.go#L217-L227

Based on that I assume that somehow client-go v0.27 is used

@VincentYuan-hub
Copy link
Author

Thank you for response. I had checked . it used v0.27.x

@pixelsoccupied
Copy link

Hi there, ran into the same issue. In my case i used the latest client-go and controller controller-runtime

k8s.io/client-go v0.27.1
sigs.k8s.io/controller-runtime v0.14.6

Potential fix of pinning everything to v0.26.4 did the trick trick for now.

replace (
	k8s.io/api => k8s.io/api v0.26.4
	k8s.io/apimachinery => k8s.io/apimachinery v0.26.4
	k8s.io/client-go => k8s.io/client-go v0.26.4
	sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.14.6
)

operator-framework/operator-sdk#6396

@sbueringer
Copy link
Member

sbueringer commented May 15, 2023

Not sure why those replace statements are needed, that's probably specific to your case.

We are just having them as normal dependencies (https://github.com/kubernetes-sigs/cluster-api/blob/main/go.mod#L35-L45) and go mod tidy etc. don' try to bump

@benjibc
Copy link

benjibc commented May 18, 2023

Thanks @sbueringer ! Do you want to consider supporting k8s.io/client-go v0.27.x going forward? Otherwise I will always be stuck on this version for k8s api if I was to include this library in my project.

@sbueringer
Copy link
Member

The main branch already supports it. Next release is currently planned for next week.

In general we create corresponding CR releases after Kubernetes releases. This time we had to wait for a fix in 0.27.2

@spolti
Copy link

spolti commented Jan 13, 2024

@sbueringer it still happening on 0.27.6.

@sbueringer
Copy link
Member

sbueringer commented Jan 15, 2024

Without more context it's had to tell what is going wrong.

What I can do is provide an example. In Cluster API v1.5.x we use controller-runtime v0.15.3 with client-go v0.27.7 without any issues.

To be clear. At the time we were only waiting for v0.27.2 to release controller-runtime v0.15.0.

v0.27.2 wasn't supposed to (and didn't) make client-go compatible with controller-runtime v0.14.x.

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

5 participants