Description
At https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/builder/controller.go#L74 , For latches the apiType of the For() call.
If a controller-runtime consumer calls Builder.For(foo).For(bar), then foo will be silently lost in favour of bar.
This contrasts with Owns' behaviour, where Builder.Owns(foo).Owns(bar) will append both foo and bar to an internal slice.
Judging by the code comment on For (For defines the type of Object being *reconciled*
), it may not be intended for For to be called multiple times on a Builder. Nonetheless, the current behaviour can be confusing.
As a workaround, a consumer who wants to watch multiple apiTypes can use Watches(foo).Watches(bar) instead.
IMO it would be nice to make the behaviour here clearer, either:
- by raising an error if For() is called and bldr.apiType is already set, or
- by making apiTypes a slice and allowing For() to be called multiple times, as Owns() or Watches() is.