6
6
import java .util .stream .Stream ;
7
7
8
8
import io .fabric8 .kubernetes .api .model .HasMetadata ;
9
+ import io .fabric8 .kubernetes .client .KubernetesClient ;
9
10
import io .javaoperatorsdk .operator .ReconcilerUtils ;
10
11
import io .javaoperatorsdk .operator .api .reconciler .Reconciler ;
11
12
12
13
@ SuppressWarnings ("rawtypes" )
13
14
public class AbstractConfigurationService implements ConfigurationService {
14
15
private final Map <String , ControllerConfiguration > configurations = new ConcurrentHashMap <>();
15
16
private final Version version ;
17
+ private KubernetesClient client ;
16
18
private Cloner cloner ;
17
19
private ExecutorServiceManager executorServiceManager ;
18
20
19
21
public AbstractConfigurationService (Version version ) {
20
- this (version , null , null );
22
+ this (version , null );
21
23
}
22
24
23
25
public AbstractConfigurationService (Version version , Cloner cloner ) {
24
- this (version , cloner , null );
26
+ this (version , cloner , null , null );
25
27
}
26
28
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
+ */
27
43
public AbstractConfigurationService (Version version , Cloner cloner ,
28
- ExecutorServiceManager executorServiceManager ) {
44
+ ExecutorServiceManager executorServiceManager , KubernetesClient client ) {
29
45
this .version = version ;
30
- init (cloner , executorServiceManager );
46
+ init (cloner , executorServiceManager , client );
31
47
}
32
48
33
49
/**
@@ -36,10 +52,19 @@ public AbstractConfigurationService(Version version, Cloner cloner,
36
52
* is useful in situations where the cloner depends on a mapper that might require additional
37
53
* configuration steps before it's ready to be used.
38
54
*
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
41
64
*/
42
- protected void init (Cloner cloner , ExecutorServiceManager executorServiceManager ) {
65
+ protected void init (Cloner cloner , ExecutorServiceManager executorServiceManager ,
66
+ KubernetesClient client ) {
67
+ this .client = client ;
43
68
this .cloner = cloner != null ? cloner : ConfigurationService .super .getResourceCloner ();
44
69
this .executorServiceManager = executorServiceManager ;
45
70
}
@@ -127,6 +152,15 @@ public Cloner getResourceCloner() {
127
152
return cloner ;
128
153
}
129
154
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
+
130
164
@ Override
131
165
public ExecutorServiceManager getExecutorServiceManager () {
132
166
// lazy init to avoid initializing thread pools for nothing in an overriding scenario
0 commit comments