Open 2uasimojo opened 3 days ago
Can we use generics for this?
To expand on what I was thinking, I thought we might be able to have some sort of wrapper type for the various options that takes a client.Client
or client.WithWatch
through generics and returns whatever it has gotten. The main drawback is that the return will always be assertable to WithWatch
even if it it isn't.
Note that this plays into https://github.com/kubernetes-sigs/controller-runtime/issues/2888, we should probably solve the two problems together
In some cases, one can wrap already-extant
client.Client
s to confer extra functionality. For example:However, it is not possible to confer
WithWatch
on an existing client: one can only obtain aclient.WithWatch
via a constructor:The resulting client is "frozen" -- i.e. can't be subjected to decorators like
WithFieldOwner
-- because those wrappers return aclient.Client
, which can'tWatch()
!It would be great to have a decorator function to allow an existing client to grow
WithWatch
functionality:Notes:
WithWatch
, but that name is already taken by the interface. Sad face.WithWatch
-specific. Sad face.client.Client
; but as written today that would be hard because theWatch()
implementation relies on internals of the specificclient
(lowercase) implementation in the library. Sad face.See #2929 where I prototyped an imperfect version of the solution that suffers from all of the above issues.