Skip to content

Commit

Permalink
fix: preserve the original itemstore (#2154)
Browse files Browse the repository at this point in the history
closes: #2152

Signed-off-by: Steven Hawkins <[email protected]>
  • Loading branch information
shawkins authored Dec 7, 2023
1 parent bb32222 commit da8bba9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private ControllerConfigurationOverrider(ControllerConfiguration<R> original) {
this.name = original.getName();
this.fieldManager = original.fieldManager();
this.informerListLimit = original.getInformerListLimit().orElse(null);
this.itemStore = original.getItemStore().orElse(null);
}

public ControllerConfigurationOverrider<R> withFinalizer(String finalizer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.client.informers.cache.BasicItemStore;
import io.fabric8.kubernetes.client.informers.cache.Cache;
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver;
import io.javaoperatorsdk.operator.api.reconciler.Constants;
import io.javaoperatorsdk.operator.api.reconciler.Context;
Expand Down Expand Up @@ -130,7 +133,15 @@ private io.javaoperatorsdk.operator.api.config.ControllerConfiguration<?> create
return configurationService.configFor(reconciler);
}

@ControllerConfiguration(namespaces = "foo")
private static class MyItemStore<T extends HasMetadata> extends BasicItemStore<T> {

public MyItemStore() {
super(Cache::metaNamespaceKeyFunc);
}

}

@ControllerConfiguration(namespaces = "foo", itemStore = MyItemStore.class)
private static class WatchCurrentReconciler implements Reconciler<ConfigMap> {

@Override
Expand Down Expand Up @@ -187,6 +198,16 @@ void overridingNamespacesShouldWork() {
assertFalse(configuration.watchCurrentNamespace());
}

@Test
void itemStorePreserved() {
var configuration = createConfiguration(new WatchCurrentReconciler());

configuration = ControllerConfigurationOverrider.override(configuration)
.build();

assertNotNull(configuration.getItemStore().orElse(null));
}

@Test
void configuredDependentShouldNotChangeOnParentOverrideEvenWhenInitialConfigIsSame() {
var configuration = createConfiguration(new OverriddenNSOnDepReconciler());
Expand Down

0 comments on commit da8bba9

Please sign in to comment.