Skip to content

fix: we need the constructor that takes a ConfigurationService for QOSDK #1954

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

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Changes from all commits
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,7 +24,6 @@
public class Operator implements LifecycleAware {
private static final Logger log = LoggerFactory.getLogger(Operator.class);

private final KubernetesClient kubernetesClient;
private final ControllerManager controllerManager;
private final LeaderElectionManager leaderElectionManager;
private final ConfigurationService configurationService;
Expand All @@ -40,15 +39,29 @@ public Operator() {
}

/**
* @param configurationService implementation
* @deprecated Use {@link #Operator(Consumer)} instead
* Creates an Operator based on the configuration provided by the specified
* {@link ConfigurationService}. If you intend to use different values than the default, you use
* {@link Operator#Operator(Consumer)} instead to override the default with your intended setup.
*
* @param configurationService a {@link ConfigurationService} providing the configuration for the
* operator
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("unused")
public Operator(ConfigurationService configurationService) {
this(null, null);
this.configurationService = configurationService;

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

leaderElectionManager = new LeaderElectionManager(controllerManager, configurationService);
}

/**
* Creates an Operator overriding the default configuration with the values provided by the
* specified {@link ConfigurationServiceOverrider}.
*
* @param overrider a {@link ConfigurationServiceOverrider} consumer used to override the default
* {@link ConfigurationService} values
*/
public Operator(Consumer<ConfigurationServiceOverrider> overrider) {
this(null, overrider);
}
Expand All @@ -65,26 +78,27 @@ public Operator(Consumer<ConfigurationServiceOverrider> overrider) {
*/
@Deprecated
public Operator(KubernetesClient client, Consumer<ConfigurationServiceOverrider> overrider) {
this(initConfigurationService(client, overrider));
}

private static ConfigurationService initConfigurationService(KubernetesClient client,
Consumer<ConfigurationServiceOverrider> overrider) {
// initialize the client if the user didn't provide one
if (client == null) {
var configurationService = ConfigurationService.newOverriddenConfigurationService(overrider);
client = configurationService.getKubernetesClient();
}

this.kubernetesClient = client;
final var kubernetesClient = client;

// override the configuration service to use the same client
if (overrider != null) {
overrider = overrider.andThen(o -> o.withKubernetesClient(this.kubernetesClient));
overrider = overrider.andThen(o -> o.withKubernetesClient(kubernetesClient));
} else {
overrider = o -> o.withKubernetesClient(this.kubernetesClient);
overrider = o -> o.withKubernetesClient(kubernetesClient);
}
this.configurationService = ConfigurationService.newOverriddenConfigurationService(overrider);

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

leaderElectionManager = new LeaderElectionManager(controllerManager, configurationService);
return ConfigurationService.newOverriddenConfigurationService(overrider);
}

/**
Expand Down Expand Up @@ -118,7 +132,7 @@ public void installShutdownHook(Duration gracefulShutdownTimeout) {
}

public KubernetesClient getKubernetesClient() {
return kubernetesClient;
return configurationService.getKubernetesClient();
}

/**
Expand Down Expand Up @@ -167,7 +181,7 @@ public void stop(Duration gracefulShutdownTimeout) throws OperatorException {
configurationService.getExecutorServiceManager().stop(gracefulShutdownTimeout);
leaderElectionManager.stop();
if (configurationService.closeClientOnStop()) {
kubernetesClient.close();
getKubernetesClient().close();
}

started = false;
Expand Down Expand Up @@ -222,7 +236,7 @@ public <P extends HasMetadata> RegisteredController<P> register(Reconciler<P> re
+ configurationService.getKnownReconcilerNames());
}

final var controller = new Controller<>(reconciler, configuration, kubernetesClient);
final var controller = new Controller<>(reconciler, configuration, getKubernetesClient());

controllerManager.add(controller);

Expand Down