operator-framework / operator-framework/java-operator-sdk
Inject config into a KubernetesDependentResource
- Langage dominant
- Java
- Étoiles
- 944
- Forks
- 242
- Merge moyen
- 1 j 4 h
- PR mergées (30 j)
- 43
Description
I'm trying to inject some dependencies into my KubernetesDependentResource.
For dependent resources I usually do this by implementing DependentResourceConfigurator:
// Dependent resource
public class MyDependentResource
extends PerResourcePollingDependentResource<MyDependent, MyPrimary>
implements DependentResourceConfigurator<MyConfig> {
@Override
public void configureWith(MyConfig config) {
this.dependency1 = config.dependency1();
}
}
// Startup code
Operator operator = new Operator();
operator.register(reconciler, r -> r.replaceNamedDependentResourceConfig(MyDependentResource.NAME, new MyConfig(/*...*/)));
But KubernetesDependentResource already implements DependentResourceConfigurator, so I can't configure my own config.
Currently working around this issue by using a singleton pattern.
I inject the dependencies into the singleton and initialise it before the dependent resource reconciler is created.
The dependent resource reconciler then fetches its dependencies from the singleton.
Is there a different way to do this?
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.