Skip to content

Commit cf17145

Browse files
feat: support informer.without-namespace-index in ConfigLoader
Signed-off-by: Antonio Fernandez Alhambra <antonio.alhambra@hivemq.com>
1 parent c1819c3 commit cf17145

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎docs/content/en/docs/documentation/operations/configuration.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ All controller-level keys are prefixed with `josdk.controller.<controller-name>.
356356
| `josdk.controller.<name>.informer.label-selector` | `String` | Label selector for the primary resource informer (alias for `label-selector`) |
357357
| `josdk.controller.<name>.informer.shard-selector` | `String` | Shard selector for the primary resource informer (alias for `shard-selector`) |
358358
| `josdk.controller.<name>.informer.list-limit` | `Long` | Page size for paginated informer list requests; omit for no pagination |
359+
| `josdk.controller.<name>.informer.without-namespace-index` | `Boolean` | Removes the namespace index the informer maintains; defaults to `false`. See [Removing the Namespace Index](../eventing#removing-the-namespace-index) |
359360

360361
#### Retry
361362

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ public ControllerConfigurationOverrider<R> withInformerListLimit(Long informerLi
210210
return this;
211211
}
212212

213+
/**
214+
* Whether to remove the namespace index the underlying informer maintains by default. Note that
215+
* event sources that disagree on this setting do not share an informer.
216+
*
217+
* @param withoutNamespaceIndex true to remove the namespace index, false (the default) to keep it
218+
* @see io.javaoperatorsdk.operator.api.config.informer.Informer#withoutNamespaceIndex()
219+
*/
220+
public ControllerConfigurationOverrider<R> withoutNamespaceIndex(boolean withoutNamespaceIndex) {
221+
config.withoutNamespaceIndex(withoutNamespaceIndex);
222+
return this;
223+
}
224+
213225
public ControllerConfigurationOverrider<R> replacingNamedDependentResourceConfig(
214226
String name, Object dependentResourceConfig) {
215227

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ public static ConfigLoader getDefault() {
170170
new ConfigBinding<>(
171171
"informer.list-limit",
172172
Long.class,
173-
ControllerConfigurationOverrider::withInformerListLimit));
173+
ControllerConfigurationOverrider::withInformerListLimit),
174+
new ConfigBinding<>(
175+
"informer.without-namespace-index",
176+
Boolean.class,
177+
ControllerConfigurationOverrider::withoutNamespaceIndex));
174178

175179
private final ConfigProvider configProvider;
176180

@@ -228,7 +232,7 @@ Consumer<ControllerConfigurationOverrider<R>> applyControllerConfigs(String cont
228232

229233
Consumer<ControllerConfigurationOverrider<R>> retryStep = buildRetryConsumer(prefix);
230234
if (retryStep != null) {
231-
consumer = consumer == null ? retryStep : consumer.andThen(retryStep);
235+
consumer = consumer.andThen(retryStep);
232236
}
233237
Consumer<ControllerConfigurationOverrider<R>> rateLimiterStep =
234238
buildRateLimiterConsumer(prefix);

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.junit.jupiter.api.Test;
2828

29+
import io.fabric8.kubernetes.api.model.ConfigMap;
2930
import io.javaoperatorsdk.operator.api.config.BaseConfigurationService;
3031
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
3132
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceOverrider;
@@ -218,10 +219,23 @@ public <T> Optional<T> getValue(String key, Class<T> type) {
218219
"josdk.controller.ctrl.informer.label-selector",
219220
"josdk.controller.ctrl.informer.shard-selector",
220221
"josdk.controller.ctrl.informer.list-limit",
222+
"josdk.controller.ctrl.informer.without-namespace-index",
221223
"josdk.controller.ctrl.rate-limiter.refresh-period",
222224
"josdk.controller.ctrl.rate-limiter.limit-for-period");
223225
}
224226

227+
@Test
228+
void applyControllerConfigsAppliesInformerWithoutNamespaceIndex() {
229+
var loader =
230+
new ConfigLoader(
231+
mapProvider(Map.of("josdk.controller.ctrl.informer.without-namespace-index", true)));
232+
var overrider = ControllerConfigurationOverrider.override(baseControllerConfig());
233+
234+
loader.<ConfigMap>applyControllerConfigs("ctrl").accept(overrider);
235+
236+
assertThat(overrider.build().getInformerConfig().isWithoutNamespaceIndex()).isTrue();
237+
}
238+
225239
@Test
226240
void operatorKeyPrefixIsJosdkDot() {
227241
assertThat(ConfigLoader.DEFAULT_OPERATOR_KEY_PREFIX).isEqualTo("josdk.");
@@ -567,7 +581,6 @@ private static boolean isTypeCompatible(Class<?> methodParam, Class<?> bindingTy
567581
if (methodParam == long.class && bindingType == Long.class) return true;
568582
if (methodParam == Long.class && bindingType == long.class) return true;
569583
if (methodParam == double.class && bindingType == Double.class) return true;
570-
if (methodParam == Double.class && bindingType == double.class) return true;
571-
return false;
584+
return methodParam == Double.class && bindingType == double.class;
572585
}
573586
}

0 commit comments

Comments
 (0)