66import java .util .stream .Stream ;
77
88import io .fabric8 .kubernetes .api .model .HasMetadata ;
9+ import io .fabric8 .kubernetes .client .KubernetesClient ;
910import io .javaoperatorsdk .operator .ReconcilerUtils ;
1011import io .javaoperatorsdk .operator .api .reconciler .Reconciler ;
1112
1213@ SuppressWarnings ("rawtypes" )
1314public class AbstractConfigurationService implements ConfigurationService {
1415 private final Map <String , ControllerConfiguration > configurations = new ConcurrentHashMap <>();
1516 private final Version version ;
17+ private KubernetesClient client ;
1618 private Cloner cloner ;
1719 private ExecutorServiceManager executorServiceManager ;
1820
1921 public AbstractConfigurationService (Version version ) {
20- this (version , null , null );
22+ this (version , null );
2123 }
2224
2325 public AbstractConfigurationService (Version version , Cloner cloner ) {
24- this (version , cloner , null );
26+ this (version , cloner , null , null );
2527 }
2628
29+ /**
30+ * Creates a new {@link AbstractConfigurationService} with the specified parameters.
31+ *
32+ * @param client the {@link KubernetesClient} instance to use to connect to the cluster, if let
33+ * {@code null}, the client will be lazily instantiated with the default configuration
34+ * provided by {@link ConfigurationService#getKubernetesClient()} the first time
35+ * {@link #getKubernetesClient()} is called
36+ * @param version the version information
37+ * @param cloner the {@link Cloner} to use, if {@code null} the default provided by
38+ * {@link ConfigurationService#getResourceCloner()} will be used
39+ * @param executorServiceManager the {@link ExecutorServiceManager} instance to be used, can be
40+ * {@code null} to lazily initialize one by default when
41+ * {@link #getExecutorServiceManager()} is called
42+ */
2743 public AbstractConfigurationService (Version version , Cloner cloner ,
28- ExecutorServiceManager executorServiceManager ) {
44+ ExecutorServiceManager executorServiceManager , KubernetesClient client ) {
2945 this .version = version ;
30- init (cloner , executorServiceManager );
46+ init (cloner , executorServiceManager , client );
3147 }
3248
3349 /**
@@ -36,10 +52,19 @@ public AbstractConfigurationService(Version version, Cloner cloner,
3652 * is useful in situations where the cloner depends on a mapper that might require additional
3753 * configuration steps before it's ready to be used.
3854 *
39- * @param cloner the {@link Cloner} instance to be used
40- * @param executorServiceManager the {@link ExecutorServiceManager} instance to be used
55+ * @param cloner the {@link Cloner} instance to be used, if {@code null}, the default provided by
56+ * {@link ConfigurationService#getResourceCloner()} will be used
57+ * @param executorServiceManager the {@link ExecutorServiceManager} instance to be used, can be
58+ * {@code null} to lazily initialize one by default when
59+ * {@link #getExecutorServiceManager()} is called
60+ * @param client the {@link KubernetesClient} instance to use to connect to the cluster, if let
61+ * {@code null}, the client will be lazily instantiated with the default configuration
62+ * provided by {@link ConfigurationService#getKubernetesClient()} the first time
63+ * {@link #getKubernetesClient()} is called
4164 */
42- protected void init (Cloner cloner , ExecutorServiceManager executorServiceManager ) {
65+ protected void init (Cloner cloner , ExecutorServiceManager executorServiceManager ,
66+ KubernetesClient client ) {
67+ this .client = client ;
4368 this .cloner = cloner != null ? cloner : ConfigurationService .super .getResourceCloner ();
4469 this .executorServiceManager = executorServiceManager ;
4570 }
@@ -127,6 +152,15 @@ public Cloner getResourceCloner() {
127152 return cloner ;
128153 }
129154
155+ @ Override
156+ public KubernetesClient getKubernetesClient () {
157+ // lazy init to avoid needing initializing a client when not needed (in tests, in particular)
158+ if (client == null ) {
159+ client = ConfigurationService .super .getKubernetesClient ();
160+ }
161+ return client ;
162+ }
163+
130164 @ Override
131165 public ExecutorServiceManager getExecutorServiceManager () {
132166 // lazy init to avoid initializing thread pools for nothing in an overriding scenario
0 commit comments