Skip to content

Commit 6345aab

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent d898afc commit 6345aab

8 files changed

Lines changed: 33 additions & 13 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
2727
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.AbstractInformerPool;
2828
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.DefaultInformerPool;
29+
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.InformerPool;
2930

3031
/**
3132
* An abstract implementation of {@link ConfigurationService} meant to ease custom implementations
@@ -195,7 +196,7 @@ public ExecutorServiceManager getExecutorServiceManager() {
195196
}
196197

197198
@Override
198-
public synchronized AbstractInformerPool informerPool() {
199+
public synchronized InformerPool informerPool() {
199200
// cached so that all controllers backed by this ConfigurationService share the same pool and
200201
// can therefore share the underlying informers; synchronized so concurrent first-access from
201202
// multiple controllers cannot create (and share out) more than one pool instance

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig;
4545
import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflowFactory;
4646
import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource;
47-
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.AbstractInformerPool;
4847
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.InformerPool;
4948

5049
/** An interface from which to retrieve configuration information. */
@@ -492,14 +491,10 @@ default boolean cloneSecondaryResourcesWhenGettingFromCache() {
492491
* and would hand out a fresh (unshared) pool on each call; {@link AbstractConfigurationService}
493492
* provides a cached implementation backed by the default sharing pool.
494493
*
495-
* <p>Typed as {@link AbstractInformerPool} rather than as the narrower {@link InformerPool}
496-
* contract consumed by the event sources, because the framework also has to inject this
497-
* configuration service into the pool.
498-
*
499494
* @return the informer pool for this configuration service
500495
*/
501496
@Experimental(
502497
"Only the configuration API around informer pooling could still change in a"
503498
+ " non-backwards-compatible way, the pooling itself is prod ready.")
504-
AbstractInformerPool informerPool();
499+
InformerPool informerPool();
505500
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.javaoperatorsdk.operator.api.reconciler.Experimental;
3232
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceFactory;
3333
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.AbstractInformerPool;
34+
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.InformerPool;
3435

3536
@SuppressWarnings({"unused", "UnusedReturnValue"})
3637
public class ConfigurationServiceOverrider {
@@ -55,7 +56,7 @@ public class ConfigurationServiceOverrider {
5556
private Set<Class<? extends HasMetadata>> defaultNonSSAResource;
5657
private Boolean useSSAToPatchPrimaryResource;
5758
private Boolean cloneSecondaryResourcesWhenGettingFromCache;
58-
private AbstractInformerPool informerPool;
59+
private InformerPool informerPool;
5960

6061
@SuppressWarnings("rawtypes")
6162
private DependentResourceFactory dependentResourceFactory;
@@ -329,7 +330,7 @@ public boolean cloneSecondaryResourcesWhenGettingFromCache() {
329330
}
330331

331332
@Override
332-
public AbstractInformerPool informerPool() {
333+
public InformerPool informerPool() {
333334
if (informerPool == null) {
334335
return super.informerPool();
335336
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/pool/AbstractInformerPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public ConfigurationService getConfigurationService() {
5959
return configurationService;
6060
}
6161

62-
/** Injecting the configuration service, so users have a cleaner API creating the pool. */
62+
@Override
6363
public void setConfigurationService(ConfigurationService configurationService) {
6464
this.configurationService = configurationService;
6565
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/pool/InformerPool.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,21 @@ <R extends HasMetadata> void start(
7878
*/
7979
<R extends HasMetadata> Optional<SharedIndexInformer<R>> releaseInformer(
8080
String controllerName, String name, InformerClassifier<R> classifier);
81+
82+
/**
83+
* Binds this pool to the {@link ConfigurationService} it belongs to. Called by the framework when
84+
* the pool is resolved from that configuration service, before the pool is used; users are not
85+
* expected to call it themselves.
86+
*
87+
* <p>The pool needs the configuration service to create and start informers: the {@link
88+
* ConfigurationService#cacheSyncTimeout()} to wait for, whether to {@link
89+
* ConfigurationService#stopOnInformerErrorDuringStartup()}, and the {@link
90+
* ConfigurationService#getInformerStoppedHandler()} to hook up.
91+
*
92+
* <p>Injecting it here, rather than requiring it as a constructor argument, is what keeps
93+
* creating a pool a plain {@code new NonSharingInformerPool()} for users configuring one through
94+
* {@link io.javaoperatorsdk.operator.api.config.ConfigurationServiceOverrider#withInformerPool}.
95+
* A pool instance therefore belongs to exactly one configuration service.
96+
*/
97+
void setConfigurationService(ConfigurationService configurationService);
8198
}

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerpool/basic/AbstractSharedInformerIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
2525
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceOverrider;
2626
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension;
27+
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.AbstractInformerPool;
2728

2829
import static org.assertj.core.api.Assertions.assertThat;
2930
import static org.awaitility.Awaitility.await;
@@ -81,7 +82,8 @@ void bothControllersReconcileWatchingConfigMap() {
8182
.isPositive();
8283
});
8384

84-
var pool = extension.getOperator().getConfigurationService().informerPool();
85+
var pool =
86+
(AbstractInformerPool) extension.getOperator().getConfigurationService().informerPool();
8587

8688
// the ConfigMap informer count depends on the pool strategy (shared vs. one-per-controller)
8789
assertThat(pool.numberOfInformersForResource(ConfigMap.class))

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerpool/deregister/AbstractDeregisterSharedInformerIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
2424
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceOverrider;
2525
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension;
26+
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.AbstractInformerPool;
2627

2728
import static org.assertj.core.api.Assertions.assertThat;
2829
import static org.awaitility.Awaitility.await;
@@ -54,7 +55,8 @@ public abstract class AbstractDeregisterSharedInformerIT {
5455
@Test
5556
void deregisteringDynamicEventSourceRemovesInformerFromPool() {
5657
var reconciler = extension.getReconcilerOfType(DeregisterReconciler.class);
57-
var pool = extension.getOperator().getConfigurationService().informerPool();
58+
var pool =
59+
(AbstractInformerPool) extension.getOperator().getConfigurationService().informerPool();
5860

5961
// Create the primary with registration enabled: the reconciler dynamically registers the event
6062
// source for the watched resource.

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerpool/dynamic/AbstractDynamicSharedInformerIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
2525
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceOverrider;
2626
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension;
27+
import io.javaoperatorsdk.operator.processing.event.source.informer.pool.AbstractInformerPool;
2728

2829
import static org.assertj.core.api.Assertions.assertThat;
2930
import static org.awaitility.Awaitility.await;
@@ -95,7 +96,8 @@ void dynamicallyRegisteredEventSourceReceivesInitialEvent() {
9596
await().untilAsserted(() -> assertThat(dynamicReconciler.getNumberOfExecutions()).isPositive());
9697

9798
// (1) Informer count for the third resource, which depends on the pool strategy.
98-
var pool = extension.getOperator().getConfigurationService().informerPool();
99+
var pool =
100+
(AbstractInformerPool) extension.getOperator().getConfigurationService().informerPool();
99101
await()
100102
.untilAsserted(
101103
() ->

0 commit comments

Comments
 (0)