@@ -49,6 +49,32 @@ public Operator(ConfigurationService configurationService) {
4949 init (configurationService , false );
5050 }
5151
52+ /**
53+ * Creates an Operator overriding the default configuration with the values provided by the
54+ * specified {@link ConfigurationServiceOverrider}.
55+ *
56+ * @param overrider a {@link ConfigurationServiceOverrider} consumer used to override the default
57+ * {@link ConfigurationService} values
58+ */
59+ public Operator (Consumer <ConfigurationServiceOverrider > overrider ) {
60+ init (initConfigurationService (null , overrider ), false );
61+ }
62+
63+ /**
64+ * In a deferred initialization scenario, the default constructor will typically be called to
65+ * create a proxy instance, usually to be replaced at some later time when the dependents (in this
66+ * case the ConfigurationService instance) are available. In this situation, we want to make it
67+ * possible to not perform the initialization steps directly so this implementation makes it
68+ * possible to not crash when a null ConfigurationService is passed only if deferred
69+ * initialization is allowed
70+ *
71+ * @param configurationService the potentially {@code null} {@link ConfigurationService} to use
72+ * for this operator
73+ * @param allowDeferredInit whether or not deferred initialization of the configuration service is
74+ * allowed
75+ * @throws IllegalStateException if the specified configuration service is {@code null} but
76+ * deferred initialization is not allowed
77+ */
5278 private void init (ConfigurationService configurationService , boolean allowDeferredInit ) {
5379 if (configurationService == null ) {
5480 if (!allowDeferredInit ) {
@@ -65,20 +91,19 @@ private void init(ConfigurationService configurationService, boolean allowDeferr
6591 }
6692 }
6793
68- /**
69- * Creates an Operator overriding the default configuration with the values provided by the
70- * specified {@link ConfigurationServiceOverrider}.
71- *
72- * @param overrider a {@link ConfigurationServiceOverrider} consumer used to override the default
73- * {@link ConfigurationService} values
74- */
75- public Operator (Consumer <ConfigurationServiceOverrider > overrider ) {
76- init (initConfigurationService (null , overrider ), false );
77- }
78-
7994 /**
8095 * Overridable by subclasses to enable deferred configuration, useful to avoid unneeded processing
81- * in injection scenarios
96+ * in injection scenarios, typically returning {@code null} here instead of performing any
97+ * configuration
98+ *
99+ * @param client a potentially {@code null} {@link KubernetesClient} to initialize the operator's
100+ * {@link ConfigurationService} with
101+ * @param overrider a potentially {@code null} {@link ConfigurationServiceOverrider} consumer to
102+ * override the default {@link ConfigurationService} with
103+ * @return a ready to use {@link ConfigurationService} using values provided by the specified
104+ * overrides and kubernetes client, if provided or {@code null} in case deferred
105+ * initialization is possible, in which case it is up to the extension to ensure that the
106+ * {@link ConfigurationService} is properly set before the operator instance is used
82107 */
83108 protected ConfigurationService initConfigurationService (
84109 KubernetesClient client , Consumer <ConfigurationServiceOverrider > overrider ) {
@@ -247,8 +272,8 @@ public <P extends HasMetadata> RegisteredController<P> register(
247272 *
248273 * @param reconciler part of the reconciler to register
249274 * @param configOverrider consumer to use to change config values
250- * @return registered controller
251275 * @param <P> the {@code HasMetadata} type associated with the reconciler
276+ * @return registered controller
252277 */
253278 public <P extends HasMetadata > RegisteredController <P > register (
254279 Reconciler <P > reconciler , Consumer <ControllerConfigurationOverrider <P >> configOverrider ) {
@@ -281,4 +306,14 @@ boolean isStarted() {
281306 public ConfigurationService getConfigurationService () {
282307 return configurationService ;
283308 }
309+
310+ /**
311+ * Make it possible for extensions to set the {@link ConfigurationService} after the operator has
312+ * been initialized
313+ *
314+ * @param configurationService the {@link ConfigurationService} to use for this operator
315+ */
316+ protected void setConfigurationService (ConfigurationService configurationService ) {
317+ init (configurationService , false );
318+ }
284319}
0 commit comments