Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
public class Operator implements LifecycleAware {
private static final Logger log = LoggerFactory.getLogger(Operator.class);

private final ControllerManager controllerManager;
private final LeaderElectionManager leaderElectionManager;
private final ConfigurationService configurationService;
private ControllerManager controllerManager;
private LeaderElectionManager leaderElectionManager;
private ConfigurationService configurationService;
private volatile boolean started = false;

public Operator() {
this((KubernetesClient) null);
init(initConfigurationService(null, null), true);
}

Operator(KubernetesClient kubernetesClient) {
this(initConfigurationService(kubernetesClient, null));
init(initConfigurationService(kubernetesClient, null), false);
}

/**
Expand All @@ -46,12 +46,23 @@ public Operator() {
* operator
*/
public Operator(ConfigurationService configurationService) {
this.configurationService = configurationService;
init(configurationService, false);
}

private void init(ConfigurationService configurationService, boolean allowDeferredInit) {
if (configurationService == null) {
if (!allowDeferredInit) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a unit test for this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test, though it's not great and additional documentation, along with a protected method for subclasses to set the configuration service after intialization, if needed.

throw new IllegalStateException(
"Deferred initialization of ConfigurationService is not allowed");
}
} else {
this.configurationService = configurationService;

final var executorServiceManager = configurationService.getExecutorServiceManager();
controllerManager = new ControllerManager(executorServiceManager);
final var executorServiceManager = configurationService.getExecutorServiceManager();
controllerManager = new ControllerManager(executorServiceManager);

leaderElectionManager = new LeaderElectionManager(controllerManager, configurationService);
leaderElectionManager = new LeaderElectionManager(controllerManager, configurationService);
}
}

/**
Expand All @@ -62,10 +73,14 @@ public Operator(ConfigurationService configurationService) {
* {@link ConfigurationService} values
*/
public Operator(Consumer<ConfigurationServiceOverrider> overrider) {
this(initConfigurationService(null, overrider));
init(initConfigurationService(null, overrider), false);
}

private static ConfigurationService initConfigurationService(
/**
* Overridable by subclasses to enable deferred configuration, useful to avoid unneeded processing
* in injection scenarios
*/
protected ConfigurationService initConfigurationService(
KubernetesClient client, Consumer<ConfigurationServiceOverrider> overrider) {
// initialize the client if the user didn't provide one
if (client == null) {
Expand Down