Description
Hello,
I have a pretty specific use case for which I would like to have a KubernetesDependentResource
with a constructor over which I need to pass certain parameters.
I noticed there is a DependentResourceFactory
interface but seems to be used internally and not meant to be specified by implementors (Controllers).
This is what I need to achieve:
public class MyDeleterBulkPods
extends
KubernetesDependentResource<Pod, MyResource>
implements
Creator<Pod, MyResource>,
Updater<Pod, MyResource>,
Deleter<MyResource>,
BulkDependentResource<Pod, MyResource> {
public MyDeleterBulkPods(param1, param2....) {
super(Pod.class);
... internal setup
}
}
public class CRUDPodsBulkDependentResource extends MyDeleterBulkPods
implements GarbageCollected<MyResource> {
public CRUDPodsBulkDependentResource(param1, param2....) {
super(param1, param2....);
... internal setup
}
}
>> Controller has...
@ControllerConfiguration(
dependents = @Dependent(type = CRUDPodsBulkDependentResource.class))
I think that implementation should not be difficult, a possible flexible way, which may be the base for bigger features like injection in Spring or any other Jakarta-CDI-based framework like Quarkus, is by recognizing dynamically whether a @Dependent
type is an actual DependentResource
or a delegate (factory).
In that approach, we could decide in method instantiateAndConfigureIfNeeded whether create the instance locally or delegate it.
Could be something like:
@ControllerConfiguration(
dependents = @Dependent( type = DR.class, strategy = Strategies.DELEGATE ), @Dependent( type = DR2.class, strategy = Strategies.DELEGATE ))
public class MyController
implements
DependentResourcesFactory,
Reconciler<MyCustomResource>,
Cleaner<MyCustomResource>,
ResourceEventAware<MyCustomResource> {
...
DependentResource createFrom(DependentResourceSpec spec, C configuration) {
... logic for determining what type we need to create
if (spec.getDependentResourceClass() ...);
return new DR(param1, param2,....)
... etc
}
}
Hope I made myself clear, if not please comment!
Thanks in advanced