Skip to content

Resource Discrimination Based on Desired State in Dependent Resources #2197

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

Closed
csviri opened this issue Jan 11, 2024 · 2 comments · Fixed by #2252
Closed

Resource Discrimination Based on Desired State in Dependent Resources #2197

csviri opened this issue Jan 11, 2024 · 2 comments · Fixed by #2252

Comments

@csviri
Copy link
Collaborator

csviri commented Jan 11, 2024

If there are multiple resources of same type we use resource discriminators in Dependent Resources to identify the one that is managed by the dependent resource. Usually those discriminate by name, in most use cases. In terms of KubernetesDependentResource the default behavior could be improved in a way, that it would take a desired state and based on the name/namespace of the desired state would select the managed resource from the resources. So there will be no need for resource discriminator in most of the cases.

This is a bit more problematic for external resources, however there the POJO representing the resource could implement an interface that would mark the id(s) of the managed resource

@csviri csviri added this to the 5.0 milestone Jan 11, 2024
@metacosm
Copy link
Collaborator

This idea sounds interesting but could you elaborate with a concrete example, please?

@csviri
Copy link
Collaborator Author

csviri commented Jan 12, 2024

Consider this sample:

@ControllerConfiguration(dependents = {
@Dependent(type = MultipleManagedDependentResourceConfigMap1.class,
useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE),
@Dependent(type = MultipleManagedDependentResourceConfigMap2.class,
useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE)
})
public class MultipleManagedDependentResourceReconciler

Where both Config Map Dependents needs a discriminator:

@KubernetesDependent(resourceDiscriminator = ConfigMap1Discriminator.class)
public class MultipleManagedDependentResourceConfigMap1

However that discriminator typically what just does is maps primary resource to name (+namespaces) of the secondary resource. However based on desired state we already could know the name/namespace of the resource to select. So we could just override in this case for KubernetesDependentResource the getSecondaryResource to get the desired and if there are more of a type select one based on the name+namespace of the desired.

@csviri csviri linked a pull request Feb 27, 2024 that will close this issue
@csviri csviri closed this as completed Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants