Skip to content

Commit 8f5279a

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 27bc53c commit 8f5279a

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/loader/ConfigLoader.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727

2828
public class ConfigLoader {
2929

30-
public static final ConfigLoader DEFAULT = new ConfigLoader();
30+
private static final ConfigLoader DEFAULT = new ConfigLoader();
31+
32+
public static ConfigLoader getDefault() {
33+
return DEFAULT;
34+
}
3135

3236
public static final String DEFAULT_OPERATOR_KEY_PREFIX = "josdk.";
3337
public static final String DEFAULT_CONTROLLER_KEY_PREFIX = "josdk.controller.";
@@ -179,7 +183,6 @@ Consumer<ControllerConfigurationOverrider<R>> applyControllerConfigs(String cont
179183
if (retryStep != null) {
180184
consumer = consumer == null ? retryStep : consumer.andThen(retryStep);
181185
}
182-
183186
return consumer;
184187
}
185188

@@ -235,7 +238,7 @@ private <O> Consumer<O> buildConsumer(List<ConfigBinding<O, ?>> bindings, String
235238
consumer = consumer == null ? step : consumer.andThen(step);
236239
}
237240
}
238-
return consumer;
241+
return consumer == null ? o -> {} : consumer;
239242
}
240243

241244
/**

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/loader/ConfigLoaderTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,17 @@ public <T> Optional<T> getValue(String key, Class<T> type) {
4444
// -- applyConfigs -----------------------------------------------------------
4545

4646
@Test
47-
void applyConfigsReturnsNullWhenNothingConfigured() {
47+
void applyConfigsReturnsNoOpWhenNothingConfigured() {
4848
var loader = new ConfigLoader(mapProvider(Map.of()));
49-
assertThat(loader.applyConfigs()).isNull();
49+
var base = new BaseConfigurationService(null);
50+
// consumer must be non-null and must leave all defaults unchanged
51+
var consumer = loader.applyConfigs();
52+
assertThat(consumer).isNotNull();
53+
var result = ConfigurationService.newOverriddenConfigurationService(base, consumer);
54+
assertThat(result.concurrentReconciliationThreads())
55+
.isEqualTo(base.concurrentReconciliationThreads());
56+
assertThat(result.concurrentWorkflowExecutorThreads())
57+
.isEqualTo(base.concurrentWorkflowExecutorThreads());
5058
}
5159

5260
@Test
@@ -129,9 +137,9 @@ void applyConfigsOnlyAppliesPresentKeys() {
129137
// -- applyControllerConfigs -------------------------------------------------
130138

131139
@Test
132-
void applyControllerConfigsReturnsNullWhenNothingConfigured() {
140+
void applyControllerConfigsReturnsNoOpWhenNothingConfigured() {
133141
var loader = new ConfigLoader(mapProvider(Map.of()));
134-
assertThat(loader.applyControllerConfigs("my-controller")).isNull();
142+
assertThat(loader.applyControllerConfigs("my-controller")).isNotNull();
135143
}
136144

137145
@Test
@@ -163,8 +171,8 @@ void applyControllerConfigsIsolatesControllersByName() {
163171
// alpha gets a consumer (key found), beta gets a consumer (key found)
164172
assertThat(loader.applyControllerConfigs("alpha")).isNotNull();
165173
assertThat(loader.applyControllerConfigs("beta")).isNotNull();
166-
// a controller with no configured keys gets null
167-
assertThat(loader.applyControllerConfigs("gamma")).isNull();
174+
// a controller with no configured keys still gets a non-null no-op consumer
175+
assertThat(loader.applyControllerConfigs("gamma")).isNotNull();
168176
}
169177

170178
@Test

sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatOperator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
public class TomcatOperator {
2929

3030
public static void main(String[] args) throws IOException {
31-
32-
Operator operator = new Operator(ConfigLoader.DEFAULT.applyConfigs());
31+
var configLoader = ConfigLoader.getDefault();
32+
Operator operator = new Operator(configLoader.applyConfigs());
3333
operator.register(
3434
new TomcatReconciler(),
35-
ConfigLoader.DEFAULT.applyControllerConfigs(TomcatReconciler.TOMCAT_CONTROLLER_NAME));
35+
configLoader.applyControllerConfigs(TomcatReconciler.TOMCAT_CONTROLLER_NAME));
3636
operator.register(
3737
new WebappReconciler(operator.getKubernetesClient()),
38-
ConfigLoader.DEFAULT.applyControllerConfigs(WebappReconciler.WEBAPP_CONTROLLER_NAME));
38+
configLoader.applyControllerConfigs(WebappReconciler.WEBAPP_CONTROLLER_NAME));
3939
operator.start();
4040

4141
new FtBasic(new TkFork(new FkRegex("/health", "ALL GOOD.")), 8080).start(Exit.NEVER);

0 commit comments

Comments
 (0)