Skip to content

Commit aca4dc1

Browse files
committed
fix: we need the constructor that takes a ConfigurationService for QOSDK (#1954)
1 parent 20ca081 commit aca4dc1

File tree

1 file changed

+31
-17
lines changed
  • operator-framework-core/src/main/java/io/javaoperatorsdk/operator

1 file changed

+31
-17
lines changed

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

+31-17
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
public class Operator implements LifecycleAware {
2525
private static final Logger log = LoggerFactory.getLogger(Operator.class);
2626

27-
private final KubernetesClient kubernetesClient;
2827
private final ControllerManager controllerManager;
2928
private final LeaderElectionManager leaderElectionManager;
3029
private final ConfigurationService configurationService;
@@ -40,15 +39,29 @@ public Operator() {
4039
}
4140

4241
/**
43-
* @param configurationService implementation
44-
* @deprecated Use {@link #Operator(Consumer)} instead
42+
* Creates an Operator based on the configuration provided by the specified
43+
* {@link ConfigurationService}. If you intend to use different values than the default, you use
44+
* {@link Operator#Operator(Consumer)} instead to override the default with your intended setup.
45+
*
46+
* @param configurationService a {@link ConfigurationService} providing the configuration for the
47+
* operator
4548
*/
46-
@Deprecated(forRemoval = true)
47-
@SuppressWarnings("unused")
4849
public Operator(ConfigurationService configurationService) {
49-
this(null, null);
50+
this.configurationService = configurationService;
51+
52+
final var executorServiceManager = configurationService.getExecutorServiceManager();
53+
controllerManager = new ControllerManager(executorServiceManager);
54+
55+
leaderElectionManager = new LeaderElectionManager(controllerManager, configurationService);
5056
}
5157

58+
/**
59+
* Creates an Operator overriding the default configuration with the values provided by the
60+
* specified {@link ConfigurationServiceOverrider}.
61+
*
62+
* @param overrider a {@link ConfigurationServiceOverrider} consumer used to override the default
63+
* {@link ConfigurationService} values
64+
*/
5265
public Operator(Consumer<ConfigurationServiceOverrider> overrider) {
5366
this(null, overrider);
5467
}
@@ -65,26 +78,27 @@ public Operator(Consumer<ConfigurationServiceOverrider> overrider) {
6578
*/
6679
@Deprecated
6780
public Operator(KubernetesClient client, Consumer<ConfigurationServiceOverrider> overrider) {
81+
this(initConfigurationService(client, overrider));
82+
}
83+
84+
private static ConfigurationService initConfigurationService(KubernetesClient client,
85+
Consumer<ConfigurationServiceOverrider> overrider) {
6886
// initialize the client if the user didn't provide one
6987
if (client == null) {
7088
var configurationService = ConfigurationService.newOverriddenConfigurationService(overrider);
7189
client = configurationService.getKubernetesClient();
7290
}
7391

74-
this.kubernetesClient = client;
92+
final var kubernetesClient = client;
7593

7694
// override the configuration service to use the same client
7795
if (overrider != null) {
78-
overrider = overrider.andThen(o -> o.withKubernetesClient(this.kubernetesClient));
96+
overrider = overrider.andThen(o -> o.withKubernetesClient(kubernetesClient));
7997
} else {
80-
overrider = o -> o.withKubernetesClient(this.kubernetesClient);
98+
overrider = o -> o.withKubernetesClient(kubernetesClient);
8199
}
82-
this.configurationService = ConfigurationService.newOverriddenConfigurationService(overrider);
83100

84-
final var executorServiceManager = configurationService.getExecutorServiceManager();
85-
controllerManager = new ControllerManager(executorServiceManager);
86-
87-
leaderElectionManager = new LeaderElectionManager(controllerManager, configurationService);
101+
return ConfigurationService.newOverriddenConfigurationService(overrider);
88102
}
89103

90104
/**
@@ -118,7 +132,7 @@ public void installShutdownHook(Duration gracefulShutdownTimeout) {
118132
}
119133

120134
public KubernetesClient getKubernetesClient() {
121-
return kubernetesClient;
135+
return configurationService.getKubernetesClient();
122136
}
123137

124138
/**
@@ -167,7 +181,7 @@ public void stop(Duration gracefulShutdownTimeout) throws OperatorException {
167181
configurationService.getExecutorServiceManager().stop(gracefulShutdownTimeout);
168182
leaderElectionManager.stop();
169183
if (configurationService.closeClientOnStop()) {
170-
kubernetesClient.close();
184+
getKubernetesClient().close();
171185
}
172186

173187
started = false;
@@ -222,7 +236,7 @@ public <P extends HasMetadata> RegisteredController<P> register(Reconciler<P> re
222236
+ configurationService.getKnownReconcilerNames());
223237
}
224238

225-
final var controller = new Controller<>(reconciler, configuration, kubernetesClient);
239+
final var controller = new Controller<>(reconciler, configuration, getKubernetesClient());
226240

227241
controllerManager.add(controller);
228242

0 commit comments

Comments
 (0)