🌱 Make event handler type aware
This ensures that type casting check executed inside source.Kind logic guaranties type safety for propagated objects.
Currently the change will only have effect in builder.WatchesRawSource, when the source.Kind is constructed externally.
For such (raw) typed source, OnlyMetadata option is no longer doing anything, so this forces user to pass a fully qualified partial object metadata type during construction. This also supposed to be correct way to do it:
pod := &metav1.PartialObjectMetadata{}
pod.SetGroupVersionKind(schema.GroupVersionKind{
Group: "",
Version: "v1",
Kind: "Pod",
})
builder.WatchesRawSource(source.Kind(cache, pod), eventHandler, opts...)
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: Danil-Grigorev Once this PR has been reviewed and has the lgtm label, please assign sbueringer for approval. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
@alvaroaleman When you are adding predicate on the type, you need to typecast from client.Object. Anything can be inside this interface, so you need to error check. Even if I expect a v1.Pod there, still, I may receive some other version of v1.Pod, which would cause panic if I don’t check safely for a type. Whatever you wrap in source.ObjectKind is then strictly checked on event handler level so possibility of that is eliminated.
This change is the first step which allows than to include type info into predicates and make it reliable later. Also it is small and does not introduce API conflicts, which I believe is a reason to merge it and get into release earlier.
I can extend this PR and introduce types in other parts, but it would be much harder to review, and likely will not go without conflicts. That depends on how conflicts will be accepted in such refactoring context. I’m not against doing it all at once, anyway.
This change is the first step which allows than to include type info into predicates and make it reliable later.
There is no point in a first step if we don't know if the direction is right. We have to have a plan how this will look in the end, we can't just do random changes that combined might or might not lead us somewhere.