operator-framework / operator-framework/java-operator-sdk

Inject config into a KubernetesDependentResource

Open
#2,087 5 comments 0 reactions 2 assignees View on GitHub

@metacosm is already working on this.

Since Oct 11, 2023.

  • #2088 by @csviri — closed without merging
kind/documentation lifecycle/stale
Dominant language
Java
Stars
944
Forks
242
Avg merge
1d 4h
Merged PRs (30d)
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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.