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

Generic Watches for builder #2955

Open
pmalek opened this issue Sep 22, 2024 · 2 comments
Open

Generic Watches for builder #2955

pmalek opened this issue Sep 22, 2024 · 2 comments
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@pmalek
Copy link

pmalek commented Sep 22, 2024

Problem statement

#2214 introduced (through #2783) generic funcs for Event, Predicate and Handler.

TypedBuilder has only 1 type parameter for the request type and since Go (as of 1.23) doesn't allow type parameters on methods golang/go#49085, Watches() uses handler.TypedEventHandler[client.Object, request] as eventHandler parameter.

That client.Object limits the handler functions to only have client.Object as argument types so users have to use:

podForService := func(ctx context.Context, obj client.Object) []reconcile.Request {
	svc , ok := obj.(*core.Service)
	if !ok {
		return nil
	}
	return nil
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
b := ctrl.NewControllerManagedBy(mgr)
b.For(&corev1.Pod{})
b.Watches(
	&corev1.Service{},
	handler.TypedEnqueueRequestsFromMapFunc(
		podForService,
	),
)

and cannot use strongly typed handlers like

podForServiceTyped := func(ctx context.Context, svc *corev1.Service) []reconcile.Request {
	return nil
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
b := ctrl.NewControllerManagedBy(mgr)
b.For(&corev1.Pod{})
b.Watches(
	&corev1.Service{},
	handler.TypedEnqueueRequestsFromMapFunc(
		podForServiceTyped,
	),
)

because

cannot use handler.TypedEnqueueRequestsFromMapFunc(podForServiceTyped) (value of type handler.TypedEventHandler[*"k8s.io/api/core/v1".Service, reconcile.Request]) as handler.TypedEventHandler[client.Object, reconcile.Request] value in argument to b.Watches: handler.TypedEventHandler[*"k8s.io/api/core/v1".Service, reconcile.Request] does not implement handler.TypedEventHandler[client.Object, reconcile.Request] (wrong type for method Create)
		have Create(context.Context, event.TypedCreateEvent[*"k8s.io/api/core/v1".Service], workqueue.TypedRateLimitingInterface[reconcile.Request])
		want Create(context.Context, event.TypedCreateEvent[client.Object], workqueue.TypedRateLimitingInterface[reconcile.Request])

Additional information

Due to golang/go#49085 this cannot be (easily?at all?) implemented as noted in #2783.

This issue is mostly for tracking and to acknowledge the API limitation.

Feel free to comment on the issue if you feel there's a way to move forward without Go implementing golang/go#49085.

Current workaround

If I understand correctly, the following is an equivalent which can be used:

src := source.Kind(
	mgr.GetCache(),
	&corev1.Service{},
	handler.TypedEnqueueRequestsFromMapFunc(
		podForServiceTyped,
	),
)
b.WatchesRawSource(src)
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/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 Dec 21, 2024
@sbueringer
Copy link
Member

You're correct. As far as I know there's nothing we can do about it. Not sure what we want to do with the issue. Maybe just close it? (folks can still find it via Google)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

4 participants