From 611d174e86f28d0fcb7794a05b9f46d26e8ba84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 18 Jan 2024 11:20:32 +0100 Subject: [PATCH 01/96] chore: set version to 5.0.0-SNAPSHOT (#2200) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- bootstrapper-maven-plugin/pom.xml | 2 +- caffeine-bounded-cache-support/pom.xml | 2 +- micrometer-support/pom.xml | 2 +- operator-framework-bom/pom.xml | 2 +- operator-framework-core/pom.xml | 2 +- operator-framework-junit5/pom.xml | 2 +- operator-framework/pom.xml | 2 +- pom.xml | 2 +- sample-operators/leader-election/pom.xml | 2 +- sample-operators/mysql-schema/pom.xml | 2 +- sample-operators/pom.xml | 2 +- sample-operators/tomcat-operator/pom.xml | 2 +- sample-operators/webpage/pom.xml | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bootstrapper-maven-plugin/pom.xml b/bootstrapper-maven-plugin/pom.xml index efa9619e57..127f51a81b 100644 --- a/bootstrapper-maven-plugin/pom.xml +++ b/bootstrapper-maven-plugin/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT bootstrapper diff --git a/caffeine-bounded-cache-support/pom.xml b/caffeine-bounded-cache-support/pom.xml index ae4fa16c39..6ba5441db5 100644 --- a/caffeine-bounded-cache-support/pom.xml +++ b/caffeine-bounded-cache-support/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 diff --git a/micrometer-support/pom.xml b/micrometer-support/pom.xml index 01205ab47a..89aa81f76b 100644 --- a/micrometer-support/pom.xml +++ b/micrometer-support/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 diff --git a/operator-framework-bom/pom.xml b/operator-framework-bom/pom.xml index a52b6d70eb..b6a31b98c2 100644 --- a/operator-framework-bom/pom.xml +++ b/operator-framework-bom/pom.xml @@ -5,7 +5,7 @@ io.javaoperatorsdk operator-framework-bom - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT Operator SDK - Bill of Materials pom Java SDK for implementing Kubernetes operators diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index f8e3f2ce75..2ea8ab4b55 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT ../pom.xml diff --git a/operator-framework-junit5/pom.xml b/operator-framework-junit5/pom.xml index f421c5ad58..39dd82ab1a 100644 --- a/operator-framework-junit5/pom.xml +++ b/operator-framework-junit5/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index d7dc9140dd..c0cfc5e44d 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 179ef741d6..954f16ca3f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.javaoperatorsdk java-operator-sdk - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT Operator SDK for Java Java SDK for implementing Kubernetes operators pom diff --git a/sample-operators/leader-election/pom.xml b/sample-operators/leader-election/pom.xml index 2d54b84c09..3646bc1681 100644 --- a/sample-operators/leader-election/pom.xml +++ b/sample-operators/leader-election/pom.xml @@ -7,7 +7,7 @@ io.javaoperatorsdk sample-operators - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT sample-leader-election diff --git a/sample-operators/mysql-schema/pom.xml b/sample-operators/mysql-schema/pom.xml index 763bc21330..c209662f7b 100644 --- a/sample-operators/mysql-schema/pom.xml +++ b/sample-operators/mysql-schema/pom.xml @@ -7,7 +7,7 @@ io.javaoperatorsdk sample-operators - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT sample-mysql-schema-operator diff --git a/sample-operators/pom.xml b/sample-operators/pom.xml index 2bac775237..c485af3052 100644 --- a/sample-operators/pom.xml +++ b/sample-operators/pom.xml @@ -7,7 +7,7 @@ io.javaoperatorsdk java-operator-sdk - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT sample-operators diff --git a/sample-operators/tomcat-operator/pom.xml b/sample-operators/tomcat-operator/pom.xml index 16bc0ed783..822b5c3e1c 100644 --- a/sample-operators/tomcat-operator/pom.xml +++ b/sample-operators/tomcat-operator/pom.xml @@ -7,7 +7,7 @@ io.javaoperatorsdk sample-operators - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT sample-tomcat-operator diff --git a/sample-operators/webpage/pom.xml b/sample-operators/webpage/pom.xml index 10dba61c41..8713c52f44 100644 --- a/sample-operators/webpage/pom.xml +++ b/sample-operators/webpage/pom.xml @@ -7,7 +7,7 @@ io.javaoperatorsdk sample-operators - 4.9.7-SNAPSHOT + 5.0.0-SNAPSHOT sample-webpage-operator From d2e00983f79d47b98ca13b555eecceb1224333bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 18 Jan 2024 14:44:20 +0100 Subject: [PATCH 02/96] improve: java version minimal 11, tested on 21 (#2207) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .github/workflows/pr.yml | 4 ++-- .github/workflows/release-project-in-dir.yml | 4 ++-- .github/workflows/snapshot-releases.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 15342af1b1..378eeb7cf9 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -34,7 +34,7 @@ jobs: integration_tests: strategy: matrix: - java: [ 11, 17 ] + java: [ 17, 21 ] kubernetes: [ 'v1.28.12', 'v1.29.7','1.30.3', '1.31.0' ] uses: ./.github/workflows/integration-tests.yml with: @@ -56,7 +56,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ 11, 17 ] + java: [ 17, 21 ] steps: - uses: actions/checkout@v4 - name: Set up Java and Maven diff --git a/.github/workflows/release-project-in-dir.yml b/.github/workflows/release-project-in-dir.yml index b271f05f02..dc79b6f6c2 100644 --- a/.github/workflows/release-project-in-dir.yml +++ b/.github/workflows/release-project-in-dir.yml @@ -26,7 +26,7 @@ jobs: - name: Set up Java and Maven uses: actions/setup-java@v4 with: - java-version: 11 + java-version: 17 distribution: temurin cache: 'maven' @@ -61,7 +61,7 @@ jobs: - name: Set up Java and Maven uses: actions/setup-java@v4 with: - java-version: 11 + java-version: 17 distribution: temurin cache: 'maven' diff --git a/.github/workflows/snapshot-releases.yml b/.github/workflows/snapshot-releases.yml index e5aff55e62..66fe9d25a3 100644 --- a/.github/workflows/snapshot-releases.yml +++ b/.github/workflows/snapshot-releases.yml @@ -21,7 +21,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: temurin - java-version: 11 + java-version: 17 cache: 'maven' - name: Build and test project run: ./mvnw ${MAVEN_ARGS} clean install --file pom.xml @@ -34,7 +34,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: temurin - java-version: 11 + java-version: 17 cache: 'maven' - name: Release Maven package uses: samuelmeuli/action-maven-publish@v1 From f8d3053b836a6b4319427a9ae142c44f29977001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 18 Jan 2024 14:49:13 +0100 Subject: [PATCH 03/96] improve: remove deprecated EventFilter (#2208) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../api/config/BaseConfigurationService.java | 30 ---- .../api/config/ControllerConfiguration.java | 21 --- .../ControllerConfigurationOverrider.java | 25 +-- .../ResolvedControllerConfiguration.java | 17 -- .../reconciler/ControllerConfiguration.java | 14 -- .../ControllerResourceEventSource.java | 7 +- .../controller/ResourceEventFilter.java | 59 ------- .../controller/ResourceEventFilters.java | 27 --- .../event/source/ResourceEventFilterTest.java | 166 ------------------ .../operator/CustomResourceFilterIT.java | 48 ----- .../CustomFilteringTestReconciler.java | 25 --- .../CustomFilteringTestResource.java | 15 -- .../CustomFilteringTestResourceSpec.java | 26 --- .../sample/customfilter/CustomFlagFilter.java | 13 -- .../customfilter/CustomFlagFilter2.java | 13 -- 15 files changed, 2 insertions(+), 504 deletions(-) delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ResourceEventFilter.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ResourceEventFilters.java delete mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventFilterTest.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/CustomResourceFilterIT.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestReconciler.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestResource.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestResourceSpec.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFlagFilter.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFlagFilter2.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index d908f52ebe..9bb0456828 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -25,8 +25,6 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilters; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; @@ -163,40 +161,12 @@ protected

ControllerConfiguration

configFor(Reconcile Utils.instantiate(annotation.itemStore(), ItemStore.class, context), dependentFieldManager, this, informerListLimit); - ResourceEventFilter

answer = deprecatedEventFilter(annotation); - config.setEventFilter(answer != null ? answer : ResourceEventFilters.passthrough()); - List specs = dependentResources(annotation, config); config.setDependentResources(specs); return config; } - @SuppressWarnings("unchecked") - private static

ResourceEventFilter

deprecatedEventFilter( - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration annotation) { - ResourceEventFilter

answer = null; - - Class>[] filterTypes = - (Class>[]) valueOrDefault(annotation, - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::eventFilters, - new Object[] {}); - for (var filterType : filterTypes) { - try { - ResourceEventFilter

filter = filterType.getConstructor().newInstance(); - - if (answer == null) { - answer = filter; - } else { - answer = answer.and(filter); - } - } catch (Exception e) { - throw new IllegalArgumentException(e); - } - } - return answer; - } - @SuppressWarnings({"unchecked", "rawtypes"}) private static List dependentResources( io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration annotation, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java index 13ddd995ad..1dca3a6bc7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java @@ -12,8 +12,6 @@ import io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval; import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilters; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; import io.javaoperatorsdk.operator.processing.retry.GradualRetry; import io.javaoperatorsdk.operator.processing.retry.Retry; @@ -83,25 +81,6 @@ default RateLimiter getRateLimiter() { return DEFAULT_RATE_LIMITER; } - /** - * Allow controllers to filter events before they are passed to the - * {@link io.javaoperatorsdk.operator.processing.event.EventHandler}. - * - *

- * Resource event filters only applies on events of the main custom resource. Not on events from - * other event sources nor the periodic events. - *

- * - * @return filter - * @deprecated use {@link ResourceConfiguration#onAddFilter()}, - * {@link ResourceConfiguration#onUpdateFilter()} or - * {@link ResourceConfiguration#genericFilter()} instead - */ - @Deprecated(forRemoval = true) - default ResourceEventFilter

getEventFilter() { - return ResourceEventFilters.passthrough(); - } - @SuppressWarnings("rawtypes") default List getDependentResources() { return Collections.emptyList(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java index 328d912109..ba270baadd 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java @@ -11,11 +11,9 @@ import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; -import io.javaoperatorsdk.operator.processing.retry.GenericRetry; import io.javaoperatorsdk.operator.processing.retry.Retry; import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES_SET; @@ -29,7 +27,6 @@ public class ControllerConfigurationOverrider { private Set namespaces; private Retry retry; private String labelSelector; - private ResourceEventFilter customResourcePredicate; private final ControllerConfiguration original; private Duration reconciliationMaxInterval; private OnAddFilter onAddFilter; @@ -48,7 +45,6 @@ private ControllerConfigurationOverrider(ControllerConfiguration original) { this.namespaces = new HashSet<>(original.getNamespaces()); this.retry = original.getRetry(); this.labelSelector = original.getLabelSelector(); - this.customResourcePredicate = original.getEventFilter(); this.reconciliationMaxInterval = original.maxReconciliationInterval().orElse(null); this.onAddFilter = original.onAddFilter().orElse(null); this.onUpdateFilter = original.onUpdateFilter().orElse(null); @@ -110,17 +106,6 @@ public ControllerConfigurationOverrider watchingAllNamespaces() { return this; } - /** - * @param retry configuration - * @return current instance of overrider - * @deprecated Use {@link #withRetry(Retry)} instead - */ - @Deprecated(forRemoval = true) - public ControllerConfigurationOverrider withRetry(RetryConfiguration retry) { - this.retry = GenericRetry.fromConfiguration(retry); - return this; - } - public ControllerConfigurationOverrider withRetry(Retry retry) { this.retry = retry; return this; @@ -136,12 +121,6 @@ public ControllerConfigurationOverrider withLabelSelector(String labelSelecto return this; } - public ControllerConfigurationOverrider withCustomResourcePredicate( - ResourceEventFilter customResourcePredicate) { - this.customResourcePredicate = customResourcePredicate; - return this; - } - public ControllerConfigurationOverrider withReconciliationMaxInterval( Duration reconciliationMaxInterval) { this.reconciliationMaxInterval = reconciliationMaxInterval; @@ -210,15 +189,13 @@ public ControllerConfigurationOverrider replacingNamedDependentResourceConfig } public ControllerConfiguration build() { - final var overridden = new ResolvedControllerConfiguration<>(original.getResourceClass(), + return new ResolvedControllerConfiguration<>(original.getResourceClass(), name, generationAware, original.getAssociatedReconcilerClassName(), retry, rateLimiter, reconciliationMaxInterval, onAddFilter, onUpdateFilter, genericFilter, original.getDependentResources(), namespaces, finalizer, labelSelector, configurations, itemStore, fieldManager, original.getConfigurationService(), informerListLimit); - overridden.setEventFilter(customResourcePredicate); - return overridden; } public static ControllerConfigurationOverrider override( diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java index 307e75080f..c36daa8f62 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java @@ -10,7 +10,6 @@ import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; @@ -34,7 +33,6 @@ public class ResolvedControllerConfiguration

private final ConfigurationService configurationService; private final String fieldManager; - private ResourceEventFilter

eventFilter; private List dependentResources; public ResolvedControllerConfiguration(Class

resourceClass, ControllerConfiguration

other) { @@ -166,21 +164,6 @@ public ConfigurationService getConfigurationService() { return configurationService; } - @Override - public ResourceEventFilter

getEventFilter() { - return eventFilter; - } - - /** - * @deprecated Use {@link OnAddFilter}, {@link OnUpdateFilter} and {@link GenericFilter} instead - * - * @param eventFilter generic event filter - */ - @Deprecated(forRemoval = true) - protected void setEventFilter(ResourceEventFilter

eventFilter) { - this.eventFilter = eventFilter; - } - @Override public Object getConfigurationFor(DependentResourceSpec spec) { return configurations.get(spec); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java index c064e669e0..783b4a9a45 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java @@ -11,7 +11,6 @@ import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; @@ -64,19 +63,6 @@ */ String labelSelector() default Constants.NO_VALUE_SET; - /** - * @deprecated Use onAddFilter, onUpdateFilter instead. - * - *

- * Resource event filters only applies on events of the main custom resource. Not on - * events from other event sources nor the periodic events. - *

- * - * @return the list of event filters. - */ - @Deprecated(forRemoval = true) - Class[] eventFilters() default {}; - /** * Filter of onAdd events of resources. * diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java index c1ac2d3352..614525e970 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java @@ -28,7 +28,6 @@ public class ControllerResourceEventSource private static final Logger log = LoggerFactory.getLogger(ControllerResourceEventSource.class); private final Controller controller; - private final ResourceEventFilter legacyFilters; @SuppressWarnings({"unchecked", "rawtypes"}) public ControllerResourceEventSource(Controller controller) { @@ -42,8 +41,6 @@ public ControllerResourceEventSource(Controller controller) { .or(onUpdateGenerationAware(config.isGenerationAware())) .or(onUpdateMarkedForDeletion()); - legacyFilters = config.getEventFilter(); - // by default the on add should be processed in all cases regarding internal filters config.onAddFilter().ifPresent(this::setOnAddFilter); config.onUpdateFilter() @@ -74,9 +71,7 @@ public void eventReceived(ResourceAction action, T resource, T oldResource) { } MDCUtils.addResourceInfo(resource); controller.getEventSourceManager().broadcastOnResourceEvent(action, resource, oldResource); - if ((legacyFilters == null || - legacyFilters.acceptChange(controller, oldResource, resource)) - && isAcceptedByFilters(action, resource, oldResource)) { + if (isAcceptedByFilters(action, resource, oldResource)) { getEventHandler().handleEvent( new ResourceEvent(action, ResourceID.fromResource(resource), resource)); } else { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ResourceEventFilter.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ResourceEventFilter.java deleted file mode 100644 index 08a86c92ae..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ResourceEventFilter.java +++ /dev/null @@ -1,59 +0,0 @@ -package io.javaoperatorsdk.operator.processing.event.source.controller; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.processing.Controller; - -/** - * A functional interface to determine whether resource events should be processed by the SDK. This - * allows users to more finely tuned which events trigger a reconciliation than was previously - * possible (where the logic was limited to generation-based checking). - * - * @param

the type of custom resources handled by this filter - */ -@Deprecated(forRemoval = true) -@FunctionalInterface -public interface ResourceEventFilter

{ - - /** - * Determines whether the change between the old version of the resource and the new one needs to - * be propagated to the controller or not. - * - * @param controller the target controller - * @param oldResource the old version of the resource, null if no old resource available - * @param newResource the new version of the resource - * @return {@code true} if the change needs to be propagated to the controller, {@code false} - * otherwise - */ - boolean acceptChange(Controller

controller, P oldResource, P newResource); - - /** - * Combines this filter with the provided one with an AND logic, i.e. the resulting filter will - * only accept the change if both this and the other filter accept it, reject it otherwise. - * - * @param other the possibly {@code null} other filter to combine this one with - * @return a composite filter implementing the AND logic between this and the provided filter - */ - default ResourceEventFilter

and(ResourceEventFilter

other) { - return other == null ? this - : (Controller

controller, P oldResource, P newResource) -> { - boolean result = acceptChange(controller, oldResource, newResource); - return result && other.acceptChange(controller, oldResource, newResource); - }; - } - - /** - * Combines this filter with the provided one with an OR logic, i.e. the resulting filter will - * accept the change if any of this or the other filter accept it, rejecting it only if both - * reject it. - * - * @param other the possibly {@code null} other filter to combine this one with - * @return a composite filter implementing the OR logic between this and the provided filter - */ - default ResourceEventFilter

or(ResourceEventFilter

other) { - return other == null ? this - : (Controller

controller, P oldResource, P newResource) -> { - boolean result = acceptChange(controller, oldResource, newResource); - return result || other.acceptChange(controller, oldResource, newResource); - }; - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ResourceEventFilters.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ResourceEventFilters.java deleted file mode 100644 index 7024388b8b..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ResourceEventFilters.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.javaoperatorsdk.operator.processing.event.source.controller; - -import io.fabric8.kubernetes.api.model.HasMetadata; - -/** - * Convenience implementations of, and utility methods for, {@link ResourceEventFilter}. - */ -@Deprecated -public final class ResourceEventFilters { - - private static final ResourceEventFilter PASSTHROUGH = - (configuration, oldResource, newResource) -> true; - - private ResourceEventFilters() {} - - /** - * Retrieves a filter that accepts all events. - * - * @param the type of custom resource the filter should handle - * @return a filter that accepts all events - */ - @SuppressWarnings("unchecked") - public static ResourceEventFilter passthrough() { - return (ResourceEventFilter) PASSTHROUGH; - } - -} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventFilterTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventFilterTest.java deleted file mode 100644 index c8ec839b59..0000000000 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventFilterTest.java +++ /dev/null @@ -1,166 +0,0 @@ -package io.javaoperatorsdk.operator.processing.event.source; - -import java.util.List; -import java.util.Objects; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.MockKubernetesClient; -import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.TestUtils; -import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; -import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.config.ResolvedControllerConfiguration; -import io.javaoperatorsdk.operator.processing.Controller; -import io.javaoperatorsdk.operator.processing.event.EventHandler; -import io.javaoperatorsdk.operator.processing.event.EventSourceManager; -import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceAction; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter; -import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; - -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -class ResourceEventFilterTest { - public static final String FINALIZER = - ReconcilerUtils.getDefaultFinalizerName(TestCustomResource.class); - - private EventHandler eventHandler; - - @BeforeEach - public void before() { - this.eventHandler = mock(EventHandler.class); - } - - private ControllerResourceEventSource init(Controller controller) { - var eventSource = new ControllerResourceEventSource<>(controller); - eventSource.setEventHandler(eventHandler); - return eventSource; - } - - @Test - public void eventFilteredByCustomPredicate() { - var config = new TestControllerConfig( - FINALIZER, - false, - (configuration, oldResource, newResource) -> oldResource == null || !Objects.equals( - oldResource.getStatus().getConfigMapStatus(), - newResource.getStatus().getConfigMapStatus())); - - final var eventSource = init(new TestController(config)); - - TestCustomResource cr = TestUtils.testCustomResource(); - cr.getMetadata().setFinalizers(List.of(FINALIZER)); - cr.getMetadata().setGeneration(1L); - cr.getStatus().setConfigMapStatus("1"); - - TestCustomResource cr2 = TestUtils.testCustomResource(); - cr.getMetadata().setFinalizers(List.of(FINALIZER)); - cr.getMetadata().setGeneration(1L); - cr.getStatus().setConfigMapStatus("2"); - - eventSource.eventReceived(ResourceAction.UPDATED, cr, cr2); - verify(eventHandler, times(1)).handleEvent(any()); - - cr.getMetadata().setGeneration(1L); - cr.getStatus().setConfigMapStatus("1"); - - eventSource.eventReceived(ResourceAction.UPDATED, cr, cr); - verify(eventHandler, times(1)).handleEvent(any()); - } - - @Test - public void eventFilteredByCustomPredicateAndGenerationAware() { - var config = new TestControllerConfig( - FINALIZER, - true, - (configuration, oldResource, newResource) -> oldResource == null || !Objects.equals( - oldResource.getStatus().getConfigMapStatus(), - newResource.getStatus().getConfigMapStatus())); - - final var eventSource = init(new TestController(config)); - - TestCustomResource cr = TestUtils.testCustomResource(); - cr.getMetadata().setFinalizers(List.of(FINALIZER)); - cr.getMetadata().setGeneration(1L); - cr.getStatus().setConfigMapStatus("1"); - - TestCustomResource cr2 = TestUtils.testCustomResource(); - cr.getMetadata().setFinalizers(List.of(FINALIZER)); - cr.getMetadata().setGeneration(2L); - cr.getStatus().setConfigMapStatus("1"); - - eventSource.eventReceived(ResourceAction.UPDATED, cr, cr2); - verify(eventHandler, times(1)).handleEvent(any()); - - cr.getMetadata().setGeneration(1L); - cr.getStatus().setConfigMapStatus("2"); - - eventSource.eventReceived(ResourceAction.UPDATED, cr, cr); - verify(eventHandler, times(1)).handleEvent(any()); - } - - @Test - public void eventAlwaysFilteredByCustomPredicate() { - var config = new TestControllerConfig( - FINALIZER, - false, - (configuration, oldResource, newResource) -> !Objects.equals( - oldResource.getStatus().getConfigMapStatus(), - newResource.getStatus().getConfigMapStatus())); - - final var eventSource = init(new TestController(config)); - - TestCustomResource cr = TestUtils.testCustomResource(); - cr.getMetadata().setGeneration(1L); - cr.getStatus().setConfigMapStatus("1"); - - eventSource.eventReceived(ResourceAction.UPDATED, cr, cr); - verify(eventHandler, times(0)).handleEvent(any()); - } - - private static class TestControllerConfig extends ControllerConfig { - public TestControllerConfig(String finalizer, boolean generationAware, - ResourceEventFilter eventFilter) { - super(finalizer, generationAware, eventFilter, TestCustomResource.class); - } - } - - private static class ControllerConfig extends - ResolvedControllerConfiguration { - - public ControllerConfig(String finalizer, boolean generationAware, - ResourceEventFilter eventFilter, Class customResourceClass) { - super(customResourceClass, - "test", - generationAware, - null, - null, - null, - null, - null, - null, - null, null, null, finalizer, null, null, null, new BaseConfigurationService(), null); - setEventFilter(eventFilter); - } - } - - private static class TestController extends Controller { - - public TestController(ControllerConfiguration configuration) { - super(null, configuration, MockKubernetesClient.client(TestCustomResource.class)); - } - - @SuppressWarnings("unchecked") - @Override - public EventSourceManager getEventSourceManager() { - return mock(EventSourceManager.class); - } - } - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CustomResourceFilterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/CustomResourceFilterIT.java deleted file mode 100644 index 6733abaa47..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CustomResourceFilterIT.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.javaoperatorsdk.operator; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.customfilter.CustomFilteringTestReconciler; -import io.javaoperatorsdk.operator.sample.customfilter.CustomFilteringTestResource; -import io.javaoperatorsdk.operator.sample.customfilter.CustomFilteringTestResourceSpec; - -import static org.assertj.core.api.Assertions.assertThat; - -class CustomResourceFilterIT { - - @RegisterExtension - LocallyRunOperatorExtension operator = - LocallyRunOperatorExtension.builder().withReconciler(new CustomFilteringTestReconciler()) - .build(); - - @Test - void doesCustomFiltering() throws InterruptedException { - var filtered1 = createTestResource("filtered1", true, false); - var filtered2 = createTestResource("filtered2", false, true); - var notFiltered = createTestResource("notfiltered", true, true); - operator.create(filtered1); - operator.create(filtered2); - operator.create(notFiltered); - - Thread.sleep(300); - - assertThat( - ((CustomFilteringTestReconciler) operator.getReconcilers().get(0)).getNumberOfExecutions()) - .isEqualTo(1); - } - - - CustomFilteringTestResource createTestResource(String name, boolean filter1, boolean filter2) { - CustomFilteringTestResource resource = new CustomFilteringTestResource(); - resource.setMetadata(new ObjectMeta()); - resource.getMetadata().setName(name); - resource.setSpec(new CustomFilteringTestResourceSpec()); - resource.getSpec().setFilter1(filter1); - resource.getSpec().setFilter2(filter2); - return resource; - } - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestReconciler.java deleted file mode 100644 index 1e42e8e6e1..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestReconciler.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.javaoperatorsdk.operator.sample.customfilter; - -import java.util.concurrent.atomic.AtomicInteger; - -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; - -@ControllerConfiguration(eventFilters = {CustomFlagFilter.class, CustomFlagFilter2.class}) -public class CustomFilteringTestReconciler implements Reconciler { - - private final AtomicInteger numberOfExecutions = new AtomicInteger(0); - - @Override - public UpdateControl reconcile(CustomFilteringTestResource resource, - Context context) { - numberOfExecutions.incrementAndGet(); - return UpdateControl.noUpdate(); - } - - public int getNumberOfExecutions() { - return numberOfExecutions.get(); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestResource.java deleted file mode 100644 index dec7b6c40a..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestResource.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.javaoperatorsdk.operator.sample.customfilter; - -import io.fabric8.kubernetes.api.model.Namespaced; -import io.fabric8.kubernetes.client.CustomResource; -import io.fabric8.kubernetes.model.annotation.Group; -import io.fabric8.kubernetes.model.annotation.ShortNames; -import io.fabric8.kubernetes.model.annotation.Version; - -@Group("sample.javaoperatorsdk") -@Version("v1") -@ShortNames("cft") -public class CustomFilteringTestResource - extends CustomResource - implements Namespaced { -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestResourceSpec.java deleted file mode 100644 index 8bb1f48054..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFilteringTestResourceSpec.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.javaoperatorsdk.operator.sample.customfilter; - -public class CustomFilteringTestResourceSpec { - - private boolean filter1; - - private boolean filter2; - - public boolean isFilter1() { - return filter1; - } - - public CustomFilteringTestResourceSpec setFilter1(boolean filter1) { - this.filter1 = filter1; - return this; - } - - public boolean isFilter2() { - return filter2; - } - - public CustomFilteringTestResourceSpec setFilter2(boolean filter2) { - this.filter2 = filter2; - return this; - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFlagFilter.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFlagFilter.java deleted file mode 100644 index bba45a44ac..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFlagFilter.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.javaoperatorsdk.operator.sample.customfilter; - -import io.javaoperatorsdk.operator.processing.Controller; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter; - -public class CustomFlagFilter implements ResourceEventFilter { - - @Override - public boolean acceptChange(Controller configuration, - CustomFilteringTestResource oldResource, CustomFilteringTestResource newResource) { - return newResource.getSpec().isFilter1(); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFlagFilter2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFlagFilter2.java deleted file mode 100644 index ae6b5d684f..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/customfilter/CustomFlagFilter2.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.javaoperatorsdk.operator.sample.customfilter; - -import io.javaoperatorsdk.operator.processing.Controller; -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter; - -public class CustomFlagFilter2 implements ResourceEventFilter { - - @Override - public boolean acceptChange(Controller configuration, - CustomFilteringTestResource oldResource, CustomFilteringTestResource newResource) { - return newResource.getSpec().isFilter2(); - } -} From 2a8dbe798f7bdbdb74cbc9ee130c6bc84d11d21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 19 Jan 2024 21:53:05 +0100 Subject: [PATCH 04/96] docs: 5.0 migration guide skeleton (#2210) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- docs/documentation/v5-0-migration.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docs/documentation/v5-0-migration.md diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md new file mode 100644 index 0000000000..e5141906dc --- /dev/null +++ b/docs/documentation/v5-0-migration.md @@ -0,0 +1,8 @@ +--- +title: Migrating from v4.7 to v5.0 +description: Migrating from v4.7 to v5.0 +layout: docs +permalink: /docs/v5-0-migration +--- + +# Migrating from v4.7 to v5.0 From 20cd0966952e63373de7e98f36131e2be7173048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 22 Jan 2024 15:25:09 +0100 Subject: [PATCH 05/96] improve: managed dependent reconciliation results not optional (#2212) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- docs/documentation/v5-0-migration.md | 6 ++++++ .../dependent/managed/ManagedDependentResourceContext.java | 4 ++-- .../ManagedBulkDependentWithReadyConditionReconciler.java | 4 ++-- .../sample/complexdependent/ComplexDependentReconciler.java | 2 +- .../workflowallfeature/WorkflowAllFeatureReconciler.java | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index e5141906dc..bc83b49103 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -6,3 +6,9 @@ permalink: /docs/v5-0-migration --- # Migrating from v4.7 to v5.0 + +## API Tweaks + +1. [Result of managed dependent resources](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java#L55-L57) + is not `Optional` anymore. In case you use this result, simply use the result + objects directly. diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java index 9c5b3dddb1..47534cc30d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java @@ -52,7 +52,7 @@ public interface ManagedDependentResourceContext { @SuppressWarnings("unused") T getMandatory(Object key, Class expectedType); - Optional getWorkflowReconcileResult(); + WorkflowReconcileResult getWorkflowReconcileResult(); - Optional getWorkflowCleanupResult(); + WorkflowCleanupResult getWorkflowCleanupResult(); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java index aca78d5d25..569c4fa359 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java @@ -7,7 +7,6 @@ import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowReconcileResult; @ControllerConfiguration(dependents = @Dependent(readyPostcondition = SampleBulkCondition.class, type = CRUDConfigMapBulkDependentResource.class)) @@ -23,7 +22,8 @@ public UpdateControl reconcile( numberOfExecutions.incrementAndGet(); var ready = context.managedDependentResourceContext().getWorkflowReconcileResult() - .map(WorkflowReconcileResult::allDependentResourcesReady).orElseThrow(); + .allDependentResourcesReady(); + resource.setStatus(new BulkDependentTestStatus()); resource.getStatus().setReady(ready); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java index da0aaf1060..853ac4f2d7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java @@ -43,7 +43,7 @@ public UpdateControl reconcile( ComplexDependentCustomResource resource, Context context) throws Exception { var ready = context.managedDependentResourceContext().getWorkflowReconcileResult() - .orElseThrow().allDependentResourcesReady(); + .allDependentResourcesReady(); var status = Objects.requireNonNullElseGet(resource.getStatus(), ComplexDependentStatus::new); status.setStatus(ready ? RECONCILE_STATUS.READY : RECONCILE_STATUS.NOT_READY); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java index 2c25d13924..03d4e22016 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java @@ -35,7 +35,7 @@ public UpdateControl reconcile( resource.getStatus() .setReady( context.managedDependentResourceContext() - .getWorkflowReconcileResult().orElseThrow() + .getWorkflowReconcileResult() .allDependentResourcesReady()); return UpdateControl.patchStatus(resource); } From 9d680a40e0e2b9031bee6a9565a08d23de590dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 22 Jan 2024 15:25:32 +0100 Subject: [PATCH 06/96] improve: remove deprecated RetryConfiguration (#2211) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../api/config/ControllerConfiguration.java | 18 +--------- .../api/config/DefaultRetryConfiguration.java | 5 --- .../api/config/RetryConfiguration.java | 33 ------------------- .../processing/retry/GenericRetry.java | 18 ---------- .../processing/event/EventProcessorTest.java | 6 ++-- .../retry/GenericRetryExecutionTest.java | 28 ---------------- 6 files changed, 4 insertions(+), 104 deletions(-) delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultRetryConfiguration.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/RetryConfiguration.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java index 1dca3a6bc7..d9bac430a7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java @@ -13,7 +13,6 @@ import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; -import io.javaoperatorsdk.operator.processing.retry.GradualRetry; import io.javaoperatorsdk.operator.processing.retry.Retry; public interface ControllerConfiguration

extends ResourceConfiguration

{ @@ -58,22 +57,7 @@ default boolean isGenerationAware() { String getAssociatedReconcilerClassName(); default Retry getRetry() { - final var configuration = getRetryConfiguration(); - return !RetryConfiguration.DEFAULT.equals(configuration) - ? GenericRetry.fromConfiguration(configuration) - : GenericRetry.DEFAULT; // NOSONAR - } - - /** - * Use {@link #getRetry()} instead. - * - * @return configuration for retry. - * @deprecated provide your own {@link Retry} implementation or use the {@link GradualRetry} - * annotation instead - */ - @Deprecated(forRemoval = true) - default RetryConfiguration getRetryConfiguration() { - return RetryConfiguration.DEFAULT; + return GenericRetry.DEFAULT; } @SuppressWarnings("rawtypes") diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultRetryConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultRetryConfiguration.java deleted file mode 100644 index 40fbb38aa7..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultRetryConfiguration.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.api.config; - -public class DefaultRetryConfiguration implements RetryConfiguration { - -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/RetryConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/RetryConfiguration.java deleted file mode 100644 index b293c7e33f..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/RetryConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.javaoperatorsdk.operator.api.config; - -import io.javaoperatorsdk.operator.processing.retry.GradualRetry; - -/** - * @deprecated specify your own {@link io.javaoperatorsdk.operator.processing.retry.Retry} - * implementation or use {@link GradualRetry} annotation instead - */ -@Deprecated(forRemoval = true) -public interface RetryConfiguration { - - RetryConfiguration DEFAULT = new DefaultRetryConfiguration(); - - int DEFAULT_MAX_ATTEMPTS = 5; - long DEFAULT_INITIAL_INTERVAL = 2000L; - double DEFAULT_MULTIPLIER = 1.5D; - - default int getMaxAttempts() { - return DEFAULT_MAX_ATTEMPTS; - } - - default long getInitialInterval() { - return DEFAULT_INITIAL_INTERVAL; - } - - default double getIntervalMultiplier() { - return DEFAULT_MULTIPLIER; - } - - default long getMaxInterval() { - return (long) (DEFAULT_INITIAL_INTERVAL * Math.pow(DEFAULT_MULTIPLIER, DEFAULT_MAX_ATTEMPTS)); - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetry.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetry.java index 9d5a83dc51..d1809de566 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetry.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetry.java @@ -1,7 +1,6 @@ package io.javaoperatorsdk.operator.processing.retry; import io.javaoperatorsdk.operator.api.config.AnnotationConfigurable; -import io.javaoperatorsdk.operator.api.config.RetryConfiguration; public class GenericRetry implements Retry, AnnotationConfigurable { private int maxAttempts = GradualRetry.DEFAULT_MAX_ATTEMPTS; @@ -19,23 +18,6 @@ public static GenericRetry noRetry() { return new GenericRetry().setMaxAttempts(0); } - /** - * @deprecated Use the {@link GradualRetry} annotation instead - * - * @param configuration retry config - * @return Retry instance - */ - @Deprecated(forRemoval = true) - public static Retry fromConfiguration(RetryConfiguration configuration) { - return configuration == null ? defaultLimitedExponentialRetry() - : new GenericRetry() - .setInitialInterval(configuration.getInitialInterval()) - .setMaxAttempts(configuration.getMaxAttempts()) - .setIntervalMultiplier(configuration.getIntervalMultiplier()) - .setMaxInterval(configuration.getMaxInterval()); - } - - public static GenericRetry every10second10TimesRetry() { return new GenericRetry().withLinearRetry().setMaxAttempts(10).setInitialInterval(10000); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java index 93e58a55c6..664c50c045 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java @@ -18,7 +18,6 @@ import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.ConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.config.RetryConfiguration; import io.javaoperatorsdk.operator.api.monitoring.Metrics; import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; @@ -28,6 +27,7 @@ import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEvent; import io.javaoperatorsdk.operator.processing.event.source.timer.TimerEventSource; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; +import io.javaoperatorsdk.operator.processing.retry.GradualRetry; import io.javaoperatorsdk.operator.processing.retry.Retry; import io.javaoperatorsdk.operator.processing.retry.RetryExecution; import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; @@ -135,7 +135,7 @@ void schedulesAnEventRetryOnException() { verify(retryTimerEventSourceMock, times(1)) .scheduleOnce(eq(ResourceID.fromResource(customResource)), - eq(RetryConfiguration.DEFAULT_INITIAL_INTERVAL)); + eq(GradualRetry.DEFAULT_INITIAL_INTERVAL)); } @Test @@ -167,7 +167,7 @@ void executesTheControllerInstantlyAfterErrorIfNewEventsReceived() { assertThat(allValues).hasSize(2); verify(retryTimerEventSourceMock, never()) .scheduleOnce(eq(ResourceID.fromResource(customResource)), - eq(RetryConfiguration.DEFAULT_INITIAL_INTERVAL)); + eq(GradualRetry.DEFAULT_INITIAL_INTERVAL)); } @Test diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/retry/GenericRetryExecutionTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/retry/GenericRetryExecutionTest.java index 1dcd9df464..1659995877 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/retry/GenericRetryExecutionTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/retry/GenericRetryExecutionTest.java @@ -4,38 +4,10 @@ import org.junit.jupiter.api.Test; -import io.javaoperatorsdk.operator.api.config.RetryConfiguration; - import static org.assertj.core.api.Assertions.assertThat; public class GenericRetryExecutionTest { - @Test - public void forFirstBackOffAlwaysReturnsInitialInterval() { - assertThat(getDefaultRetryExecution().nextDelay().get()) - .isEqualTo(RetryConfiguration.DEFAULT_INITIAL_INTERVAL); - } - - @Test - public void delayIsMultipliedEveryNextDelayCall() { - RetryExecution retryExecution = getDefaultRetryExecution(); - - Optional res = callNextDelayNTimes(retryExecution, 1); - assertThat(res.get()).isEqualTo(RetryConfiguration.DEFAULT_INITIAL_INTERVAL); - - res = retryExecution.nextDelay(); - assertThat(res.get()) - .isEqualTo((long) (RetryConfiguration.DEFAULT_INITIAL_INTERVAL - * RetryConfiguration.DEFAULT_MULTIPLIER)); - - res = retryExecution.nextDelay(); - assertThat(res.get()) - .isEqualTo( - (long) (RetryConfiguration.DEFAULT_INITIAL_INTERVAL - * RetryConfiguration.DEFAULT_MULTIPLIER - * RetryConfiguration.DEFAULT_MULTIPLIER)); - } - @Test public void noNextDelayIfMaxAttemptLimitReached() { RetryExecution retryExecution = From 8da2c88dee4b8a5b5e64c1eb78f1cbb5c9c788fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 6 Feb 2024 10:43:25 +0100 Subject: [PATCH 07/96] feat: JDK client is now the default (#2235) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .github/workflows/integration-tests.yml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index be811d309e..63a4b1c47b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -12,7 +12,7 @@ on: http-client: type: string required: false - default: 'okhttp' + default: 'jdk' experimental: type: boolean required: false diff --git a/pom.xml b/pom.xml index 954f16ca3f..fc4bed238f 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ ${java.version} java-operator-sdk https://sonarcloud.io - okhttp + jdk 5.10.1 6.13.4 From 0aad525ef6ada952c1315104b9eaadaa5977f930 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Wed, 7 Feb 2024 13:36:18 +0100 Subject: [PATCH 08/96] fix: update SCM information (#2237) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chris Laprun Signed-off-by: Attila Mészáros --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index fc4bed238f..b49df8f4d4 100644 --- a/pom.xml +++ b/pom.xml @@ -29,8 +29,8 @@ - scm:git:git://github.com/java-operator-sdk/java-operator-sdk.git - scm:git:git@github.com/java-operator-sdk/java-operator-sdk.git + scm:git:git://github.com/operator-framework/java-operator-sdk.git + scm:git:git@github.com/operator-framework/java-operator-sdk.git https://github.com/operator-framework/java-operator-sdk/tree/main From 27e9376cb355cc3c337709a1a47bf6b670b156df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 4 Mar 2024 17:11:03 +0100 Subject: [PATCH 09/96] feat: move name is directly to dependent resource (#2250) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: move name is directly to dependent resource - use this name when throwing aggregate exception Signed-off-by: Attila Mészáros * refactor to use a dedicated interface for setting the name Signed-off-by: Attila Mészáros * refactor: add default implementation for name() (#2255) Signed-off-by: Chris Laprun Signed-off-by: Attila Mészáros --------- Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun Signed-off-by: Attila Mészáros --- .../dependent/DependentResource.java | 5 +++ .../api/reconciler/dependent/NameSetter.java | 7 ++++ .../dependent/AbstractDependentResource.java | 19 ++++++++++- ...actEventSourceHolderDependentResource.java | 5 +++ .../KubernetesDependentResource.java | 7 +++- .../workflow/AbstractWorkflowExecutor.java | 13 ++++---- .../workflow/DefaultManagedWorkflow.java | 14 ++++++-- .../dependent/workflow/DefaultWorkflow.java | 4 +-- .../workflow/DependentResourceNode.java | 29 ++++------------- .../dependent/workflow/WorkflowBuilder.java | 12 ++----- .../dependent/workflow/WorkflowResult.java | 20 +++--------- .../ControllerConfigurationOverriderTest.java | 9 ++---- ...dentResourceConfigurationResolverTest.java | 5 +-- .../dependent/EmptyTestDependentResource.java | 11 +++++++ .../AbstractWorkflowExecutorTest.java | 12 ++++--- .../workflow/WorkflowBuilderTest.java | 2 ++ .../WorkflowReconcileExecutorTest.java | 2 +- .../dependent/workflow/WorkflowTest.java | 32 ++++++++++++------- .../config/BaseConfigurationServiceTest.java | 8 +---- 19 files changed, 118 insertions(+), 98 deletions(-) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/NameSetter.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java index 8230dc4cf9..98d700324d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java @@ -68,4 +68,9 @@ static String defaultNameFor(Class dependentResourc default boolean isDeletable() { return this instanceof Deleter; } + + default String name() { + return defaultNameFor(getClass()); + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/NameSetter.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/NameSetter.java new file mode 100644 index 0000000000..952bf14490 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/NameSetter.java @@ -0,0 +1,7 @@ +package io.javaoperatorsdk.operator.api.reconciler.dependent; + +public interface NameSetter { + + void setName(String name); + +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java index 566f0f7625..afd9e91d51 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java @@ -11,13 +11,14 @@ import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.api.reconciler.dependent.NameSetter; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.processing.dependent.Matcher.Result; import io.javaoperatorsdk.operator.processing.event.ResourceID; @Ignore public abstract class AbstractDependentResource - implements DependentResource { + implements DependentResource, NameSetter { private static final Logger log = LoggerFactory.getLogger(AbstractDependentResource.class); private final boolean creatable = this instanceof Creator; @@ -29,14 +30,21 @@ public abstract class AbstractDependentResource private ResourceDiscriminator resourceDiscriminator; private final DependentResourceReconciler dependentResourceReconciler; + protected String name; + @SuppressWarnings({"unchecked"}) protected AbstractDependentResource() { + this(null); + } + + protected AbstractDependentResource(String name) { creator = creatable ? (Creator) this : null; updater = updatable ? (Updater) this : null; dependentResourceReconciler = this instanceof BulkDependentResource ? new BulkDependentResourceReconciler<>((BulkDependentResource) this) : new SingleDependentResourceReconciler<>(this); + this.name = name == null ? DependentResource.defaultNameFor(this.getClass()) : name; } /** @@ -183,4 +191,13 @@ protected boolean isUpdatable() { public boolean isDeletable() { return deletable; } + + @Override + public String name() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java index 6562afd09f..0b9f2ae897 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java @@ -31,6 +31,11 @@ public abstract class AbstractEventSourceHolderDependentResource resourceType) { + this(resourceType, null); + } + + protected AbstractEventSourceHolderDependentResource(Class resourceType, String name) { + super(name); this.resourceType = resourceType; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index e7c7dbc0a7..347533c8dd 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -42,7 +42,12 @@ public abstract class KubernetesDependentResource resourceType) { - super(resourceType); + this(resourceType, null); + } + + @SuppressWarnings("unchecked") + public KubernetesDependentResource(Class resourceType, String name) { + super(resourceType, name); updaterMatcher = this instanceof ResourceUpdaterMatcher ? (ResourceUpdaterMatcher) this diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java index 56e5e17d07..05b546553c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java @@ -18,7 +18,7 @@ import io.javaoperatorsdk.operator.processing.event.ResourceID; @SuppressWarnings("rawtypes") -public abstract class AbstractWorkflowExecutor

{ +abstract class AbstractWorkflowExecutor

{ protected final Workflow

workflow; protected final P primary; @@ -133,17 +133,16 @@ protected void registerOrDeregisterEventSourceBasedOnActivation( boolean activationConditionMet, DependentResourceNode dependentResourceNode) { if (dependentResourceNode.getActivationCondition().isPresent()) { + final var dr = dependentResourceNode.getDependentResource(); + final var eventSourceRetriever = context.eventSourceRetriever(); if (activationConditionMet) { var eventSource = - dependentResourceNode.getDependentResource().eventSource(context.eventSourceRetriever() - .eventSourceContextForDynamicRegistration()); + dr.eventSource(eventSourceRetriever.eventSourceContextForDynamicRegistration()); var es = eventSource.orElseThrow(); - context.eventSourceRetriever() - .dynamicallyRegisterEventSource(dependentResourceNode.getName(), es); + eventSourceRetriever.dynamicallyRegisterEventSource(dr.name(), es); } else { - context.eventSourceRetriever() - .dynamicallyDeRegisterEventSource(dependentResourceNode.getName()); + eventSourceRetriever.dynamicallyDeRegisterEventSource(dr.name()); } } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java index 27400230df..fb0b733c32 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java @@ -12,8 +12,10 @@ import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceReferencer; +import io.javaoperatorsdk.operator.api.reconciler.dependent.NameSetter; import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.KubernetesClientAware; +import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET; import static io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow.THROW_EXCEPTION_AUTOMATICALLY_DEFAULT; @SuppressWarnings("rawtypes") @@ -77,13 +79,14 @@ public Workflow

resolve(KubernetesClient client, ControllerConfiguration

configuration) { final var alreadyResolved = new HashMap(orderedSpecs.size()); for (DependentResourceSpec spec : orderedSpecs) { - final var node = new DependentResourceNode(spec.getName(), + final var dependentResource = resolve(spec, client, configuration); + final var node = new DependentResourceNode( spec.getReconcileCondition(), spec.getDeletePostCondition(), spec.getReadyCondition(), spec.getActivationCondition(), - resolve(spec, client, configuration)); - alreadyResolved.put(node.getName(), node); + dependentResource); + alreadyResolved.put(dependentResource.name(), node); spec.getDependsOn() .forEach(depend -> node.addDependsOnRelation(alreadyResolved.get(depend))); } @@ -104,6 +107,11 @@ private DependentResource resolve(DependentResourceSpec spec, configuration.getConfigurationService().dependentResourceFactory() .createFrom(spec, configuration); + final var name = spec.getName(); + if (name != null && !NO_VALUE_SET.equals(name) && dependentResource instanceof NameSetter) { + ((NameSetter) dependentResource).setName(name); + } + if (dependentResource instanceof KubernetesClientAware) { ((KubernetesClientAware) dependentResource).setKubernetesClient(client); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java index 056b5906a0..e52823b4f8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java @@ -21,7 +21,7 @@ * @param

primary resource */ @SuppressWarnings("rawtypes") -public class DefaultWorkflow

implements Workflow

{ +class DefaultWorkflow

implements Workflow

{ private final Map dependentResourceNodes; private final Set topLevelResources; @@ -78,7 +78,7 @@ private Map toMap(Set node bottomLevelResource.remove(dependsOn); } } - map.put(node.getName(), node); + map.put(node.getDependentResource().name(), node); } if (topLevelResources.isEmpty()) { throw new IllegalStateException( diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java index 4c82ee19f3..3e8a762c5e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java @@ -8,29 +8,24 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; @SuppressWarnings("rawtypes") -public class DependentResourceNode { +class DependentResourceNode { private final List dependsOn = new LinkedList<>(); private final List parents = new LinkedList<>(); - private final String name; + private Condition reconcilePrecondition; private Condition deletePostcondition; private Condition readyPostcondition; private Condition activationCondition; private final DependentResource dependentResource; - DependentResourceNode(String name, DependentResource dependentResource) { - this(name, null, null, null, null, dependentResource); - } - DependentResourceNode(DependentResource dependentResource) { - this(getNameFor(dependentResource), null, null, null, null, dependentResource); + this(null, null, null, null, dependentResource); } - public DependentResourceNode(String name, Condition reconcilePrecondition, + public DependentResourceNode(Condition reconcilePrecondition, Condition deletePostcondition, Condition readyPostcondition, Condition activationCondition, DependentResource dependentResource) { - this.name = name; this.reconcilePrecondition = reconcilePrecondition; this.deletePostcondition = deletePostcondition; this.readyPostcondition = readyPostcondition; @@ -55,16 +50,10 @@ public List getParents() { return parents; } - public String getName() { - return name; - } - - public Optional> getReconcilePrecondition() { return Optional.ofNullable(reconcilePrecondition); } - public Optional> getDeletePostcondition() { return Optional.ofNullable(deletePostcondition); } @@ -106,18 +95,12 @@ public boolean equals(Object o) { return false; } DependentResourceNode that = (DependentResourceNode) o; - return name.equals(that.name); + return this.getDependentResource().name().equals(that.getDependentResource().name()); } @Override public int hashCode() { - return name.hashCode(); - } - - @SuppressWarnings("rawtypes") - static String getNameFor(DependentResource dependentResource) { - return DependentResource.defaultNameFor(dependentResource.getClass()) + "#" - + dependentResource.hashCode(); + return this.getDependentResource().name().hashCode(); } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java index e416de0260..2f7a6b2afa 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java @@ -20,14 +20,9 @@ public class WorkflowBuilder

{ private boolean isCleaner = false; public WorkflowBuilder

addDependentResource(DependentResource dependentResource) { - return addDependentResource(dependentResource, null); - } - - public WorkflowBuilder

addDependentResource(DependentResource dependentResource, String name) { - currentNode = name == null ? new DependentResourceNode<>(dependentResource) - : new DependentResourceNode<>(name, dependentResource); + currentNode = new DependentResourceNode<>(dependentResource); isCleaner = isCleaner || dependentResource.isDeletable(); - final var actualName = currentNode.getName(); + final var actualName = dependentResource.name(); dependentResourceNodes.put(actualName, currentNode); return this; } @@ -69,8 +64,7 @@ public WorkflowBuilder

withActivationCondition(Condition activationCondition) DependentResourceNode getNodeByDependentResource(DependentResource dependentResource) { // first check by name - final var node = - dependentResourceNodes.get(DependentResourceNode.getNameFor(dependentResource)); + final var node = dependentResourceNodes.get(dependentResource.name()); if (node != null) { return node; } else { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java index 77fc2dcbfe..5105791bff 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java @@ -3,6 +3,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.stream.Collectors; import io.javaoperatorsdk.operator.AggregatedOperatorException; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; @@ -37,22 +38,9 @@ public boolean erroredDependentsExist() { public void throwAggregateExceptionIfErrorsPresent() { if (erroredDependentsExist()) { - Map exceptionMap = new HashMap<>(); - Map numberOfClasses = new HashMap<>(); - - for (Entry entry : erroredDependents.entrySet()) { - String name = entry.getKey().getClass().getName(); - var num = numberOfClasses.getOrDefault(name, 0); - if (num > 0) { - exceptionMap.put(name + NUMBER_DELIMITER + num, entry.getValue()); - } else { - exceptionMap.put(name, entry.getValue()); - } - numberOfClasses.put(name, num + 1); - } - - throw new AggregatedOperatorException("Exception(s) during workflow execution.", - exceptionMap); + throw new AggregatedOperatorException("Exception(s) during workflow execution.", + erroredDependents.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey().name(), Entry::getValue))); } } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java index 1c86886d89..fa860c917d 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java @@ -26,11 +26,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; class ControllerConfigurationOverriderTest { private final BaseConfigurationService configurationService = new BaseConfigurationService(); @@ -75,8 +71,7 @@ void overridingNSShouldPreserveUntouchedDependents() { private static class NamedDependentReconciler implements Reconciler { @Override - public UpdateControl reconcile(ConfigMap resource, Context context) - throws Exception { + public UpdateControl reconcile(ConfigMap resource, Context context) { return null; } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java index 3187b32645..31f140c558 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java @@ -24,10 +24,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import static io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolverTest.CustomAnnotationReconciler.DR_NAME; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; class DependentResourceConfigurationResolverTest { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/EmptyTestDependentResource.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/EmptyTestDependentResource.java index 4fe88296ac..b41fc0bac7 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/EmptyTestDependentResource.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/EmptyTestDependentResource.java @@ -9,6 +9,8 @@ public class EmptyTestDependentResource implements DependentResource { + private String name; + @Override public ReconcileResult reconcile(TestCustomResource primary, Context context) { @@ -19,5 +21,14 @@ public ReconcileResult reconcile(TestCustomResource primary, public Class resourceType() { return Deployment.class; } + + @Override + public String name() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java index 941c3fa434..219e9af869 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java @@ -35,11 +35,8 @@ public class AbstractWorkflowExecutorTest { public class TestDependent extends KubernetesDependentResource { - private final String name; - public TestDependent(String name) { - super(ConfigMap.class); - this.name = name; + super(ConfigMap.class, name); } @Override @@ -52,7 +49,7 @@ public ReconcileResult reconcile(TestCustomResource primary, @Override public String toString() { - return name; + return name(); } } @@ -110,6 +107,11 @@ public Class resourceType() { return String.class; } + @Override + public String name() { + return name; + } + @Override public String toString() { return name; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilderTest.java index 9a61931a61..b41ee430f7 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilderTest.java @@ -13,8 +13,10 @@ class WorkflowBuilderTest { @Test void workflowIsCleanerIfAtLeastOneDRIsCleaner() { var dr = mock(DependentResource.class); + when(dr.name()).thenReturn("dr"); var deleter = mock(DependentResource.class); when(deleter.isDeletable()).thenReturn(true); + when(deleter.name()).thenReturn("deleter"); var workflow = new WorkflowBuilder() .addDependentResource(deleter) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java index d90e8d6d97..7bfc481450 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java @@ -539,7 +539,7 @@ void reconcilePreconditionNotCheckedOnNonActiveDependent() { @Test void deletesDependentsOfNonActiveDependentButNotTheNonActive() { TestDeleterDependent drDeleter2 = new TestDeleterDependent("DR_DELETER_2"); - TestDeleterDependent drDeleter3 = new TestDeleterDependent("DR_DELETER_2"); + TestDeleterDependent drDeleter3 = new TestDeleterDependent("DR_DELETER_3"); var workflow = new WorkflowBuilder() .addDependentResource(dr1).withActivationCondition(notMetCondition) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java index 72ec14ebbf..ef48fccd6e 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java @@ -14,9 +14,10 @@ import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.withSettings; +import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.*; @SuppressWarnings("rawtypes") class WorkflowTest { @@ -25,9 +26,9 @@ class WorkflowTest { @Test void zeroTopLevelDRShouldThrowException() { - var dr1 = mock(DependentResource.class); - var dr2 = mock(DependentResource.class); - var dr3 = mock(DependentResource.class); + var dr1 = mockDependent("dr1"); + var dr2 = mockDependent("dr2"); + var dr3 = mockDependent("dr3"); var cyclicWorkflowBuilderSetup = new WorkflowBuilder() .addDependentResource(dr1).dependsOn() @@ -41,9 +42,9 @@ void zeroTopLevelDRShouldThrowException() { @Test void calculatesTopLevelResources() { - var dr1 = mock(DependentResource.class); - var dr2 = mock(DependentResource.class); - var independentDR = mock(DependentResource.class); + var dr1 = mockDependent("dr1"); + var dr2 = mockDependent("dr2"); + var independentDR = mockDependent("independentDR"); var workflow = new WorkflowBuilder() .addDependentResource(independentDR) @@ -61,9 +62,9 @@ void calculatesTopLevelResources() { @Test void calculatesBottomLevelResources() { - var dr1 = mock(DependentResource.class); - var dr2 = mock(DependentResource.class); - var independentDR = mock(DependentResource.class); + var dr1 = mockDependent("dr1"); + var dr2 = mockDependent("dr2"); + var independentDR = mockDependent("independentDR"); Workflow workflow = new WorkflowBuilder() .addDependentResource(independentDR) @@ -98,4 +99,11 @@ void isDeletableShouldWork() { GarbageCollected.class)); assertFalse(DefaultWorkflow.isDeletable(dr.getClass())); } + + static DependentResource mockDependent(String name) { + var res = mock(DependentResource.class); + when(res.name()).thenReturn(name); + return res; + } + } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java index 0b89da68db..ff47285c17 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java @@ -46,13 +46,7 @@ import io.javaoperatorsdk.operator.sample.readonly.ConfigMapReader; import io.javaoperatorsdk.operator.sample.readonly.ReadOnlyDependent; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; class BaseConfigurationServiceTest { From ad749019b30d99a964cda9bdaeda77d6d11e83a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 7 Mar 2024 11:47:51 +0100 Subject: [PATCH 10/96] format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../processing/dependent/workflow/WorkflowResult.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java index 5105791bff..75366925bd 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java @@ -1,6 +1,5 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; -import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.stream.Collectors; @@ -38,9 +37,9 @@ public boolean erroredDependentsExist() { public void throwAggregateExceptionIfErrorsPresent() { if (erroredDependentsExist()) { - throw new AggregatedOperatorException("Exception(s) during workflow execution.", - erroredDependents.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey().name(), Entry::getValue))); + throw new AggregatedOperatorException("Exception(s) during workflow execution.", + erroredDependents.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey().name(), Entry::getValue))); } } } From 1aa3bf51d27746c171cf2cb7bac70680ebf51722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 7 Mar 2024 13:52:42 +0100 Subject: [PATCH 11/96] fix: test after rebase on master (#2270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../workflow/WorkflowResultTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResultTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResultTest.java index 48cf3fa75a..c89ca53f07 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResultTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResultTest.java @@ -28,8 +28,8 @@ void throwsExceptionWithoutNumberingIfAllDifferentClass() { @Test void numbersDependentClassNamesIfMoreOfSameType() { - var res = new WorkflowResult(Map.of(new DependentA(), new RuntimeException(), - new DependentA(), new RuntimeException())); + var res = new WorkflowResult(Map.of(new DependentA("name1"), new RuntimeException(), + new DependentA("name2"), new RuntimeException())); try { res.throwAggregateExceptionIfErrorsPresent(); } catch (AggregatedOperatorException e) { @@ -39,6 +39,25 @@ void numbersDependentClassNamesIfMoreOfSameType() { @SuppressWarnings("rawtypes") static class DependentA implements DependentResource { + + private final String name; + + public DependentA() { + this(null); + } + + public DependentA(String name) { + this.name = name; + } + + @Override + public String name() { + if (name == null) { + return DependentResource.super.name(); + } + return name; + } + @Override public ReconcileResult reconcile(HasMetadata primary, Context context) { return null; From 8744ab2da913343bb6e22879f716416972201c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 8 Mar 2024 17:53:08 +0100 Subject: [PATCH 12/96] feat: use java 17 as baseline (#2271) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- bootstrapper-maven-plugin/src/main/resources/templates/pom.xml | 2 +- pom.xml | 2 +- sample-operators/leader-election/pom.xml | 2 +- sample-operators/mysql-schema/pom.xml | 2 +- sample-operators/tomcat-operator/pom.xml | 2 +- sample-operators/webpage/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bootstrapper-maven-plugin/src/main/resources/templates/pom.xml b/bootstrapper-maven-plugin/src/main/resources/templates/pom.xml index fe9d29300e..6ada7516c7 100644 --- a/bootstrapper-maven-plugin/src/main/resources/templates/pom.xml +++ b/bootstrapper-maven-plugin/src/main/resources/templates/pom.xml @@ -11,7 +11,7 @@ jar - 11 + 17 ${java.version} ${java.version} {{josdkVersion}} diff --git a/pom.xml b/pom.xml index b49df8f4d4..41c74f1975 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ UTF-8 - 11 + 17 ${java.version} ${java.version} java-operator-sdk diff --git a/sample-operators/leader-election/pom.xml b/sample-operators/leader-election/pom.xml index 3646bc1681..63346634dd 100644 --- a/sample-operators/leader-election/pom.xml +++ b/sample-operators/leader-election/pom.xml @@ -71,7 +71,7 @@ ${jib-maven-plugin.version} - gcr.io/distroless/java:11 + gcr.io/distroless/java17-debian11 leader-election-operator diff --git a/sample-operators/mysql-schema/pom.xml b/sample-operators/mysql-schema/pom.xml index c209662f7b..32895db6b0 100644 --- a/sample-operators/mysql-schema/pom.xml +++ b/sample-operators/mysql-schema/pom.xml @@ -98,7 +98,7 @@ ${jib-maven-plugin.version} - gcr.io/distroless/java:11 + gcr.io/distroless/java17-debian11 mysql-schema-operator diff --git a/sample-operators/tomcat-operator/pom.xml b/sample-operators/tomcat-operator/pom.xml index 822b5c3e1c..4ae7abd3c3 100644 --- a/sample-operators/tomcat-operator/pom.xml +++ b/sample-operators/tomcat-operator/pom.xml @@ -100,7 +100,7 @@ ${jib-maven-plugin.version} - gcr.io/distroless/java:11 + gcr.io/distroless/java17-debian11 tomcat-operator diff --git a/sample-operators/webpage/pom.xml b/sample-operators/webpage/pom.xml index 8713c52f44..23554fa79f 100644 --- a/sample-operators/webpage/pom.xml +++ b/sample-operators/webpage/pom.xml @@ -71,7 +71,7 @@ ${jib-maven-plugin.version} - gcr.io/distroless/java:11 + gcr.io/distroless/java17-debian11 webpage-operator From 37c68678033f05223d4175c8a49670ffcf56e9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sat, 9 Mar 2024 12:58:33 +0100 Subject: [PATCH 13/96] improve: matcher always considers metadata (#2273) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../GenericKubernetesResourceMatcher.java | 54 +++++-------------- .../GenericResourceUpdaterMatcher.java | 2 +- .../GenericKubernetesResourceMatcherTest.java | 9 ++-- .../ServiceDependentResource.java | 4 +- 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcher.java index c71da5d5ad..05ee05b036 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcher.java @@ -58,7 +58,7 @@ static Matcher matcherFor( @Override public Result match(R actualResource, P primary, Context

context) { var desired = dependentResource.desired(primary, context); - return match(desired, actualResource, false, false, false, context); + return match(desired, actualResource, false, false, context); } /** @@ -67,9 +67,6 @@ public Result match(R actualResource, P primary, Context

context) { * * @param desired the desired resource * @param actualResource the actual resource - * @param considerLabelsAndAnnotations {@code true} if labels and annotations will be checked for - * equality, {@code false} otherwise (meaning that metadata changes will be ignored for - * matching purposes) * @param labelsAndAnnotationsEquality if true labels and annotation match exactly in the actual * and desired state if false, additional elements are allowed in actual annotations. * Considered only if considerLabelsAndAnnotations is true. @@ -89,9 +86,9 @@ public Result match(R actualResource, P primary, Context

context) { */ public static Result match(R desired, R actualResource, - boolean considerLabelsAndAnnotations, boolean labelsAndAnnotationsEquality, + boolean labelsAndAnnotationsEquality, boolean valuesEquality, Context

context) { - return match(desired, actualResource, considerLabelsAndAnnotations, + return match(desired, actualResource, labelsAndAnnotationsEquality, valuesEquality, context, EMPTY_ARRAY); } @@ -101,9 +98,6 @@ public static Result match(R d * * @param desired the desired resource * @param actualResource the actual resource - * @param considerLabelsAndAnnotations {@code true} if labels and annotations will be checked for - * equality, {@code false} otherwise (meaning that metadata changes will be ignored for - * matching purposes) * @param labelsAndAnnotationsEquality if true labels and annotation match exactly in the actual * and desired state if false, additional elements are allowed in actual annotations. * Considered only if considerLabelsAndAnnotations is true. @@ -116,9 +110,9 @@ public static Result match(R d */ public static Result match(R desired, R actualResource, - boolean considerLabelsAndAnnotations, boolean labelsAndAnnotationsEquality, + boolean labelsAndAnnotationsEquality, Context

context, String... ignorePaths) { - return match(desired, actualResource, considerLabelsAndAnnotations, + return match(desired, actualResource, labelsAndAnnotationsEquality, false, context, ignorePaths); } @@ -133,9 +127,6 @@ public static Result match(R d * matches the desired state or not * @param primary the primary resource from which we want to compute the desired state * @param context the {@link Context} instance within which this method is called - * @param considerLabelsAndAnnotations {@code true} to consider the metadata of the actual - * resource when determining if it matches the desired state, {@code false} if matching - * should occur only considering the spec of the resources * @param labelsAndAnnotationsEquality if true labels and annotation match exactly in the actual * and desired state if false, additional elements are allowed in actual annotations. * Considered only if considerLabelsAndAnnotations is true. @@ -150,28 +141,28 @@ public static Result match(R d */ public static Result match( KubernetesDependentResource dependentResource, R actualResource, P primary, - Context

context, boolean considerLabelsAndAnnotations, + Context

context, boolean labelsAndAnnotationsEquality, String... ignorePaths) { final var desired = dependentResource.desired(primary, context); - return match(desired, actualResource, considerLabelsAndAnnotations, + return match(desired, actualResource, labelsAndAnnotationsEquality, context, ignorePaths); } public static Result match( KubernetesDependentResource dependentResource, R actualResource, P primary, - Context

context, boolean considerLabelsAndAnnotations, + Context

context, + boolean specEquality, boolean labelsAndAnnotationsEquality, - boolean specEquality) { + String... ignorePaths) { final var desired = dependentResource.desired(primary, context); - return match(desired, actualResource, considerLabelsAndAnnotations, - labelsAndAnnotationsEquality, specEquality, context); + return match(desired, actualResource, + labelsAndAnnotationsEquality, specEquality, context, ignorePaths); } public static Result match(R desired, - R actualResource, - boolean considerMetadata, boolean labelsAndAnnotationsEquality, boolean valuesEquality, + R actualResource, boolean labelsAndAnnotationsEquality, boolean valuesEquality, Context

context, String... ignoredPaths) { final List ignoreList = @@ -195,8 +186,7 @@ public static Result match(R d matched = match(valuesEquality, node, ignoreList); } else if (nodeIsChildOf(node, List.of(METADATA))) { // conditionally consider labels and annotations - if (considerMetadata - && nodeIsChildOf(node, List.of(METADATA_LABELS, METADATA_ANNOTATIONS))) { + if (nodeIsChildOf(node, List.of(METADATA_LABELS, METADATA_ANNOTATIONS))) { matched = match(labelsAndAnnotationsEquality, node, Collections.emptyList()); } } else if (!nodeIsChildOf(node, IGNORED_FIELDS)) { @@ -227,20 +217,4 @@ static String getPath(JsonNode n) { return n.get(PATH).asText(); } - @Deprecated(forRemoval = true) - public static Result match( - KubernetesDependentResource dependentResource, R actualResource, P primary, - Context

context, boolean considerLabelsAndAnnotations, boolean specEquality) { - final var desired = dependentResource.desired(primary, context); - return match(desired, actualResource, considerLabelsAndAnnotations, specEquality, context); - } - - @Deprecated(forRemoval = true) - public static Result match( - KubernetesDependentResource dependentResource, R actualResource, P primary, - Context

context, boolean considerLabelsAndAnnotations, String... ignorePaths) { - final var desired = dependentResource.desired(primary, context); - return match(desired, actualResource, considerLabelsAndAnnotations, true, context, ignorePaths); - } - } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java index 43d0b2fedf..16b72d6dce 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java @@ -43,7 +43,7 @@ public R updateResource(R actual, R desired, Context context) { @Override public boolean matches(R actual, R desired, Context context) { - return GenericKubernetesResourceMatcher.match(desired, actual, true, + return GenericKubernetesResourceMatcher.match(desired, actual, false, false, context).matched(); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java index a2eea9279c..370d3d62c1 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java @@ -55,8 +55,7 @@ void matchesAdditiveOnlyChanges() { @Test void matchesWithStrongSpecEquality() { actual.getSpec().getTemplate().getMetadata().getLabels().put("new-key", "val"); - assertThat(match(dependentResource, actual, null, context, true, true, - true) + assertThat(match(desired, actual, true, true, context) .matched()) .withFailMessage("Adding values should fail matching when strong equality is required") .isFalse(); @@ -127,11 +126,11 @@ void matchesMetadata() { .withFailMessage("Annotations shouldn't matter when metadata is not considered") .isTrue(); - assertThat(match(dependentResource, actual, null, context, true, true, true).matched()) + assertThat(match(desired, actual, true, true, context).matched()) .withFailMessage("Annotations should matter when metadata is considered") .isFalse(); - assertThat(match(dependentResource, actual, null, context, true, false).matched()) + assertThat(match(desired, actual, false, false, context).matched()) .withFailMessage( "Should match when strong equality is not considered and only additive changes are made") .isTrue(); @@ -157,7 +156,7 @@ void matchConfigMap() { var actual = createConfigMap(); actual.getData().put("key2", "val2"); - var match = GenericKubernetesResourceMatcher.match(desired, actual, true, + var match = GenericKubernetesResourceMatcher.match(desired, actual, true, false, context); assertThat(match.matched()).isTrue(); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/ServiceDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/ServiceDependentResource.java index a1f5f6faf0..e0699093de 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/ServiceDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/ServiceDependentResource.java @@ -39,8 +39,10 @@ protected Service desired(SSALegacyMatcherCustomResource primary, @Override public Result match(Service actualResource, SSALegacyMatcherCustomResource primary, Context context) { + var desired = desired(primary, context); + return GenericKubernetesResourceMatcher.match(this, actualResource, primary, context, - true, false, false); + false, false); } // override just to check the exec count From 7927fc3b24e92c75f15c4cef13460470cabbda63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 11 Mar 2024 19:30:33 +0100 Subject: [PATCH 14/96] feat: API to check if next reconciliation is imminent (#2272) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/api/reconciler/Context.java | 13 ++++ .../api/reconciler/DefaultContext.java | 7 ++ .../processing/event/EventProcessor.java | 4 ++ .../NextReconciliationImminentIT.java | 66 +++++++++++++++++++ ...tReconciliationImminentCustomResource.java | 18 +++++ .../NextReconciliationImminentReconciler.java | 58 ++++++++++++++++ .../NextReconciliationImminentStatus.java | 14 ++++ 7 files changed, 180 insertions(+) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/NextReconciliationImminentIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentReconciler.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentStatus.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java index e157ed5fd7..78592495ad 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java @@ -51,5 +51,18 @@ Optional getSecondaryResource(Class expectedType, * @return the {@link IndexerResourceCache} associated with the associated {@link Reconciler} for * this context */ + @SuppressWarnings("unused") IndexedResourceCache

getPrimaryCache(); + + /** + * Determines whether a new reconciliation will be triggered right after the current + * reconciliation is finished. This allows to optimize certain situations, helping avoid unneeded + * API calls. A reconciler might, for example, skip updating the status when it's known another + * reconciliation is already scheduled, which would in turn trigger another status update, thus + * rendering the current one moot. + * + * @return {@code true} is another reconciliation is already scheduled, {@code false} otherwise + **/ + boolean isNextReconciliationImminent(); + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java index 2b0f20ef33..633daea6aa 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java @@ -13,6 +13,7 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedDependentResourceContext; import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; +import io.javaoperatorsdk.operator.processing.event.ResourceID; public class DefaultContext

implements Context

{ @@ -45,6 +46,12 @@ public IndexedResourceCache

getPrimaryCache() { return controller.getEventSourceManager().getControllerResourceEventSource(); } + @Override + public boolean isNextReconciliationImminent() { + return controller.getEventProcessor() + .isNextReconciliationImminent(ResourceID.fromResource(primaryResource)); + } + @Override public Stream getSecondaryResourcesAsStream(Class expectedType) { return controller.getEventSourceManager().getResourceEventSourcesFor(expectedType).stream() diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java index 2809efde8a..95755c33f0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java @@ -409,6 +409,10 @@ public synchronized void start() throws OperatorException { handleAlreadyMarkedEvents(); } + public boolean isNextReconciliationImminent(ResourceID resourceID) { + return resourceStateManager.getOrCreate(resourceID).eventPresent(); + } + private void handleAlreadyMarkedEvents() { for (var state : resourceStateManager.resourcesWithEventPresent()) { log.debug("Handling already marked event on start. State: {}", state); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/NextReconciliationImminentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/NextReconciliationImminentIT.java new file mode 100644 index 0000000000..9f9b464a83 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/NextReconciliationImminentIT.java @@ -0,0 +1,66 @@ +package io.javaoperatorsdk.operator; + +import java.time.Duration; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.nextreconciliationimminent.NextReconciliationImminentCustomResource; +import io.javaoperatorsdk.operator.sample.nextreconciliationimminent.NextReconciliationImminentReconciler; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class NextReconciliationImminentIT { + + private static final Logger log = + LoggerFactory.getLogger(NextReconciliationImminentIT.class); + + public static final int WAIT_FOR_EVENT = 300; + public static final String TEST_RESOURCE_NAME = "test1"; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(new NextReconciliationImminentReconciler()) + .build(); + + @Test + void skippingStatusUpdateWithNextReconciliationImminent() throws InterruptedException { + var resource = extension.create(testResource()); + + var reconciler = extension.getReconcilerOfType(NextReconciliationImminentReconciler.class); + await().untilAsserted(() -> assertThat(reconciler.isReconciliationWaiting()).isTrue()); + Thread.sleep(WAIT_FOR_EVENT); + + resource.getMetadata().getAnnotations().put("trigger", "" + System.currentTimeMillis()); + extension.replace(resource); + Thread.sleep(WAIT_FOR_EVENT); + log.info("Made change to trigger event"); + + reconciler.allowReconciliationToProceed(); + Thread.sleep(WAIT_FOR_EVENT); + // second event arrived + await().untilAsserted(() -> assertThat(reconciler.isReconciliationWaiting()).isTrue()); + reconciler.allowReconciliationToProceed(); + + await().pollDelay(Duration.ofMillis(WAIT_FOR_EVENT)).untilAsserted(() -> { + assertThat(extension.get(NextReconciliationImminentCustomResource.class, TEST_RESOURCE_NAME) + .getStatus().getUpdateNumber()).isEqualTo(1); + }); + } + + + NextReconciliationImminentCustomResource testResource() { + var res = new NextReconciliationImminentCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(TEST_RESOURCE_NAME) + .build()); + return res; + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentCustomResource.java new file mode 100644 index 0000000000..fba4242925 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentCustomResource.java @@ -0,0 +1,18 @@ +package io.javaoperatorsdk.operator.sample.nextreconciliationimminent; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("nri") +public class NextReconciliationImminentCustomResource + extends CustomResource + implements Namespaced { + + + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentReconciler.java new file mode 100644 index 0000000000..be3ad70ee8 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentReconciler.java @@ -0,0 +1,58 @@ +package io.javaoperatorsdk.operator.sample.nextreconciliationimminent; + +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.TimeUnit; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; + +@ControllerConfiguration(generationAwareEventProcessing = false) +public class NextReconciliationImminentReconciler + implements Reconciler { + + private static final Logger log = + LoggerFactory.getLogger(NextReconciliationImminentReconciler.class); + + private final SynchronousQueue queue = new SynchronousQueue<>(); + private volatile boolean reconciliationWaiting = false; + + @Override + public UpdateControl reconcile( + NextReconciliationImminentCustomResource resource, + Context context) throws InterruptedException { + log.info("started reconciliation"); + reconciliationWaiting = true; + // wait long enough to get manually allowed + queue.poll(120, TimeUnit.SECONDS); + log.info("Continue after wait"); + reconciliationWaiting = false; + + if (context.isNextReconciliationImminent()) { + return UpdateControl.noUpdate(); + } else { + if (resource.getStatus() == null) { + resource.setStatus(new NextReconciliationImminentStatus()); + } + resource.getStatus().setUpdateNumber(resource.getStatus().getUpdateNumber() + 1); + log.info("Patching status"); + return UpdateControl.patchStatus(resource); + } + } + + public void allowReconciliationToProceed() { + try { + queue.put(true); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + public boolean isReconciliationWaiting() { + return reconciliationWaiting; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentStatus.java new file mode 100644 index 0000000000..ee4528af7a --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentStatus.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.sample.nextreconciliationimminent; + +public class NextReconciliationImminentStatus { + + private int updateNumber; + + public int getUpdateNumber() { + return updateNumber; + } + + public void setUpdateNumber(int updateNumber) { + this.updateNumber = updateNumber; + } +} From 7a24651925d5e6cc78022d20436b9acf2f960ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 11 Mar 2024 20:16:14 +0100 Subject: [PATCH 15/96] feat: Workflow extracted to a separate annotation (#2274) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../main/resources/templates/Reconciler.java | 4 +- .../api/config/BaseConfigurationService.java | 24 ++-- .../api/config/ControllerConfiguration.java | 9 +- .../ControllerConfigurationOverrider.java | 9 +- .../ResolvedControllerConfiguration.java | 25 ++-- .../api/config/workflow/WorkflowSpec.java | 19 +++ .../reconciler/ControllerConfiguration.java | 10 -- .../operator/api/reconciler/Workflow.java | 14 ++ .../workflow/ManagedWorkflowFactory.java | 9 +- .../workflow/ManagedWorkflowSupport.java | 7 +- .../ControllerConfigurationOverriderTest.java | 126 +++++++++--------- ...dentResourceConfigurationResolverTest.java | 10 +- .../workflow/ManagedWorkflowTest.java | 6 +- .../config/BaseConfigurationServiceTest.java | 57 ++++---- .../ManagedBulkDependentReconciler.java | 8 +- ...DependentWithReadyConditionReconciler.java | 8 +- .../ManagedDeleterBulkReconciler.java | 9 +- .../ExternalBulkResourceReconciler.java | 8 +- ...anerForManagedDependentTestReconciler.java | 3 +- .../ComplexDependentReconciler.java | 33 +++-- ...NotExistingDependentWithSSAReconciler.java | 8 +- ...ntAnnotationSecondaryMapperReconciler.java | 3 +- .../DependentCustomMappingReconciler.java | 4 +- ...DependentDifferentNamespaceReconciler.java | 8 +- .../DependentFilterTestReconciler.java | 4 +- ...entFilterCustomResourceTestReconciler.java | 9 +- .../DependentResourceCrossRefReconciler.java | 3 +- .../ExternalStateDependentReconciler.java | 4 +- .../ExternalStateBulkDependentReconciler.java | 11 +- ...cKubernetesDependentManagedReconciler.java | 4 +- ...InformerRelatedBehaviorTestReconciler.java | 13 +- ...ndentDefaultDeleteConditionReconciler.java | 3 +- ...endentResourceMultiInformerReconciler.java | 4 +- ...pleManagedDependentResourceReconciler.java | 3 +- ...edExternalDependentResourceReconciler.java | 3 +- .../MultipleOwnerDependentReconciler.java | 8 +- ...OrderedManagedDependentTestReconciler.java | 16 +-- ...DependentPrimaryIndexerTestReconciler.java | 4 +- ...PrimaryToSecondaryDependentReconciler.java | 3 +- .../sample/restart/RestartTestReconciler.java | 9 +- .../ServiceStrictMatcherTestReconciler.java | 8 +- .../SpecialResourceTestReconciler.java | 9 +- .../SSALegacyMatcherReconciler.java | 8 +- ...StatefulSetDesiredSanitizerReconciler.java | 9 +- .../UnmodifiableDependentPartReconciler.java | 8 +- .../WorkflowActivationCleanupReconciler.java | 3 +- ...WorkflowActivationConditionReconciler.java | 3 +- .../WorkflowAllFeatureReconciler.java | 3 +- .../WorkflowMultipleActivationReconciler.java | 8 +- .../sample/MySQLSchemaReconciler.java | 19 +-- .../operator/sample/TomcatReconciler.java | 15 +-- .../WebPageManagedDependentsReconciler.java | 16 +-- 52 files changed, 318 insertions(+), 313 deletions(-) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java diff --git a/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java b/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java index 03ac06f882..f3efb2114d 100644 --- a/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java +++ b/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java @@ -11,13 +11,15 @@ import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import java.util.Map; import java.util.Optional; -@ControllerConfiguration(dependents = {@Dependent(type = ConfigMapDependentResource.class)}) +@Workflow(dependents = {@Dependent(type = ConfigMapDependentResource.class)}) +@ControllerConfiguration public class {{artifactClassId}}Reconciler implements Reconciler<{{artifactClassId}}CustomResource> { public UpdateControl<{{artifactClassId}}CustomResource> reconcile({{artifactClassId}}CustomResource primary, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index 9bb0456828..eab8e61f72 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -19,8 +19,10 @@ import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.Utils.Configurator; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.Constants; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; @@ -97,6 +99,7 @@ public ControllerConfiguration getConfigurationFor( protected

ControllerConfiguration

configFor(Reconciler

reconciler) { final var annotation = reconciler.getClass().getAnnotation( io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.class); + if (annotation == null) { throw new OperatorException( "Missing mandatory @" @@ -161,21 +164,26 @@ protected

ControllerConfiguration

configFor(Reconcile Utils.instantiate(annotation.itemStore(), ItemStore.class, context), dependentFieldManager, this, informerListLimit); - List specs = dependentResources(annotation, config); - config.setDependentResources(specs); + + final var workflowAnnotation = reconciler.getClass().getAnnotation( + io.javaoperatorsdk.operator.api.reconciler.Workflow.class); + if (workflowAnnotation != null) { + List specs = dependentResources(workflowAnnotation, config); + WorkflowSpec workflowSpec = new WorkflowSpec(specs); + config.setWorkflowSpec(workflowSpec); + } return config; } @SuppressWarnings({"unchecked", "rawtypes"}) private static List dependentResources( - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration annotation, + Workflow annotation, ControllerConfiguration parent) { - final var dependents = - valueOrDefault(annotation, - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::dependents, - new Dependent[] {}); - if (dependents.length == 0) { + final var dependents = annotation.dependents(); + + + if (dependents == null || dependents.length == 0) { return Collections.emptyList(); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java index d9bac430a7..2031283f37 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java @@ -1,14 +1,12 @@ package io.javaoperatorsdk.operator.api.config; import java.time.Duration; -import java.util.Collections; -import java.util.List; import java.util.Optional; import java.util.Set; import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval; import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; @@ -65,9 +63,8 @@ default RateLimiter getRateLimiter() { return DEFAULT_RATE_LIMITER; } - @SuppressWarnings("rawtypes") - default List getDependentResources() { - return Collections.emptyList(); + default Optional getWorkflowSpec() { + return Optional.empty(); } default Optional maxReconciliationInterval() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java index ba270baadd..9f98214b91 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java @@ -10,6 +10,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; @@ -38,6 +39,7 @@ public class ControllerConfigurationOverrider { private String name; private String fieldManager; private Long informerListLimit; + private WorkflowSpec workflowSpec; private ControllerConfigurationOverrider(ControllerConfiguration original) { this.finalizer = original.getFinalizerName(); @@ -55,6 +57,7 @@ private ControllerConfigurationOverrider(ControllerConfiguration original) { this.fieldManager = original.fieldManager(); this.informerListLimit = original.getInformerListLimit().orElse(null); this.itemStore = original.getItemStore().orElse(null); + this.workflowSpec = original.getWorkflowSpec().orElse(null); } public ControllerConfigurationOverrider withFinalizer(String finalizer) { @@ -175,7 +178,7 @@ public ControllerConfigurationOverrider withInformerListLimit( public ControllerConfigurationOverrider replacingNamedDependentResourceConfig(String name, Object dependentResourceConfig) { - final var specs = original.getDependentResources(); + final var specs = original.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); final var spec = specs.stream() .filter(drs -> drs.getName().equals(name)).findFirst() .orElseThrow( @@ -193,9 +196,9 @@ public ControllerConfiguration build() { name, generationAware, original.getAssociatedReconcilerClassName(), retry, rateLimiter, reconciliationMaxInterval, onAddFilter, onUpdateFilter, genericFilter, - original.getDependentResources(), namespaces, finalizer, labelSelector, configurations, itemStore, fieldManager, - original.getConfigurationService(), informerListLimit); + original.getConfigurationService(), informerListLimit, + original.getWorkflowSpec().orElse(null)); } public static ControllerConfigurationOverrider override( diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java index c36daa8f62..9a94d5d667 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java @@ -8,6 +8,7 @@ import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationProvider; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; @@ -32,8 +33,7 @@ public class ResolvedControllerConfiguration

private final ItemStore

itemStore; private final ConfigurationService configurationService; private final String fieldManager; - - private List dependentResources; + private WorkflowSpec workflowSpec; public ResolvedControllerConfiguration(Class

resourceClass, ControllerConfiguration

other) { this(resourceClass, other.getName(), other.isGenerationAware(), @@ -41,11 +41,11 @@ public ResolvedControllerConfiguration(Class

resourceClass, ControllerConfigu other.maxReconciliationInterval().orElse(null), other.onAddFilter().orElse(null), other.onUpdateFilter().orElse(null), other.genericFilter().orElse(null), - other.getDependentResources(), other.getNamespaces(), + other.getNamespaces(), other.getFinalizerName(), other.getLabelSelector(), Collections.emptyMap(), other.getItemStore().orElse(null), other.fieldManager(), other.getConfigurationService(), - other.getInformerListLimit().orElse(null)); + other.getInformerListLimit().orElse(null), other.getWorkflowSpec().orElse(null)); } public static Duration getMaxReconciliationInterval(long interval, TimeUnit timeUnit) { @@ -70,16 +70,16 @@ public ResolvedControllerConfiguration(Class

resourceClass, String name, RateLimiter rateLimiter, Duration maxReconciliationInterval, OnAddFilter onAddFilter, OnUpdateFilter onUpdateFilter, GenericFilter genericFilter, - List dependentResources, Set namespaces, String finalizer, String labelSelector, Map configurations, ItemStore

itemStore, String fieldManager, - ConfigurationService configurationService, Long informerListLimit) { + ConfigurationService configurationService, Long informerListLimit, + WorkflowSpec workflowSpec) { this(resourceClass, name, generationAware, associatedReconcilerClassName, retry, rateLimiter, maxReconciliationInterval, onAddFilter, onUpdateFilter, genericFilter, namespaces, finalizer, labelSelector, configurations, itemStore, fieldManager, configurationService, informerListLimit); - setDependentResources(dependentResources); + setWorkflowSpec(workflowSpec); } protected ResolvedControllerConfiguration(Class

resourceClass, String name, @@ -105,6 +105,7 @@ protected ResolvedControllerConfiguration(Class

resourceClass, String name, this.finalizer = ControllerConfiguration.ensureValidFinalizerName(finalizer, getResourceTypeName()); this.fieldManager = fieldManager; + this.workflowSpec = workflowSpec; } protected ResolvedControllerConfiguration(Class

resourceClass, String name, @@ -144,14 +145,14 @@ public RateLimiter getRateLimiter() { return rateLimiter; } + @Override - public List getDependentResources() { - return dependentResources; + public Optional getWorkflowSpec() { + return Optional.ofNullable(workflowSpec); } - protected void setDependentResources(List dependentResources) { - this.dependentResources = dependentResources == null ? Collections.emptyList() - : Collections.unmodifiableList(dependentResources); + public void setWorkflowSpec(WorkflowSpec workflowSpec) { + this.workflowSpec = workflowSpec; } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java new file mode 100644 index 0000000000..f1eea3c5d3 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java @@ -0,0 +1,19 @@ +package io.javaoperatorsdk.operator.api.config.workflow; + +import java.util.List; + +import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; + +public class WorkflowSpec { + + @SuppressWarnings("rawtypes") + private final List dependentResourceSpecs; + + public WorkflowSpec(List dependentResourceSpecs) { + this.dependentResourceSpecs = dependentResourceSpecs; + } + + public List getDependentResourceSpecs() { + return dependentResourceSpecs; + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java index 783b4a9a45..49cf56c1aa 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java @@ -7,7 +7,6 @@ import java.lang.annotation.Target; import io.fabric8.kubernetes.client.informers.cache.ItemStore; -import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; @@ -93,15 +92,6 @@ MaxReconciliationInterval maxReconciliationInterval() default @MaxReconciliationInterval( interval = MaxReconciliationInterval.DEFAULT_INTERVAL); - - /** - * Optional list of {@link Dependent} configurations which associate a resource type to a - * {@link io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource} implementation - * - * @return the array of {@link Dependent} configurations - */ - Dependent[] dependents() default {}; - /** * Optional {@link Retry} implementation for the associated controller to use. * diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java new file mode 100644 index 0000000000..6726a1d32b --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.api.reconciler; + +import java.lang.annotation.*; + +import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; + +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +public @interface Workflow { + + Dependent[] dependents(); + +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowFactory.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowFactory.java index eb01dcd3f4..cc735f137e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowFactory.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowFactory.java @@ -1,17 +1,20 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; +import java.util.Optional; + import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; public interface ManagedWorkflowFactory> { @SuppressWarnings({"rawtypes", "unchecked"}) ManagedWorkflowFactory DEFAULT = (configuration) -> { - final var dependentResourceSpecs = configuration.getDependentResources(); - if (dependentResourceSpecs == null || dependentResourceSpecs.isEmpty()) { + final Optional workflowSpec = configuration.getWorkflowSpec(); + if (workflowSpec.isEmpty()) { return (ManagedWorkflow) (client, configuration1) -> new DefaultWorkflow(null); } ManagedWorkflowSupport support = new ManagedWorkflowSupport(); - return support.createWorkflow(dependentResourceSpecs); + return support.createWorkflow(workflowSpec.orElseThrow()); }; @SuppressWarnings("rawtypes") diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java index b5a6fd26b2..f3fa894712 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java @@ -12,6 +12,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; @SuppressWarnings({"rawtypes", "unchecked"}) class ManagedWorkflowSupport { @@ -38,10 +39,10 @@ public void checkForNameDuplication(List dependentResourc } } - public

ManagedWorkflow

createWorkflow( - List dependentResourceSpecs) { - return createAsDefault(dependentResourceSpecs); + WorkflowSpec workflowSpec) { + + return createAsDefault(workflowSpec.getDependentResourceSpecs()); }

DefaultManagedWorkflow

createAsDefault( diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java index fa860c917d..d8caf50868 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java @@ -11,11 +11,8 @@ 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; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; @@ -42,7 +39,8 @@ void overridingNSShouldPreserveUntouchedDependents() { var configuration = createConfiguration(new NamedDependentReconciler()); // check that we have the proper number of dependent configs - var dependentResources = configuration.getDependentResources(); + var dependentResources = + configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); assertEquals(2, dependentResources.size()); // override the NS @@ -57,59 +55,13 @@ void overridingNSShouldPreserveUntouchedDependents() { assertEquals(Set.of(namespace), configuration.getNamespaces()); // check that we still have the proper number of dependent configs - dependentResources = configuration.getDependentResources(); + dependentResources = configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); assertEquals(2, dependentResources.size()); final var resourceConfig = extractDependentKubernetesResourceConfig( configuration, 1); assertEquals(stringConfig, resourceConfig); } - @ControllerConfiguration(dependents = { - @Dependent(type = NamedDependentReconciler.NamedDependentResource.class), - @Dependent(type = NamedDependentReconciler.ExternalDependentResource.class) - }) - private static class NamedDependentReconciler implements Reconciler { - - @Override - public UpdateControl reconcile(ConfigMap resource, Context context) { - return null; - } - - private static class NamedDependentResource - extends KubernetesDependentResource { - - public NamedDependentResource() { - super(ConfigMap.class); - } - } - - private static class ExternalDependentResource implements DependentResource, - DependentResourceConfigurator { - - private String config = "UNSET"; - - @Override - public ReconcileResult reconcile(ConfigMap primary, Context context) { - return null; - } - - @Override - public Class resourceType() { - return Object.class; - } - - @Override - public void configureWith(String config) { - this.config = config; - } - - @Override - public Optional configuration() { - return Optional.of(config); - } - } - } - @SuppressWarnings("rawtypes") private KubernetesDependentResourceConfig extractFirstDependentKubernetesResourceConfig( io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration) { @@ -119,7 +71,8 @@ private KubernetesDependentResourceConfig extractFirstDependentKubernetesResourc private Object extractDependentKubernetesResourceConfig( io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration, int index) { - final var spec = configuration.getDependentResources().get(index); + final var spec = + configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().get(index); return DependentResourceConfigurationResolver.configurationFor(spec, configuration); } @@ -316,7 +269,7 @@ void alreadyOverriddenDependentNamespacesShouldNotBePropagated() { @Test void replaceNamedDependentResourceConfigShouldWork() { var configuration = createConfiguration(new OneDepReconciler()); - var dependents = configuration.getDependentResources(); + var dependents = configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); assertFalse(dependents.isEmpty()); assertEquals(1, dependents.size()); @@ -349,7 +302,7 @@ void replaceNamedDependentResourceConfigShouldWork() { .withLabelSelector(labelSelector) .build()) .build(); - dependents = overridden.getDependentResources(); + dependents = overridden.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); dependentSpec = dependents.stream().filter(dr -> dr.getName().equals(dependentResourceName)) .findFirst().orElseThrow(); config = (KubernetesDependentResourceConfig) DependentResourceConfigurationResolver @@ -361,7 +314,8 @@ void replaceNamedDependentResourceConfigShouldWork() { assertTrue(dependentSpec.getReadyCondition() instanceof TestCondition); } - @ControllerConfiguration(dependents = @Dependent(type = ReadOnlyDependent.class)) + @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class)) + @ControllerConfiguration private static class WatchAllNamespacesReconciler implements Reconciler { @Override @@ -370,7 +324,8 @@ public UpdateControl reconcile(ConfigMap resource, Context } } - @ControllerConfiguration(dependents = @Dependent(type = WatchAllNSDependent.class)) + @Workflow(dependents = @Dependent(type = WatchAllNSDependent.class)) + @ControllerConfiguration private static class DependentWatchesAllNSReconciler implements Reconciler { @Override @@ -389,9 +344,9 @@ public boolean isMet(DependentResource dependentResource, } } - @ControllerConfiguration(namespaces = OneDepReconciler.CONFIGURED_NS, - dependents = @Dependent(type = ReadOnlyDependent.class, - readyPostcondition = TestCondition.class)) + @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class, + readyPostcondition = TestCondition.class)) + @ControllerConfiguration(namespaces = OneDepReconciler.CONFIGURED_NS) private static class OneDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "foo"; @@ -418,8 +373,8 @@ public WatchAllNSDependent() { } } - @ControllerConfiguration(namespaces = OverriddenNSOnDepReconciler.CONFIGURED_NS, - dependents = @Dependent(type = OverriddenNSDependent.class)) + @Workflow(dependents = @Dependent(type = OverriddenNSDependent.class)) + @ControllerConfiguration(namespaces = OverriddenNSOnDepReconciler.CONFIGURED_NS) private static class OverriddenNSOnDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "parentNS"; @@ -440,4 +395,51 @@ public OverriddenNSDependent() { super(ConfigMap.class); } } + + @Workflow(dependents = { + @Dependent(type = NamedDependentReconciler.NamedDependentResource.class), + @Dependent(type = NamedDependentReconciler.ExternalDependentResource.class) + }) + @ControllerConfiguration + private static class NamedDependentReconciler implements Reconciler { + + @Override + public UpdateControl reconcile(ConfigMap resource, Context context) { + return null; + } + + private static class NamedDependentResource + extends KubernetesDependentResource { + + public NamedDependentResource() { + super(ConfigMap.class); + } + } + + private static class ExternalDependentResource implements DependentResource, + DependentResourceConfigurator { + + private String config = "UNSET"; + + @Override + public ReconcileResult reconcile(ConfigMap primary, Context context) { + return null; + } + + @Override + public Class resourceType() { + return Object.class; + } + + @Override + public void configureWith(String config) { + this.config = config; + } + + @Override + public Optional configuration() { + return Optional.of(config); + } + } + } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java index 31f140c558..0b7dcd53a1 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java @@ -12,10 +12,7 @@ import io.fabric8.kubernetes.api.model.Service; import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; @@ -57,7 +54,7 @@ void controllerConfigurationProvidedShouldBeReturnedIfAvailable() { final var overridden = ControllerConfigurationOverrider.override(cfg) .replacingNamedDependentResourceConfig(DR_NAME, newConfig) .build(); - final var spec = cfg.getDependentResources().stream() + final var spec = cfg.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().stream() .filter(s -> DR_NAME.equals(s.getName())) .findFirst() .orElseThrow(); @@ -122,12 +119,13 @@ public Object configFrom(Annotation configAnnotation, assertEquals(overriddenConverter, converter); } - @ControllerConfiguration(dependents = { + @Workflow(dependents = { @Dependent(type = CustomAnnotatedDep.class, name = DR_NAME), @Dependent(type = ChildCustomAnnotatedDep.class), @Dependent(type = ConfigMapDep.class), @Dependent(type = ServiceDep.class) }) + @ControllerConfiguration static class CustomAnnotationReconciler implements Reconciler { public static final String DR_NAME = "first"; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java index 649e0c3050..5327439a31 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java @@ -1,12 +1,14 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.Test; import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; @@ -62,7 +64,9 @@ ManagedWorkflow managedWorkflow(DependentResourceSpec... specs) { final var configuration = mock(ControllerConfiguration.class); final var specList = List.of(specs); - when(configuration.getDependentResources()).thenReturn(specList); + var ws = new WorkflowSpec(specList); + when(configuration.getWorkflowSpec()).thenReturn(Optional.of(ws)); + return new BaseConfigurationService().getWorkflowFactory() .workflowFor(configuration); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java index ff47285c17..276e90d3ed 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java @@ -23,11 +23,7 @@ import io.javaoperatorsdk.operator.api.config.dependent.Configured; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; @@ -81,7 +77,8 @@ void defaultValuesShouldBeConsistent() { @SuppressWarnings("rawtypes") private KubernetesDependentResourceConfig extractDependentKubernetesResourceConfig( io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration, int index) { - final var spec = configuration.getDependentResources().get(index); + final var spec = + configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().get(index); return (KubernetesDependentResourceConfig) DependentResourceConfigurationResolver .configurationFor(spec, configuration); } @@ -90,11 +87,11 @@ private KubernetesDependentResourceConfig extractDependentKubernetesResourceConf @SuppressWarnings("rawtypes") void getDependentResources() { var configuration = configFor(new NoDepReconciler()); - var dependents = configuration.getDependentResources(); - assertTrue(dependents.isEmpty()); + var workflowSpec = configuration.getWorkflowSpec(); + assertTrue(workflowSpec.isEmpty()); configuration = configFor(new OneDepReconciler()); - dependents = configuration.getDependentResources(); + var dependents = configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); assertFalse(dependents.isEmpty()); assertEquals(1, dependents.size()); final var dependentResourceName = DependentResource.defaultNameFor(ReadOnlyDependent.class); @@ -111,7 +108,7 @@ void getDependentResources() { assertEquals(Set.of(OneDepReconciler.CONFIGURED_NS), config.namespaces()); configuration = configFor(new NamedDepReconciler()); - dependents = configuration.getDependentResources(); + dependents = configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); assertFalse(dependents.isEmpty()); assertEquals(1, dependents.size()); dependentSpec = findByName(dependents, NamedDepReconciler.NAME); @@ -150,7 +147,7 @@ void tryingToAddDuplicatedDependentsWithoutNameShouldFail() { @Test void addingDuplicatedDependentsWithNameShouldWork() { var config = configFor(new NamedDuplicatedDepReconciler()); - var dependents = config.getDependentResources(); + var dependents = config.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); assertEquals(2, dependents.size()); assertTrue(findByNameOptional(dependents, NamedDuplicatedDepReconciler.NAME).isPresent() && findByNameOptional(dependents, DependentResource.defaultNameFor(ReadOnlyDependent.class)) @@ -296,7 +293,9 @@ void shouldUseSSAShouldAlsoWorkWithManualConfiguration() { private static int getValue( io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration, int index) { return ((CustomConfig) DependentResourceConfigurationResolver - .configurationFor(configuration.getDependentResources().get(index), configuration)) + .configurationFor( + configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().get(index), + configuration)) .getValue(); } @@ -311,8 +310,8 @@ public UpdateControl reconcile(ConfigMap resource, Context } } - @ControllerConfiguration(namespaces = OneDepReconciler.CONFIGURED_NS, - dependents = @Dependent(type = ReadOnlyDependent.class)) + @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class)) + @ControllerConfiguration(namespaces = OneDepReconciler.CONFIGURED_NS) private static class OneDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "foo"; @@ -324,8 +323,8 @@ public UpdateControl reconcile(ConfigMapReader resource, } } - @ControllerConfiguration( - dependents = @Dependent(type = ReadOnlyDependent.class, name = NamedDepReconciler.NAME)) + @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class, name = NamedDepReconciler.NAME)) + @ControllerConfiguration private static class NamedDepReconciler implements Reconciler { private static final String NAME = "foo"; @@ -337,11 +336,11 @@ public UpdateControl reconcile(ConfigMapReader resource, } } - @ControllerConfiguration( - dependents = { - @Dependent(type = ReadOnlyDependent.class), - @Dependent(type = ReadOnlyDependent.class) - }) + @Workflow(dependents = { + @Dependent(type = ReadOnlyDependent.class), + @Dependent(type = ReadOnlyDependent.class) + }) + @ControllerConfiguration private static class DuplicatedDepReconciler implements Reconciler { @Override @@ -351,11 +350,11 @@ public UpdateControl reconcile(ConfigMapReader resource, } } - @ControllerConfiguration( - dependents = { - @Dependent(type = ReadOnlyDependent.class, name = NamedDuplicatedDepReconciler.NAME), - @Dependent(type = ReadOnlyDependent.class) - }) + @Workflow(dependents = { + @Dependent(type = ReadOnlyDependent.class, name = NamedDuplicatedDepReconciler.NAME), + @Dependent(type = ReadOnlyDependent.class) + }) + @ControllerConfiguration private static class NamedDuplicatedDepReconciler implements Reconciler { private static final String NAME = "duplicated"; @@ -377,10 +376,11 @@ public UpdateControl reconcile(ConfigMapReader resource, } } - @ControllerConfiguration(dependents = { + @Workflow(dependents = { @Dependent(type = SelectorReconciler.WithAnnotation.class), @Dependent(type = ReadOnlyDependent.class) }) + @ControllerConfiguration private static class SelectorReconciler implements Reconciler { @Override @@ -526,10 +526,11 @@ public UpdateControl reconcile(ConfigMap resource, Context } } - @ControllerConfiguration(dependents = { + @Workflow(dependents = { @Dependent(type = CustomAnnotatedDep.class), @Dependent(type = ChildCustomAnnotatedDep.class) }) + @ControllerConfiguration() private static class CustomAnnotationReconciler implements Reconciler { @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentReconciler.java index 3b2acd942e..95be38fc4d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentReconciler.java @@ -2,13 +2,11 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(dependents = @Dependent(type = CRUDConfigMapBulkDependentResource.class)) +@Workflow(dependents = @Dependent(type = CRUDConfigMapBulkDependentResource.class)) +@ControllerConfiguration public class ManagedBulkDependentReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java index 569c4fa359..8da3ba944f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java @@ -2,14 +2,12 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(dependents = @Dependent(readyPostcondition = SampleBulkCondition.class, +@Workflow(dependents = @Dependent(readyPostcondition = SampleBulkCondition.class, type = CRUDConfigMapBulkDependentResource.class)) +@ControllerConfiguration() public class ManagedBulkDependentWithReadyConditionReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedDeleterBulkReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedDeleterBulkReconciler.java index e759bdd200..db5ba60044 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedDeleterBulkReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedDeleterBulkReconciler.java @@ -1,13 +1,10 @@ package io.javaoperatorsdk.operator.sample.bulkdependent; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration( - dependents = @Dependent(type = ConfigMapDeleterBulkDependentResource.class)) +@Workflow(dependents = @Dependent(type = ConfigMapDeleterBulkDependentResource.class)) +@ControllerConfiguration public class ManagedDeleterBulkReconciler implements Reconciler { @Override public UpdateControl reconcile( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkResourceReconciler.java index 2543422d74..f11621e4c2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkResourceReconciler.java @@ -1,13 +1,11 @@ package io.javaoperatorsdk.operator.sample.bulkdependent.external; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; -@ControllerConfiguration(dependents = @Dependent(type = ExternalBulkDependentResource.class)) +@Workflow(dependents = @Dependent(type = ExternalBulkDependentResource.class)) +@ControllerConfiguration() public class ExternalBulkResourceReconciler implements Reconciler { @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java index 6be29c5092..c4bbb3c9f0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java @@ -6,7 +6,8 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration(dependents = {@Dependent(type = ConfigMapDependentResource.class)}) +@Workflow(dependents = {@Dependent(type = ConfigMapDependentResource.class)}) +@ControllerConfiguration public class CleanerForManagedDependentTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java index 853ac4f2d7..42db07333f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java @@ -15,23 +15,22 @@ import static io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentReconciler.SERVICE_EVENT_SOURCE_NAME; import static io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentReconciler.STATEFUL_SET_EVENT_SOURCE_NAME; -@ControllerConfiguration( - name = "project-operator", - dependents = { - @Dependent(name = "first-svc", type = FirstService.class, - useEventSourceWithName = SERVICE_EVENT_SOURCE_NAME), - @Dependent(name = "second-svc", type = SecondService.class, - useEventSourceWithName = SERVICE_EVENT_SOURCE_NAME), - @Dependent(name = "first", type = FirstStatefulSet.class, - useEventSourceWithName = STATEFUL_SET_EVENT_SOURCE_NAME, - dependsOn = {"first-svc"}, - readyPostcondition = StatefulSetReadyCondition.class), - @Dependent(name = "second", - type = SecondStatefulSet.class, - useEventSourceWithName = STATEFUL_SET_EVENT_SOURCE_NAME, - dependsOn = {"second-svc", "first"}, - readyPostcondition = StatefulSetReadyCondition.class), - }) +@Workflow(dependents = { + @Dependent(name = "first-svc", type = FirstService.class, + useEventSourceWithName = SERVICE_EVENT_SOURCE_NAME), + @Dependent(name = "second-svc", type = SecondService.class, + useEventSourceWithName = SERVICE_EVENT_SOURCE_NAME), + @Dependent(name = "first", type = FirstStatefulSet.class, + useEventSourceWithName = STATEFUL_SET_EVENT_SOURCE_NAME, + dependsOn = {"first-svc"}, + readyPostcondition = StatefulSetReadyCondition.class), + @Dependent(name = "second", + type = SecondStatefulSet.class, + useEventSourceWithName = STATEFUL_SET_EVENT_SOURCE_NAME, + dependsOn = {"second-svc", "first"}, + readyPostcondition = StatefulSetReadyCondition.class), +}) +@ControllerConfiguration(name = "project-operator") public class ComplexDependentReconciler implements Reconciler, EventSourceInitializer { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java index 884b5a859d..49091783f8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java @@ -2,14 +2,12 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(type = ConfigMapDependentResource.class)}) +@ControllerConfiguration() public class CreateOnlyIfNotExistingDependentWithSSAReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java index ec4a2c86b9..b8a3168a56 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java @@ -13,8 +13,9 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration(dependents = @Dependent( +@Workflow(dependents = @Dependent( type = DependentAnnotationSecondaryMapperReconciler.ConfigMapDependentResource.class)) +@ControllerConfiguration public class DependentAnnotationSecondaryMapperReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingReconciler.java index 8c14f829ff..6ac2626111 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingReconciler.java @@ -3,8 +3,8 @@ import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration( - dependents = {@Dependent(type = CustomMappingConfigMapDependentResource.class)}) +@Workflow(dependents = {@Dependent(type = CustomMappingConfigMapDependentResource.class)}) +@ControllerConfiguration public class DependentCustomMappingReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java index de9ea20f4a..d858c34223 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java @@ -6,10 +6,10 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration( - dependents = { - @Dependent(type = ConfigMapDependentResource.class), - }) +@Workflow(dependents = { + @Dependent(type = ConfigMapDependentResource.class), +}) +@ControllerConfiguration public class DependentDifferentNamespaceReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java index 114491d9b9..97ff1b5484 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java @@ -5,8 +5,8 @@ import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(onUpdateFilter = UpdateFilter.class, - dependents = {@Dependent(type = FilteredDependentConfigMap.class)}) +@Workflow(dependents = {@Dependent(type = FilteredDependentConfigMap.class)}) +@ControllerConfiguration(onUpdateFilter = UpdateFilter.class) public class DependentFilterTestReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java index 4ce74c75eb..d8551c72e6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java @@ -6,11 +6,10 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration( - namespaces = Constants.WATCH_CURRENT_NAMESPACE, - dependents = { - @Dependent(type = ConfigMapDependentResource.class), - }) +@Workflow(dependents = { + @Dependent(type = ConfigMapDependentResource.class) +}) +@ControllerConfiguration(namespaces = Constants.WATCH_CURRENT_NAMESPACE) public class DependentOperationEventFilterCustomResourceTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java index bb319741b3..0d6d63024f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java @@ -14,11 +14,12 @@ import static io.javaoperatorsdk.operator.sample.dependentresourcecrossref.DependentResourceCrossRefReconciler.SECRET_NAME; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(name = SECRET_NAME, type = DependentResourceCrossRefReconciler.SecretDependentResource.class), @Dependent(type = DependentResourceCrossRefReconciler.ConfigMapDependentResource.class, dependsOn = SECRET_NAME)}) +@ControllerConfiguration public class DependentResourceCrossRefReconciler implements Reconciler, ErrorStatusHandler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java index 8755e7099c..fd67e7805d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java @@ -11,8 +11,8 @@ import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration( - dependents = @Dependent(type = ExternalWithStateDependentResource.class)) +@Workflow(dependents = @Dependent(type = ExternalWithStateDependentResource.class)) +@ControllerConfiguration public class ExternalStateDependentReconciler implements Reconciler, EventSourceInitializer, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java index ebc1655c38..dba6623254 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java @@ -5,19 +5,14 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration( - dependents = @Dependent(type = BulkDependentResourceExternalWithState.class)) +@Workflow(dependents = @Dependent(type = BulkDependentResourceExternalWithState.class)) +@ControllerConfiguration public class ExternalStateBulkDependentReconciler implements Reconciler, EventSourceInitializer, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java index 64651ec23e..bab120cfac 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java @@ -3,8 +3,8 @@ import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration( - dependents = {@Dependent(type = ConfigMapGenericKubernetesDependent.class)}) +@Workflow(dependents = {@Dependent(type = ConfigMapGenericKubernetesDependent.class)}) +@ControllerConfiguration public class GenericKubernetesDependentManagedReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java index f71f243c79..8b0511e486 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java @@ -6,19 +6,16 @@ import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.client.KubernetesClient; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; +@Workflow(dependents = @Dependent( + name = InformerRelatedBehaviorTestReconciler.CONFIG_MAP_DEPENDENT_RESOURCE, + type = ConfigMapDependentResource.class)) @ControllerConfiguration( - name = InformerRelatedBehaviorTestReconciler.INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER, - dependents = @Dependent( - name = InformerRelatedBehaviorTestReconciler.CONFIG_MAP_DEPENDENT_RESOURCE, - type = ConfigMapDependentResource.class)) + name = InformerRelatedBehaviorTestReconciler.INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER) public class InformerRelatedBehaviorTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java index 8ef1035e9b..2fa2c6213b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java @@ -7,11 +7,12 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.dependent.workflow.KubernetesResourceDeletedCondition; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(name = "ConfigMap", type = ConfigMapDependent.class), @Dependent(type = SecretDependent.class, dependsOn = "ConfigMap", deletePostcondition = KubernetesResourceDeletedCondition.class) }) +@ControllerConfiguration public class ManagedDependentDefaultDeleteConditionReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java index 81c2308eb5..29b0db91c9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java @@ -6,17 +6,17 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(name = MultipleManagedDependentResourceMultiInformerReconciler.CONFIG_MAP_1_DR, type = MultipleManagedDependentResourceMultiInformerConfigMap1.class), @Dependent(name = MultipleManagedDependentResourceMultiInformerReconciler.CONFIG_MAP_2_DR, type = MultipleManagedDependentResourceMultiInformerConfigMap2.class) }) +@ControllerConfiguration public class MultipleManagedDependentResourceMultiInformerReconciler implements Reconciler, TestExecutionInfoProvider { - public static final String CONFIG_MAP_EVENT_SOURCE = "ConfigMapEventSource"; public static final String DATA_KEY = "key"; public static final String CONFIG_MAP_1_DR = "ConfigMap1"; public static final String CONFIG_MAP_2_DR = "ConfigMap2"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java index 2d9b4f3ee9..7cf66614af 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java @@ -13,12 +13,13 @@ import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.CONFIG_MAP_EVENT_SOURCE; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(type = MultipleManagedDependentResourceConfigMap1.class, useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE), @Dependent(type = MultipleManagedDependentResourceConfigMap2.class, useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE) }) +@ControllerConfiguration public class MultipleManagedDependentResourceReconciler implements Reconciler, TestExecutionInfoProvider, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java index 349409ec73..0773ff063a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java @@ -17,12 +17,13 @@ import static io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype.MultipleManagedExternalDependentResourceReconciler.CONFIG_MAP_EVENT_SOURCE; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(type = ExternalDependentResource1.class, useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE), @Dependent(type = ExternalDependentResource2.class, useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE) }) +@ControllerConfiguration() public class MultipleManagedExternalDependentResourceReconciler implements Reconciler, TestExecutionInfoProvider, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentReconciler.java index c1f1262414..763f136c8d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentReconciler.java @@ -2,16 +2,14 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(type = MultipleOwnerDependentConfigMap.class) }) +@ControllerConfiguration() public class MultipleOwnerDependentReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java index f7172ca44d..5f8595a131 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java @@ -5,20 +5,16 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; +@Workflow(dependents = { + @Dependent(type = ConfigMapDependentResource1.class, name = "cm1"), + @Dependent(type = ConfigMapDependentResource2.class, dependsOn = "cm1") +}) @ControllerConfiguration( - namespaces = Constants.WATCH_CURRENT_NAMESPACE, - dependents = { - @Dependent(type = ConfigMapDependentResource1.class, name = "cm1"), - @Dependent(type = ConfigMapDependentResource2.class, dependsOn = "cm1") - }) + namespaces = Constants.WATCH_CURRENT_NAMESPACE) public class OrderedManagedDependentTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java index 89b2a43700..712635659c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java @@ -8,6 +8,7 @@ import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -15,8 +16,9 @@ import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; -@ControllerConfiguration(dependents = @Dependent( +@Workflow(dependents = @Dependent( type = DependentPrimaryIndexerTestReconciler.ReadOnlyConfigMapDependent.class)) +@ControllerConfiguration public class DependentPrimaryIndexerTestReconciler extends AbstractPrimaryIndexerTestReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java index c51111b206..fc156bed4f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java @@ -24,11 +24,12 @@ * Note that this is usually just used with read only resources. So it has limited usage, one reason * to use it is to have nice condition on that resource within a workflow. */ -@ControllerConfiguration(dependents = {@Dependent(type = ConfigMapDependent.class, +@Workflow(dependents = {@Dependent(type = ConfigMapDependent.class, name = CONFIG_MAP, reconcilePrecondition = ConfigMapReconcilePrecondition.class, useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE), @Dependent(type = SecretDependent.class, dependsOn = CONFIG_MAP)}) +@ControllerConfiguration() public class PrimaryToSecondaryDependentReconciler implements Reconciler, TestExecutionInfoProvider, EventSourceInitializer { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestReconciler.java index decd9b597b..e7daf5b2eb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestReconciler.java @@ -2,15 +2,12 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration( - dependents = @Dependent(type = ConfigMapDependentResource.class)) +@Workflow(dependents = @Dependent(type = ConfigMapDependentResource.class)) +@ControllerConfiguration public class RestartTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java index 64e81e7c31..0746de2897 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java @@ -2,13 +2,11 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(dependents = {@Dependent(type = ServiceDependentResource.class)}) +@Workflow(dependents = {@Dependent(type = ServiceDependentResource.class)}) +@ControllerConfiguration public class ServiceStrictMatcherTestReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java index 5fa7d778b3..b36b6f31a2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java @@ -6,11 +6,10 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration( - namespaces = Constants.WATCH_CURRENT_NAMESPACE, - dependents = { - @Dependent(type = ServiceAccountDependentResource.class), - }) +@Workflow(dependents = { + @Dependent(type = ServiceAccountDependentResource.class), +}) +@ControllerConfiguration(namespaces = Constants.WATCH_CURRENT_NAMESPACE) public class SpecialResourceTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherReconciler.java index a513133670..e0cdf50c96 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherReconciler.java @@ -2,13 +2,11 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(dependents = {@Dependent(type = ServiceDependentResource.class)}) +@Workflow(dependents = {@Dependent(type = ServiceDependentResource.class)}) +@ControllerConfiguration public class SSALegacyMatcherReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java index c884619227..3b30acfc5c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java @@ -1,13 +1,10 @@ package io.javaoperatorsdk.operator.sample.statefulsetdesiredsanitizer; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration( - dependents = {@Dependent(type = StatefulSetDesiredSanitizerDependentResource.class)}) +@Workflow(dependents = {@Dependent(type = StatefulSetDesiredSanitizerDependentResource.class)}) +@ControllerConfiguration public class StatefulSetDesiredSanitizerReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java index fd63a2cb12..9cc4a3e9d6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java @@ -2,13 +2,11 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(dependents = {@Dependent(type = UnmodifiablePartConfigMapDependent.class)}) +@Workflow(dependents = {@Dependent(type = UnmodifiablePartConfigMapDependent.class)}) +@ControllerConfiguration public class UnmodifiableDependentPartReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java index 3f2fba15c5..6a30f3d9f4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java @@ -3,10 +3,11 @@ import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(type = ConfigMapDependentResource.class, activationCondition = TestActivcationCondition.class), }) +@ControllerConfiguration public class WorkflowActivationCleanupReconciler implements Reconciler, Cleaner { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionReconciler.java index 33db3043ba..8669c24cb7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionReconciler.java @@ -3,11 +3,12 @@ import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(type = ConfigMapDependentResource.class), @Dependent(type = RouteDependentResource.class, activationCondition = IsOpenShiftCondition.class) }) +@ControllerConfiguration public class WorkflowActivationConditionReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java index 03d4e22016..1fadcdad66 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java @@ -7,7 +7,7 @@ import static io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureReconciler.DEPLOYMENT_NAME; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(name = DEPLOYMENT_NAME, type = DeploymentDependentResource.class, readyPostcondition = DeploymentReadyCondition.class), @Dependent(type = ConfigMapDependentResource.class, @@ -15,6 +15,7 @@ deletePostcondition = ConfigMapDeletePostCondition.class, dependsOn = DEPLOYMENT_NAME) }) +@ControllerConfiguration public class WorkflowAllFeatureReconciler implements Reconciler, Cleaner { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java index 8277e7f8e7..aeb4403f7c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java @@ -2,17 +2,15 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -@ControllerConfiguration(dependents = { +@Workflow(dependents = { @Dependent(type = ConfigMapDependentResource.class, activationCondition = ActivationCondition.class), @Dependent(type = SecretDependentResource.class) }) +@ControllerConfiguration public class WorkflowMultipleActivationReconciler implements Reconciler { diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java index 95db43b228..1a4b704591 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java @@ -4,12 +4,7 @@ import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.api.model.Secret; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler; -import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.sample.dependent.SchemaDependentResource; import io.javaoperatorsdk.operator.sample.dependent.SecretDependentResource; @@ -19,12 +14,12 @@ import static io.javaoperatorsdk.operator.sample.dependent.SecretDependentResource.MYSQL_SECRET_USERNAME; import static java.lang.String.format; -@ControllerConfiguration( - dependents = { - @Dependent(type = SecretDependentResource.class, name = SecretDependentResource.NAME), - @Dependent(type = SchemaDependentResource.class, name = SchemaDependentResource.NAME, - dependsOn = SecretDependentResource.NAME) - }) +@Workflow(dependents = { + @Dependent(type = SecretDependentResource.class, name = SecretDependentResource.NAME), + @Dependent(type = SchemaDependentResource.class, name = SchemaDependentResource.NAME, + dependsOn = SecretDependentResource.NAME) +}) +@ControllerConfiguration public class MySQLSchemaReconciler implements Reconciler, ErrorStatusHandler { diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatReconciler.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatReconciler.java index de4a63431b..796da31d5d 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatReconciler.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatReconciler.java @@ -7,21 +7,18 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.DeploymentStatus; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; /** * Runs a specified number of Tomcat app server Pods. It uses a Deployment to create the Pods. Also * creates a Service over which the Pods can be accessed. */ -@ControllerConfiguration( - dependents = { - @Dependent(type = DeploymentDependentResource.class), - @Dependent(type = ServiceDependentResource.class) - }) +@Workflow(dependents = { + @Dependent(type = DeploymentDependentResource.class), + @Dependent(type = ServiceDependentResource.class) +}) +@ControllerConfiguration public class TomcatReconciler implements Reconciler { private final Logger log = LoggerFactory.getLogger(getClass()); diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java index d370cd3315..44149aed4d 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java @@ -13,14 +13,14 @@ /** * Shows how to implement a reconciler with managed dependent resources. */ -@ControllerConfiguration( - dependents = { - @Dependent(type = ConfigMapDependentResource.class), - @Dependent(type = DeploymentDependentResource.class), - @Dependent(type = ServiceDependentResource.class), - @Dependent(type = IngressDependentResource.class, - reconcilePrecondition = ExposedIngressCondition.class) - }) +@Workflow(dependents = { + @Dependent(type = ConfigMapDependentResource.class), + @Dependent(type = DeploymentDependentResource.class), + @Dependent(type = ServiceDependentResource.class), + @Dependent(type = IngressDependentResource.class, + reconcilePrecondition = ExposedIngressCondition.class) +}) +@ControllerConfiguration public class WebPageManagedDependentsReconciler implements Reconciler, ErrorStatusHandler, Cleaner { From 8e799e2cb674bd530588e42a25f0349916719946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 11 Mar 2024 23:19:30 +0100 Subject: [PATCH 16/96] fix: pom properties cleanup (#2280) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- caffeine-bounded-cache-support/pom.xml | 5 ----- micrometer-support/pom.xml | 7 +------ operator-framework-junit5/pom.xml | 5 ----- pom.xml | 1 + sample-operators/leader-election/pom.xml | 6 ------ sample-operators/mysql-schema/pom.xml | 6 ------ sample-operators/pom.xml | 4 ---- sample-operators/tomcat-operator/pom.xml | 6 ------ sample-operators/webpage/pom.xml | 6 ------ 9 files changed, 2 insertions(+), 44 deletions(-) diff --git a/caffeine-bounded-cache-support/pom.xml b/caffeine-bounded-cache-support/pom.xml index 6ba5441db5..6961fc11d7 100644 --- a/caffeine-bounded-cache-support/pom.xml +++ b/caffeine-bounded-cache-support/pom.xml @@ -12,11 +12,6 @@ caffeine-bounded-cache-support Operator SDK - Caffeine Bounded Cache Support - - 11 - 11 - - io.javaoperatorsdk diff --git a/micrometer-support/pom.xml b/micrometer-support/pom.xml index 89aa81f76b..6ca02379b1 100644 --- a/micrometer-support/pom.xml +++ b/micrometer-support/pom.xml @@ -11,12 +11,7 @@ micrometer-support Operator SDK - Micrometer Support - - - 11 - 11 - - + io.micrometer diff --git a/operator-framework-junit5/pom.xml b/operator-framework-junit5/pom.xml index 39dd82ab1a..5f4fa10644 100644 --- a/operator-framework-junit5/pom.xml +++ b/operator-framework-junit5/pom.xml @@ -12,11 +12,6 @@ operator-framework-junit-5 Operator SDK - Framework - JUnit 5 extension - - 11 - 11 - - io.javaoperatorsdk diff --git a/pom.xml b/pom.xml index 41c74f1975..78addb90e6 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,7 @@ 2.23.0 1.0 1.9.0 + 3.4.1 diff --git a/sample-operators/leader-election/pom.xml b/sample-operators/leader-election/pom.xml index 63346634dd..eea2ae19aa 100644 --- a/sample-operators/leader-election/pom.xml +++ b/sample-operators/leader-election/pom.xml @@ -15,12 +15,6 @@ An E2E test for leader election jar - - 11 - 11 - 3.4.3 - - diff --git a/sample-operators/mysql-schema/pom.xml b/sample-operators/mysql-schema/pom.xml index 32895db6b0..e6eeb1930c 100644 --- a/sample-operators/mysql-schema/pom.xml +++ b/sample-operators/mysql-schema/pom.xml @@ -15,12 +15,6 @@ Provisions Schemas in a MySQL database jar - - 11 - 11 - 3.4.3 - - diff --git a/sample-operators/pom.xml b/sample-operators/pom.xml index c485af3052..07895b8b94 100644 --- a/sample-operators/pom.xml +++ b/sample-operators/pom.xml @@ -14,10 +14,6 @@ Operator SDK - Samples pom - - 3.1.4 - - tomcat-operator webpage diff --git a/sample-operators/tomcat-operator/pom.xml b/sample-operators/tomcat-operator/pom.xml index 4ae7abd3c3..af0e8ac6df 100644 --- a/sample-operators/tomcat-operator/pom.xml +++ b/sample-operators/tomcat-operator/pom.xml @@ -15,12 +15,6 @@ Provisions Tomcat Pods and deploys Webapplications in them jar - - 11 - 11 - 3.4.3 - - diff --git a/sample-operators/webpage/pom.xml b/sample-operators/webpage/pom.xml index 23554fa79f..576ffa7157 100644 --- a/sample-operators/webpage/pom.xml +++ b/sample-operators/webpage/pom.xml @@ -15,12 +15,6 @@ Provisions an nginx Webserver based on a CRD with give html jar - - 11 - 11 - 3.4.3 - - From f3ade921e64bfebc72af5a7bfed89b93c7798694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 12 Mar 2024 14:43:09 +0100 Subject: [PATCH 17/96] improve: remove EventSourceInitializer (#2257) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun Signed-off-by: Attila Mészáros --- .../main/resources/templates/Reconciler.java | 1 - .../cache/sample/AbstractTestReconciler.java | 4 +- docs/documentation/v5-0-migration.md | 5 ++ ...Initializer.java => EventSourceUtils.java} | 30 ++-------- .../operator/api/reconciler/Reconciler.java | 20 ++++++- .../operator/processing/Controller.java | 25 ++------ .../processing/event/EventSourceManager.java | 4 +- .../processing/event/NamedEventSource.java | 4 +- .../processing/event/source/EventSource.java | 6 +- ...zerTest.java => EventSourceUtilsTest.java} | 6 +- .../ControllerResourceEventSourceTest.java | 9 ++- .../StandaloneBulkDependentReconciler.java | 5 +- .../ChangeNamespaceTestReconciler.java | 5 +- ...ClusterScopedCustomResourceReconciler.java | 5 +- .../ComplexDependentReconciler.java | 3 +- ...CreateUpdateEventFilterTestReconciler.java | 5 +- .../DependentReInitializationReconciler.java | 5 +- .../dependentssa/DependentSSAReconciler.java | 5 +- .../ExternalStateDependentReconciler.java | 3 +- .../ExternalStateReconciler.java | 3 +- .../ExternalStateBulkDependentReconciler.java | 3 +- .../sample/filter/FilterTestReconciler.java | 5 +- ...bernetesDependentStandaloneReconciler.java | 5 +- ...cKubernetesResourceHandlingReconciler.java | 5 +- .../IndexDiscriminatorTestReconciler.java | 4 +- ...formerEventSourceTestCustomReconciler.java | 12 +--- ...endentGarbageCollectionTestReconciler.java | 3 +- .../MultipleDependentResourceReconciler.java | 4 +- ...pleManagedDependentResourceReconciler.java | 3 +- ...edExternalDependentResourceReconciler.java | 3 +- ...ultipleSecondaryEventSourceReconciler.java | 5 +- ...ourcePollingEventSourceTestReconciler.java | 5 +- .../PrimaryIndexerTestReconciler.java | 7 +-- .../primarytosecondary/JobReconciler.java | 4 +- ...PrimaryToSecondaryDependentReconciler.java | 3 +- .../StandaloneDependentTestReconciler.java | 12 +++- .../operator/sample/WebappReconciler.java | 13 +---- .../WebPageDependentsWorkflowReconciler.java | 4 +- .../operator/sample/WebPageReconciler.java | 28 ++------- ...WebPageStandaloneDependentsReconciler.java | 57 ++++++++++++++----- 40 files changed, 155 insertions(+), 183 deletions(-) rename operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/{EventSourceInitializer.java => EventSourceUtils.java} (69%) rename operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/{EventSourceInitializerTest.java => EventSourceUtilsTest.java} (75%) diff --git a/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java b/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java index f3efb2114d..6d03196fe9 100644 --- a/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java +++ b/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java @@ -5,7 +5,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java index b6e3ba2c8f..7a53db8bd9 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java @@ -28,7 +28,7 @@ import com.github.benmanes.caffeine.cache.Caffeine; public abstract class AbstractTestReconciler

> - implements Reconciler

, EventSourceInitializer

{ + implements Reconciler

{ private static final Logger log = LoggerFactory.getLogger(BoundedCacheClusterScopeTestReconciler.class); @@ -82,7 +82,7 @@ public Map prepareEventSources( Mappers.fromOwnerReference(this instanceof BoundedCacheClusterScopeTestReconciler)) .build(), context); - return EventSourceInitializer.nameEventSources(es); + return EventSourceUtils.nameEventSources(es); } private void ensureStatus(P resource) { diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index bc83b49103..f4ec51f4fb 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -12,3 +12,8 @@ permalink: /docs/v5-0-migration 1. [Result of managed dependent resources](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java#L55-L57) is not `Optional` anymore. In case you use this result, simply use the result objects directly. +2. `EventSourceInitializer` is not a separate interface anymore. It is part of the `Reconciler` interface with a + default implementation. You can simply remove this interface from your reconciler. The + [`EventSourceUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java#L11-L11) + now contains all the utility methods used for event sources naming that were previously defined in + the `EventSourceInitializer` interface. diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java similarity index 69% rename from operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java rename to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java index 09c1687e1e..8b89d95b71 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java @@ -8,24 +8,7 @@ import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; -/** - * An interface that a {@link Reconciler} can implement to have the SDK register the provided - * {@link EventSource} - * - * @param

the primary resource type handled by the associated {@link Reconciler} - */ -public interface EventSourceInitializer

{ - - /** - * Prepares a map of {@link EventSource} implementations keyed by the name with which they need to - * be registered by the SDK. - * - * @param context a {@link EventSourceContext} providing access to information useful to event - * sources - * @return a map of event sources to register - */ - Map prepareEventSources(EventSourceContext

context); - +public class EventSourceUtils { /** * Utility method to easily create map with generated name for event sources. This is for the use * case when the event sources are not access explicitly by name in the reconciler. @@ -33,7 +16,7 @@ public interface EventSourceInitializer

{ * @param eventSources to name * @return even source with default names */ - static Map nameEventSources(EventSource... eventSources) { + public static Map nameEventSources(EventSource... eventSources) { Map eventSourceMap = new HashMap<>(eventSources.length); for (EventSource eventSource : eventSources) { eventSourceMap.put(generateNameFor(eventSource), eventSource); @@ -42,7 +25,7 @@ static Map nameEventSources(EventSource... eventSources) { } @SuppressWarnings("unchecked") - static Map eventSourcesFromWorkflow( + public static Map eventSourcesFromWorkflow( EventSourceContext context, Workflow workflow) { Map result = new HashMap<>(); @@ -54,13 +37,13 @@ static Map eventSourcesFromWorkflow } @SuppressWarnings("rawtypes") - static Map nameEventSourcesFromDependentResource( + public static Map nameEventSourcesFromDependentResource( EventSourceContext context, DependentResource... dependentResources) { return nameEventSourcesFromDependentResource(context, Arrays.asList(dependentResources)); } @SuppressWarnings("unchecked,rawtypes") - static Map nameEventSourcesFromDependentResource( + public static Map nameEventSourcesFromDependentResource( EventSourceContext context, Collection dependentResources) { if (dependentResources != null) { @@ -81,9 +64,8 @@ static Map nameEventSourcesFromDepe * @param eventSource EventSource * @return generated name */ - static String generateNameFor(EventSource eventSource) { + public static String generateNameFor(EventSource eventSource) { // we can have multiple event sources for the same class return eventSource.getClass().getName() + "#" + eventSource.hashCode(); } - } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java index 55df9d1cea..2047762c35 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java @@ -1,8 +1,11 @@ package io.javaoperatorsdk.operator.api.reconciler; +import java.util.*; + import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; -public interface Reconciler { +public interface Reconciler

{ /** * The implementation of this operation is required to be idempotent. Always use the UpdateControl @@ -14,6 +17,19 @@ public interface Reconciler { * @return UpdateControl to manage updates on the custom resource (usually the status) after * reconciliation. */ - UpdateControl reconcile(R resource, Context context) throws Exception; + UpdateControl

reconcile(P resource, Context

context) throws Exception; + + + /** + * Prepares a map of {@link EventSource} implementations keyed by the name with which they need to + * be registered by the SDK. + * + * @param context a {@link EventSourceContext} providing access to information useful to event + * sources + * @return a map of event sources to register + */ + default Map prepareEventSources(EventSourceContext

context) { + return Map.of(); + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 93f10d3e21..05a1c92943 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -1,11 +1,6 @@ package io.javaoperatorsdk.operator.processing; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,16 +20,7 @@ import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager; import io.javaoperatorsdk.operator.api.monitoring.Metrics; import io.javaoperatorsdk.operator.api.monitoring.Metrics.ControllerExecution; -import io.javaoperatorsdk.operator.api.reconciler.Cleaner; -import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ContextInitializer; -import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer; -import io.javaoperatorsdk.operator.api.reconciler.Ignore; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceNotFoundException; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceProvider; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceReferencer; @@ -223,11 +209,8 @@ private void initContextIfNeeded(P resource, Context

context) { } public void initAndRegisterEventSources(EventSourceContext

context) { - if (reconciler instanceof EventSourceInitializer) { - final var provider = (EventSourceInitializer

) this.reconciler; - final var ownSources = provider.prepareEventSources(context); - ownSources.forEach(eventSourceManager::registerEventSource); - } + final var ownSources = this.reconciler.prepareEventSources(context); + ownSources.forEach(eventSourceManager::registerEventSource); // register created event sources final var dependentResourcesByName = diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java index bd299b464a..9772c9edd5 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java @@ -14,7 +14,7 @@ import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager; import io.javaoperatorsdk.operator.api.config.NamespaceChangeable; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.LifecycleAware; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -150,7 +150,7 @@ public final synchronized void registerEventSource(String name, EventSource even Objects.requireNonNull(eventSource, "EventSource must not be null"); try { if (name == null || name.isBlank()) { - name = EventSourceInitializer.generateNameFor(eventSource); + name = EventSourceUtils.generateNameFor(eventSource); } if (eventSource instanceof ManagedInformerEventSource) { var managedInformerEventSource = ((ManagedInformerEventSource) eventSource); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java index a1d1a601e4..a4e4ead83a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java @@ -4,7 +4,7 @@ import java.util.Optional; import io.javaoperatorsdk.operator.OperatorException; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.processing.event.source.Configurable; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.EventSourceStartPriority; @@ -19,7 +19,7 @@ class NamedEventSource implements EventSource, EventSourceMetadata { NamedEventSource(EventSource original, String name) { this.original = original; this.name = name; - nameSet = !name.equals(EventSourceInitializer.generateNameFor(original)); + nameSet = !name.equals(EventSourceUtils.generateNameFor(original)); } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java index ec2783f797..05a034a7a7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java @@ -7,10 +7,8 @@ /** * Creates an event source to trigger your reconciler whenever something happens to a secondary or - * external resource that would not normally trigger your reconciler (as the primary resources are - * not changed). To register EventSources with so that your reconciler is triggered, please make - * your reconciler implement - * {@link io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer}. + * external resource that should cause a reconciliation of the primary resource. EventSource + * generalizes the concept of Informers and extends it to external (i.e. non Kubernetes) resources. */ public interface EventSource extends LifecycleAware, EventSourceHealthIndicator { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtilsTest.java similarity index 75% rename from operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializerTest.java rename to operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtilsTest.java index b89ae730ee..b606f1fc1c 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtilsTest.java @@ -8,15 +8,15 @@ import static org.assertj.core.api.Assertions.assertThat; -class EventSourceInitializerTest { +class EventSourceUtilsTest { @Test @SuppressWarnings({"rawtypes", "unchecked"}) void defaultNameDifferentForOtherInstance() { var eventSource1 = new PollingEventSource(HashMap::new, 1000, String.class); var eventSource2 = new PollingEventSource(HashMap::new, 1000, String.class); - var eventSourceName1 = EventSourceInitializer.generateNameFor(eventSource1); - var eventSourceName2 = EventSourceInitializer.generateNameFor(eventSource2); + var eventSourceName1 = EventSourceUtils.generateNameFor(eventSource1); + var eventSourceName2 = EventSourceUtils.generateNameFor(eventSource2); assertThat(eventSourceName1).isNotEqualTo(eventSourceName2); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSourceTest.java index 64f0993139..04e0bc0aff 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSourceTest.java @@ -11,6 +11,8 @@ import io.javaoperatorsdk.operator.TestUtils; import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.ResolvedControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.event.EventHandler; import io.javaoperatorsdk.operator.processing.event.EventSourceManager; @@ -152,18 +154,21 @@ void genericFilterFiltersOutAddUpdateAndDeleteEvents() { @SuppressWarnings("unchecked") private static class TestController extends Controller { + private static final Reconciler reconciler = + (resource, context) -> UpdateControl.noUpdate(); + private final EventSourceManager eventSourceManager = mock(EventSourceManager.class); public TestController(OnAddFilter onAddFilter, OnUpdateFilter onUpdateFilter, GenericFilter genericFilter) { - super(null, new TestConfiguration(true, onAddFilter, onUpdateFilter, genericFilter), + super(reconciler, new TestConfiguration(true, onAddFilter, onUpdateFilter, genericFilter), MockKubernetesClient.client(TestCustomResource.class)); } public TestController(boolean generationAware) { - super(null, new TestConfiguration(generationAware, null, null, null), + super(reconciler, new TestConfiguration(generationAware, null, null, null), MockKubernetesClient.client(TestCustomResource.class)); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java index 6af93232b4..ef07bb5520 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java @@ -9,8 +9,7 @@ @ControllerConfiguration public class StandaloneBulkDependentReconciler - implements Reconciler, TestExecutionInfoProvider, - EventSourceInitializer { + implements Reconciler, TestExecutionInfoProvider { private final AtomicInteger numberOfExecutions = new AtomicInteger(0); @@ -38,7 +37,7 @@ public int getNumberOfExecutions() { @Override public Map prepareEventSources( EventSourceContext context) { - return EventSourceInitializer + return EventSourceUtils .nameEventSources(dependent.initEventSource(context)); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java index 7d51f311e1..36a46c9da3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java @@ -13,8 +13,7 @@ @ControllerConfiguration public class ChangeNamespaceTestReconciler - implements Reconciler, - EventSourceInitializer { + implements Reconciler { private final ConcurrentHashMap numberOfResourceReconciliations = new ConcurrentHashMap<>(); @@ -27,7 +26,7 @@ public Map prepareEventSources( new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) .build(), context); - return EventSourceInitializer.nameEventSources(configMapES); + return EventSourceUtils.nameEventSources(configMapES); } @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java index a6f5e00c96..eedb5ae70b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java @@ -13,8 +13,7 @@ @ControllerConfiguration public class ClusterScopedCustomResourceReconciler - implements Reconciler, - EventSourceInitializer { + implements Reconciler { public static final String DATA_KEY = "data-key"; @@ -59,6 +58,6 @@ public Map prepareEventSources( .withSecondaryToPrimaryMapper(Mappers.fromOwnerReference(true)) .withLabelSelector(TEST_LABEL_KEY + "=" + TEST_LABEL_VALUE) .build(), context); - return EventSourceInitializer.nameEventSources(ies); + return EventSourceUtils.nameEventSources(ies); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java index 42db07333f..e8fa40c63e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java @@ -31,8 +31,7 @@ readyPostcondition = StatefulSetReadyCondition.class), }) @ControllerConfiguration(name = "project-operator") -public class ComplexDependentReconciler implements Reconciler, - EventSourceInitializer { +public class ComplexDependentReconciler implements Reconciler { public static final String SERVICE_EVENT_SOURCE_NAME = "serviceEventSource"; public static final String STATEFUL_SET_EVENT_SOURCE_NAME = "statefulSetEventSource"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index ab0369d998..d59c87236c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -15,8 +15,7 @@ @ControllerConfiguration public class CreateUpdateEventFilterTestReconciler - implements Reconciler, - EventSourceInitializer { + implements Reconciler { private static final class DirectConfigMapDependentResource extends @@ -97,7 +96,7 @@ public Map prepareEventSources( informerEventSource = new InformerEventSource<>(informerConfiguration, context.getClient()); this.configMapDR.setEventSource(informerEventSource); - return EventSourceInitializer.nameEventSources(informerEventSource); + return EventSourceUtils.nameEventSources(informerEventSource); } public int getNumberOfExecutions() { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java index a8e6a48e6b..65916d7a58 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java @@ -7,8 +7,7 @@ @ControllerConfiguration public class DependentReInitializationReconciler - implements Reconciler, - EventSourceInitializer { + implements Reconciler { private final ConfigMapDependentResource configMapDependentResource; @@ -27,7 +26,7 @@ public UpdateControl reconcile( @Override public Map prepareEventSources( EventSourceContext context) { - return EventSourceInitializer.nameEventSourcesFromDependentResource(context, + return EventSourceUtils.nameEventSourcesFromDependentResource(context, configMapDependentResource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java index 9b52dee28d..e40ba9c0c0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java @@ -11,8 +11,7 @@ @ControllerConfiguration public class DependentSSAReconciler - implements Reconciler, TestExecutionInfoProvider, - EventSourceInitializer { + implements Reconciler, TestExecutionInfoProvider { private final AtomicInteger numberOfExecutions = new AtomicInteger(0); @@ -55,7 +54,7 @@ public int getNumberOfExecutions() { @Override public Map prepareEventSources( EventSourceContext context) { - return EventSourceInitializer.nameEventSourcesFromDependentResource(context, + return EventSourceUtils.nameEventSourcesFromDependentResource(context, ssaConfigMapDependent); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java index fd67e7805d..9c2b019adc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java @@ -15,7 +15,6 @@ @ControllerConfiguration public class ExternalStateDependentReconciler implements Reconciler, - EventSourceInitializer, TestExecutionInfoProvider { public static final String ID_KEY = "id"; @@ -39,7 +38,7 @@ public Map prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( InformerConfiguration.from(ConfigMap.class, context).build(), context); - return EventSourceInitializer.nameEventSources(configMapEventSource); + return EventSourceUtils.nameEventSources(configMapEventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java index 66c53c3971..148309cad8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java @@ -23,7 +23,6 @@ @ControllerConfiguration() public class ExternalStateReconciler implements Reconciler, Cleaner, - EventSourceInitializer, TestExecutionInfoProvider { public static final String ID_KEY = "id"; @@ -116,7 +115,7 @@ public Map prepareEventSources( return externalResource.map(Set::of).orElseGet(Collections::emptySet); }, context, Duration.ofMillis(300L), ExternalResource.class); - return EventSourceInitializer.nameEventSources(configMapEventSource, + return EventSourceUtils.nameEventSources(configMapEventSource, externalResourceEventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java index dba6623254..a69feabb71 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java @@ -15,7 +15,6 @@ @ControllerConfiguration public class ExternalStateBulkDependentReconciler implements Reconciler, - EventSourceInitializer, TestExecutionInfoProvider { private final AtomicInteger numberOfExecutions = new AtomicInteger(0); @@ -38,7 +37,7 @@ public Map prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( InformerConfiguration.from(ConfigMap.class, context).build(), context); - return EventSourceInitializer.nameEventSources(configMapEventSource); + return EventSourceUtils.nameEventSources(configMapEventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java index ab5c9b7400..541e220f4a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java @@ -12,8 +12,7 @@ @ControllerConfiguration(onUpdateFilter = UpdateFilter.class) public class FilterTestReconciler - implements Reconciler, - EventSourceInitializer { + implements Reconciler { public static final String CONFIG_MAP_FILTER_VALUE = "config_map_skip_this"; public static final String CUSTOM_RESOURCE_FILTER_VALUE = "custom_resource_skip_this"; @@ -59,6 +58,6 @@ public Map prepareEventSources( .equals(CONFIG_MAP_FILTER_VALUE)) .build(), context); - return EventSourceInitializer.nameEventSources(configMapES); + return EventSourceUtils.nameEventSources(configMapES); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java index 1969ad8f2a..1cb1372abe 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java @@ -7,8 +7,7 @@ @ControllerConfiguration public class GenericKubernetesDependentStandaloneReconciler - implements Reconciler, - EventSourceInitializer { + implements Reconciler { private final ConfigMapGenericKubernetesDependent dependent = new ConfigMapGenericKubernetesDependent(); @@ -28,6 +27,6 @@ public UpdateControl reconci @Override public Map prepareEventSources( EventSourceContext context) { - return EventSourceInitializer.nameEventSources(dependent.eventSource(context).orElseThrow()); + return EventSourceUtils.nameEventSources(dependent.eventSource(context).orElseThrow()); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java index 45be0281f6..2b967fa62c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java @@ -14,8 +14,7 @@ @ControllerConfiguration public class GenericKubernetesResourceHandlingReconciler - implements Reconciler, - EventSourceInitializer { + implements Reconciler { public static final String VERSION = "v1"; @@ -72,6 +71,6 @@ public Map prepareEventSources( new GroupVersionKind("", VERSION, KIND), context).build(), context); - return EventSourceInitializer.nameEventSources(informerEventSource); + return EventSourceUtils.nameEventSources(informerEventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestReconciler.java index 4acda2feee..927f7e8efd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestReconciler.java @@ -16,7 +16,7 @@ public class IndexDiscriminatorTestReconciler implements Reconciler, Cleaner, - TestExecutionInfoProvider, EventSourceInitializer { + TestExecutionInfoProvider { public static final String FIRST_CONFIG_MAP_SUFFIX_1 = "-1"; public static final String FIRST_CONFIG_MAP_SUFFIX_2 = "-2"; @@ -81,7 +81,7 @@ public Map prepareEventSources( secondDependentResourceConfigMap .setResourceDiscriminator( new TestIndexDiscriminator(CONFIG_MAP_INDEX_2, FIRST_CONFIG_MAP_SUFFIX_2)); - return EventSourceInitializer.nameEventSources(eventSource); + return EventSourceUtils.nameEventSources(eventSource); } public static String configMapKey(ConfigMap configMap) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java index bf92550542..d9a44cb027 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java @@ -9,12 +9,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; @@ -25,8 +20,7 @@ */ @ControllerConfiguration public class InformerEventSourceTestCustomReconciler - implements Reconciler, - EventSourceInitializer { + implements Reconciler { private static final Logger LOGGER = LoggerFactory.getLogger(InformerEventSourceTestCustomReconciler.class); @@ -46,7 +40,7 @@ public Map prepareEventSources( .withSecondaryToPrimaryMapper(Mappers.fromAnnotation(RELATED_RESOURCE_NAME)) .build(); - return EventSourceInitializer + return EventSourceUtils .nameEventSources(new InformerEventSource<>(config, context)); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java index fcb2192539..7a033800af 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java @@ -16,7 +16,6 @@ @ControllerConfiguration public class DependentGarbageCollectionTestReconciler implements Reconciler, - EventSourceInitializer, ErrorStatusHandler { private KubernetesClient kubernetesClient; @@ -31,7 +30,7 @@ public DependentGarbageCollectionTestReconciler() { @Override public Map prepareEventSources( EventSourceContext context) { - return EventSourceInitializer.nameEventSourcesFromDependentResource(context, + return EventSourceUtils.nameEventSourcesFromDependentResource(context, configMapDependent); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java index 2dc7f6490f..e75764bc77 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java @@ -14,7 +14,7 @@ @ControllerConfiguration public class MultipleDependentResourceReconciler implements Reconciler, - TestExecutionInfoProvider, EventSourceInitializer { + TestExecutionInfoProvider { public static final int FIRST_CONFIG_MAP_ID = 1; public static final int SECOND_CONFIG_MAP_ID = 2; @@ -64,6 +64,6 @@ public Map prepareEventSources( firstDependentResourceConfigMap.configureWith(eventSource); secondDependentResourceConfigMap.configureWith(eventSource); - return EventSourceInitializer.nameEventSources(eventSource); + return EventSourceUtils.nameEventSources(eventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java index 7cf66614af..8651f13fac 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java @@ -22,8 +22,7 @@ @ControllerConfiguration public class MultipleManagedDependentResourceReconciler implements Reconciler, - TestExecutionInfoProvider, - EventSourceInitializer { + TestExecutionInfoProvider { public static final String CONFIG_MAP_EVENT_SOURCE = "ConfigMapEventSource"; public static final String DATA_KEY = "key"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java index 0773ff063a..1e7577302b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java @@ -26,8 +26,7 @@ @ControllerConfiguration() public class MultipleManagedExternalDependentResourceReconciler implements Reconciler, - TestExecutionInfoProvider, - EventSourceInitializer { + TestExecutionInfoProvider { public static final String CONFIG_MAP_EVENT_SOURCE = "ConfigMapEventSource"; protected ExternalServiceMock externalServiceMock = ExternalServiceMock.getInstance(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java index 8f4ed834aa..1c8e1a1c60 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java @@ -16,8 +16,7 @@ @ControllerConfiguration public class MultipleSecondaryEventSourceReconciler - implements Reconciler, TestExecutionInfoProvider, - EventSourceInitializer { + implements Reconciler, TestExecutionInfoProvider { private final AtomicInteger numberOfExecutions = new AtomicInteger(0); @@ -76,7 +75,7 @@ public Map prepareEventSources( }).build(); InformerEventSource configMapEventSource = new InformerEventSource<>(config, context); - return EventSourceInitializer.nameEventSources(configMapEventSource); + return EventSourceUtils.nameEventSources(configMapEventSource); } ConfigMap configMap(String name, MultipleSecondaryEventSourceCustomResource resource) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java index 81d8773986..6915d89e40 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java @@ -12,8 +12,7 @@ @ControllerConfiguration public class PerResourcePollingEventSourceTestReconciler - implements Reconciler, - EventSourceInitializer { + implements Reconciler { public static final int POLL_PERIOD = 100; private final Map numberOfExecutions = new ConcurrentHashMap<>(); @@ -38,7 +37,7 @@ public Map prepareEventSources( return Set.of(UUID.randomUUID().toString()); }, context, Duration.ofMillis(POLL_PERIOD), String.class); - return EventSourceInitializer.nameEventSources(eventSource); + return EventSourceUtils.nameEventSources(eventSource); } public int getNumberOfExecutions(String name) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java index 6890a3c8c4..bc05a171cf 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java @@ -7,15 +7,14 @@ import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; @ControllerConfiguration public class PrimaryIndexerTestReconciler - extends AbstractPrimaryIndexerTestReconciler implements - EventSourceInitializer { + extends AbstractPrimaryIndexerTestReconciler { @Override public Map prepareEventSources( @@ -36,7 +35,7 @@ public Map prepareEventSources( .collect(Collectors.toSet())) .build(); - return EventSourceInitializer + return EventSourceUtils .nameEventSources(new InformerEventSource<>(informerConfiguration, context)); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java index ace158360a..f2f975f248 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java @@ -20,7 +20,7 @@ */ @ControllerConfiguration() public class JobReconciler - implements Reconciler, EventSourceInitializer, ErrorStatusHandler { + implements Reconciler, ErrorStatusHandler { private static final String JOB_CLUSTER_INDEX = "job-cluster-index"; @@ -79,7 +79,7 @@ public Map prepareEventSources(EventSourceContext cont primary.getSpec().getClusterName(), primary.getMetadata().getNamespace()))); } - return EventSourceInitializer + return EventSourceUtils .nameEventSources(new InformerEventSource<>(informerConfiguration.build(), context)); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java index fc156bed4f..3283c76a93 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java @@ -31,8 +31,7 @@ @Dependent(type = SecretDependent.class, dependsOn = CONFIG_MAP)}) @ControllerConfiguration() public class PrimaryToSecondaryDependentReconciler - implements Reconciler, TestExecutionInfoProvider, - EventSourceInitializer { + implements Reconciler, TestExecutionInfoProvider { public static final String DATA_KEY = "data"; public static final String CONFIG_MAP = "ConfigMap"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java index 3798fdbcbb..5d852d86b3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java @@ -7,14 +7,20 @@ import io.fabric8.kubernetes.client.KubernetesClientException; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.StandaloneDependentResourceIT; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler; +import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @ControllerConfiguration public class StandaloneDependentTestReconciler implements Reconciler, - EventSourceInitializer, ErrorStatusHandler { private volatile boolean errorOccurred = false; @@ -27,7 +33,7 @@ public StandaloneDependentTestReconciler() { @Override public Map prepareEventSources( EventSourceContext context) { - return EventSourceInitializer.nameEventSourcesFromDependentResource(context, + return EventSourceUtils.nameEventSourcesFromDependentResource(context, deploymentDependent); } diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java index 5b87d23aac..0329350fdb 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java @@ -20,14 +20,7 @@ import io.fabric8.kubernetes.client.dsl.ExecListener; import io.fabric8.kubernetes.client.dsl.ExecWatch; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Cleaner; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; @@ -35,7 +28,7 @@ @ControllerConfiguration public class WebappReconciler - implements Reconciler, Cleaner, EventSourceInitializer { + implements Reconciler, Cleaner { private static final Logger log = LoggerFactory.getLogger(WebappReconciler.class); @@ -66,7 +59,7 @@ public Map prepareEventSources(EventSourceContext c (Webapp primary) -> Set.of(new ResourceID(primary.getSpec().getTomcat(), primary.getMetadata().getNamespace()))) .build(); - return EventSourceInitializer + return EventSourceUtils .nameEventSources(new InformerEventSource<>(configuration, context)); } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index 8494af5402..3d3b583659 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -26,7 +26,7 @@ labelSelector = WebPageDependentsWorkflowReconciler.DEPENDENT_RESOURCE_LABEL_SELECTOR) @SuppressWarnings("unused") public class WebPageDependentsWorkflowReconciler - implements Reconciler, ErrorStatusHandler, EventSourceInitializer { + implements Reconciler, ErrorStatusHandler { public static final String DEPENDENT_RESOURCE_LABEL_SELECTOR = "!low-level"; @@ -49,7 +49,7 @@ public WebPageDependentsWorkflowReconciler(KubernetesClient kubernetesClient) { @Override public Map prepareEventSources(EventSourceContext context) { - return EventSourceInitializer.nameEventSourcesFromDependentResource(context, configMapDR, + return EventSourceUtils.nameEventSourcesFromDependentResource(context, configMapDR, deploymentDR, serviceDR, ingressDR); } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index 4be2da11c7..df6ba7ddb8 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -8,46 +8,28 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.ConfigMapBuilder; -import io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder; -import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.*; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.Replaceable; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler; -import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.rate.RateLimited; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.sample.customresource.WebPage; -import static io.javaoperatorsdk.operator.sample.Utils.configMapName; -import static io.javaoperatorsdk.operator.sample.Utils.createStatus; -import static io.javaoperatorsdk.operator.sample.Utils.deploymentName; -import static io.javaoperatorsdk.operator.sample.Utils.handleError; -import static io.javaoperatorsdk.operator.sample.Utils.isValidHtml; -import static io.javaoperatorsdk.operator.sample.Utils.makeDesiredIngress; -import static io.javaoperatorsdk.operator.sample.Utils.serviceName; -import static io.javaoperatorsdk.operator.sample.Utils.setInvalidHtmlErrorMessage; -import static io.javaoperatorsdk.operator.sample.Utils.simulateErrorIfRequested; +import static io.javaoperatorsdk.operator.sample.Utils.*; import static io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler.SELECTOR; /** Shows how to implement reconciler using the low level api directly. */ @RateLimited(maxReconciliations = 2, within = 3) @ControllerConfiguration public class WebPageReconciler - implements Reconciler, ErrorStatusHandler, EventSourceInitializer { + implements Reconciler, ErrorStatusHandler { public static final String INDEX_HTML = "index.html"; @@ -77,7 +59,7 @@ public Map prepareEventSources(EventSourceContext new InformerEventSource<>(InformerConfiguration.from(Ingress.class, context) .withLabelSelector(SELECTOR) .build(), context); - return EventSourceInitializer.nameEventSources(configMapEventSource, deploymentEventSource, + return EventSourceUtils.nameEventSources(configMapEventSource, deploymentEventSource, serviceEventSource, ingressEventSource); } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java index 1799d72cea..4e4fa22b6b 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java @@ -3,53 +3,70 @@ import java.util.Arrays; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler; +import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow; import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowBuilder; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.sample.customresource.WebPage; -import io.javaoperatorsdk.operator.sample.dependentresource.*; +import io.javaoperatorsdk.operator.sample.dependentresource.ConfigMapDependentResource; +import io.javaoperatorsdk.operator.sample.dependentresource.DeploymentDependentResource; +import io.javaoperatorsdk.operator.sample.dependentresource.ExposedIngressCondition; +import io.javaoperatorsdk.operator.sample.dependentresource.IngressDependentResource; +import io.javaoperatorsdk.operator.sample.dependentresource.ServiceDependentResource; import static io.javaoperatorsdk.operator.sample.Utils.*; import static io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler.SELECTOR; /** - * Shows how to implement reconciler using standalone dependent resources. + * Shows how to implement reconciler using standalone dependent resources and workflows. */ @ControllerConfiguration public class WebPageStandaloneDependentsReconciler - implements Reconciler, ErrorStatusHandler, EventSourceInitializer { - - private static final Logger log = - LoggerFactory.getLogger(WebPageStandaloneDependentsReconciler.class); + implements Reconciler, ErrorStatusHandler { - private Workflow workflow; + private final Workflow workflow; public WebPageStandaloneDependentsReconciler() { + // initialize the workflow workflow = createDependentResourcesAndWorkflow(); } @Override public Map prepareEventSources(EventSourceContext context) { - return EventSourceInitializer.eventSourcesFromWorkflow(context, workflow); + // initializes the dependents' event sources from the given context + return EventSourceUtils.eventSourcesFromWorkflow(context, workflow); } @Override public UpdateControl reconcile(WebPage webPage, Context context) throws Exception { + // for testing purposes simulateErrorIfRequested(webPage); + // validate the html page and update the status with an error message if it isn't valid if (!isValidHtml(webPage)) { return UpdateControl.patchStatus(setInvalidHtmlErrorMessage(webPage)); } + // Explicitly reconcile the dependent resources. + // Calling the workflow reconciliation explicitly allows control over the workflow customization + // but also *when* dependents are reconciled (as opposed to before the main reconciler's + // reconcile method in the managed case). + // With the default configuration, this will throw an exception if one of the dependents + // couldn't be properly reconciled workflow.reconcile(webPage, context); + // retrieve the name of the ConfigMap secondary resource to update the status if everything went + // well webPage.setStatus( createStatus( context.getSecondaryResource(ConfigMap.class).orElseThrow().getMetadata().getName())); @@ -62,25 +79,37 @@ public ErrorStatusUpdateControl updateErrorStatus( return handleError(resource, e); } + /** + * Initializes the dependent resources and connect them in the context of a {@link Workflow} + * + * @return the {@link Workflow} that will reconcile automatically secondary resources + */ @SuppressWarnings({"unchecked", "rawtypes"}) private Workflow createDependentResourcesAndWorkflow() { + // create the dependent resources var configMapDR = new ConfigMapDependentResource(); var deploymentDR = new DeploymentDependentResource(); var serviceDR = new ServiceDependentResource(); var ingressDR = new IngressDependentResource(); + // configure them with our label selector Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR) .forEach(dr -> dr.configureWith(new KubernetesDependentResourceConfigBuilder() .withLabelSelector(SELECTOR + "=true").build())); + // connect the dependent resources into a workflow, configuring them as we go + // Note the method call order is significant and configuration applies to the dependent being + // configured as defined by the method call order (in this example, the reconcile pre-condition + // that is added applies to the Ingress dependent) return new WorkflowBuilder() .addDependentResource(configMapDR) .addDependentResource(deploymentDR) .addDependentResource(serviceDR) .addDependentResource(ingressDR) + // prevent the Ingress from being created based on the linked condition (here: only if the + // `exposed` flag is set in the primary resource), delete the Ingress if it already exists + // and the condition becomes false .withReconcilePrecondition(new ExposedIngressCondition()) .build(); } - - } From 18cf3a5a2e80185095ed4d3120dde4e2b1fcb148 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Wed, 13 Mar 2024 16:24:00 +0100 Subject: [PATCH 18/96] refactor: make loadFromProperties private (#2287) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chris Laprun Signed-off-by: Attila Mészáros --- .../io/javaoperatorsdk/operator/api/config/Utils.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java index 6971de6476..d318560480 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java @@ -33,11 +33,8 @@ public class Utils { * via the {@code git-commit-id-plugin} maven plugin. * * @return a {@link Version} object encapsulating the version information - * @deprecated use {@link #VERSION} instead, as this method will be made internal in a future - * release */ - @Deprecated - public static Version loadFromProperties() { + private static Version loadFromProperties() { final var is = Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties"); @@ -79,9 +76,8 @@ public static int ensureValid(int value, String description, int minValue, int d throw new IllegalArgumentException( "Default value for " + description + " must be greater than " + minValue); } - log.warn("Requested " + description + " should be greater than " + minValue + ". Requested: " - + value + ", using " + defaultValue + (defaultValue == minValue ? "" : " (default)") + - " instead"); + log.warn("Requested {} should be greater than {}. Requested: {}, using {}{} instead", + description, minValue, value, defaultValue, defaultValue == minValue ? "" : " (default)"); value = defaultValue; } return value; From 4fb55528a8206e06101ff66ccf98d55c2f266b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 13 Mar 2024 17:11:44 +0100 Subject: [PATCH 19/96] feat: distinguish resources based on desired state (#2252) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Attila Mészáros --- .../dependent/DependentResource.java | 10 +++ .../dependent/AbstractDependentResource.java | 39 +++++++- .../KubernetesDependentResource.java | 24 +++++ .../operator/ExternalStateBulkIT.java | 2 +- .../operator/MultipleDependentResourceIT.java | 90 +++++++++++-------- ...ependentResourceWithNoDiscriminatorIT.java | 65 ++++++++++++++ ...ipleManagedDependentNoDiscriminatorIT.java | 81 +++++++++++++++++ .../operator/PrimaryIndexerIT.java | 3 +- .../PrimaryToSecondaryDependentIT.java | 3 +- .../ExternalStateReconciler.java | 2 +- .../ExternalWithStateDependentResource.java | 20 +++-- .../MultipleDependentResourceConfigMap.java | 15 ++-- ...ltipleDependentResourceCustomResource.java | 8 +- .../MultipleDependentResourceReconciler.java | 29 +----- .../MultipleDependentResourceSpec.java | 14 +++ .../MultipleDependentResourceConfigMap.java | 37 ++++++++ ...sourceCustomResourceWithDiscriminator.java | 19 ++++ ...ntResourceWithDiscriminatorReconciler.java | 68 ++++++++++++++ ...endentResourceWithDiscriminatorStatus.java | 5 ++ ...gedDependentNoDiscriminatorConfigMap1.java | 38 ++++++++ ...gedDependentNoDiscriminatorConfigMap2.java | 39 ++++++++ ...ependentNoDiscriminatorCustomResource.java | 16 ++++ ...leManagedDependentNoDiscriminatorSpec.java | 15 ++++ ...dentSameTypeNoDiscriminatorReconciler.java | 57 ++++++++++++ .../AbstractPrimaryIndexerTestReconciler.java | 2 + ...DependentPrimaryIndexerTestReconciler.java | 14 +++ .../ConfigMapDependent.java | 16 ++++ .../UnmodifiablePartConfigMapDependent.java | 2 +- 28 files changed, 643 insertions(+), 90 deletions(-) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceWithNoDiscriminatorIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentNoDiscriminatorIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceSpec.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceConfigMap.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceCustomResourceWithDiscriminator.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorStatus.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java index 98d700324d..eec011e5e8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java @@ -49,6 +49,16 @@ default Optional> eventSource( return Optional.empty(); } + /** + * Retrieves the secondary resource (if it exists) associated with the specified primary resource + * for this DependentResource. + * + * @param primary the primary resource for which we want to retrieve the secondary resource + * associated with this DependentResource + * @param context the current {@link Context} in which the operation is called + * @return the secondary resource or {@link Optional#empty()} if it doesn't exist + * @throws IllegalStateException if more than one secondary is found to match the primary resource + */ default Optional getSecondaryResource(P primary, Context

context) { return Optional.empty(); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java index afd9e91d51..f7960c4709 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java @@ -1,6 +1,7 @@ package io.javaoperatorsdk.operator.processing.dependent; import java.util.Optional; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,8 +105,39 @@ protected ReconcileResult reconcile(P primary, R actualResource, Context

c @Override public Optional getSecondaryResource(P primary, Context

context) { - return resourceDiscriminator == null ? context.getSecondaryResource(resourceType()) - : resourceDiscriminator.distinguish(resourceType(), primary, context); + if (resourceDiscriminator != null) { + return resourceDiscriminator.distinguish(resourceType(), primary, context); + } else { + var secondaryResources = context.getSecondaryResources(resourceType()); + if (secondaryResources.isEmpty()) { + return Optional.empty(); + } else { + return selectManagedSecondaryResource(secondaryResources, primary, context); + } + } + } + + /** + * Selects the actual secondary resource matching the desired state derived from the primary + * resource when several resources of the same type are found in the context. This method allows + * for optimized implementations in subclasses since this default implementation will check each + * secondary candidates for equality with the specified desired state, which might end up costly. + * + * @param secondaryResources to select the target resource from + * + * @return the matching secondary resource or {@link Optional#empty()} if none matches + * @throws IllegalStateException if more than one candidate is found, in which case some other + * mechanism might be necessary to distinguish between candidate secondary resources + */ + protected Optional selectManagedSecondaryResource(Set secondaryResources, P primary, + Context

context) { + R desired = desired(primary, context); + var targetResources = secondaryResources.stream().filter(r -> r.equals(desired)).toList(); + if (targetResources.size() > 1) { + throw new IllegalStateException( + "More than one secondary resource related to primary: " + targetResources); + } + return targetResources.isEmpty() ? Optional.empty() : Optional.of(targetResources.get(0)); } private void throwIfNull(R desired, P primary, String descriptor) { @@ -173,8 +205,7 @@ protected void handleDelete(P primary, R secondary, Context

context) { "handleDelete method must be implemented if Deleter trait is supported"); } - public void setResourceDiscriminator( - ResourceDiscriminator resourceDiscriminator) { + public void setResourceDiscriminator(ResourceDiscriminator resourceDiscriminator) { this.resourceDiscriminator = resourceDiscriminator; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 347533c8dd..3e0e5f2115 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -1,6 +1,7 @@ package io.javaoperatorsdk.operator.processing.dependent.kubernetes; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -285,6 +286,29 @@ protected void addSecondaryToPrimaryMapperAnnotations(R desired, P primary, Stri } } + @Override + protected Optional selectManagedSecondaryResource(Set secondaryResources, P primary, + Context

context) { + ResourceID managedResourceID = managedSecondaryResourceID(primary, context); + return secondaryResources.stream() + .filter(r -> r.getMetadata().getName().equals(managedResourceID.getName()) && + Objects.equals(r.getMetadata().getNamespace(), + managedResourceID.getNamespace().orElse(null))) + .findFirst(); + } + + /** + * Override this method in order to optimize and not compute the desired when selecting the target + * secondary resource. Simply, a static ResourceID can be returned. + * + * @param primary resource + * @param context of current reconciliation + * @return id of the target managed resource + */ + protected ResourceID managedSecondaryResourceID(P primary, Context

context) { + return ResourceID.fromResource(desired(primary, context)); + } + protected boolean addOwnerReference() { return garbageCollected; } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java index 7452958b8c..a0cc9c5e8e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java @@ -34,7 +34,7 @@ class ExternalStateBulkIT { .build(); @Test - void reconcilesResourceWithPersistentState() throws InterruptedException { + void reconcilesResourceWithPersistentState() { var resource = operator.create(testResource()); assertResources(resource, INITIAL_TEST_DATA, INITIAL_BULK_SIZE); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java index d3e7f77fd5..224e9c487a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java @@ -1,7 +1,6 @@ package io.javaoperatorsdk.operator; import java.time.Duration; -import java.util.stream.IntStream; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -9,54 +8,73 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceConfigMap; import io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceCustomResource; import io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceReconciler; +import io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceSpec; +import io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator.*; +import static io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceConfigMap.DATA_KEY; +import static io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceConfigMap.getConfigMapName; +import static io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceReconciler.FIRST_CONFIG_MAP_ID; +import static io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceReconciler.SECOND_CONFIG_MAP_ID; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -class MultipleDependentResourceIT { +public class MultipleDependentResourceIT { + + public static final String CHANGED_VALUE = "changed value"; + public static final String INITIAL_VALUE = "initial value"; - public static final String TEST_RESOURCE_NAME = "multipledependentresource-testresource"; @RegisterExtension - LocallyRunOperatorExtension operator = + LocallyRunOperatorExtension extension = LocallyRunOperatorExtension.builder() - .withReconciler(MultipleDependentResourceReconciler.class) - .waitForNamespaceDeletion(true) + .withReconciler(new MultipleDependentResourceReconciler()) .build(); @Test - void twoConfigMapsHaveBeenCreated() { - MultipleDependentResourceCustomResource customResource = createTestCustomResource(); - operator.create(customResource); - - var reconciler = operator.getReconcilerOfType(MultipleDependentResourceReconciler.class); - - await().pollDelay(Duration.ofMillis(300)) - .until(() -> reconciler.getNumberOfExecutions() <= 1); - - IntStream.of(MultipleDependentResourceReconciler.FIRST_CONFIG_MAP_ID, - MultipleDependentResourceReconciler.SECOND_CONFIG_MAP_ID).forEach(configMapId -> { - ConfigMap configMap = - operator.get(ConfigMap.class, customResource.getConfigMapName(configMapId)); - assertThat(configMap).isNotNull(); - assertThat(configMap.getMetadata().getName()) - .isEqualTo(customResource.getConfigMapName(configMapId)); - assertThat(configMap.getData().get(MultipleDependentResourceConfigMap.DATA_KEY)) - .isEqualTo(String.valueOf(configMapId)); - }); - } + void handlesCRUDOperations() { + var res = extension.create(testResource()); + + await().untilAsserted(() -> { + var cm1 = extension.get(ConfigMap.class, getConfigMapName(FIRST_CONFIG_MAP_ID)); + var cm2 = extension.get(ConfigMap.class, getConfigMapName(SECOND_CONFIG_MAP_ID)); + + assertThat(cm1).isNotNull(); + assertThat(cm2).isNotNull(); + assertThat(cm1.getData()).containsEntry(DATA_KEY, INITIAL_VALUE); + assertThat(cm2.getData()).containsEntry(DATA_KEY, INITIAL_VALUE); + }); + + res.getSpec().setValue(CHANGED_VALUE); + res = extension.replace(res); + + await().untilAsserted(() -> { + var cm1 = extension.get(ConfigMap.class, getConfigMapName(FIRST_CONFIG_MAP_ID)); + var cm2 = extension.get(ConfigMap.class, getConfigMapName(SECOND_CONFIG_MAP_ID)); - public MultipleDependentResourceCustomResource createTestCustomResource() { - MultipleDependentResourceCustomResource resource = - new MultipleDependentResourceCustomResource(); - resource.setMetadata( - new ObjectMetaBuilder() - .withName(TEST_RESOURCE_NAME) - .withNamespace(operator.getNamespace()) - .build()); - return resource; + assertThat(cm1.getData()).containsEntry(DATA_KEY, CHANGED_VALUE); + assertThat(cm2.getData()).containsEntry(DATA_KEY, CHANGED_VALUE); + }); + + extension.delete(res); + + await().timeout(Duration.ofSeconds(120)).untilAsserted(() -> { + var cm1 = extension.get(ConfigMap.class, getConfigMapName(FIRST_CONFIG_MAP_ID)); + var cm2 = extension.get(ConfigMap.class, getConfigMapName(SECOND_CONFIG_MAP_ID)); + + assertThat(cm1).isNull(); + assertThat(cm2).isNull(); + }); } + MultipleDependentResourceCustomResource testResource() { + var res = new MultipleDependentResourceCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName("test1") + .build()); + res.setSpec(new MultipleDependentResourceSpec()); + res.getSpec().setValue(INITIAL_VALUE); + + return res; + } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceWithNoDiscriminatorIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceWithNoDiscriminatorIT.java new file mode 100644 index 0000000000..908cb58f79 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceWithNoDiscriminatorIT.java @@ -0,0 +1,65 @@ +package io.javaoperatorsdk.operator; + +import java.time.Duration; +import java.util.stream.IntStream; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator.MultipleDependentResourceConfigMap; +import io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator.MultipleDependentResourceCustomResourceWithDiscriminator; +import io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator.MultipleDependentResourceWithDiscriminatorReconciler; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +class MultipleDependentResourceWithNoDiscriminatorIT { + + public static final String TEST_RESOURCE_NAME = "multipledependentresource-testresource"; + @RegisterExtension + LocallyRunOperatorExtension operator = + LocallyRunOperatorExtension.builder() + .withReconciler(MultipleDependentResourceWithDiscriminatorReconciler.class) + .waitForNamespaceDeletion(true) + .build(); + + @Test + void twoConfigMapsHaveBeenCreated() { + MultipleDependentResourceCustomResourceWithDiscriminator customResource = + createTestCustomResource(); + operator.create(customResource); + + var reconciler = + operator.getReconcilerOfType(MultipleDependentResourceWithDiscriminatorReconciler.class); + + await().pollDelay(Duration.ofMillis(300)) + .until(() -> reconciler.getNumberOfExecutions() <= 1); + + IntStream.of(MultipleDependentResourceWithDiscriminatorReconciler.FIRST_CONFIG_MAP_ID, + MultipleDependentResourceWithDiscriminatorReconciler.SECOND_CONFIG_MAP_ID) + .forEach(configMapId -> { + ConfigMap configMap = + operator.get(ConfigMap.class, customResource.getConfigMapName(configMapId)); + assertThat(configMap).isNotNull(); + assertThat(configMap.getMetadata().getName()) + .isEqualTo(customResource.getConfigMapName(configMapId)); + assertThat(configMap.getData().get(MultipleDependentResourceConfigMap.DATA_KEY)) + .isEqualTo(String.valueOf(configMapId)); + }); + } + + public MultipleDependentResourceCustomResourceWithDiscriminator createTestCustomResource() { + MultipleDependentResourceCustomResourceWithDiscriminator resource = + new MultipleDependentResourceCustomResourceWithDiscriminator(); + resource.setMetadata( + new ObjectMetaBuilder() + .withName(TEST_RESOURCE_NAME) + .withNamespace(operator.getNamespace()) + .build()); + return resource; + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentNoDiscriminatorIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentNoDiscriminatorIT.java new file mode 100644 index 0000000000..361aa099af --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentNoDiscriminatorIT.java @@ -0,0 +1,81 @@ +package io.javaoperatorsdk.operator; + +import java.time.Duration; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator.*; + +import static io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator.MultipleManagedDependentSameTypeNoDiscriminatorReconciler.DATA_KEY; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class MultipleManagedDependentNoDiscriminatorIT { + + public static final String RESOURCE_NAME = "test1"; + public static final String INITIAL_VALUE = "initial_value"; + public static final String CHANGED_VALUE = "changed_value"; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(new MultipleManagedDependentSameTypeNoDiscriminatorReconciler()) + .build(); + + @Test + void handlesCRUDOperations() { + var res = extension.create(testResource()); + + await().untilAsserted(() -> { + var cm1 = extension.get(ConfigMap.class, + RESOURCE_NAME + MultipleManagedDependentNoDiscriminatorConfigMap1.NAME_SUFFIX); + var cm2 = extension.get(ConfigMap.class, + RESOURCE_NAME + MultipleManagedDependentNoDiscriminatorConfigMap2.NAME_SUFFIX); + + assertThat(cm1).isNotNull(); + assertThat(cm2).isNotNull(); + assertThat(cm1.getData()).containsEntry(DATA_KEY, INITIAL_VALUE); + assertThat(cm2.getData()).containsEntry(DATA_KEY, INITIAL_VALUE); + }); + + res.getSpec().setValue(CHANGED_VALUE); + res = extension.replace(res); + + await().untilAsserted(() -> { + var cm1 = extension.get(ConfigMap.class, + RESOURCE_NAME + MultipleManagedDependentNoDiscriminatorConfigMap1.NAME_SUFFIX); + var cm2 = extension.get(ConfigMap.class, + RESOURCE_NAME + MultipleManagedDependentNoDiscriminatorConfigMap2.NAME_SUFFIX); + + assertThat(cm1.getData()).containsEntry(DATA_KEY, CHANGED_VALUE); + assertThat(cm2.getData()).containsEntry(DATA_KEY, CHANGED_VALUE); + }); + + extension.delete(res); + + await().timeout(Duration.ofSeconds(60)).untilAsserted(() -> { + var cm1 = extension.get(ConfigMap.class, + RESOURCE_NAME + MultipleManagedDependentNoDiscriminatorConfigMap1.NAME_SUFFIX); + var cm2 = extension.get(ConfigMap.class, + RESOURCE_NAME + MultipleManagedDependentNoDiscriminatorConfigMap2.NAME_SUFFIX); + + assertThat(cm1).isNull(); + assertThat(cm2).isNull(); + }); + } + + MultipleManagedDependentNoDiscriminatorCustomResource testResource() { + var res = new MultipleManagedDependentNoDiscriminatorCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(RESOURCE_NAME) + .build()); + res.setSpec(new MultipleManagedDependentNoDiscriminatorSpec()); + res.getSpec().setValue(INITIAL_VALUE); + return res; + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryIndexerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryIndexerIT.java index 16f223ce38..fb202de390 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryIndexerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryIndexerIT.java @@ -13,12 +13,13 @@ import io.javaoperatorsdk.operator.sample.primaryindexer.PrimaryIndexerTestCustomResourceSpec; import io.javaoperatorsdk.operator.sample.primaryindexer.PrimaryIndexerTestReconciler; +import static io.javaoperatorsdk.operator.sample.primaryindexer.AbstractPrimaryIndexerTestReconciler.CONFIG_MAP_NAME; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; class PrimaryIndexerIT { - public static final String CONFIG_MAP_NAME = "common-config-map"; + public static final String RESOURCE_NAME1 = "test1"; public static final String RESOURCE_NAME2 = "test2"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java index eaa7e4410f..0e48b726e9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java @@ -14,6 +14,7 @@ import io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler; import io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentSpec; +import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.ConfigMapDependent.TEST_CONFIG_MAP_NAME; import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.ConfigMapReconcilePrecondition.DO_NOT_RECONCILE; import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.DATA_KEY; import static org.assertj.core.api.Assertions.assertThat; @@ -21,7 +22,7 @@ class PrimaryToSecondaryDependentIT { - public static final String TEST_CONFIG_MAP_NAME = "testconfigmap"; + public static final String TEST_CR_NAME = "test1"; public static final String TEST_DATA = "testData"; public diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java index 148309cad8..a9c3bb5a28 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java @@ -20,7 +20,7 @@ import io.javaoperatorsdk.operator.support.ExternalResource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration() +@ControllerConfiguration public class ExternalStateReconciler implements Reconciler, Cleaner, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java index c25113b406..0965c49636 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java @@ -34,16 +34,26 @@ public ExternalWithStateDependentResource() { @SuppressWarnings("unchecked") public Set fetchResources( ExternalStateCustomResource primaryResource) { - Optional configMapOptional = - getExternalStateEventSource().getSecondaryResource(primaryResource); - - return configMapOptional.map(configMap -> { - var id = configMap.getData().get(ID_KEY); + return getResourceID(primaryResource).map(id -> { var externalResource = externalService.read(id); return externalResource.map(Set::of).orElseGet(Collections::emptySet); }).orElseGet(Collections::emptySet); } + @Override + protected Optional selectManagedSecondaryResource( + Set secondaryResources, + ExternalStateCustomResource primary, Context context) { + var id = getResourceID(primary); + return id.flatMap(k -> secondaryResources.stream().filter(e -> e.getId().equals(k)).findAny()); + } + + private Optional getResourceID(ExternalStateCustomResource primaryResource) { + Optional configMapOptional = + getExternalStateEventSource().getSecondaryResource(primaryResource); + return configMapOptional.map(cm -> cm.getData().get(ID_KEY)); + } + @Override protected ExternalResource desired(ExternalStateCustomResource primary, Context context) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceConfigMap.java index 5c2e9974b5..39ed7f9f0b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceConfigMap.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceConfigMap.java @@ -1,6 +1,5 @@ package io.javaoperatorsdk.operator.sample.multipledependentresource; -import java.util.HashMap; import java.util.Map; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -12,9 +11,9 @@ public class MultipleDependentResourceConfigMap extends CRUDKubernetesDependentResource { public static final String DATA_KEY = "key"; - private final int value; + private final String value; - public MultipleDependentResourceConfigMap(int value) { + public MultipleDependentResourceConfigMap(String value) { super(ConfigMap.class); this.value = value; } @@ -22,15 +21,17 @@ public MultipleDependentResourceConfigMap(int value) { @Override protected ConfigMap desired(MultipleDependentResourceCustomResource primary, Context context) { - Map data = new HashMap<>(); - data.put(DATA_KEY, String.valueOf(value)); return new ConfigMapBuilder() .withNewMetadata() - .withName(primary.getConfigMapName(value)) + .withName(getConfigMapName(value)) .withNamespace(primary.getMetadata().getNamespace()) .endMetadata() - .withData(data) + .withData(Map.of(DATA_KEY, primary.getSpec().getValue())) .build(); } + + public static String getConfigMapName(String id) { + return "configmap" + id; + } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceCustomResource.java index 55f0d60f2d..60ba494e8a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceCustomResource.java @@ -3,19 +3,13 @@ import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; -import io.fabric8.kubernetes.model.annotation.Kind; import io.fabric8.kubernetes.model.annotation.ShortNames; import io.fabric8.kubernetes.model.annotation.Version; @Group("sample.javaoperatorsdk") @Version("v1") -@Kind("MultipleDependentResourceCustomResource") @ShortNames("mdr") public class MultipleDependentResourceCustomResource - extends CustomResource + extends CustomResource implements Namespaced { - - public String getConfigMapName(int id) { - return "configmap" + id; - } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java index e75764bc77..4befd18d87 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java @@ -1,60 +1,37 @@ package io.javaoperatorsdk.operator.sample.multipledependentresource; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; -import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; -import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @ControllerConfiguration public class MultipleDependentResourceReconciler - implements Reconciler, - TestExecutionInfoProvider { + implements Reconciler { - public static final int FIRST_CONFIG_MAP_ID = 1; - public static final int SECOND_CONFIG_MAP_ID = 2; - private final AtomicInteger numberOfExecutions = new AtomicInteger(0); + public static final String FIRST_CONFIG_MAP_ID = "1"; + public static final String SECOND_CONFIG_MAP_ID = "2"; private final MultipleDependentResourceConfigMap firstDependentResourceConfigMap; private final MultipleDependentResourceConfigMap secondDependentResourceConfigMap; public MultipleDependentResourceReconciler() { firstDependentResourceConfigMap = new MultipleDependentResourceConfigMap(FIRST_CONFIG_MAP_ID); - secondDependentResourceConfigMap = new MultipleDependentResourceConfigMap(SECOND_CONFIG_MAP_ID); - - firstDependentResourceConfigMap - .setResourceDiscriminator( - new ResourceIDMatcherDiscriminator<>( - p -> new ResourceID(p.getConfigMapName(FIRST_CONFIG_MAP_ID), - p.getMetadata().getNamespace()))); - secondDependentResourceConfigMap - .setResourceDiscriminator( - new ResourceIDMatcherDiscriminator<>( - p -> new ResourceID(p.getConfigMapName(SECOND_CONFIG_MAP_ID), - p.getMetadata().getNamespace()))); } @Override public UpdateControl reconcile( MultipleDependentResourceCustomResource resource, Context context) { - numberOfExecutions.getAndIncrement(); firstDependentResourceConfigMap.reconcile(resource, context); secondDependentResourceConfigMap.reconcile(resource, context); return UpdateControl.noUpdate(); } - - public int getNumberOfExecutions() { - return numberOfExecutions.get(); - } - @Override public Map prepareEventSources( EventSourceContext context) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceSpec.java new file mode 100644 index 0000000000..def3fa9088 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceSpec.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.sample.multipledependentresource; + +public class MultipleDependentResourceSpec { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceConfigMap.java new file mode 100644 index 0000000000..661e8e54be --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceConfigMap.java @@ -0,0 +1,37 @@ +package io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator; + +import java.util.HashMap; +import java.util.Map; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; + +public class MultipleDependentResourceConfigMap + extends + CRUDKubernetesDependentResource { + + public static final String DATA_KEY = "key"; + private final int value; + + public MultipleDependentResourceConfigMap(int value) { + super(ConfigMap.class); + this.value = value; + } + + @Override + protected ConfigMap desired(MultipleDependentResourceCustomResourceWithDiscriminator primary, + Context context) { + Map data = new HashMap<>(); + data.put(DATA_KEY, String.valueOf(value)); + + return new ConfigMapBuilder() + .withNewMetadata() + .withName(primary.getConfigMapName(value)) + .withNamespace(primary.getMetadata().getNamespace()) + .endMetadata() + .withData(data) + .build(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceCustomResourceWithDiscriminator.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceCustomResourceWithDiscriminator.java new file mode 100644 index 0000000000..7491d5e3ae --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceCustomResourceWithDiscriminator.java @@ -0,0 +1,19 @@ +package io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("mdwd") +public class MultipleDependentResourceCustomResourceWithDiscriminator + extends CustomResource + implements Namespaced { + + public String getConfigMapName(int id) { + return "configmap" + id; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java new file mode 100644 index 0000000000..aae9d23cc7 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java @@ -0,0 +1,68 @@ +package io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator; + +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.processing.event.ResourceID; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; +import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; +import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; + +@ControllerConfiguration +public class MultipleDependentResourceWithDiscriminatorReconciler + implements Reconciler, + TestExecutionInfoProvider { + + public static final int FIRST_CONFIG_MAP_ID = 1; + public static final int SECOND_CONFIG_MAP_ID = 2; + private final AtomicInteger numberOfExecutions = new AtomicInteger(0); + + private final MultipleDependentResourceConfigMap firstDependentResourceConfigMap; + private final MultipleDependentResourceConfigMap secondDependentResourceConfigMap; + + public MultipleDependentResourceWithDiscriminatorReconciler() { + firstDependentResourceConfigMap = new MultipleDependentResourceConfigMap(FIRST_CONFIG_MAP_ID); + secondDependentResourceConfigMap = new MultipleDependentResourceConfigMap(SECOND_CONFIG_MAP_ID); + + firstDependentResourceConfigMap + .setResourceDiscriminator( + new ResourceIDMatcherDiscriminator<>( + p -> new ResourceID(p.getConfigMapName(FIRST_CONFIG_MAP_ID), + p.getMetadata().getNamespace()))); + secondDependentResourceConfigMap + .setResourceDiscriminator( + new ResourceIDMatcherDiscriminator<>( + p -> new ResourceID(p.getConfigMapName(SECOND_CONFIG_MAP_ID), + p.getMetadata().getNamespace()))); + } + + @Override + public UpdateControl reconcile( + MultipleDependentResourceCustomResourceWithDiscriminator resource, + Context context) { + numberOfExecutions.getAndIncrement(); + firstDependentResourceConfigMap.reconcile(resource, context); + secondDependentResourceConfigMap.reconcile(resource, context); + return UpdateControl.noUpdate(); + } + + + public int getNumberOfExecutions() { + return numberOfExecutions.get(); + } + + @Override + public Map prepareEventSources( + EventSourceContext context) { + InformerEventSource eventSource = + new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) + .build(), context); + firstDependentResourceConfigMap.configureWith(eventSource); + secondDependentResourceConfigMap.configureWith(eventSource); + + return EventSourceUtils.nameEventSources(eventSource); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorStatus.java new file mode 100644 index 0000000000..84543b8a12 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorStatus.java @@ -0,0 +1,5 @@ +package io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator; + +public class MultipleDependentResourceWithDiscriminatorStatus { + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java new file mode 100644 index 0000000000..6d0bc303df --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java @@ -0,0 +1,38 @@ +package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; + +import java.util.HashMap; +import java.util.Map; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; + +@KubernetesDependent +public class MultipleManagedDependentNoDiscriminatorConfigMap1 + extends + CRUDKubernetesDependentResource { + + public static final String NAME_SUFFIX = "-1"; + + public MultipleManagedDependentNoDiscriminatorConfigMap1() { + super(ConfigMap.class); + } + + @Override + protected ConfigMap desired(MultipleManagedDependentNoDiscriminatorCustomResource primary, + Context context) { + Map data = new HashMap<>(); + data.put(MultipleManagedDependentSameTypeNoDiscriminatorReconciler.DATA_KEY, + primary.getSpec().getValue()); + + return new ConfigMapBuilder() + .withNewMetadata() + .withName(primary.getMetadata().getName() + NAME_SUFFIX) + .withNamespace(primary.getMetadata().getNamespace()) + .endMetadata() + .withData(data) + .build(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java new file mode 100644 index 0000000000..937291d83d --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java @@ -0,0 +1,39 @@ +package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; + +import java.util.HashMap; +import java.util.Map; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; + +import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; + +@KubernetesDependent +public class MultipleManagedDependentNoDiscriminatorConfigMap2 + extends + CRUDKubernetesDependentResource { + + public static final String NAME_SUFFIX = "-2"; + + public MultipleManagedDependentNoDiscriminatorConfigMap2() { + super(ConfigMap.class); + } + + @Override + protected ConfigMap desired(MultipleManagedDependentNoDiscriminatorCustomResource primary, + Context context) { + Map data = new HashMap<>(); + data.put(DATA_KEY, primary.getSpec().getValue()); + + return new ConfigMapBuilder() + .withNewMetadata() + .withName(primary.getMetadata().getName() + NAME_SUFFIX) + .withNamespace(primary.getMetadata().getNamespace()) + .endMetadata() + .withData(data) + .build(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java new file mode 100644 index 0000000000..611d96f74e --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java @@ -0,0 +1,16 @@ +package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("mnd") +public class MultipleManagedDependentNoDiscriminatorCustomResource + extends CustomResource + implements Namespaced { + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java new file mode 100644 index 0000000000..4ccc1d84f4 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; + +public class MultipleManagedDependentNoDiscriminatorSpec { + + private String value; + + public String getValue() { + return value; + } + + public MultipleManagedDependentNoDiscriminatorSpec setValue(String value) { + this.value = value; + return this; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java new file mode 100644 index 0000000000..0e446454da --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java @@ -0,0 +1,57 @@ +package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; + +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; +import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; +import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; + +import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.CONFIG_MAP_EVENT_SOURCE; + +@Workflow(dependents = { + @Dependent(type = MultipleManagedDependentNoDiscriminatorConfigMap1.class, + useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE), + @Dependent(type = MultipleManagedDependentNoDiscriminatorConfigMap2.class, + useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE) +}) +@ControllerConfiguration +public class MultipleManagedDependentSameTypeNoDiscriminatorReconciler + implements Reconciler, + TestExecutionInfoProvider { + + public static final String CONFIG_MAP_EVENT_SOURCE = "ConfigMapEventSource"; + public static final String DATA_KEY = "key"; + + private final AtomicInteger numberOfExecutions = new AtomicInteger(0); + + public MultipleManagedDependentSameTypeNoDiscriminatorReconciler() {} + + @Override + public UpdateControl reconcile( + MultipleManagedDependentNoDiscriminatorCustomResource resource, + Context context) { + numberOfExecutions.getAndIncrement(); + + return UpdateControl.noUpdate(); + } + + + public int getNumberOfExecutions() { + return numberOfExecutions.get(); + } + + @Override + public Map prepareEventSources( + EventSourceContext context) { + InformerEventSource ies = + new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) + .build(), context); + + return Map.of(CONFIG_MAP_EVENT_SOURCE, ies); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/AbstractPrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/AbstractPrimaryIndexerTestReconciler.java index 3b8fc43bfb..0fcdc8e39d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/AbstractPrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/AbstractPrimaryIndexerTestReconciler.java @@ -15,6 +15,8 @@ public class AbstractPrimaryIndexerTestReconciler implements Reconciler { + public static final String CONFIG_MAP_NAME = "common-config-map"; + private final Map numberOfExecutions = new ConcurrentHashMap<>(); protected static final String CONFIG_MAP_RELATION_INDEXER = "cm-indexer"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java index 712635659c..513cc2cb5d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java @@ -5,6 +5,9 @@ import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; @@ -32,6 +35,17 @@ public ReadOnlyConfigMapDependent() { super(ConfigMap.class); } + @Override + protected ConfigMap desired(PrimaryIndexerTestCustomResource primary, + Context context) { + return new ConfigMapBuilder() + .withMetadata(new ObjectMetaBuilder() + .withName(CONFIG_MAP_NAME) + .withNamespace(primary.getMetadata().getNamespace()) + .build()) + .build(); + } + @Override public Set toPrimaryResourceIDs(ConfigMap resource) { return cache.byIndex(CONFIG_MAP_RELATION_INDEXER, resource.getMetadata().getName()) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapDependent.java index d08bc2131f..364e9088f7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapDependent.java @@ -1,12 +1,28 @@ package io.javaoperatorsdk.operator.sample.primarytosecondaydependent; import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; public class ConfigMapDependent extends KubernetesDependentResource { + public static final String TEST_CONFIG_MAP_NAME = "testconfigmap"; + public ConfigMapDependent() { super(ConfigMap.class); } + + @Override + protected ConfigMap desired(PrimaryToSecondaryDependentCustomResource primary, + Context context) { + return new ConfigMapBuilder() + .withMetadata(new ObjectMetaBuilder() + .withName(TEST_CONFIG_MAP_NAME) + .withNamespace(primary.getMetadata().getNamespace()) + .build()) + .build(); + } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java index a103e53162..d373fe7d26 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java @@ -21,7 +21,7 @@ public UnmodifiablePartConfigMapDependent() { @Override protected ConfigMap desired(UnmodifiableDependentPartCustomResource primary, Context context) { - var actual = getSecondaryResource(primary, context); + var actual = context.getSecondaryResource(ConfigMap.class); ConfigMap res = new ConfigMapBuilder() .withMetadata(new ObjectMetaBuilder() .withName(primary.getMetadata().getName()) From 00a433fa8a749c16afba7e5ff78fd57ba1e0721e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 18 Mar 2024 14:02:46 +0100 Subject: [PATCH 20/96] feat: explicit workflow invocation (#2289) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- docs/documentation/v5-0-migration.md | 2 + .../api/config/BaseConfigurationService.java | 2 +- .../api/config/workflow/WorkflowSpec.java | 9 ++- .../operator/api/reconciler/Context.java | 11 +++- .../api/reconciler/DefaultContext.java | 11 ++-- .../operator/api/reconciler/Workflow.java | 8 +++ ...dWorkflowAndDependentResourceContext.java} | 39 ++++++++++- ...dWorkflowAndDependentResourceContext.java} | 23 ++++++- .../operator/processing/Controller.java | 59 +++++++++++++++-- .../workflow/ManagedWorkflowTest.java | 2 +- .../operator/WorkflowExplicitCleanupIT.java | 50 ++++++++++++++ .../WorkflowExplicitInvocationIT.java | 66 +++++++++++++++++++ ...DependentWithReadyConditionReconciler.java | 2 +- .../ComplexDependentReconciler.java | 2 +- .../WorkflowAllFeatureReconciler.java | 2 +- .../ConfigMapDependent.java | 29 ++++++++ ...WorkflowExplicitCleanupCustomResource.java | 15 +++++ .../WorkflowExplicitCleanupReconciler.java | 32 +++++++++ .../WorkflowExplicitCleanupSpec.java | 15 +++++ .../ConfigMapDependent.java | 29 ++++++++ ...kflowExplicitInvocationCustomResource.java | 15 +++++ .../WorkflowExplicitInvocationReconciler.java | 39 +++++++++++ .../WorkflowExplicitInvocationSpec.java | 15 +++++ 23 files changed, 453 insertions(+), 24 deletions(-) rename operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/{DefaultManagedDependentResourceContext.java => DefaultManagedWorkflowAndDependentResourceContext.java} (53%) rename operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/{ManagedDependentResourceContext.java => ManagedWorkflowAndDependentResourceContext.java} (75%) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitCleanupIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/ConfigMapDependent.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/ConfigMapDependent.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index f4ec51f4fb..f69625afad 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -17,3 +17,5 @@ permalink: /docs/v5-0-migration [`EventSourceUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java#L11-L11) now contains all the utility methods used for event sources naming that were previously defined in the `EventSourceInitializer` interface. +3. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed + via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index eab8e61f72..846c16046c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -169,7 +169,7 @@ protected

ControllerConfiguration

configFor(Reconcile io.javaoperatorsdk.operator.api.reconciler.Workflow.class); if (workflowAnnotation != null) { List specs = dependentResources(workflowAnnotation, config); - WorkflowSpec workflowSpec = new WorkflowSpec(specs); + WorkflowSpec workflowSpec = new WorkflowSpec(specs, workflowAnnotation.explicitInvocation()); config.setWorkflowSpec(workflowSpec); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java index f1eea3c5d3..ab89bb07db 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java @@ -8,12 +8,19 @@ public class WorkflowSpec { @SuppressWarnings("rawtypes") private final List dependentResourceSpecs; + private final boolean explicitInvocation; - public WorkflowSpec(List dependentResourceSpecs) { + public WorkflowSpec(List dependentResourceSpecs, + boolean explicitInvocation) { this.dependentResourceSpecs = dependentResourceSpecs; + this.explicitInvocation = explicitInvocation; } public List getDependentResourceSpecs() { return dependentResourceSpecs; } + + public boolean isExplicitInvocation() { + return explicitInvocation; + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java index 78592495ad..a997835822 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java @@ -8,7 +8,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedDependentResourceContext; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedWorkflowAndDependentResourceContext; import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; import io.javaoperatorsdk.operator.processing.event.source.IndexerResourceCache; @@ -34,7 +34,14 @@ Optional getSecondaryResource(Class expectedType, ControllerConfiguration

getControllerConfiguration(); - ManagedDependentResourceContext managedDependentResourceContext(); + /** + * Retrieve the {@link ManagedWorkflowAndDependentResourceContext} used to interact with + * {@link io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource}s and associated + * {@link io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow} + * + * @return the {@link ManagedWorkflowAndDependentResourceContext} + */ + ManagedWorkflowAndDependentResourceContext managedWorkflowAndDependentResourceContext(); EventSourceRetriever

eventSourceRetriever(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java index 633daea6aa..9ff7ddd7a3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java @@ -9,8 +9,8 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedDependentResourceContext; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedDependentResourceContext; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedWorkflowAndDependentResourceContext; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedWorkflowAndDependentResourceContext; import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -21,14 +21,15 @@ public class DefaultContext

implements Context

{ private final Controller

controller; private final P primaryResource; private final ControllerConfiguration

controllerConfiguration; - private final DefaultManagedDependentResourceContext defaultManagedDependentResourceContext; + private final DefaultManagedWorkflowAndDependentResourceContext

defaultManagedDependentResourceContext; public DefaultContext(RetryInfo retryInfo, Controller

controller, P primaryResource) { this.retryInfo = retryInfo; this.controller = controller; this.primaryResource = primaryResource; this.controllerConfiguration = controller.getConfiguration(); - this.defaultManagedDependentResourceContext = new DefaultManagedDependentResourceContext(); + this.defaultManagedDependentResourceContext = + new DefaultManagedWorkflowAndDependentResourceContext<>(controller, primaryResource, this); } @Override @@ -79,7 +80,7 @@ public ControllerConfiguration

getControllerConfiguration() { } @Override - public ManagedDependentResourceContext managedDependentResourceContext() { + public ManagedWorkflowAndDependentResourceContext managedWorkflowAndDependentResourceContext() { return defaultManagedDependentResourceContext; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java index 6726a1d32b..04a5b21606 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java @@ -2,6 +2,7 @@ import java.lang.annotation.*; +import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; @Inherited @@ -11,4 +12,11 @@ Dependent[] dependents(); + /** + * If true, managed workflow should be explicitly invoked within the reconciler implementation. If + * false workflow is invoked just before the {@link Reconciler#reconcile(HasMetadata, Context)} + * method. + */ + boolean explicitInvocation() default false; + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedDependentResourceContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java similarity index 53% rename from operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedDependentResourceContext.java rename to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java index 61414468c8..a3743cf124 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedDependentResourceContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java @@ -3,14 +3,30 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowCleanupResult; import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowReconcileResult; @SuppressWarnings("rawtypes") -public class DefaultManagedDependentResourceContext implements ManagedDependentResourceContext { - public static final Object RECONCILE_RESULT_KEY = new Object(); - public static final Object CLEANUP_RESULT_KEY = new Object(); +public class DefaultManagedWorkflowAndDependentResourceContext

+ implements ManagedWorkflowAndDependentResourceContext { + + public static final Object RECONCILE_RESULT_KEY = new Object(); + public static final Object CLEANUP_RESULT_KEY = new Object(); private final ConcurrentHashMap attributes = new ConcurrentHashMap(); + private final Controller

controller; + private final P primaryResource; + private final Context

context; + + public DefaultManagedWorkflowAndDependentResourceContext(Controller

controller, + P primaryResource, + Context

context) { + this.controller = controller; + this.primaryResource = primaryResource; + this.context = context; + } @Override public Optional get(Object key, Class expectedType) { @@ -45,4 +61,21 @@ public Optional getWorkflowReconcileResult() { public Optional getWorkflowCleanupResult() { return get(CLEANUP_RESULT_KEY, WorkflowCleanupResult.class); } + + @Override + public void reconcileManagedWorkflow() { + if (!controller.isWorkflowExplicitInvocation()) { + throw new IllegalStateException("Workflow explicit invocation is not set."); + } + controller.reconcileManagedWorkflow(primaryResource, context); + } + + @Override + public void cleanupManageWorkflow() { + if (!controller.isWorkflowExplicitInvocation()) { + throw new IllegalStateException("Workflow explicit invocation is not set."); + } + controller.cleanupManagedWorkflow(primaryResource, context); + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedWorkflowAndDependentResourceContext.java similarity index 75% rename from operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java rename to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedWorkflowAndDependentResourceContext.java index 47534cc30d..f5a25a6d9c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedWorkflowAndDependentResourceContext.java @@ -10,7 +10,7 @@ * Contextual information related to {@link DependentResource} either to retrieve the actual * implementations to interact with them or to pass information between them and/or the reconciler */ -public interface ManagedDependentResourceContext { +public interface ManagedWorkflowAndDependentResourceContext { /** * Retrieve a contextual object, if it exists and is of the specified expected type, associated @@ -37,7 +37,6 @@ public interface ManagedDependentResourceContext { * @return an Optional containing the previous value associated with the key or * {@link Optional#empty()} if none existed */ - @SuppressWarnings("unchecked") T put(Object key, T value); /** @@ -54,5 +53,25 @@ public interface ManagedDependentResourceContext { WorkflowReconcileResult getWorkflowReconcileResult(); + @SuppressWarnings("unused") WorkflowCleanupResult getWorkflowCleanupResult(); + + /** + * Explicitly reconcile the declared workflow for the associated + * {@link io.javaoperatorsdk.operator.api.reconciler.Reconciler} + * + * @throws IllegalStateException if called when explicit invocation is not requested + */ + void reconcileManagedWorkflow(); + + /** + * Explicitly clean-up dependent resources in the declared workflow for the associated + * {@link io.javaoperatorsdk.operator.api.reconciler.Reconciler}. Note that calling this method is + * only needed if the associated reconciler implements the + * {@link io.javaoperatorsdk.operator.api.reconciler.Cleaner} interface. + * + * @throws IllegalStateException if called when explicit invocation is not requested + */ + void cleanupManageWorkflow(); + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 05a1c92943..ab30a4019e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -1,6 +1,11 @@ package io.javaoperatorsdk.operator.processing; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,9 +23,18 @@ import io.javaoperatorsdk.operator.RegisteredController; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager; +import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.monitoring.Metrics; import io.javaoperatorsdk.operator.api.monitoring.Metrics.ControllerExecution; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Cleaner; +import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ContextInitializer; +import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.Ignore; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceNotFoundException; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceProvider; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceReferencer; @@ -129,9 +143,11 @@ public Map metadata() { @Override public UpdateControl

execute() throws Exception { initContextIfNeeded(resource, context); - if (!managedWorkflow.isEmpty()) { - managedWorkflow.reconcile(resource, context); - } + configuration.getWorkflowSpec().ifPresent(ws -> { + if (!managedWorkflow.isEmpty() && !isWorkflowExplicitInvocation()) { + managedWorkflow.reconcile(resource, context); + } + }); return reconciler.reconcile(resource, context); } }); @@ -171,9 +187,12 @@ public Map metadata() { public DeleteControl execute() { initContextIfNeeded(resource, context); WorkflowCleanupResult workflowCleanupResult = null; - if (managedWorkflow.hasCleaner()) { + + // The cleanup is called also when explicit invocation is true, but the cleaner is not implemented + if (managedWorkflow.hasCleaner() || !isWorkflowExplicitInvocation()) { workflowCleanupResult = managedWorkflow.cleanup(resource, context); } + if (isCleaner) { var cleanupResult = ((Cleaner

) reconciler).cleanup(resource, context); if (!cleanupResult.isRemoveFinalizer()) { @@ -430,4 +449,32 @@ public ExecutorServiceManager getExecutorServiceManager() { public EventSourceContext

eventSourceContext() { return eventSourceContext; } + + public void reconcileManagedWorkflow(P primary, Context

context) { + if (!managedWorkflow.isEmpty()) { + var res = managedWorkflow.reconcile(primary, context); + ((DefaultManagedWorkflowAndDependentResourceContext) context + .managedWorkflowAndDependentResourceContext()) + .setWorkflowExecutionResult(res); + res.throwAggregateExceptionIfErrorsPresent(); + } + } + + public WorkflowCleanupResult cleanupManagedWorkflow(P resource, Context

context) { + if (managedWorkflow.hasCleaner()) { + var workflowCleanupResult = managedWorkflow.cleanup(resource, context); + ((DefaultManagedWorkflowAndDependentResourceContext) context + .managedWorkflowAndDependentResourceContext()) + .setWorkflowCleanupResult(workflowCleanupResult); + workflowCleanupResult.throwAggregateExceptionIfErrorsPresent(); + return workflowCleanupResult; + } else { + return null; + } + } + + public boolean isWorkflowExplicitInvocation() { + return configuration.getWorkflowSpec().map(WorkflowSpec::isExplicitInvocation) + .orElse(false); + } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java index 5327439a31..fc254aa217 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java @@ -64,7 +64,7 @@ ManagedWorkflow managedWorkflow(DependentResourceSpec... specs) { final var configuration = mock(ControllerConfiguration.class); final var specList = List.of(specs); - var ws = new WorkflowSpec(specList); + var ws = new WorkflowSpec(specList, false); when(configuration.getWorkflowSpec()).thenReturn(Optional.of(ws)); return new BaseConfigurationService().getWorkflowFactory() diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitCleanupIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitCleanupIT.java new file mode 100644 index 0000000000..b26bfdd443 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitCleanupIT.java @@ -0,0 +1,50 @@ +package io.javaoperatorsdk.operator; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.workflowexplicitcleanup.WorkflowExplicitCleanupCustomResource; +import io.javaoperatorsdk.operator.sample.workflowexplicitcleanup.WorkflowExplicitCleanupReconciler; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class WorkflowExplicitCleanupIT { + + public static final String RESOURCE_NAME = "test1"; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(WorkflowExplicitCleanupReconciler.class) + .build(); + + @Test + void workflowInvokedExplicitly() { + var res = extension.create(testResource()); + + await().untilAsserted(() -> { + assertThat(extension.get(ConfigMap.class, RESOURCE_NAME)).isNotNull(); + }); + + extension.delete(res); + + // The ConfigMap is not garbage collected, this tests that even if the cleaner is not + // implemented the workflow cleanup still called even if there is explicit invocation + await().untilAsserted(() -> { + assertThat(extension.get(ConfigMap.class, RESOURCE_NAME)).isNull(); + }); + } + + WorkflowExplicitCleanupCustomResource testResource() { + var res = new WorkflowExplicitCleanupCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(RESOURCE_NAME) + .build()); + return res; + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java new file mode 100644 index 0000000000..dba08faba0 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java @@ -0,0 +1,66 @@ +package io.javaoperatorsdk.operator; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.workflowexplicitinvocation.WorkflowExplicitInvocationCustomResource; +import io.javaoperatorsdk.operator.sample.workflowexplicitinvocation.WorkflowExplicitInvocationReconciler; +import io.javaoperatorsdk.operator.sample.workflowexplicitinvocation.WorkflowExplicitInvocationSpec; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class WorkflowExplicitInvocationIT { + + public static final String RESOURCE_NAME = "test1"; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(WorkflowExplicitInvocationReconciler.class) + .build(); + + @Test + void workflowInvokedExplicitly() { + var res = extension.create(testResource()); + var reconciler = extension.getReconcilerOfType(WorkflowExplicitInvocationReconciler.class); + + await().untilAsserted(() -> { + assertThat(reconciler.getNumberOfExecutions()).isEqualTo(1); + assertThat(extension.get(ConfigMap.class, RESOURCE_NAME)).isNull(); + }); + + reconciler.setInvokeWorkflow(true); + + // trigger reconciliation + res.getSpec().setValue("changed value"); + res = extension.replace(res); + + await().untilAsserted(() -> { + assertThat(reconciler.getNumberOfExecutions()).isEqualTo(2); + assertThat(extension.get(ConfigMap.class, RESOURCE_NAME)).isNotNull(); + }); + + extension.delete(res); + + // The ConfigMap is not garbage collected, this tests that even if the cleaner is not + // implemented the workflow cleanup still called even if there is explicit invocation + await().untilAsserted(() -> { + assertThat(extension.get(ConfigMap.class, RESOURCE_NAME)).isNull(); + }); + } + + WorkflowExplicitInvocationCustomResource testResource() { + var res = new WorkflowExplicitInvocationCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(RESOURCE_NAME) + .build()); + res.setSpec(new WorkflowExplicitInvocationSpec()); + res.getSpec().setValue("initial value"); + return res; + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java index 8da3ba944f..aca1e98c88 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java @@ -19,7 +19,7 @@ public UpdateControl reconcile( Context context) throws Exception { numberOfExecutions.incrementAndGet(); - var ready = context.managedDependentResourceContext().getWorkflowReconcileResult() + var ready = context.managedWorkflowAndDependentResourceContext().getWorkflowReconcileResult() .allDependentResourcesReady(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java index e8fa40c63e..81bcb7e153 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java @@ -40,7 +40,7 @@ public class ComplexDependentReconciler implements Reconciler reconcile( ComplexDependentCustomResource resource, Context context) throws Exception { - var ready = context.managedDependentResourceContext().getWorkflowReconcileResult() + var ready = context.managedWorkflowAndDependentResourceContext().getWorkflowReconcileResult() .allDependentResourcesReady(); var status = Objects.requireNonNullElseGet(resource.getStatus(), ComplexDependentStatus::new); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java index 1fadcdad66..f5c14d6f96 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java @@ -35,7 +35,7 @@ public UpdateControl reconcile( } resource.getStatus() .setReady( - context.managedDependentResourceContext() + context.managedWorkflowAndDependentResourceContext() .getWorkflowReconcileResult() .allDependentResourcesReady()); return UpdateControl.patchStatus(resource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/ConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/ConfigMapDependent.java new file mode 100644 index 0000000000..91bf73906f --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/ConfigMapDependent.java @@ -0,0 +1,29 @@ +package io.javaoperatorsdk.operator.sample.workflowexplicitcleanup; + +import java.util.Map; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; + +public class ConfigMapDependent extends + CRUDNoGCKubernetesDependentResource { + + public ConfigMapDependent() { + super(ConfigMap.class); + } + + @Override + protected ConfigMap desired(WorkflowExplicitCleanupCustomResource primary, + Context context) { + return new ConfigMapBuilder() + .withMetadata(new ObjectMetaBuilder() + .withName(primary.getMetadata().getName()) + .withNamespace(primary.getMetadata().getNamespace()) + .build()) + .withData(Map.of("key", "val")) + .build(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java new file mode 100644 index 0000000000..b2057a54dd --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.sample.workflowexplicitcleanup; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("wec") +public class WorkflowExplicitCleanupCustomResource + extends CustomResource + implements Namespaced { +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java new file mode 100644 index 0000000000..128bb9629c --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java @@ -0,0 +1,32 @@ +package io.javaoperatorsdk.operator.sample.workflowexplicitcleanup; + +import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; + +@Workflow(explicitInvocation = true, + dependents = @Dependent(type = ConfigMapDependent.class)) +@ControllerConfiguration +public class WorkflowExplicitCleanupReconciler + implements Reconciler, + Cleaner { + + @Override + public UpdateControl reconcile( + WorkflowExplicitCleanupCustomResource resource, + Context context) { + + context.managedWorkflowAndDependentResourceContext().reconcileManagedWorkflow(); + + return UpdateControl.noUpdate(); + } + + @Override + public DeleteControl cleanup(WorkflowExplicitCleanupCustomResource resource, + Context context) { + + context.managedWorkflowAndDependentResourceContext().cleanupManageWorkflow(); + // this can be checked + // context.managedWorkflowAndDependentResourceContext().getWorkflowCleanupResult() + return DeleteControl.defaultDelete(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java new file mode 100644 index 0000000000..d8da8797f5 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.sample.workflowexplicitcleanup; + +public class WorkflowExplicitCleanupSpec { + + private String value; + + public String getValue() { + return value; + } + + public WorkflowExplicitCleanupSpec setValue(String value) { + this.value = value; + return this; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/ConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/ConfigMapDependent.java new file mode 100644 index 0000000000..e26fcfcf11 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/ConfigMapDependent.java @@ -0,0 +1,29 @@ +package io.javaoperatorsdk.operator.sample.workflowexplicitinvocation; + +import java.util.Map; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; + +public class ConfigMapDependent extends + CRUDNoGCKubernetesDependentResource { + + public ConfigMapDependent() { + super(ConfigMap.class); + } + + @Override + protected ConfigMap desired(WorkflowExplicitInvocationCustomResource primary, + Context context) { + return new ConfigMapBuilder() + .withMetadata(new ObjectMetaBuilder() + .withName(primary.getMetadata().getName()) + .withNamespace(primary.getMetadata().getNamespace()) + .build()) + .withData(Map.of("key", primary.getSpec().getValue())) + .build(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java new file mode 100644 index 0000000000..827a17ddaf --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.sample.workflowexplicitinvocation; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("wei") +public class WorkflowExplicitInvocationCustomResource + extends CustomResource + implements Namespaced { +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java new file mode 100644 index 0000000000..dc7bce4296 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java @@ -0,0 +1,39 @@ +package io.javaoperatorsdk.operator.sample.workflowexplicitinvocation; + +import java.util.concurrent.atomic.AtomicInteger; + +import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; + +@Workflow(explicitInvocation = true, + dependents = @Dependent(type = ConfigMapDependent.class)) +@ControllerConfiguration +public class WorkflowExplicitInvocationReconciler + implements Reconciler { + + private final AtomicInteger numberOfExecutions = new AtomicInteger(0); + + private volatile boolean invokeWorkflow = false; + + @Override + public UpdateControl reconcile( + WorkflowExplicitInvocationCustomResource resource, + Context context) { + + numberOfExecutions.addAndGet(1); + if (invokeWorkflow) { + context.managedWorkflowAndDependentResourceContext().reconcileManagedWorkflow(); + } + + + return UpdateControl.noUpdate(); + } + + public int getNumberOfExecutions() { + return numberOfExecutions.get(); + } + + public void setInvokeWorkflow(boolean invokeWorkflow) { + this.invokeWorkflow = invokeWorkflow; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java new file mode 100644 index 0000000000..2112d348e2 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.sample.workflowexplicitinvocation; + +public class WorkflowExplicitInvocationSpec { + + private String value; + + public String getValue() { + return value; + } + + public WorkflowExplicitInvocationSpec setValue(String value) { + this.value = value; + return this; + } +} From 9fba9fe020a56bfb6a6980eb178cc575d78416d3 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Tue, 5 Nov 2024 19:44:42 +0100 Subject: [PATCH 21/96] feat: use ssa for status update by default from `UpdateControl` (#2278) Signed-off-by: Chris Laprun --- docs/documentation/v5-0-migration.md | 9 +- .../api/config/ConfigurationService.java | 10 ++ .../config/ConfigurationServiceOverrider.java | 14 ++ ...edWorkflowAndDependentResourceContext.java | 2 +- .../operator/processing/Controller.java | 6 +- .../event/ReconciliationDispatcher.java | 78 +++++---- .../event/ReconciliationDispatcherTest.java | 14 +- .../operator/StatusPatchNotLockingIT.java | 4 +- .../operator/StatusPatchSSAMigrationIT.java | 155 ++++++++++++++++++ .../StatusPatchLockingCustomResource.java | 4 +- 10 files changed, 243 insertions(+), 53 deletions(-) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index f69625afad..b34a7a6b21 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -17,5 +17,12 @@ permalink: /docs/v5-0-migration [`EventSourceUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java#L11-L11) now contains all the utility methods used for event sources naming that were previously defined in the `EventSourceInitializer` interface. -3. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed +3. Patching status through `UpdateControl` like the `patchStatus` method now by default + uses Server Side Apply instead of simple patch. To use the former approach, use the feature flag + in [`ConfigurationService`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L400-L400) + !!! IMPORTANT !!! + Migration from a non-SSA based controller to SSA based controller can cause problems, due to known issues. + See the following [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L71-L82) where it is demonstrated. + Also, the related part of a [workaround](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L110-L116). +4. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index 111ef03b1b..1bebfe4ade 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -461,4 +461,14 @@ default boolean parseResourceVersionsForEventFilteringAndCaching() { return false; } + /** + * {@link io.javaoperatorsdk.operator.api.reconciler.UpdateControl} patchStatus can either use + * simple update or SSA for status subresource patching. + * + * @return true by default + */ + default boolean useSSAForResourceStatusPatch() { + return true; + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java index 4996035943..f75284a3cf 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java @@ -41,6 +41,7 @@ public class ConfigurationServiceOverrider { private Set> defaultNonSSAResource; private Boolean previousAnnotationForDependentResources; private Boolean parseResourceVersions; + private Boolean useSSAForResourceStatusPatch; @SuppressWarnings("rawtypes") private DependentResourceFactory dependentResourceFactory; @@ -203,6 +204,11 @@ public ConfigurationServiceOverrider wihtParseResourceVersions( return this; } + public ConfigurationServiceOverrider withUseSSAForResourceStatusPatch(boolean value) { + this.useSSAForResourceStatusPatch = value; + return this; + } + public ConfigurationService build() { return new BaseConfigurationService(original.getVersion(), cloner, client) { @Override @@ -344,6 +350,14 @@ public boolean parseResourceVersionsForEventFilteringAndCaching() { ? parseResourceVersions : super.parseResourceVersionsForEventFilteringAndCaching(); } + + @Override + public boolean useSSAForResourceStatusPatch() { + return useSSAForResourceStatusPatch != null + ? useSSAForResourceStatusPatch + : super.useSSAForResourceStatusPatch(); + + } }; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java index a3743cf124..ee2987983d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java @@ -11,7 +11,7 @@ @SuppressWarnings("rawtypes") public class DefaultManagedWorkflowAndDependentResourceContext

- implements ManagedWorkflowAndDependentResourceContext { + implements ManagedWorkflowAndDependentResourceContext { public static final Object RECONCILE_RESULT_KEY = new Object(); public static final Object CLEANUP_RESULT_KEY = new Object(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index ab30a4019e..5421ef75d0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -173,9 +173,9 @@ public String successTypeName(DeleteControl deleteControl) { return deleteControl.isRemoveFinalizer() ? DELETE : FINALIZER_NOT_REMOVED; } - @Override - public ResourceID resourceID() { - return ResourceID.fromResource(resource); + @Override + public ResourceID resourceID() { + return ResourceID.fromResource(resource); } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java index 9189cc6822..8ba1f2c606 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java @@ -12,6 +12,8 @@ import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.PatchContext; +import io.fabric8.kubernetes.client.dsl.base.PatchType; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.api.ObservedGenerationAware; import io.javaoperatorsdk.operator.api.config.Cloner; @@ -25,9 +27,7 @@ import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.Controller; -import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getName; -import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getUID; -import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion; +import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.*; /** * Handles calls and results of a Reconciler and finalizer related logic @@ -45,8 +45,7 @@ class ReconciliationDispatcher

{ private final boolean retryConfigurationHasZeroAttempts; private final Cloner cloner; - ReconciliationDispatcher(Controller

controller, - CustomResourceFacade

customResourceFacade) { + ReconciliationDispatcher(Controller

controller, CustomResourceFacade

customResourceFacade) { this.controller = controller; this.customResourceFacade = customResourceFacade; this.cloner = controller.getConfiguration().getConfigurationService().getResourceCloner(); @@ -56,7 +55,8 @@ class ReconciliationDispatcher

{ } public ReconciliationDispatcher(Controller

controller) { - this(controller, new CustomResourceFacade<>(controller.getCRClient())); + this(controller, + new CustomResourceFacade<>(controller.getCRClient(), controller.getConfiguration())); } public PostExecutionControl

handleExecution(ExecutionScope

executionScope) { @@ -135,33 +135,25 @@ private PostExecutionControl

reconcileExecution(ExecutionScope

executionSc UpdateControl

updateControl = controller.reconcile(resourceForExecution, context); P updatedCustomResource = null; + final var toUpdate = + updateControl.isNoUpdate() ? originalResource : updateControl.getResource(); if (updateControl.isUpdateResourceAndStatus()) { - updatedCustomResource = - updateCustomResource(updateControl.getResource()); - updateControl - .getResource() + updatedCustomResource = updateCustomResource(toUpdate); + toUpdate .getMetadata() .setResourceVersion(updatedCustomResource.getMetadata().getResourceVersion()); - updatedCustomResource = - updateStatusGenerationAware(updateControl.getResource(), originalResource, - updateControl.isPatchStatus()); - } else if (updateControl.isUpdateStatus()) { - updatedCustomResource = - updateStatusGenerationAware(updateControl.getResource(), originalResource, - updateControl.isPatchStatus()); } else if (updateControl.isUpdateResource()) { + updatedCustomResource = updateCustomResource(toUpdate); + } + + // check if status also needs to be updated + final var updateObservedGeneration = updateControl.isNoUpdate() + ? shouldUpdateObservedGenerationAutomatically(resourceForExecution) + : shouldUpdateObservedGenerationAutomatically(updatedCustomResource); + if (updateControl.isUpdateResourceAndStatus() || updateControl.isUpdateStatus() + || updateObservedGeneration) { updatedCustomResource = - updateCustomResource(updateControl.getResource()); - if (shouldUpdateObservedGenerationAutomatically(updatedCustomResource)) { - updatedCustomResource = - updateStatusGenerationAware(updateControl.getResource(), originalResource, - updateControl.isPatchStatus()); - } - } else if (updateControl.isNoUpdate() - && shouldUpdateObservedGenerationAutomatically(resourceForExecution)) { - updatedCustomResource = - updateStatusGenerationAware(originalResource, originalResource, - updateControl.isPatchStatus()); + updateStatusGenerationAware(toUpdate, originalResource, updateControl.isPatchStatus()); } return createPostExecutionControl(updatedCustomResource, updateControl); } @@ -376,10 +368,16 @@ public P conflictRetryingUpdate(P resource, Function modificationFun static class CustomResourceFacade { private final MixedOperation, Resource> resourceOperation; + private final boolean useSSAToUpdateStatus; + private final String fieldManager; public CustomResourceFacade( - MixedOperation, Resource> resourceOperation) { + MixedOperation, Resource> resourceOperation, + ControllerConfiguration configuration) { this.resourceOperation = resourceOperation; + this.useSSAToUpdateStatus = + configuration.getConfigurationService().useSSAForResourceStatusPatch(); + this.fieldManager = configuration.fieldManager(); } public R getResource(String namespace, String name) { @@ -409,14 +407,30 @@ public R updateStatus(R resource) { } public R patchStatus(R resource, R originalResource) { - log.trace("Updating status for resource: {}", resource); + log.trace("Patching status for resource: {} with ssa: {}", resource, useSSAToUpdateStatus); String resourceVersion = resource.getMetadata().getResourceVersion(); // don't do optimistic locking on patch originalResource.getMetadata().setResourceVersion(null); resource.getMetadata().setResourceVersion(null); try { - return resource(originalResource) - .editStatus(r -> resource); + if (useSSAToUpdateStatus) { + var managedFields = resource.getMetadata().getManagedFields(); + try { + + resource.getMetadata().setManagedFields(null); + var res = resource(resource); + return res.subresource("status").patch(new PatchContext.Builder() + .withFieldManager(fieldManager) + .withForce(true) + .withPatchType(PatchType.SERVER_SIDE_APPLY) + .build()); + } finally { + resource.getMetadata().setManagedFields(managedFields); + } + } else { + var res = resource(originalResource); + return res.editStatus(r -> resource); + } } finally { // restore initial resource version originalResource.getMetadata().setResourceVersion(resourceVersion); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java index c6aacb9071..d2e4cd52dc 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java @@ -43,19 +43,9 @@ import static io.javaoperatorsdk.operator.TestUtils.markForDeletion; import static io.javaoperatorsdk.operator.processing.event.ReconciliationDispatcher.MAX_UPDATE_RETRY; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @SuppressWarnings({"unchecked", "rawtypes"}) class ReconciliationDispatcherTest { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java index 1746e5737d..0a82bed51a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java @@ -58,10 +58,12 @@ void valuesAreDeletedIfSetToNull() { assertThat(actual.getStatus().getMessage()).isEqualTo(MESSAGE); }); + // resource needs to be read again to we don't replace the with wrong managed fields + resource = operator.get(StatusPatchLockingCustomResource.class, TEST_RESOURCE_NAME); resource.getSpec().setMessageInStatus(false); operator.replace(resource); - await().untilAsserted(() -> { + await().timeout(Duration.ofMinutes(3)).untilAsserted(() -> { var actual = operator.get(StatusPatchLockingCustomResource.class, TEST_RESOURCE_NAME); assertThat(actual.getStatus()).isNotNull(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java new file mode 100644 index 0000000000..01702a5400 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java @@ -0,0 +1,155 @@ +package io.javaoperatorsdk.operator; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +import io.fabric8.kubernetes.api.model.Namespace; +import io.fabric8.kubernetes.api.model.NamespaceBuilder; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingCustomResource; +import io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingCustomResourceSpec; +import io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingReconciler; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class StatusPatchSSAMigrationIT { + + public static final String TEST_RESOURCE_NAME = "test"; + + private final KubernetesClient client = new KubernetesClientBuilder().build(); + private String testNamespace; + + @BeforeEach + void beforeEach(TestInfo testInfo) { + LocallyRunOperatorExtension.applyCrd(StatusPatchLockingCustomResource.class, + client); + testInfo.getTestMethod() + .ifPresent(method -> testNamespace = KubernetesResourceUtil.sanitizeName(method.getName())); + client.namespaces().resource(testNamespace(testNamespace)).create(); + } + + @AfterEach + void afterEach() { + client.namespaces().withName(testNamespace).delete(); + await().untilAsserted(() -> { + var ns = client.namespaces().withName(testNamespace).get(); + assertThat(ns).isNull(); + }); + client.close(); + } + + + @Test + void testMigratingToSSA() { + var operator = startOperator(false); + var testResource = client.resource(testResource()).create(); + + await().untilAsserted(() -> { + var res = client.resource(testResource).get(); + assertThat(res.getStatus()).isNotNull(); + assertThat(res.getStatus().getMessage()).isEqualTo(StatusPatchLockingReconciler.MESSAGE); + assertThat(res.getStatus().getValue()).isEqualTo(1); + }); + operator.stop(); + + // start operator with SSA + operator = startOperator(true); + await().untilAsserted(() -> { + var res = client.resource(testResource).get(); + assertThat(res.getStatus()).isNotNull(); + assertThat(res.getStatus().getMessage()).isEqualTo(StatusPatchLockingReconciler.MESSAGE); + assertThat(res.getStatus().getValue()).isEqualTo(2); + }); + + var actualResource = client.resource(testResource()).get(); + actualResource.getSpec().setMessageInStatus(false); + client.resource(actualResource).update(); + + await().untilAsserted(() -> { + var res = client.resource(testResource).get(); + assertThat(res.getStatus()).isNotNull(); + // !!! This is wrong, the message should be null, + // see issue in Kubernetes: https://github.com/kubernetes/kubernetes/issues/99003 + assertThat(res.getStatus().getMessage()).isNotNull(); + assertThat(res.getStatus().getValue()).isEqualTo(3); + }); + + client.resource(testResource()).delete(); + operator.stop(); + } + + @Test + void workaroundMigratingFromToSSA() { + var operator = startOperator(false); + var testResource = client.resource(testResource()).create(); + + await().untilAsserted(() -> { + var res = client.resource(testResource).get(); + assertThat(res.getStatus()).isNotNull(); + assertThat(res.getStatus().getMessage()).isEqualTo(StatusPatchLockingReconciler.MESSAGE); + assertThat(res.getStatus().getValue()).isEqualTo(1); + }); + operator.stop(); + + // start operator with SSA + operator = startOperator(true); + await().untilAsserted(() -> { + var res = client.resource(testResource).get(); + assertThat(res.getStatus()).isNotNull(); + assertThat(res.getStatus().getMessage()).isEqualTo(StatusPatchLockingReconciler.MESSAGE); + assertThat(res.getStatus().getValue()).isEqualTo(2); + }); + + var actualResource = client.resource(testResource()).get(); + actualResource.getSpec().setMessageInStatus(false); + // removing the managed field entry for former method works + actualResource.getMetadata().setManagedFields(actualResource.getMetadata().getManagedFields() + .stream().filter(r -> !r.getOperation().equals("Update") && r.getSubresource() != null) + .toList()); + client.resource(actualResource).update(); + + await().untilAsserted(() -> { + var res = client.resource(testResource).get(); + assertThat(res.getStatus()).isNotNull(); + assertThat(res.getStatus().getMessage()).isNull(); + assertThat(res.getStatus().getValue()).isEqualTo(3); + }); + + client.resource(testResource()).delete(); + operator.stop(); + } + + + private Operator startOperator(boolean patchStatusWithSSA) { + var operator = new Operator(o -> o.withCloseClientOnStop(false) + .withUseSSAForResourceStatusPatch(patchStatusWithSSA)); + operator.register(new StatusPatchLockingReconciler(), + o -> o.settingNamespaces(testNamespace)); + + operator.start(); + return operator; + } + + StatusPatchLockingCustomResource testResource() { + StatusPatchLockingCustomResource res = new StatusPatchLockingCustomResource(); + res.setSpec(new StatusPatchLockingCustomResourceSpec()); + res.setMetadata(new ObjectMetaBuilder() + .withName(TEST_RESOURCE_NAME) + .withNamespace(testNamespace) + .build()); + return res; + } + + private Namespace testNamespace(String name) { + return new NamespaceBuilder().withMetadata(new ObjectMetaBuilder() + .withName(name) + .build()).build(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResource.java index 4d77259999..93ec97884d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResource.java @@ -3,14 +3,12 @@ import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; -import io.fabric8.kubernetes.model.annotation.Kind; import io.fabric8.kubernetes.model.annotation.ShortNames; import io.fabric8.kubernetes.model.annotation.Version; @Group("sample.javaoperatorsdk") @Version("v1") -@Kind("StatusUpdateLockingCustomResource") -@ShortNames("sul") +@ShortNames("spl") public class StatusPatchLockingCustomResource extends CustomResource From 98c02ced8ec8db060ad1510169d43feb3c711960 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Wed, 20 Mar 2024 12:20:42 +0100 Subject: [PATCH 22/96] refactor: make WorkflowSpec an interface (#2300) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chris Laprun Signed-off-by: Attila Mészáros --- .../api/config/BaseConfigurationService.java | 17 +++++++++++++---- .../api/config/workflow/WorkflowSpec.java | 19 +++---------------- .../workflow/ManagedWorkflowSupport.java | 4 +--- .../workflow/ManagedWorkflowTest.java | 13 +++++++++++-- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index 846c16046c..af9930d00c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -7,7 +7,6 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.Function; -import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -168,8 +167,18 @@ protected

ControllerConfiguration

configFor(Reconcile final var workflowAnnotation = reconciler.getClass().getAnnotation( io.javaoperatorsdk.operator.api.reconciler.Workflow.class); if (workflowAnnotation != null) { - List specs = dependentResources(workflowAnnotation, config); - WorkflowSpec workflowSpec = new WorkflowSpec(specs, workflowAnnotation.explicitInvocation()); + final var specs = dependentResources(workflowAnnotation, config); + WorkflowSpec workflowSpec = new WorkflowSpec() { + @Override + public List getDependentResourceSpecs() { + return specs; + } + + @Override + public boolean isExplicitInvocation() { + return workflowAnnotation.explicitInvocation(); + } + }; config.setWorkflowSpec(workflowSpec); } @@ -212,7 +221,7 @@ private static List dependentResources( eventSourceName); specsMap.put(dependentName, spec); } - return specsMap.values().stream().collect(Collectors.toUnmodifiableList()); + return specsMap.values().stream().toList(); } protected boolean createIfNeeded() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java index ab89bb07db..1b1c9da668 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java @@ -4,23 +4,10 @@ import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; -public class WorkflowSpec { +public interface WorkflowSpec { @SuppressWarnings("rawtypes") - private final List dependentResourceSpecs; - private final boolean explicitInvocation; + List getDependentResourceSpecs(); - public WorkflowSpec(List dependentResourceSpecs, - boolean explicitInvocation) { - this.dependentResourceSpecs = dependentResourceSpecs; - this.explicitInvocation = explicitInvocation; - } - - public List getDependentResourceSpecs() { - return dependentResourceSpecs; - } - - public boolean isExplicitInvocation() { - return explicitInvocation; - } + boolean isExplicitInvocation(); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java index f3fa894712..816f61749d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java @@ -39,9 +39,7 @@ public void checkForNameDuplication(List dependentResourc } } - public

ManagedWorkflow

createWorkflow( - WorkflowSpec workflowSpec) { - + public

ManagedWorkflow

createWorkflow(WorkflowSpec workflowSpec) { return createAsDefault(workflowSpec.getDependentResourceSpecs()); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java index fc254aa217..e618e44e46 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java @@ -62,9 +62,18 @@ void isCleanerIfHasDeleter() { @SuppressWarnings("unchecked") ManagedWorkflow managedWorkflow(DependentResourceSpec... specs) { final var configuration = mock(ControllerConfiguration.class); - final var specList = List.of(specs); - var ws = new WorkflowSpec(specList, false); + var ws = new WorkflowSpec() { + @Override + public List getDependentResourceSpecs() { + return List.of(specs); + } + + @Override + public boolean isExplicitInvocation() { + return false; + } + }; when(configuration.getWorkflowSpec()).thenReturn(Optional.of(ws)); return new BaseConfigurationService().getWorkflowFactory() From e58c7dd538e74808d55a1dcad18cc771f33341f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 21 Mar 2024 09:38:00 +0100 Subject: [PATCH 23/96] improve: replace current formatting plugins with spotless plugin (#2302) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .github/workflows/pr.yml | 3 +- bootstrapper-maven-plugin/pom.xml | 52 +- caffeine-bounded-cache-support/pom.xml | 12 +- micrometer-support/pom.xml | 18 +- operator-framework-bom/pom.xml | 294 ++++--- operator-framework-core/pom.xml | 102 ++- .../operator/ControllerManager.java | 1 - .../workflow/ManagedWorkflowFactory.java | 1 - .../dependent/EmptyTestDependentResource.java | 1 - operator-framework-junit5/pom.xml | 10 +- operator-framework/pom.xml | 14 +- .../ConfigMapDependentResource.java | 2 - .../DeploymentDependentResource.java | 2 - pom.xml | 832 +++++++++--------- sample-operators/leader-election/pom.xml | 180 ++-- .../sample/LeaderElectionTestReconciler.java | 5 +- .../operator/sample/LeaderElectionE2E.java | 3 +- sample-operators/mysql-schema/pom.xml | 202 +++-- .../operator/sample/MySQLDbConfig.java | 1 - sample-operators/pom.xml | 34 +- sample-operators/tomcat-operator/pom.xml | 206 +++-- sample-operators/webpage/pom.xml | 150 ++-- 22 files changed, 1055 insertions(+), 1070 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 378eeb7cf9..471cea503e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -26,8 +26,7 @@ jobs: cache: 'maven' - name: Check code format run: | - ./mvnw ${MAVEN_ARGS} formatter:validate -Dconfigfile=$PWD/contributing/eclipse-google-style.xml -pl '!operator-framework-bom' --file pom.xml - ./mvnw ${MAVEN_ARGS} impsort:check -pl '!operator-framework-bom' --file pom.xml + ./mvnw ${MAVEN_ARGS} spotless:check --file pom.xml - name: Run unit tests run: ./mvnw ${MAVEN_ARGS} clean install --file pom.xml diff --git a/bootstrapper-maven-plugin/pom.xml b/bootstrapper-maven-plugin/pom.xml index 127f51a81b..491e811dad 100644 --- a/bootstrapper-maven-plugin/pom.xml +++ b/bootstrapper-maven-plugin/pom.xml @@ -1,10 +1,10 @@ - + + 4.0.0 - java-operator-sdk io.javaoperatorsdk + java-operator-sdk 5.0.0-SNAPSHOT @@ -72,29 +72,29 @@ - - - org.apache.maven.plugins - maven-plugin-plugin - ${maven-plugin-plugin.version} - - josdk-bootstrapper - - - - org.codehaus.mojo - templating-maven-plugin - ${templating-maven-plugin.version} - - - filtering-java-templates - - filter-sources - - - - + + + org.apache.maven.plugins + maven-plugin-plugin + ${maven-plugin-plugin.version} + + josdk-bootstrapper + + + + org.codehaus.mojo + templating-maven-plugin + ${templating-maven-plugin.version} + + + filtering-java-templates + + filter-sources + + + + - + diff --git a/caffeine-bounded-cache-support/pom.xml b/caffeine-bounded-cache-support/pom.xml index 6961fc11d7..32bfa6ad13 100644 --- a/caffeine-bounded-cache-support/pom.xml +++ b/caffeine-bounded-cache-support/pom.xml @@ -1,13 +1,11 @@ - + + 4.0.0 - java-operator-sdk io.javaoperatorsdk + java-operator-sdk 5.0.0-SNAPSHOT - 4.0.0 caffeine-bounded-cache-support Operator SDK - Caffeine Bounded Cache Support @@ -65,10 +63,10 @@ However, this is needed to compile the tests so let's disable apt just for the compile phase --> default-compile - compile compile + compile -proc:none @@ -80,4 +78,4 @@ - \ No newline at end of file + diff --git a/micrometer-support/pom.xml b/micrometer-support/pom.xml index 6ca02379b1..a24acef29e 100644 --- a/micrometer-support/pom.xml +++ b/micrometer-support/pom.xml @@ -1,17 +1,15 @@ - + + 4.0.0 - java-operator-sdk io.javaoperatorsdk + java-operator-sdk 5.0.0-SNAPSHOT - 4.0.0 micrometer-support Operator SDK - Micrometer Support - + io.micrometer @@ -37,9 +35,9 @@ test - org.awaitility - awaitility - test + org.awaitility + awaitility + test io.javaoperatorsdk @@ -54,4 +52,4 @@ - \ No newline at end of file + diff --git a/operator-framework-bom/pom.xml b/operator-framework-bom/pom.xml index b6a31b98c2..96a5e01495 100644 --- a/operator-framework-bom/pom.xml +++ b/operator-framework-bom/pom.xml @@ -1,142 +1,170 @@ - - 4.0.0 + + 4.0.0 - io.javaoperatorsdk - operator-framework-bom - 5.0.0-SNAPSHOT - Operator SDK - Bill of Materials - pom - Java SDK for implementing Kubernetes operators - https://github.com/operator-framework/java-operator-sdk + io.javaoperatorsdk + operator-framework-bom + 5.0.0-SNAPSHOT + pom + Operator SDK - Bill of Materials + Java SDK for implementing Kubernetes operators + https://github.com/operator-framework/java-operator-sdk - - - Apache 2 License - https://www.apache.org/licenses/LICENSE-2.0.html - - - - - Attila Meszaros - csviri@gmail.com - - - Christophe Laprun - claprun@redhat.com - - + + + Apache 2 License + https://www.apache.org/licenses/LICENSE-2.0.html + + + + + Attila Meszaros + csviri@gmail.com + + + Christophe Laprun + claprun@redhat.com + + - - scm:git:git://github.com/java-operator-sdk/java-operator-sdk.git - scm:git:git@github.com/java-operator-sdk/java-operator-sdk.git - https://github.com/operator-framework/java-operator-sdk/tree/master - + + scm:git:git://github.com/java-operator-sdk/java-operator-sdk.git + scm:git:git@github.com/java-operator-sdk/java-operator-sdk.git + https://github.com/operator-framework/java-operator-sdk/tree/master + - - - - io.javaoperatorsdk - operator-framework-core - ${project.version} - - - io.javaoperatorsdk - operator-framework - ${project.version} - - - io.javaoperatorsdk - micrometer-support - ${project.version} - - - io.javaoperatorsdk - operator-framework-junit-5 - ${project.version} - - - + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + - - 1.7.0 - 3.2.5 - 3.3.1 - 3.10.0 - + + 1.6.13 + 3.2.4 + 3.3.1 + 3.10.0 + 2.43.0 + - - - release - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - - sign-artifacts - verify - - sign - - - - --pinentry-mode - loopback - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-maven-plugin.version} - true - - ossrh - https://oss.sonatype.org/ - true - - - - - - + + + + io.javaoperatorsdk + operator-framework-core + ${project.version} + + + io.javaoperatorsdk + operator-framework + ${project.version} + + + io.javaoperatorsdk + micrometer-support + ${project.version} + + + io.javaoperatorsdk + operator-framework-junit-5 + ${project.version} + + + - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + pom.xml + ./**/pom.xml + + + + + + contributing/eclipse-google-style.xml + + + contributing/eclipse.importorder + + + + + + + + + + + release + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + + sign + + verify + + + --pinentry-mode + loopback + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + true + + + + + + diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index 2ea8ab4b55..1ff0d34e8c 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -1,7 +1,5 @@ - + 4.0.0 io.javaoperatorsdk @@ -11,58 +9,9 @@ operator-framework-core + jar Operator SDK - Framework - Core Core framework for implementing Kubernetes operators - jar - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - - io.github.git-commit-id - git-commit-id-maven-plugin - ${git-commit-id-maven-plugin.version} - - - get-the-git-infos - - revision - - initialize - - - - true - ${project.build.outputDirectory}/version.properties - - - ^git.build.time$ - ^git.commit.id.(abbrev|full)$ - git.branch - - full - - - - org.codehaus.mojo - templating-maven-plugin - 3.0.0 - - - filtering-java-templates - - filter-sources - - - - - - - @@ -127,4 +76,51 @@ test + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + io.github.git-commit-id + git-commit-id-maven-plugin + ${git-commit-id-maven-plugin.version} + + true + ${project.build.outputDirectory}/version.properties + + ^git.build.time$ + ^git.commit.id.(abbrev|full)$ + git.branch + + full + + + + get-the-git-infos + + revision + + initialize + + + + + org.codehaus.mojo + templating-maven-plugin + 3.0.0 + + + filtering-java-templates + + filter-sources + + + + + + diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerManager.java index e90070d3c2..a755e4db7e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerManager.java @@ -89,4 +89,3 @@ synchronized int size() { return controllers.size(); } } - diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowFactory.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowFactory.java index cc735f137e..ef839896f4 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowFactory.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowFactory.java @@ -20,4 +20,3 @@ public interface ManagedWorkflowFactory> { @SuppressWarnings("rawtypes") ManagedWorkflow workflowFor(C configuration); } - diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/EmptyTestDependentResource.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/EmptyTestDependentResource.java index b41fc0bac7..25a849e3ab 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/EmptyTestDependentResource.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/EmptyTestDependentResource.java @@ -31,4 +31,3 @@ public void setName(String name) { this.name = name; } } - diff --git a/operator-framework-junit5/pom.xml b/operator-framework-junit5/pom.xml index 5f4fa10644..8477be3783 100644 --- a/operator-framework-junit5/pom.xml +++ b/operator-framework-junit5/pom.xml @@ -1,13 +1,11 @@ - + + 4.0.0 - java-operator-sdk io.javaoperatorsdk + java-operator-sdk 5.0.0-SNAPSHOT - 4.0.0 operator-framework-junit-5 Operator SDK - Framework - JUnit 5 extension @@ -41,4 +39,4 @@ - \ No newline at end of file + diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index c0cfc5e44d..bac97460b0 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -1,13 +1,11 @@ - + + 4.0.0 - java-operator-sdk io.javaoperatorsdk + java-operator-sdk 5.0.0-SNAPSHOT - 4.0.0 operator-framework Operator SDK - Framework - Plain Java @@ -103,14 +101,14 @@ However, this is needed to compile the tests so let's disable apt just for the compile phase --> default-compile - compile compile + compile - -proc:none - + -proc:none + diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java index d6947c2834..ac1310998e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java @@ -26,5 +26,3 @@ protected ConfigMap desired(CreateOnlyIfNotExistingDependentWithSSACustomResourc return configMap; } } - - diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentDependentResource.java index 61cf18f57b..30cd555abe 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentDependentResource.java @@ -25,5 +25,3 @@ protected Deployment desired(WorkflowAllFeatureCustomResource primary, return deployment; } } - - diff --git a/pom.xml b/pom.xml index 78addb90e6..8d825704e8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,47 +1,64 @@ - - 4.0.0 + + 4.0.0 - io.javaoperatorsdk - java-operator-sdk - 5.0.0-SNAPSHOT - Operator SDK for Java - Java SDK for implementing Kubernetes operators - pom - https://github.com/operator-framework/java-operator-sdk + io.javaoperatorsdk + java-operator-sdk + 5.0.0-SNAPSHOT + pom + Operator SDK for Java + Java SDK for implementing Kubernetes operators + https://github.com/operator-framework/java-operator-sdk - - - Apache 2 License - https://www.apache.org/licenses/LICENSE-2.0.html - - - - - Adam Sandor - adam.sandor@container-solutions.com - - - Attila Meszaros - csviri@gmail.com - - + + + Apache 2 License + https://www.apache.org/licenses/LICENSE-2.0.html + + + + + Adam Sandor + adam.sandor@container-solutions.com + + + Attila Meszaros + csviri@gmail.com + + - - scm:git:git://github.com/operator-framework/java-operator-sdk.git - scm:git:git@github.com/operator-framework/java-operator-sdk.git - https://github.com/operator-framework/java-operator-sdk/tree/main - + + operator-framework-bom + operator-framework-core + operator-framework-junit5 + operator-framework + micrometer-support + sample-operators + caffeine-bounded-cache-support + bootstrapper-maven-plugin + - - UTF-8 - 17 - ${java.version} - ${java.version} - java-operator-sdk - https://sonarcloud.io - jdk + + scm:git:git://github.com/operator-framework/java-operator-sdk.git + scm:git:git@github.com/operator-framework/java-operator-sdk.git + https://github.com/operator-framework/java-operator-sdk/tree/main + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + + + UTF-8 + 17 + ${java.version} + ${java.version} + java-operator-sdk + https://sonarcloud.io + jdk 5.10.1 6.13.4 @@ -60,23 +77,21 @@ 0.9.11 2.16.1 - 2.11 - 3.12.1 - 3.5.0 - 3.10.0 - 3.3.1 - 3.3.1 - 3.4.2 - 3.4.0 - 3.2.5 - 1.7.0 - 3.0.0 - 3.1.3 - 9.0.1 - 2.23.0 - 1.0 - 1.9.0 - 3.4.1 + 2.11 + 3.12.1 + 3.5.0 + 3.10.0 + 3.3.1 + 3.3.1 + 3.4.2 + 3.4.0 + 3.2.5 + 1.7.0 + 3.0.0 + 3.1.3 + 9.0.1 8.0.0 + 3.4.1 + 2.43.0 @@ -159,374 +174,349 @@ ${mokito.version} - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} - - - org.apache.logging.log4j - log4j-core - ${log4j.version} - test - - - org.apache.logging.log4j - log4j2-core - ${log4j.version} - - - com.github.spullara.mustache.java - compiler - ${mustache.version} - - - io.javaoperatorsdk - operator-framework-core - ${project.version} - - - io.javaoperatorsdk - operator-framework - ${project.version} - - - com.github.ben-manes.caffeine - caffeine - ${caffeine.version} - - - io.javaoperatorsdk - jenvtest - ${jenvtest.version} - test - - - - io.fabric8 - kubernetes-httpclient-okhttp - ${fabric8-client.version} - - - io.fabric8 - kubernetes-httpclient-vertx - ${fabric8-client.version} - - - - io.fabric8 - kubernetes-httpclient-jdk - ${fabric8-client.version} - - - io.fabric8 - kubernetes-httpclient-jetty - ${fabric8-client.version} - - - + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + test + + + org.apache.logging.log4j + log4j2-core + ${log4j.version} + + + com.github.spullara.mustache.java + compiler + ${mustache.version} + + + io.javaoperatorsdk + operator-framework-core + ${project.version} + + + io.javaoperatorsdk + operator-framework + ${project.version} + + + + com.squareup.okhttp3 + okhttp + ${okhttp.version} + + + com.squareup.okhttp3 + logging-interceptor + ${okhttp.version} + + + com.squareup.okhttp3 + mockwebserver + ${okhttp.version} + + + com.github.ben-manes.caffeine + caffeine + ${caffeine.version} + + + io.javaoperatorsdk + jenvtest + ${jenvtest.version} + test + + + + io.fabric8 + kubernetes-httpclient-okhttp + ${fabric8-client.version} + + + io.fabric8 + kubernetes-httpclient-vertx + ${fabric8-client.version} + + + + io.fabric8 + kubernetes-httpclient-jdk + ${fabric8-client.version} + + + io.fabric8 + kubernetes-httpclient-jetty + ${fabric8-client.version} + + + - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots/ - - true - always - - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - - org.apache.maven.plugins - maven-resources-plugin - ${maven-resources-plugin.version} - - - org.apache.maven.plugins - maven-jar-plugin - ${maven-jar-plugin.version} - - - org.apache.maven.plugins - maven-clean-plugin - ${maven-clean-plugin.version} - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - - org.apache.maven.plugins - maven-install-plugin - ${maven-install-plugin.version} - - - net.revelc.code.formatter - formatter-maven-plugin - ${formatter-maven-plugin.version} - - .cache - - - - net.revelc.code - impsort-maven-plugin - ${impsort-maven-plugin.version} - - .cache - java.,javax.,org.,io.,com. - * - true - true - - - - + + + + true + always + + ossrh + https://oss.sonatype.org/content/repositories/snapshots/ + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + org.apache.maven.plugins + maven-install-plugin + ${maven-install-plugin.version} + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + com.diffplug.spotless + spotless-maven-plugin + + + + pom.xml + ./**/pom.xml + + + + + + contributing/eclipse-google-style.xml + + + contributing/eclipse.importorder + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Test.java + + + **/*IT.java + **/*E2E.java + + WatchPermissionAwareTest + + + + + + + all-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Test.java + **/*IT.java + **/*E2E.java + + + + + + + + no-unit-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IT.java + + + **/*Test.java + **/*E2E.java + + + + + + + + + minimal-watch-timeout-dependent-it + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*ITS.java + + + **/*Test.java + **/*E2E.java + **/*IT.java + + + + + + + + end-to-end-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*E2E.java + + + **/*Test.java + **/*IT.java + + + + + + + + release + - - org.commonjava.maven.plugins - directory-maven-plugin - ${directory-maven-plugin.version} - - - directories - - highest-basedir - - initialize - - josdk.project.root - - - - - - org.apache.maven.plugins - maven-surefire-plugin + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IT.java + **/*E2E.java + **/InformerRelatedBehaviorTest.java + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + + sign + + verify - - **/*Test.java - - - **/*IT.java - **/*E2E.java - - WatchPermissionAwareTest + + --pinentry-mode + loopback + - - - net.revelc.code.formatter - formatter-maven-plugin - - - - format - - - - ${josdk.project.root}/contributing/eclipse-google-style.xml - - - - - - net.revelc.code - impsort-maven-plugin - - - sort - - sort - - - - + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + true + + - - - - all-tests - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*Test.java - **/*IT.java - **/*E2E.java - - - - - - - - no-unit-tests - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IT.java - - - **/*Test.java - **/*E2E.java - - - - - - - - - minimal-watch-timeout-dependent-it - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*ITS.java - - - **/*Test.java - **/*E2E.java - **/*IT.java - - - - - - - - end-to-end-tests - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*E2E.java - - - **/*Test.java - **/*IT.java - - - - - - - - release - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IT.java - **/*E2E.java - **/InformerRelatedBehaviorTest.java - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - - - sign-artifacts - verify - - sign - - - - --pinentry-mode - loopback - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-maven-plugin.version} - true - - ossrh - https://oss.sonatype.org/ - true - - - - - - + + + diff --git a/sample-operators/leader-election/pom.xml b/sample-operators/leader-election/pom.xml index eea2ae19aa..3a1b0a48a3 100644 --- a/sample-operators/leader-election/pom.xml +++ b/sample-operators/leader-election/pom.xml @@ -1,99 +1,97 @@ - - 4.0.0 + + 4.0.0 - - io.javaoperatorsdk - sample-operators - 5.0.0-SNAPSHOT - - - sample-leader-election - Operator SDK - Samples - Leader Election - An E2E test for leader election - jar + + io.javaoperatorsdk + sample-operators + 5.0.0-SNAPSHOT + - - - - io.javaoperatorsdk - operator-framework-bom - ${project.version} - pom - import - - - + sample-leader-election + jar + Operator SDK - Samples - Leader Election + An E2E test for leader election + - - io.javaoperatorsdk - operator-framework - - - org.apache.logging.log4j - log4j-slf4j-impl - - - org.takes - takes - 1.24.4 - - - org.awaitility - awaitility - compile - - - io.javaoperatorsdk - operator-framework-junit-5 - test - - - org.junit.jupiter - junit-jupiter-params - test - + + io.javaoperatorsdk + operator-framework-bom + ${project.version} + pom + import + - - - - com.google.cloud.tools - jib-maven-plugin - ${jib-maven-plugin.version} - - - gcr.io/distroless/java17-debian11 - - - leader-election-operator - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - - - - io.fabric8 - java-generator-maven-plugin - ${fabric8-client.version} - - - - generate - - - - - src/main/resources/kubernetes - - - - + + + + + io.javaoperatorsdk + operator-framework + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.takes + takes + 1.24.4 + + + org.awaitility + awaitility + compile + + + io.javaoperatorsdk + operator-framework-junit-5 + test + + + org.junit.jupiter + junit-jupiter-params + test + + + + + + com.google.cloud.tools + jib-maven-plugin + ${jib-maven-plugin.version} + + + gcr.io/distroless/java17-debian11 + + + leader-election-operator + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.12.1 + + + + io.fabric8 + java-generator-maven-plugin + ${fabric8-client.version} + + src/main/resources/kubernetes + + + + + generate + + + + + + diff --git a/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java b/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java index 4cd8627328..51e0e2cf48 100644 --- a/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java +++ b/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java @@ -2,15 +2,14 @@ import java.time.Duration; import java.util.ArrayList; +import javaoperatorsdk.sample.v1.LeaderElection; +import javaoperatorsdk.sample.v1.LeaderElectionStatus; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; -import javaoperatorsdk.sample.v1.LeaderElection; -import javaoperatorsdk.sample.v1.LeaderElectionStatus; - @ControllerConfiguration() public class LeaderElectionTestReconciler implements Reconciler { diff --git a/sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java b/sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java index 7932472aab..709496ba3d 100644 --- a/sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java +++ b/sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java @@ -10,6 +10,7 @@ import java.util.OptionalInt; import java.util.UUID; import java.util.stream.IntStream; +import javaoperatorsdk.sample.v1.LeaderElection; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -27,8 +28,6 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; -import javaoperatorsdk.sample.v1.LeaderElection; - import static io.javaoperatorsdk.operator.junit.AbstractOperatorExtension.CRD_READY_WAIT; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/sample-operators/mysql-schema/pom.xml b/sample-operators/mysql-schema/pom.xml index e6eeb1930c..554a937f2c 100644 --- a/sample-operators/mysql-schema/pom.xml +++ b/sample-operators/mysql-schema/pom.xml @@ -1,110 +1,108 @@ - - 4.0.0 + + 4.0.0 - - io.javaoperatorsdk - sample-operators - 5.0.0-SNAPSHOT - - - sample-mysql-schema-operator - Operator SDK - Samples - MySQL Schema - Provisions Schemas in a MySQL database - jar + + io.javaoperatorsdk + sample-operators + 5.0.0-SNAPSHOT + - - - - io.javaoperatorsdk - operator-framework-bom - ${project.version} - pom - import - - - + sample-mysql-schema-operator + jar + Operator SDK - Samples - MySQL Schema + Provisions Schemas in a MySQL database + - - io.javaoperatorsdk - operator-framework - - - io.javaoperatorsdk - micrometer-support - - - org.takes - takes - 1.24.4 - - - mysql - mysql-connector-java - 8.0.30 - - - io.fabric8 - crd-generator-apt - provided - - - org.apache.logging.log4j - log4j-slf4j-impl - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.awaitility - awaitility - test - - - io.javaoperatorsdk - operator-framework-junit-5 - test - + + io.javaoperatorsdk + operator-framework-bom + ${project.version} + pom + import + + + + + + io.javaoperatorsdk + operator-framework + + + io.javaoperatorsdk + micrometer-support + + + org.takes + takes + 1.24.4 + + + mysql + mysql-connector-java + 8.0.30 + + + io.fabric8 + crd-generator-apt + provided + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.awaitility + awaitility + test + + + io.javaoperatorsdk + operator-framework-junit-5 + test + + - - - - org.apache.maven.plugins - maven-surefire-plugin - - 0 - - - - com.google.cloud.tools - jib-maven-plugin - ${jib-maven-plugin.version} - - - gcr.io/distroless/java17-debian11 - - - mysql-schema-operator - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - - - + + + + org.apache.maven.plugins + maven-surefire-plugin + + 0 + + + + com.google.cloud.tools + jib-maven-plugin + ${jib-maven-plugin.version} + + + gcr.io/distroless/java17-debian11 + + + mysql-schema-operator + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.12.1 + + + - \ No newline at end of file + diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLDbConfig.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLDbConfig.java index 7cc06dd373..0f63cc846a 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLDbConfig.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLDbConfig.java @@ -43,4 +43,3 @@ public String getPassword() { return password; } } - diff --git a/sample-operators/pom.xml b/sample-operators/pom.xml index 07895b8b94..6d09f9a3ad 100644 --- a/sample-operators/pom.xml +++ b/sample-operators/pom.xml @@ -1,23 +1,21 @@ - - 4.0.0 + + 4.0.0 - - io.javaoperatorsdk - java-operator-sdk - 5.0.0-SNAPSHOT - + + io.javaoperatorsdk + java-operator-sdk + 5.0.0-SNAPSHOT + - sample-operators - Operator SDK - Samples - pom + sample-operators + pom + Operator SDK - Samples - - tomcat-operator - webpage - mysql-schema - leader-election - + + tomcat-operator + webpage + mysql-schema + leader-election + diff --git a/sample-operators/tomcat-operator/pom.xml b/sample-operators/tomcat-operator/pom.xml index af0e8ac6df..5e04d9c88c 100644 --- a/sample-operators/tomcat-operator/pom.xml +++ b/sample-operators/tomcat-operator/pom.xml @@ -1,112 +1,110 @@ - - 4.0.0 + + 4.0.0 - - io.javaoperatorsdk - sample-operators - 5.0.0-SNAPSHOT - - - sample-tomcat-operator - Operator SDK - Samples - Tomcat - Provisions Tomcat Pods and deploys Webapplications in them - jar + + io.javaoperatorsdk + sample-operators + 5.0.0-SNAPSHOT + - - - - io.javaoperatorsdk - operator-framework-bom - ${project.version} - pom - import - - - + sample-tomcat-operator + jar + Operator SDK - Samples - Tomcat + Provisions Tomcat Pods and deploys Webapplications in them + - - io.javaoperatorsdk - operator-framework - - - io.fabric8 - kubernetes-httpclient-okhttp - - - - - io.fabric8 - kubernetes-httpclient-vertx - - - io.fabric8 - crd-generator-apt - provided - - - org.apache.logging.log4j - log4j-slf4j-impl - - - org.takes - takes - 1.24.4 - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.awaitility - awaitility - 4.2.0 - test - - - io.javaoperatorsdk - operator-framework-junit-5 - test - + + io.javaoperatorsdk + operator-framework-bom + ${project.version} + pom + import + + + + + + io.javaoperatorsdk + operator-framework + + + io.fabric8 + kubernetes-httpclient-okhttp + + + + + io.fabric8 + kubernetes-httpclient-vertx + + + io.fabric8 + crd-generator-apt + provided + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.takes + takes + 1.24.4 + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.awaitility + awaitility + 4.2.0 + test + + + io.javaoperatorsdk + operator-framework-junit-5 + test + + - - - - org.apache.maven.plugins - maven-surefire-plugin - - 0 - - - - com.google.cloud.tools - jib-maven-plugin - ${jib-maven-plugin.version} - - - gcr.io/distroless/java17-debian11 - - - tomcat-operator - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - - - + + + + org.apache.maven.plugins + maven-surefire-plugin + + 0 + + + + com.google.cloud.tools + jib-maven-plugin + ${jib-maven-plugin.version} + + + gcr.io/distroless/java17-debian11 + + + tomcat-operator + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.12.1 + + + - \ No newline at end of file + diff --git a/sample-operators/webpage/pom.xml b/sample-operators/webpage/pom.xml index 576ffa7157..ad961b8393 100644 --- a/sample-operators/webpage/pom.xml +++ b/sample-operators/webpage/pom.xml @@ -1,83 +1,81 @@ - - 4.0.0 + + 4.0.0 - - io.javaoperatorsdk - sample-operators - 5.0.0-SNAPSHOT - - - sample-webpage-operator - Operator SDK - Samples - WebPage - Provisions an nginx Webserver based on a CRD with give html - jar + + io.javaoperatorsdk + sample-operators + 5.0.0-SNAPSHOT + - - - - io.javaoperatorsdk - operator-framework-bom - ${project.version} - pom - import - - - + sample-webpage-operator + jar + Operator SDK - Samples - WebPage + Provisions an nginx Webserver based on a CRD with give html + - - io.javaoperatorsdk - operator-framework - - - org.apache.logging.log4j - log4j-slf4j-impl - - - org.takes - takes - 1.24.4 - - - io.fabric8 - crd-generator-apt - provided - - - org.awaitility - awaitility - compile - - - io.javaoperatorsdk - operator-framework-junit-5 - test - + + io.javaoperatorsdk + operator-framework-bom + ${project.version} + pom + import + - - - - com.google.cloud.tools - jib-maven-plugin - ${jib-maven-plugin.version} - - - gcr.io/distroless/java17-debian11 - - - webpage-operator - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - - - + + + + + io.javaoperatorsdk + operator-framework + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.takes + takes + 1.24.4 + + + io.fabric8 + crd-generator-apt + provided + + + org.awaitility + awaitility + compile + + + io.javaoperatorsdk + operator-framework-junit-5 + test + + + + + + com.google.cloud.tools + jib-maven-plugin + ${jib-maven-plugin.version} + + + gcr.io/distroless/java17-debian11 + + + webpage-operator + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.12.1 + + + - \ No newline at end of file + From 2899ae0673e1ca19f9c93c63fb22df13a555f91d Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 21 Mar 2024 22:51:19 +0100 Subject: [PATCH 24/96] refactor: make ManagedWorkflowSupport public to be able to reuse it (#2308) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chris Laprun Signed-off-by: Attila Mészáros --- .../processing/dependent/workflow/ManagedWorkflowSupport.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java index 816f61749d..d6404aa392 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowSupport.java @@ -15,7 +15,7 @@ import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; @SuppressWarnings({"rawtypes", "unchecked"}) -class ManagedWorkflowSupport { +public class ManagedWorkflowSupport { public void checkForNameDuplication(List dependentResourceSpecs) { if (dependentResourceSpecs == null) { From 4347e8f28af845670441676233ecb6186b17c023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 24 Mar 2024 19:35:33 +0100 Subject: [PATCH 25/96] fix: package fix leader election sample (#2303) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../leader-election/k8s/namespace-inferred-operator.yaml | 2 +- sample-operators/leader-election/k8s/operator.yaml | 2 +- .../operator/sample/LeaderElectionTestReconciler.java | 4 ++-- .../kubernetes/leaderelections.sample.javaoperatorsdk-v1.yml | 4 ++-- .../io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sample-operators/leader-election/k8s/namespace-inferred-operator.yaml b/sample-operators/leader-election/k8s/namespace-inferred-operator.yaml index 13724a911a..cf8e743bd2 100644 --- a/sample-operators/leader-election/k8s/namespace-inferred-operator.yaml +++ b/sample-operators/leader-election/k8s/namespace-inferred-operator.yaml @@ -46,7 +46,7 @@ rules: verbs: - '*' - apiGroups: - - "sample.javaoperatorsdk" + - "sample.operator.javaoperatorsdk.io" resources: - leaderelections - leaderelections/status diff --git a/sample-operators/leader-election/k8s/operator.yaml b/sample-operators/leader-election/k8s/operator.yaml index 9d289a2d6c..eea9348072 100644 --- a/sample-operators/leader-election/k8s/operator.yaml +++ b/sample-operators/leader-election/k8s/operator.yaml @@ -50,7 +50,7 @@ rules: verbs: - '*' - apiGroups: - - "sample.javaoperatorsdk" + - "sample.operator.javaoperatorsdk.io" resources: - leaderelections - leaderelections/status diff --git a/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java b/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java index 51e0e2cf48..36fb3f2ef8 100644 --- a/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java +++ b/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java @@ -2,13 +2,13 @@ import java.time.Duration; import java.util.ArrayList; -import javaoperatorsdk.sample.v1.LeaderElection; -import javaoperatorsdk.sample.v1.LeaderElectionStatus; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.sample.v1.LeaderElection; +import io.javaoperatorsdk.operator.sample.v1.LeaderElectionStatus; @ControllerConfiguration() public class LeaderElectionTestReconciler diff --git a/sample-operators/leader-election/src/main/resources/kubernetes/leaderelections.sample.javaoperatorsdk-v1.yml b/sample-operators/leader-election/src/main/resources/kubernetes/leaderelections.sample.javaoperatorsdk-v1.yml index cc9d8c3fc6..e0580f8901 100644 --- a/sample-operators/leader-election/src/main/resources/kubernetes/leaderelections.sample.javaoperatorsdk-v1.yml +++ b/sample-operators/leader-election/src/main/resources/kubernetes/leaderelections.sample.javaoperatorsdk-v1.yml @@ -4,9 +4,9 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: leaderelections.sample.javaoperatorsdk + name: leaderelections.sample.operator.javaoperatorsdk.io spec: - group: sample.javaoperatorsdk + group: sample.operator.javaoperatorsdk.io names: kind: LeaderElection singular: leaderelection diff --git a/sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java b/sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java index 709496ba3d..863407999d 100644 --- a/sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java +++ b/sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java @@ -10,7 +10,6 @@ import java.util.OptionalInt; import java.util.UUID; import java.util.stream.IntStream; -import javaoperatorsdk.sample.v1.LeaderElection; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -27,6 +26,7 @@ import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import io.javaoperatorsdk.operator.sample.v1.LeaderElection; import static io.javaoperatorsdk.operator.junit.AbstractOperatorExtension.CRD_READY_WAIT; import static org.assertj.core.api.Assertions.assertThat; From f236accd61ca46d8d902e33ba037729dbfb077af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 25 Mar 2024 10:51:26 +0100 Subject: [PATCH 26/96] feat: remove resource discriminator (#2299) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- docs/documentation/v5-0-migration.md | 2 + .../operator/api/reconciler/Context.java | 5 +- .../api/reconciler/DefaultContext.java | 6 - .../api/reconciler/IndexDiscriminator.java | 50 --------- .../api/reconciler/ResourceDiscriminator.java | 11 -- .../ResourceIDMatcherDiscriminator.java | 45 -------- .../dependent/AbstractDependentResource.java | 20 +--- .../kubernetes/KubernetesDependent.java | 3 - .../KubernetesDependentConverter.java | 7 +- .../KubernetesDependentResource.java | 8 -- .../KubernetesDependentResourceConfig.java | 13 +-- ...ernetesDependentResourceConfigBuilder.java | 10 +- .../operator/IndexDiscriminatorIT.java | 77 ------------- .../dependent/FirstService.java | 9 +- .../dependent/FirstStatefulSet.java | 10 +- .../NamePrefixResourceDiscriminator.java | 31 ------ .../dependent/SecondService.java | 9 +- .../dependent/SecondStatefulSet.java | 8 +- .../IndexDiscriminatorTestCustomResource.java | 16 --- .../IndexDiscriminatorTestDRConfigMap.java | 38 ------- .../IndexDiscriminatorTestReconciler.java | 104 ------------------ .../IndexDiscriminatorTestSpec.java | 15 --- .../IndexDiscriminatorTestStatus.java | 5 - .../TestIndexDiscriminator.java | 14 --- ...ntResourceWithDiscriminatorReconciler.java | 12 -- .../ConfigMap1MultiInformerDiscriminator.java | 28 ----- .../ConfigMap2MultiInformerDiscriminator.java | 28 ----- ...endentResourceMultiInformerConfigMap1.java | 2 +- ...endentResourceMultiInformerConfigMap2.java | 2 +- .../ConfigMap1Discriminator.java | 26 ----- .../ConfigMap2Discriminator.java | 26 ----- ...pleManagedDependentResourceConfigMap1.java | 2 +- ...pleManagedDependentResourceConfigMap2.java | 2 +- .../ExternalDependentResource1.java | 4 - .../ExternalDependentResource2.java | 4 - .../ExternalResourceDiscriminator.java | 25 ----- .../ConfigMapDependentResource1.java | 12 +- .../ConfigMapDependentResource2.java | 12 +- 38 files changed, 23 insertions(+), 678 deletions(-) delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/IndexDiscriminator.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceDiscriminator.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceIDMatcherDiscriminator.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/IndexDiscriminatorIT.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/NamePrefixResourceDiscriminator.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestCustomResource.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestDRConfigMap.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestReconciler.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestSpec.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/TestIndexDiscriminator.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/ConfigMap1MultiInformerDiscriminator.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/ConfigMap2MultiInformerDiscriminator.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/ConfigMap1Discriminator.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/ConfigMap2Discriminator.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalResourceDiscriminator.java diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index b34a7a6b21..01b483449e 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -26,3 +26,5 @@ permalink: /docs/v5-0-migration Also, the related part of a [workaround](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L110-L116). 4. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. +5. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should + work without it by default. To optimize and handle special cases see the relevant section in [Dependent Resource documentation](/docs/dependent-resources#multiple-dependent-resources-of-same-type). diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java index a997835822..27547703b7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java @@ -17,7 +17,7 @@ public interface Context

{ Optional getRetryInfo(); default Optional getSecondaryResource(Class expectedType) { - return getSecondaryResource(expectedType, (String) null); + return getSecondaryResource(expectedType, null); } Set getSecondaryResources(Class expectedType); @@ -29,9 +29,6 @@ default Stream getSecondaryResourcesAsStream(Class expectedType) { @Deprecated(forRemoval = true) Optional getSecondaryResource(Class expectedType, String eventSourceName); - Optional getSecondaryResource(Class expectedType, - ResourceDiscriminator discriminator); - ControllerConfiguration

getControllerConfiguration(); /** diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java index 9ff7ddd7a3..86f29e6878 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java @@ -68,12 +68,6 @@ public Optional getSecondaryResource(Class expectedType, String eventS .getSecondaryResource(primaryResource); } - @Override - public Optional getSecondaryResource(Class expectedType, - ResourceDiscriminator discriminator) { - return discriminator.distinguish(expectedType, primaryResource, this); - } - @Override public ControllerConfiguration

getControllerConfiguration() { return controllerConfiguration; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/IndexDiscriminator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/IndexDiscriminator.java deleted file mode 100644 index 7a27397b26..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/IndexDiscriminator.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.javaoperatorsdk.operator.api.reconciler; - -import java.util.Optional; -import java.util.function.Function; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; - -/** - * Uses a custom index of {@link InformerEventSource} to access the target resource. The index needs - * to be explicitly created when the event source is defined. This approach improves the performance - * to access the resource. - */ -public class IndexDiscriminator - implements ResourceDiscriminator { - - private final String indexName; - private final String eventSourceName; - private final Function keyMapper; - - public IndexDiscriminator(String indexName, Function keyMapper) { - this(indexName, null, keyMapper); - } - - public IndexDiscriminator(String indexName, String eventSourceName, - Function keyMapper) { - this.indexName = indexName; - this.eventSourceName = eventSourceName; - this.keyMapper = keyMapper; - } - - @Override - public Optional distinguish(Class resource, - P primary, - Context

context) { - - InformerEventSource eventSource = - (InformerEventSource) context - .eventSourceRetriever() - .getResourceEventSourceFor(resource, eventSourceName); - var resources = eventSource.byIndex(indexName, keyMapper.apply(primary)); - if (resources.isEmpty()) { - return Optional.empty(); - } else if (resources.size() > 1) { - throw new IllegalStateException("More than one resource found"); - } else { - return Optional.of(resources.get(0)); - } - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceDiscriminator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceDiscriminator.java deleted file mode 100644 index 072e7d8078..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceDiscriminator.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.javaoperatorsdk.operator.api.reconciler; - -import java.util.Optional; - -import io.fabric8.kubernetes.api.model.HasMetadata; - -public interface ResourceDiscriminator { - - Optional distinguish(Class resource, P primary, Context

context); - -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceIDMatcherDiscriminator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceIDMatcherDiscriminator.java deleted file mode 100644 index da773fc210..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceIDMatcherDiscriminator.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.javaoperatorsdk.operator.api.reconciler; - -import java.util.Optional; -import java.util.function.Function; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.Cache; - -public class ResourceIDMatcherDiscriminator - implements ResourceDiscriminator { - - - private final String eventSourceName; - private final Function mapper; - - public ResourceIDMatcherDiscriminator(Function mapper) { - this(null, mapper); - } - - public ResourceIDMatcherDiscriminator(String eventSourceName, Function mapper) { - this.eventSourceName = eventSourceName; - this.mapper = mapper; - } - - @SuppressWarnings("unchecked") - @Override - public Optional distinguish(Class resource, P primary, Context

context) { - var resourceID = mapper.apply(primary); - if (eventSourceName != null) { - return ((Cache) context.eventSourceRetriever().getResourceEventSourceFor(resource, - eventSourceName)) - .get(resourceID); - } else { - var eventSources = context.eventSourceRetriever().getResourceEventSourcesFor(resource); - if (eventSources.size() == 1) { - return ((Cache) eventSources.get(0)).get(resourceID); - } else { - return context.getSecondaryResourcesAsStream(resource) - .filter(resourceID::isSameResource) - .findFirst(); - } - } - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java index f7960c4709..e9ef90f6dd 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java @@ -9,7 +9,6 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.Ignore; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.NameSetter; @@ -28,7 +27,6 @@ public abstract class AbstractDependentResource protected Creator creator; protected Updater updater; - private ResourceDiscriminator resourceDiscriminator; private final DependentResourceReconciler dependentResourceReconciler; protected String name; @@ -105,16 +103,14 @@ protected ReconcileResult reconcile(P primary, R actualResource, Context

c @Override public Optional getSecondaryResource(P primary, Context

context) { - if (resourceDiscriminator != null) { - return resourceDiscriminator.distinguish(resourceType(), primary, context); + + var secondaryResources = context.getSecondaryResources(resourceType()); + if (secondaryResources.isEmpty()) { + return Optional.empty(); } else { - var secondaryResources = context.getSecondaryResources(resourceType()); - if (secondaryResources.isEmpty()) { - return Optional.empty(); - } else { - return selectManagedSecondaryResource(secondaryResources, primary, context); - } + return selectManagedSecondaryResource(secondaryResources, primary, context); } + } /** @@ -205,10 +201,6 @@ protected void handleDelete(P primary, R secondary, Context

context) { "handleDelete method must be implemented if Deleter trait is supported"); } - public void setResourceDiscriminator(ResourceDiscriminator resourceDiscriminator) { - this.resourceDiscriminator = resourceDiscriminator; - } - protected boolean isCreatable() { return creatable; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java index eb4c9cf9b0..572741dcbd 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java @@ -6,7 +6,6 @@ import java.lang.annotation.Target; import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; @@ -70,8 +69,6 @@ */ Class genericFilter() default GenericFilter.class; - Class resourceDiscriminator() default ResourceDiscriminator.class; - /** * Creates the resource only if did not exist before, this applies only if SSA is used. */ diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java index 7a434aecf1..493f0b0146 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java @@ -8,7 +8,6 @@ import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.config.dependent.ConfigurationConverter; import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; @@ -33,7 +32,6 @@ public KubernetesDependentResourceConfig configFrom(KubernetesDependent confi OnUpdateFilter onUpdateFilter = null; OnDeleteFilter onDeleteFilter = null; GenericFilter genericFilter = null; - ResourceDiscriminator resourceDiscriminator = null; Boolean useSSA = null; if (configAnnotation != null) { if (!Arrays.equals(KubernetesDependent.DEFAULT_NAMESPACES, configAnnotation.namespaces())) { @@ -54,9 +52,6 @@ public KubernetesDependentResourceConfig configFrom(KubernetesDependent confi genericFilter = Utils.instantiate(configAnnotation.genericFilter(), GenericFilter.class, context); - resourceDiscriminator = - Utils.instantiate(configAnnotation.resourceDiscriminator(), ResourceDiscriminator.class, - context); createResourceOnlyIfNotExistingWithSSA = configAnnotation.createResourceOnlyIfNotExistingWithSSA(); useSSA = configAnnotation.useSSA().asBoolean(); @@ -64,6 +59,6 @@ public KubernetesDependentResourceConfig configFrom(KubernetesDependent confi return new KubernetesDependentResourceConfig(namespaces, labelSelector, configuredNS, createResourceOnlyIfNotExistingWithSSA, - resourceDiscriminator, useSSA, onAddFilter, onUpdateFilter, onDeleteFilter, genericFilter); + useSSA, onAddFilter, onUpdateFilter, onDeleteFilter, genericFilter); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 3e0e5f2115..600298c558 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -59,10 +59,6 @@ public KubernetesDependentResource(Class resourceType, String name) { @Override public void configureWith(KubernetesDependentResourceConfig config) { this.kubernetesDependentResourceConfig = config; - var discriminator = kubernetesDependentResourceConfig.getResourceDiscriminator(); - if (discriminator != null) { - setResourceDiscriminator(discriminator); - } } private void configureWith(String labelSelector, Set namespaces, @@ -250,10 +246,6 @@ protected InformerEventSource createEventSource(EventSourceContext

cont onUpdateFilter = kubernetesDependentResourceConfig.onUpdateFilter(); onDeleteFilter = kubernetesDependentResourceConfig.onDeleteFilter(); genericFilter = kubernetesDependentResourceConfig.genericFilter(); - var discriminator = kubernetesDependentResourceConfig.getResourceDiscriminator(); - if (discriminator != null) { - setResourceDiscriminator(discriminator); - } configureWith(kubernetesDependentResourceConfig.labelSelector(), kubernetesDependentResourceConfig.namespaces(), !kubernetesDependentResourceConfig.wereNamespacesConfigured(), context); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java index 9b3838831d..b1cb743232 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java @@ -4,7 +4,6 @@ import java.util.Set; import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; @@ -20,7 +19,6 @@ public class KubernetesDependentResourceConfig { private String labelSelector; private final boolean namespacesWereConfigured; private final boolean createResourceOnlyIfNotExistingWithSSA; - private final ResourceDiscriminator resourceDiscriminator; private final Boolean useSSA; private final OnAddFilter onAddFilter; @@ -31,7 +29,7 @@ public class KubernetesDependentResourceConfig { public KubernetesDependentResourceConfig() { this(Constants.SAME_AS_CONTROLLER_NAMESPACES_SET, NO_VALUE_SET, true, DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA, - null, null, null, + null, null, null, null, null); } @@ -39,7 +37,6 @@ public KubernetesDependentResourceConfig(Set namespaces, String labelSelector, boolean configuredNS, boolean createResourceOnlyIfNotExistingWithSSA, - ResourceDiscriminator resourceDiscriminator, Boolean useSSA, OnAddFilter onAddFilter, OnUpdateFilter onUpdateFilter, @@ -52,7 +49,6 @@ public KubernetesDependentResourceConfig(Set namespaces, this.onUpdateFilter = onUpdateFilter; this.onDeleteFilter = onDeleteFilter; this.genericFilter = genericFilter; - this.resourceDiscriminator = resourceDiscriminator; this.useSSA = useSSA; } @@ -60,7 +56,7 @@ public KubernetesDependentResourceConfig(Set namespaces, @Deprecated(forRemoval = true) public KubernetesDependentResourceConfig(Set namespaces, String labelSelector) { this(namespaces, labelSelector, true, DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA, - null, null, null, + null, null, null, null, null); } @@ -104,11 +100,6 @@ public GenericFilter genericFilter() { return genericFilter; } - @SuppressWarnings("rawtypes") - public ResourceDiscriminator getResourceDiscriminator() { - return resourceDiscriminator; - } - @SuppressWarnings("unused") protected void setNamespaces(Set namespaces) { if (!wereNamespacesConfigured() && namespaces != null && !namespaces.isEmpty()) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java index a18d8b8a41..854ec7a56f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java @@ -3,7 +3,6 @@ import java.util.Set; import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; @@ -14,7 +13,6 @@ public final class KubernetesDependentResourceConfigBuilder { private Set namespaces = Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; private String labelSelector; private boolean createResourceOnlyIfNotExistingWithSSA; - private ResourceDiscriminator resourceDiscriminator; private Boolean useSSA; private OnAddFilter onAddFilter; private OnUpdateFilter onUpdateFilter; @@ -43,12 +41,6 @@ public KubernetesDependentResourceConfigBuilder withCreateResourceOnlyIfNotEx return this; } - public KubernetesDependentResourceConfigBuilder withResourceDiscriminator( - ResourceDiscriminator resourceDiscriminator) { - this.resourceDiscriminator = resourceDiscriminator; - return this; - } - public KubernetesDependentResourceConfigBuilder withUseSSA(Boolean useSSA) { this.useSSA = useSSA; return this; @@ -80,7 +72,7 @@ public KubernetesDependentResourceConfigBuilder withGenericFilter( public KubernetesDependentResourceConfig build() { return new KubernetesDependentResourceConfig<>(namespaces, labelSelector, namespaces != Constants.SAME_AS_CONTROLLER_NAMESPACES_SET, - createResourceOnlyIfNotExistingWithSSA, resourceDiscriminator, useSSA, onAddFilter, + createResourceOnlyIfNotExistingWithSSA, useSSA, onAddFilter, onUpdateFilter, onDeleteFilter, genericFilter); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/IndexDiscriminatorIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/IndexDiscriminatorIT.java deleted file mode 100644 index fe5b63de8a..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/IndexDiscriminatorIT.java +++ /dev/null @@ -1,77 +0,0 @@ -package io.javaoperatorsdk.operator; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.indexdiscriminator.IndexDiscriminatorTestCustomResource; -import io.javaoperatorsdk.operator.sample.indexdiscriminator.IndexDiscriminatorTestReconciler; -import io.javaoperatorsdk.operator.sample.indexdiscriminator.IndexDiscriminatorTestSpec; - -import static io.javaoperatorsdk.operator.sample.indexdiscriminator.IndexDiscriminatorTestDRConfigMap.DATA_KEY; -import static io.javaoperatorsdk.operator.sample.indexdiscriminator.IndexDiscriminatorTestReconciler.FIRST_CONFIG_MAP_SUFFIX_1; -import static io.javaoperatorsdk.operator.sample.indexdiscriminator.IndexDiscriminatorTestReconciler.FIRST_CONFIG_MAP_SUFFIX_2; -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; - -class IndexDiscriminatorIT { - - public static final String TEST_RESOURCE_1 = "test1"; - public static final String CHANGED_SPEC_VALUE = "otherValue"; - @RegisterExtension - LocallyRunOperatorExtension operator = - LocallyRunOperatorExtension.builder().withReconciler(IndexDiscriminatorTestReconciler.class) - .build(); - - @Test - void resourcesFoundAndReconciled() { - var res = operator.create(createTestCustomResource()); - var reconciler = operator.getReconcilerOfType(IndexDiscriminatorTestReconciler.class); - - await().untilAsserted(() -> { - assertThat(reconciler.getNumberOfExecutions()).isEqualTo(1); - assertThat(operator.get(ConfigMap.class, TEST_RESOURCE_1 + FIRST_CONFIG_MAP_SUFFIX_1)) - .isNotNull(); - assertThat(operator.get(ConfigMap.class, TEST_RESOURCE_1 + FIRST_CONFIG_MAP_SUFFIX_2)) - .isNotNull(); - }); - - res.getSpec().setValue(CHANGED_SPEC_VALUE); - res = operator.replace(res); - - await().untilAsserted(() -> { - assertThat(reconciler.getNumberOfExecutions()).isEqualTo(2); - var cm1 = operator.get(ConfigMap.class, TEST_RESOURCE_1 + FIRST_CONFIG_MAP_SUFFIX_1); - var cm2 = operator.get(ConfigMap.class, TEST_RESOURCE_1 + FIRST_CONFIG_MAP_SUFFIX_2); - assertThat(cm1).isNotNull(); - assertThat(cm2).isNotNull(); - assertThat(cm1.getData().get(DATA_KEY)).isEqualTo(CHANGED_SPEC_VALUE); - assertThat(cm2.getData().get(DATA_KEY)).isEqualTo(CHANGED_SPEC_VALUE); - }); - - operator.delete(res); - - await().untilAsserted(() -> { - var cm1 = operator.get(ConfigMap.class, TEST_RESOURCE_1 + FIRST_CONFIG_MAP_SUFFIX_1); - var cm2 = operator.get(ConfigMap.class, TEST_RESOURCE_1 + FIRST_CONFIG_MAP_SUFFIX_2); - assertThat(cm1).isNull(); - assertThat(cm2).isNull(); - }); - } - - public IndexDiscriminatorTestCustomResource createTestCustomResource() { - IndexDiscriminatorTestCustomResource resource = - new IndexDiscriminatorTestCustomResource(); - resource.setMetadata( - new ObjectMetaBuilder() - .withName(TEST_RESOURCE_1) - .withNamespace(operator.getNamespace()) - .build()); - resource.setSpec(new IndexDiscriminatorTestSpec()); - resource.getSpec().setValue("default"); - return resource; - } - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstService.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstService.java index b6b0513254..f568ce08e5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstService.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstService.java @@ -1,9 +1,8 @@ package io.javaoperatorsdk.operator.sample.complexdependent.dependent; -import io.fabric8.kubernetes.api.model.Service; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(resourceDiscriminator = FirstService.Discriminator.class) +@KubernetesDependent public class FirstService extends BaseService { public static final String DISCRIMINATOR_PREFIX = "first"; @@ -11,10 +10,4 @@ public FirstService() { super(DISCRIMINATOR_PREFIX); } - public static class Discriminator extends NamePrefixResourceDiscriminator { - protected Discriminator() { - super(DISCRIMINATOR_PREFIX); - } - } - } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstStatefulSet.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstStatefulSet.java index f50b94fe5f..d5740616b2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstStatefulSet.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstStatefulSet.java @@ -1,9 +1,8 @@ package io.javaoperatorsdk.operator.sample.complexdependent.dependent; -import io.fabric8.kubernetes.api.model.apps.StatefulSet; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(resourceDiscriminator = FirstStatefulSet.Discriminator.class) +@KubernetesDependent public class FirstStatefulSet extends BaseStatefulSet { public static final String DISCRIMINATOR_PREFIX = "first"; @@ -12,11 +11,4 @@ public FirstStatefulSet() { super(DISCRIMINATOR_PREFIX); } - - public static class Discriminator extends NamePrefixResourceDiscriminator { - protected Discriminator() { - super(DISCRIMINATOR_PREFIX); - } - } - } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/NamePrefixResourceDiscriminator.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/NamePrefixResourceDiscriminator.java deleted file mode 100644 index eef8566c78..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/NamePrefixResourceDiscriminator.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.javaoperatorsdk.operator.sample.complexdependent.dependent; - -import java.util.Optional; -import java.util.stream.Collectors; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; -import io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentCustomResource; - -public abstract class NamePrefixResourceDiscriminator - implements ResourceDiscriminator { - - private final String prefix; - - protected NamePrefixResourceDiscriminator(String prefix) { - this.prefix = prefix; - } - - @Override - public Optional distinguish(Class resource, ComplexDependentCustomResource primary, - Context context) { - var resources = context.getSecondaryResources(resource); - var filtered = resources.stream().filter(r -> r.getMetadata().getName().startsWith(prefix)) - .collect(Collectors.toList()); - if (filtered.size() > 1) { - throw new IllegalStateException("More resources than expected for" + primary); - } - return filtered.isEmpty() ? Optional.empty() : Optional.of(filtered.get(0)); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondService.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondService.java index c939d1c2e6..ee6f5210d0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondService.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondService.java @@ -1,9 +1,8 @@ package io.javaoperatorsdk.operator.sample.complexdependent.dependent; -import io.fabric8.kubernetes.api.model.Service; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(resourceDiscriminator = SecondService.Discriminator.class) +@KubernetesDependent() public class SecondService extends BaseService { public static final String DISCRIMINATOR_PREFIX = "second"; @@ -11,10 +10,4 @@ public class SecondService extends BaseService { public SecondService() { super(DISCRIMINATOR_PREFIX); } - - public static class Discriminator extends NamePrefixResourceDiscriminator { - protected Discriminator() { - super(DISCRIMINATOR_PREFIX); - } - } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondStatefulSet.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondStatefulSet.java index 7a07682c57..3786d90c00 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondStatefulSet.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondStatefulSet.java @@ -1,9 +1,8 @@ package io.javaoperatorsdk.operator.sample.complexdependent.dependent; -import io.fabric8.kubernetes.api.model.apps.StatefulSet; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(resourceDiscriminator = SecondStatefulSet.Discriminator.class) +@KubernetesDependent public class SecondStatefulSet extends BaseStatefulSet { public static final String DISCRIMINATOR_PREFIX = "second"; @@ -12,9 +11,4 @@ public SecondStatefulSet() { super(DISCRIMINATOR_PREFIX); } - public static class Discriminator extends NamePrefixResourceDiscriminator { - protected Discriminator() { - super(DISCRIMINATOR_PREFIX); - } - } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestCustomResource.java deleted file mode 100644 index 729b1d80eb..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestCustomResource.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.javaoperatorsdk.operator.sample.indexdiscriminator; - -import io.fabric8.kubernetes.api.model.Namespaced; -import io.fabric8.kubernetes.client.CustomResource; -import io.fabric8.kubernetes.model.annotation.Group; -import io.fabric8.kubernetes.model.annotation.ShortNames; -import io.fabric8.kubernetes.model.annotation.Version; - -@Group("sample.javaoperatorsdk") -@Version("v1") -@ShortNames("idt") -public class IndexDiscriminatorTestCustomResource - extends CustomResource - implements Namespaced { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestDRConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestDRConfigMap.java deleted file mode 100644 index 88dc40f55c..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestDRConfigMap.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.javaoperatorsdk.operator.sample.indexdiscriminator; - -import java.util.HashMap; -import java.util.Map; - -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.ConfigMapBuilder; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; - -@KubernetesDependent -public class IndexDiscriminatorTestDRConfigMap - extends CRUDNoGCKubernetesDependentResource { - - public static final String DATA_KEY = "key"; - private final String suffix; - - public IndexDiscriminatorTestDRConfigMap(String value) { - super(ConfigMap.class); - this.suffix = value; - } - - @Override - protected ConfigMap desired(IndexDiscriminatorTestCustomResource primary, - Context context) { - Map data = new HashMap<>(); - data.put(DATA_KEY, primary.getSpec().getValue()); - - return new ConfigMapBuilder() - .withNewMetadata() - .withName(primary.getMetadata().getName() + suffix) - .withNamespace(primary.getMetadata().getNamespace()) - .endMetadata() - .withData(data) - .build(); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestReconciler.java deleted file mode 100644 index 927f7e8efd..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestReconciler.java +++ /dev/null @@ -1,104 +0,0 @@ -package io.javaoperatorsdk.operator.sample.indexdiscriminator; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.*; -import io.javaoperatorsdk.operator.processing.event.source.EventSource; -import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; -import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; - -@ControllerConfiguration -public class IndexDiscriminatorTestReconciler - implements Reconciler, - Cleaner, - TestExecutionInfoProvider { - - public static final String FIRST_CONFIG_MAP_SUFFIX_1 = "-1"; - public static final String FIRST_CONFIG_MAP_SUFFIX_2 = "-2"; - public static final String CONFIG_MAP_INDEX_1 = "CONFIG_MAP_INDEX1"; - public static final String CONFIG_MAP_INDEX_2 = "CONFIG_MAP_INDEX2"; - - private final AtomicInteger numberOfExecutions = new AtomicInteger(0); - - private final IndexDiscriminatorTestDRConfigMap firstDependentResourceConfigMap; - private final IndexDiscriminatorTestDRConfigMap secondDependentResourceConfigMap; - - public IndexDiscriminatorTestReconciler() { - firstDependentResourceConfigMap = - new IndexDiscriminatorTestDRConfigMap(FIRST_CONFIG_MAP_SUFFIX_1); - secondDependentResourceConfigMap = - new IndexDiscriminatorTestDRConfigMap(FIRST_CONFIG_MAP_SUFFIX_2); - } - - @Override - public UpdateControl reconcile( - IndexDiscriminatorTestCustomResource resource, - Context context) { - numberOfExecutions.getAndIncrement(); - firstDependentResourceConfigMap.reconcile(resource, context); - secondDependentResourceConfigMap.reconcile(resource, context); - return UpdateControl.noUpdate(); - } - - public int getNumberOfExecutions() { - return numberOfExecutions.get(); - } - - @Override - public Map prepareEventSources( - EventSourceContext context) { - - InformerEventSource eventSource = - new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) - .build(), context); - - eventSource.addIndexer(CONFIG_MAP_INDEX_1, cm -> { - if (cm.getMetadata().getName().endsWith(FIRST_CONFIG_MAP_SUFFIX_1)) { - return List.of(configMapKey(cm)); - } else { - return Collections.emptyList(); - } - }); - eventSource.addIndexer(CONFIG_MAP_INDEX_2, cm -> { - if (cm.getMetadata().getName().endsWith(FIRST_CONFIG_MAP_SUFFIX_2)) { - return List.of(configMapKey(cm)); - } else { - return Collections.emptyList(); - } - }); - - firstDependentResourceConfigMap.configureWith(eventSource); - secondDependentResourceConfigMap.configureWith(eventSource); - - firstDependentResourceConfigMap - .setResourceDiscriminator( - new TestIndexDiscriminator(CONFIG_MAP_INDEX_1, FIRST_CONFIG_MAP_SUFFIX_1)); - secondDependentResourceConfigMap - .setResourceDiscriminator( - new TestIndexDiscriminator(CONFIG_MAP_INDEX_2, FIRST_CONFIG_MAP_SUFFIX_2)); - return EventSourceUtils.nameEventSources(eventSource); - } - - public static String configMapKey(ConfigMap configMap) { - return configMap.getMetadata().getName() + "#" + configMap.getMetadata().getNamespace(); - } - - public static String configMapKeyFromPrimary(IndexDiscriminatorTestCustomResource primary, - String nameSuffix) { - return primary.getMetadata().getName() + nameSuffix + "#" - + primary.getMetadata().getNamespace(); - } - - @Override - public DeleteControl cleanup(IndexDiscriminatorTestCustomResource resource, - Context context) { - firstDependentResourceConfigMap.delete(resource, context); - secondDependentResourceConfigMap.delete(resource, context); - return DeleteControl.defaultDelete(); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestSpec.java deleted file mode 100644 index fcedd48abe..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestSpec.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.javaoperatorsdk.operator.sample.indexdiscriminator; - -public class IndexDiscriminatorTestSpec { - - private String value; - - public String getValue() { - return value; - } - - public IndexDiscriminatorTestSpec setValue(String value) { - this.value = value; - return this; - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestStatus.java deleted file mode 100644 index d31c86e8de..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/IndexDiscriminatorTestStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.indexdiscriminator; - -public class IndexDiscriminatorTestStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/TestIndexDiscriminator.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/TestIndexDiscriminator.java deleted file mode 100644 index a56e44ced8..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/indexdiscriminator/TestIndexDiscriminator.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.javaoperatorsdk.operator.sample.indexdiscriminator; - -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.reconciler.IndexDiscriminator; - -import static io.javaoperatorsdk.operator.sample.indexdiscriminator.IndexDiscriminatorTestReconciler.configMapKeyFromPrimary; - -public class TestIndexDiscriminator - extends IndexDiscriminator { - - public TestIndexDiscriminator(String indexName, String nameSuffix) { - super(indexName, p -> configMapKeyFromPrimary(p, nameSuffix)); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java index aae9d23cc7..f82d178bcb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java @@ -6,7 +6,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; -import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @@ -26,17 +25,6 @@ public class MultipleDependentResourceWithDiscriminatorReconciler public MultipleDependentResourceWithDiscriminatorReconciler() { firstDependentResourceConfigMap = new MultipleDependentResourceConfigMap(FIRST_CONFIG_MAP_ID); secondDependentResourceConfigMap = new MultipleDependentResourceConfigMap(SECOND_CONFIG_MAP_ID); - - firstDependentResourceConfigMap - .setResourceDiscriminator( - new ResourceIDMatcherDiscriminator<>( - p -> new ResourceID(p.getConfigMapName(FIRST_CONFIG_MAP_ID), - p.getMetadata().getNamespace()))); - secondDependentResourceConfigMap - .setResourceDiscriminator( - new ResourceIDMatcherDiscriminator<>( - p -> new ResourceID(p.getConfigMapName(SECOND_CONFIG_MAP_ID), - p.getMetadata().getNamespace()))); } @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/ConfigMap1MultiInformerDiscriminator.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/ConfigMap1MultiInformerDiscriminator.java deleted file mode 100644 index 32cf830bc1..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/ConfigMap1MultiInformerDiscriminator.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer; - -import java.util.Optional; - -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; -import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; - -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceConfigMap1.NAME_SUFFIX; - -public class ConfigMap1MultiInformerDiscriminator - implements - ResourceDiscriminator { - @Override - public Optional distinguish(Class resource, - MultipleManagedDependentResourceMultiInformerCustomResource primary, - Context context) { - InformerEventSource ies = - (InformerEventSource) context - .eventSourceRetriever().getResourceEventSourceFor(ConfigMap.class, - MultipleManagedDependentResourceMultiInformerReconciler.CONFIG_MAP_1_DR); - - return ies.get(new ResourceID(primary.getMetadata().getName() + NAME_SUFFIX, - primary.getMetadata().getNamespace())); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/ConfigMap2MultiInformerDiscriminator.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/ConfigMap2MultiInformerDiscriminator.java deleted file mode 100644 index cc6a0a656e..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/ConfigMap2MultiInformerDiscriminator.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer; - -import java.util.Optional; - -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; -import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; - -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceConfigMap2.NAME_SUFFIX; - -public class ConfigMap2MultiInformerDiscriminator - implements - ResourceDiscriminator { - @Override - public Optional distinguish(Class resource, - MultipleManagedDependentResourceMultiInformerCustomResource primary, - Context context) { - InformerEventSource ies = - (InformerEventSource) context - .eventSourceRetriever().getResourceEventSourceFor(ConfigMap.class, - MultipleManagedDependentResourceMultiInformerReconciler.CONFIG_MAP_2_DR); - - return ies.get(new ResourceID(primary.getMetadata().getName() + NAME_SUFFIX, - primary.getMetadata().getNamespace())); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java index 2a63b7267e..510ea37075 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java @@ -10,7 +10,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler; -@KubernetesDependent(resourceDiscriminator = ConfigMap1MultiInformerDiscriminator.class) +@KubernetesDependent public class MultipleManagedDependentResourceMultiInformerConfigMap1 extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java index 8db20cac14..2d27e162a7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java @@ -11,7 +11,7 @@ import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; -@KubernetesDependent(resourceDiscriminator = ConfigMap2MultiInformerDiscriminator.class) +@KubernetesDependent public class MultipleManagedDependentResourceMultiInformerConfigMap2 extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/ConfigMap1Discriminator.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/ConfigMap1Discriminator.java deleted file mode 100644 index cc20dfa45e..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/ConfigMap1Discriminator.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype; - -import java.util.Optional; - -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; -import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; - -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceConfigMap1.NAME_SUFFIX; - -public class ConfigMap1Discriminator - implements ResourceDiscriminator { - @Override - public Optional distinguish(Class resource, - MultipleManagedDependentResourceCustomResource primary, - Context context) { - InformerEventSource ies = - (InformerEventSource) context - .eventSourceRetriever().getResourceEventSourceFor(ConfigMap.class); - - return ies.get(new ResourceID(primary.getMetadata().getName() + NAME_SUFFIX, - primary.getMetadata().getNamespace())); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/ConfigMap2Discriminator.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/ConfigMap2Discriminator.java deleted file mode 100644 index 8bda6afcee..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/ConfigMap2Discriminator.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype; - -import java.util.Optional; - -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; -import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; - -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceConfigMap2.NAME_SUFFIX; - -public class ConfigMap2Discriminator - implements ResourceDiscriminator { - @Override - public Optional distinguish(Class resource, - MultipleManagedDependentResourceCustomResource primary, - Context context) { - InformerEventSource ies = - (InformerEventSource) context - .eventSourceRetriever().getResourceEventSourceFor(ConfigMap.class); - - return ies.get(new ResourceID(primary.getMetadata().getName() + NAME_SUFFIX, - primary.getMetadata().getNamespace())); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java index 98f8033076..8fe7cf5330 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java @@ -9,7 +9,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(resourceDiscriminator = ConfigMap1Discriminator.class) +@KubernetesDependent public class MultipleManagedDependentResourceConfigMap1 extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java index d4cdd4170f..b76f108d6b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java @@ -11,7 +11,7 @@ import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; -@KubernetesDependent(resourceDiscriminator = ConfigMap2Discriminator.class) +@KubernetesDependent public class MultipleManagedDependentResourceConfigMap2 extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource1.java index cfe67a3796..4dee39e8e6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource1.java @@ -4,10 +4,6 @@ public class ExternalDependentResource1 extends AbstractExternalDependentResourc public static final String SUFFIX = "-1"; - public ExternalDependentResource1() { - setResourceDiscriminator(new ExternalResourceDiscriminator(SUFFIX)); - } - @Override protected String resourceIDSuffix() { return SUFFIX; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource2.java index 29bb237e1a..b37aa65bdf 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource2.java @@ -4,10 +4,6 @@ public class ExternalDependentResource2 extends AbstractExternalDependentResourc public static final String SUFFIX = "-2"; - public ExternalDependentResource2() { - setResourceDiscriminator(new ExternalResourceDiscriminator(SUFFIX)); - } - @Override protected String resourceIDSuffix() { return SUFFIX; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalResourceDiscriminator.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalResourceDiscriminator.java deleted file mode 100644 index 5a394113c1..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalResourceDiscriminator.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype; - -import java.util.Optional; - -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; -import io.javaoperatorsdk.operator.support.ExternalResource; - -public class ExternalResourceDiscriminator implements - ResourceDiscriminator { - - private final String suffix; - - public ExternalResourceDiscriminator(String suffix) { - this.suffix = suffix; - } - - @Override - public Optional distinguish(Class resource, - MultipleManagedExternalDependentResourceCustomResource primary, - Context context) { - var resources = context.getSecondaryResources(ExternalResource.class); - return resources.stream().filter(r -> r.getId().endsWith(suffix)).findFirst(); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java index bf8d60d9c4..14530cf17e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java @@ -6,14 +6,11 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ResourceIDMatcherDiscriminator; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import io.javaoperatorsdk.operator.processing.event.ResourceID; -@KubernetesDependent(labelSelector = "dependent = cm1", - resourceDiscriminator = ConfigMapDependentResource1.CM1ResourceDiscriminator.class) +@KubernetesDependent(labelSelector = "dependent = cm1") public class ConfigMapDependentResource1 extends CRUDKubernetesDependentResource { @@ -45,11 +42,4 @@ protected ConfigMap desired(OrderedManagedDependentCustomResource primary, return configMap; } - public static class CM1ResourceDiscriminator - extends ResourceIDMatcherDiscriminator { - public CM1ResourceDiscriminator() { - super(p -> new ResourceID(p.getMetadata().getName() + "1", p.getMetadata().getNamespace())); - } - } - } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java index 2b17d615b9..35ae69586e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java @@ -6,14 +6,11 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ResourceIDMatcherDiscriminator; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import io.javaoperatorsdk.operator.processing.event.ResourceID; -@KubernetesDependent(labelSelector = "dependent = cm2", - resourceDiscriminator = ConfigMapDependentResource2.CM2ResourceDiscriminator.class) +@KubernetesDependent(labelSelector = "dependent = cm2") public class ConfigMapDependentResource2 extends CRUDKubernetesDependentResource { @@ -45,11 +42,4 @@ protected ConfigMap desired(OrderedManagedDependentCustomResource primary, return configMap; } - public static class CM2ResourceDiscriminator - extends ResourceIDMatcherDiscriminator { - public CM2ResourceDiscriminator() { - super(p -> new ResourceID(p.getMetadata().getName() + "2", p.getMetadata().getNamespace())); - } - } - } From 2bd34def6b73e36f6ba24d1921350e9638a4e1c7 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Tue, 26 Mar 2024 15:57:54 +0100 Subject: [PATCH 27/96] refactor: remove deprecated getTerminationTimeoutSeconds and associated (#2297) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chris Laprun Signed-off-by: Attila Mészáros --- docs/documentation/v5-0-migration.md | 13 +++++++++---- .../io/javaoperatorsdk/operator/Operator.java | 12 +----------- .../api/config/ConfigurationService.java | 16 ---------------- .../config/ConfigurationServiceOverrider.java | 11 ----------- .../ConfigurationServiceOverriderTest.java | 3 --- 5 files changed, 10 insertions(+), 45 deletions(-) diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index 01b483449e..92ddaaa8b8 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -18,13 +18,18 @@ permalink: /docs/v5-0-migration now contains all the utility methods used for event sources naming that were previously defined in the `EventSourceInitializer` interface. 3. Patching status through `UpdateControl` like the `patchStatus` method now by default - uses Server Side Apply instead of simple patch. To use the former approach, use the feature flag + uses Server Side Apply instead of simple patch. To use the former approach, use the feature flag in [`ConfigurationService`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L400-L400) !!! IMPORTANT !!! - Migration from a non-SSA based controller to SSA based controller can cause problems, due to known issues. - See the following [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L71-L82) where it is demonstrated. - Also, the related part of a [workaround](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L110-L116). + Migration from a non-SSA based controller to SSA based controller can cause problems, due to known issues. + See the + following [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L71-L82) + where it is demonstrated. Also, the related part of + a [workaround](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L110-L116). 4. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. 5. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should work without it by default. To optimize and handle special cases see the relevant section in [Dependent Resource documentation](/docs/dependent-resources#multiple-dependent-resources-of-same-type). +6. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed, + use `Operator.stop(Duration)` instead. +7. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java index 3fc01e1f64..d3f2f57c6d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java @@ -98,17 +98,6 @@ private static ConfigurationService initConfigurationService(KubernetesClient cl return ConfigurationService.newOverriddenConfigurationService(overrider); } - /** - * Uses {@link ConfigurationService#getTerminationTimeoutSeconds()} for graceful shutdown timeout - * - * @deprecated use the overloaded version with graceful shutdown timeout parameter. - * - */ - @Deprecated(forRemoval = true) - public void installShutdownHook() { - installShutdownHook(Duration.ofSeconds(configurationService.getTerminationTimeoutSeconds())); - } - /** * Adds a shutdown hook that automatically calls {@link #stop()} when the app shuts down. Note * that graceful shutdown is usually not needed, but some {@link Reconciler} implementations might @@ -120,6 +109,7 @@ public void installShutdownHook() { * @param gracefulShutdownTimeout timeout to wait for executor threads to complete actual * reconciliations */ + @SuppressWarnings("unused") public void installShutdownHook(Duration gracefulShutdownTimeout) { if (!leaderElectionManager.isLeaderElectionEnabled()) { Runtime.getRuntime().addShutdownHook(new Thread(() -> stop(gracefulShutdownTimeout))); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index 1bebfe4ade..7bbbdcf45a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -185,22 +185,6 @@ default int minConcurrentWorkflowExecutorThreads() { return MIN_DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER; } - int DEFAULT_TERMINATION_TIMEOUT_SECONDS = 10; - - /** - * Retrieves the number of seconds the SDK waits for reconciliation threads to terminate before - * shutting down. - * - * @deprecated use {@link io.javaoperatorsdk.operator.Operator#stop(Duration)} instead. Where the - * parameter can be passed to specify graceful timeout. - * - * @return the number of seconds to wait before terminating reconciliation threads - */ - @Deprecated(forRemoval = true) - default int getTerminationTimeoutSeconds() { - return DEFAULT_TERMINATION_TIMEOUT_SECONDS; - } - default Metrics getMetrics() { return Metrics.NOOP; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java index f75284a3cf..d4362df615 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java @@ -27,7 +27,6 @@ public class ConfigurationServiceOverrider { private Integer concurrentWorkflowExecutorThreads; private Integer minConcurrentWorkflowExecutorThreads; private Cloner cloner; - private Integer timeoutSeconds; private Boolean closeClientOnStop; private KubernetesClient client; private ExecutorService executorService; @@ -94,11 +93,6 @@ public ConfigurationServiceOverrider withResourceCloner(Cloner cloner) { return this; } - public ConfigurationServiceOverrider withTerminationTimeoutSeconds(int timeoutSeconds) { - this.timeoutSeconds = timeoutSeconds; - return this; - } - public ConfigurationServiceOverrider withMetrics(Metrics metrics) { this.metrics = metrics; return this; @@ -268,11 +262,6 @@ public int minConcurrentWorkflowExecutorThreads() { : original.minConcurrentWorkflowExecutorThreads(); } - @Override - public int getTerminationTimeoutSeconds() { - return timeoutSeconds != null ? timeoutSeconds : original.getTerminationTimeoutSeconds(); - } - @Override public Metrics getMetrics() { return metrics != null ? metrics : original.getMetrics(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java index 7a4a5793ba..2d8444af68 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java @@ -60,7 +60,6 @@ public R clone(R object) { } }) .withConcurrentReconciliationThreads(25) - .withTerminationTimeoutSeconds(100) .withMetrics(new Metrics() {}) .withLeaderElectionConfiguration(new LeaderElectionConfiguration("newLease", "newLeaseNS")) .withInformerStoppedHandler((informer, ex) -> { @@ -72,8 +71,6 @@ public R clone(R object) { overridden.checkCRDAndValidateLocalModel()); assertNotEquals(config.concurrentReconciliationThreads(), overridden.concurrentReconciliationThreads()); - assertNotEquals(config.getTerminationTimeoutSeconds(), - overridden.getTerminationTimeoutSeconds()); assertNotEquals(config.getExecutorService(), overridden.getExecutorService()); assertNotEquals(config.getWorkflowExecutorService(), overridden.getWorkflowExecutorService()); assertNotEquals(config.getMetrics(), overridden.getMetrics()); From 26e9d847447b0f4671e7d2b27f54272dcd732ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 27 Mar 2024 13:13:46 +0100 Subject: [PATCH 28/96] improve: additional logging to mysql schema e2e test (#2320) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- sample-operators/leader-election/pom.xml | 6 ++++++ sample-operators/mysql-schema/pom.xml | 5 +++++ .../sample/dependent/SchemaDependentResource.java | 11 ++++++++--- .../operator/sample/schema/Schema.java | 10 +++++++++- sample-operators/tomcat-operator/pom.xml | 5 +++++ sample-operators/webpage/pom.xml | 5 +++++ 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/sample-operators/leader-election/pom.xml b/sample-operators/leader-election/pom.xml index 3a1b0a48a3..bcbc4fbcff 100644 --- a/sample-operators/leader-election/pom.xml +++ b/sample-operators/leader-election/pom.xml @@ -33,6 +33,12 @@ org.apache.logging.log4j log4j-slf4j-impl + compile + + + org.apache.logging.log4j + log4j-core + compile org.takes diff --git a/sample-operators/mysql-schema/pom.xml b/sample-operators/mysql-schema/pom.xml index 554a937f2c..dedb681116 100644 --- a/sample-operators/mysql-schema/pom.xml +++ b/sample-operators/mysql-schema/pom.xml @@ -53,6 +53,11 @@ org.apache.logging.log4j log4j-slf4j-impl + + org.apache.logging.log4j + log4j-core + compile + org.junit.jupiter junit-jupiter-api diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java index 77d8932e58..476898af00 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java @@ -30,7 +30,7 @@ import static io.javaoperatorsdk.operator.sample.dependent.SecretDependentResource.MYSQL_SECRET_USERNAME; import static java.lang.String.format; -@SchemaConfig(pollPeriod = 700, host = "127.0.0.1", +@SchemaConfig(pollPeriod = 400, host = "127.0.0.1", port = SchemaDependentResource.LOCAL_PORT, user = "root", password = "password") // NOSONAR: password is only used locally, example only @Configured(by = SchemaConfig.class, with = ResourcePollerConfig.class, @@ -63,7 +63,9 @@ public void configureWith(ResourcePollerConfig config) { @Override public Schema desired(MySQLSchema primary, Context context) { - return new Schema(primary.getMetadata().getName(), primary.getSpec().getEncoding()); + var desired = new Schema(primary.getMetadata().getName(), primary.getSpec().getEncoding()); + log.debug("Desired schema: {}", desired); + return desired; } @Override @@ -72,6 +74,7 @@ public Schema create(Schema target, MySQLSchema mySQLSchema, Context fetchResources(MySQLSchema primaryResource) { try (Connection connection = getConnection()) { - return SchemaService.getSchema(connection, primaryResource.getMetadata().getName()) + var schema = SchemaService.getSchema(connection, primaryResource.getMetadata().getName()) .map(Set::of).orElseGet(Collections::emptySet); + log.debug("Fetched schema: {}", schema); + return schema; } catch (SQLException e) { throw new RuntimeException("Error while trying read Schema", e); } diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/schema/Schema.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/schema/Schema.java index 34c1e54255..87fb88e9a4 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/schema/Schema.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/schema/Schema.java @@ -28,11 +28,19 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; Schema schema = (Schema) o; - return Objects.equals(name, schema.name) && Objects.equals(characterSet, schema.characterSet); + return Objects.equals(name, schema.name); } @Override public int hashCode() { return Objects.hash(name, characterSet); } + + @Override + public String toString() { + return "Schema{" + + "name='" + name + '\'' + + ", characterSet='" + characterSet + '\'' + + '}'; + } } diff --git a/sample-operators/tomcat-operator/pom.xml b/sample-operators/tomcat-operator/pom.xml index 5e04d9c88c..158133160d 100644 --- a/sample-operators/tomcat-operator/pom.xml +++ b/sample-operators/tomcat-operator/pom.xml @@ -49,6 +49,11 @@ org.apache.logging.log4j log4j-slf4j-impl + + org.apache.logging.log4j + log4j-core + compile + org.takes takes diff --git a/sample-operators/webpage/pom.xml b/sample-operators/webpage/pom.xml index ad961b8393..5470ece6d3 100644 --- a/sample-operators/webpage/pom.xml +++ b/sample-operators/webpage/pom.xml @@ -34,6 +34,11 @@ org.apache.logging.log4j log4j-slf4j-impl + + org.apache.logging.log4j + log4j-core + compile + org.takes takes From ab49b79db78b7799d6b8c4d6e924fcc851506165 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Wed, 27 Mar 2024 18:20:48 +0100 Subject: [PATCH 29/96] feat: handle clustered resource on secondary to primary mapper init (#2321) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2311 Overriding getPrimaryResourceType should allow to make things work even in deeper hierarchies. Signed-off-by: Chris Laprun Signed-off-by: Attila Mészáros --- .../operator/api/config/Utils.java | 37 +++++++++++-------- .../GenericKubernetesDependentResource.java | 9 ++++- .../KubernetesDependentResource.java | 25 ++++++++++--- .../AbstractWorkflowExecutorTest.java | 5 +++ ...ConfigMapDeleterBulkDependentResource.java | 10 +++-- .../dependent/BaseDependentResource.java | 5 +++ 6 files changed, 65 insertions(+), 26 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java index d318560480..ea776f3a6c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java @@ -103,21 +103,22 @@ static boolean getBooleanFromSystemPropsOrDefault(String propertyName, boolean d return defaultValue; } else { property = property.trim().toLowerCase(); - switch (property) { - case "true": - return true; - case "false": - return false; - default: - return defaultValue; - } + return switch (property) { + case "true" -> true; + case "false" -> false; + default -> defaultValue; + }; } } public static Class getFirstTypeArgumentFromExtendedClass(Class clazz) { + return getTypeArgumentFromExtendedClassByIndex(clazz, 0); + } + + public static Class getTypeArgumentFromExtendedClassByIndex(Class clazz, int index) { try { Type type = clazz.getGenericSuperclass(); - return (Class) ((ParameterizedType) type).getActualTypeArguments()[0]; + return (Class) ((ParameterizedType) type).getActualTypeArguments()[index]; } catch (Exception e) { throw new RuntimeException(GENERIC_PARAMETER_TYPE_ERROR_PREFIX + clazz.getSimpleName() @@ -186,27 +187,31 @@ private static Optional> extractType(Class clazz, public static Class getFirstTypeArgumentFromSuperClassOrInterface(Class clazz, Class expectedImplementedInterface) { + return getTypeArgumentFromSuperClassOrInterfaceByIndex(clazz, expectedImplementedInterface, 0); + } + + public static Class getTypeArgumentFromSuperClassOrInterfaceByIndex(Class clazz, + Class expectedImplementedInterface, int index) { // first check super class if it exists try { final Class superclass = clazz.getSuperclass(); if (!superclass.equals(Object.class)) { try { - return getFirstTypeArgumentFromExtendedClass(clazz); + return getTypeArgumentFromExtendedClassByIndex(clazz, index); } catch (Exception e) { // try interfaces try { - return getFirstTypeArgumentFromInterface(clazz, expectedImplementedInterface); + return getTypeArgumentFromInterfaceByIndex(clazz, expectedImplementedInterface, index); } catch (Exception ex) { // try on the parent - return getFirstTypeArgumentFromSuperClassOrInterface(superclass, - expectedImplementedInterface); + return getTypeArgumentFromSuperClassOrInterfaceByIndex(superclass, + expectedImplementedInterface, index); } } } - return getFirstTypeArgumentFromInterface(clazz, expectedImplementedInterface); + return getTypeArgumentFromInterfaceByIndex(clazz, expectedImplementedInterface, index); } catch (Exception e) { - throw new OperatorException( - GENERIC_PARAMETER_TYPE_ERROR_PREFIX + clazz.getSimpleName(), e); + throw new OperatorException(GENERIC_PARAMETER_TYPE_ERROR_PREFIX + clazz.getSimpleName(), e); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java index 266872bd38..591b357f31 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java @@ -2,6 +2,7 @@ import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.processing.GroupVersionKind; @@ -23,8 +24,14 @@ protected InformerConfiguration.InformerConfigurationBuilder getPrimaryResourceType() { + return (Class

) Utils.getFirstTypeArgumentFromExtendedClass(getClass()); + } + @SuppressWarnings("unused") - public GroupVersionKindPlural getGroupVersionKind() { + public GroupVersionKind getGroupVersionKind() { return groupVersionKind; } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 600298c558..3d4693daef 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -9,9 +9,11 @@ import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.dsl.Resource; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.ReconcilerUtils; +import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.config.dependent.Configured; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Constants; @@ -36,8 +38,12 @@ public abstract class KubernetesDependentResource> { private static final Logger log = LoggerFactory.getLogger(KubernetesDependentResource.class); - private final ResourceUpdaterMatcher updaterMatcher; private final boolean garbageCollected = this instanceof GarbageCollected; + @SuppressWarnings("unchecked") + private final ResourceUpdaterMatcher updaterMatcher = this instanceof ResourceUpdaterMatcher + ? (ResourceUpdaterMatcher) this + : GenericResourceUpdaterMatcher.updaterMatcherFor(resourceType()); + private final boolean clustered; private KubernetesDependentResourceConfig kubernetesDependentResourceConfig; private volatile Boolean useSSA; @@ -46,16 +52,23 @@ public KubernetesDependentResource(Class resourceType) { this(resourceType, null); } - @SuppressWarnings("unchecked") public KubernetesDependentResource(Class resourceType, String name) { super(resourceType, name); + final var primaryResourceType = getPrimaryResourceType(); + clustered = !Namespaced.class.isAssignableFrom(primaryResourceType); + } - updaterMatcher = this instanceof ResourceUpdaterMatcher - ? (ResourceUpdaterMatcher) this - : GenericResourceUpdaterMatcher.updaterMatcherFor(resourceType); + protected KubernetesDependentResource(Class resourceType, String name, + boolean primaryIsClustered) { + super(resourceType, name); + clustered = primaryIsClustered; } @SuppressWarnings("unchecked") + protected Class

getPrimaryResourceType() { + return (Class

) Utils.getTypeArgumentFromExtendedClassByIndex(getClass(), 1); + } + @Override public void configureWith(KubernetesDependentResourceConfig config) { this.kubernetesDependentResourceConfig = config; @@ -87,7 +100,7 @@ private SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { if (this instanceof SecondaryToPrimaryMapper) { return (SecondaryToPrimaryMapper) this; } else if (garbageCollected) { - return Mappers.fromOwnerReferences(false); + return Mappers.fromOwnerReferences(clustered); } else if (useNonOwnerRefBasedSecondaryToPrimaryMapping()) { return Mappers.fromDefaultAnnotations(); } else { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java index 219e9af869..adebd635f7 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java @@ -39,6 +39,11 @@ public TestDependent(String name) { super(ConfigMap.class, name); } + @Override + protected Class getPrimaryResourceType() { + return TestCustomResource.class; + } + @Override public ReconcileResult reconcile(TestCustomResource primary, Context context) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java index 29a9af89e7..cb52ebdd05 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java @@ -34,6 +34,11 @@ public ConfigMapDeleterBulkDependentResource() { super(ConfigMap.class); } + @Override + protected Class getPrimaryResourceType() { + return BulkDependentTestCustomResource.class; + } + @Override public Map desiredResources(BulkDependentTestCustomResource primary, Context context) { @@ -41,13 +46,12 @@ public Map desiredResources(BulkDependentTestCustomResource p Map res = new HashMap<>(); for (int i = 0; i < number; i++) { var key = Integer.toString(i); - res.put(key, desired(primary, key, context)); + res.put(key, desired(primary, key)); } return res; } - public ConfigMap desired(BulkDependentTestCustomResource primary, String key, - Context context) { + public ConfigMap desired(BulkDependentTestCustomResource primary, String key) { ConfigMap configMap = new ConfigMap(); configMap.setMetadata(new ObjectMetaBuilder() .withName(primary.getMetadata().getName() + INDEX_DELIMITER + key) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java index 08e7e5fe2e..eee439cbfe 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java @@ -16,6 +16,11 @@ public BaseDependentResource(Class resourceType, String component) { this.component = component; } + @Override + protected Class getPrimaryResourceType() { + return ComplexDependentCustomResource.class; + } + protected String name(ComplexDependentCustomResource primary) { return String.format("%s-%s", component, primary.getSpec().getProjectId()); } From bf7e58e452669b0fd08d0034e5eff0a8674c9058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 8 Apr 2024 15:05:21 +0200 Subject: [PATCH 30/96] feat: using SSA for finalizer and primary patch (#2305) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Attila Mészáros --- docs/documentation/v5-0-migration.md | 18 +- .../api/config/ConfigurationService.java | 11 +- .../config/ConfigurationServiceOverrider.java | 14 +- .../reconciler/ErrorStatusUpdateControl.java | 16 +- .../api/reconciler/UpdateControl.java | 114 +++--------- .../operator/processing/Controller.java | 4 +- .../processing/event/EventProcessor.java | 11 -- .../event/PostExecutionControl.java | 2 +- .../event/ReconciliationDispatcher.java | 174 +++++++++++------- .../processing/event/EventProcessorTest.java | 15 -- .../event/ReconciliationDispatcherTest.java | 165 ++++++++++------- .../sample/simple/TestCustomReconciler.java | 2 +- ...ava => PatchResourceAndStatusNoSSAIT.java} | 38 ++-- .../PatchResourceAndStatusWithSSAIT.java | 13 ++ .../operator/PatchResourceWithSSAIT.java | 15 ++ .../operator/PatchWithSSAITBase.java | 59 ++++++ .../operator/ReconcilerExecutorIT.java | 1 - .../operator/StatusPatchSSAMigrationIT.java | 2 +- .../operator/StatusUpdateLockingIT.java | 22 ++- ...rConfigurationAnnotationProcessorTest.java | 2 +- .../ComplexDependentReconciler.java | 2 +- .../DoubleUpdateTestCustomResourceSpec.java | 15 -- .../DoubleUpdateTestCustomResourceStatus.java | 19 -- .../ErrorStatusHandlerTestReconciler.java | 2 +- ...ResourceAndStatusNoSSACustomResource.java} | 6 +- ...atchResourceAndStatusNoSSAReconciler.java} | 23 +-- .../PatchResourceAndStatusNoSSASpec.java | 15 ++ .../PatchResourceAndStatusNoSSAStatus.java | 19 ++ ...tchResourceAndStatusWithSSAReconciler.java | 37 ++++ .../PatchResourceWithSSACustomResource.java | 16 ++ .../PatchResourceWithSSAReconciler.java | 41 +++++ .../PatchResourceWithSSASpec.java | 23 +++ .../PatchResourceWithSSAStatus.java | 14 ++ .../sample/simple/TestReconciler.java | 26 +-- .../StatusUpdateLockingCustomResource.java | 4 - .../StatusUpdateLockingReconciler.java | 3 +- .../SubResourceTestCustomReconciler.java | 2 +- .../MultilevelReconciler.java | 2 +- .../ReconcilerImplemented2Interfaces.java | 2 +- ...rImplementedIntermediateAbstractClass.java | 2 +- .../sample/LeaderElectionTestReconciler.java | 2 +- .../sample/MySQLSchemaReconciler.java | 2 +- .../operator/sample/Utils.java | 13 +- .../WebPageDependentsWorkflowReconciler.java | 8 +- .../WebPageManagedDependentsReconciler.java | 7 +- .../operator/sample/WebPageReconciler.java | 5 +- .../sample/WebPageOperatorAbstractTest.java | 2 +- 47 files changed, 607 insertions(+), 403 deletions(-) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{UpdatingResAndSubResIT.java => PatchResourceAndStatusNoSSAIT.java} (51%) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusWithSSAIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceWithSSAIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchWithSSAITBase.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResourceSpec.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResourceStatus.java rename operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/{doubleupdate/DoubleUpdateTestCustomResource.java => patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java} (66%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/{doubleupdate/DoubleUpdateTestCustomReconciler.java => patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java} (58%) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSACustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAReconciler.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSASpec.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAStatus.java diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index 92ddaaa8b8..36748ea1dc 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -17,15 +17,21 @@ permalink: /docs/v5-0-migration [`EventSourceUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java#L11-L11) now contains all the utility methods used for event sources naming that were previously defined in the `EventSourceInitializer` interface. -3. Patching status through `UpdateControl` like the `patchStatus` method now by default - uses Server Side Apply instead of simple patch. To use the former approach, use the feature flag - in [`ConfigurationService`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L400-L400) +3. Updates through `UpdateControl` now use [Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/server-side-apply/) by default to add the finalizer and for all + the patch operations in `UpdateControl`. The update operations were removed. If you do not wish to use SSA, you can deactivate the feature using `ConfigurationService.useSSAToPatchPrimaryResource` and related `ConfigurationServiceOverrider.withUseSSAToPatchPrimaryResource`. + !!! IMPORTANT !!! - Migration from a non-SSA based controller to SSA based controller can cause problems, due to known issues. - See the - following [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L71-L82) + + See known issues with migration from non-SSA to SSA based status updates here: + [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L71-L82) where it is demonstrated. Also, the related part of a [workaround](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L110-L116). + + Related automatic observed generation handling changes: + Automated Observed Generation (see features in docs), is automatically handled for non-SSA, even if + the status sub-resource is not instructed to be updated. This is not true for SSA, observed generation is updated + only when patch status is instructed by `UpdateControl`. + 4. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. 5. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index 7bbbdcf45a..83acf0566d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -446,12 +446,15 @@ default boolean parseResourceVersionsForEventFilteringAndCaching() { } /** - * {@link io.javaoperatorsdk.operator.api.reconciler.UpdateControl} patchStatus can either use - * simple update or SSA for status subresource patching. + * {@link io.javaoperatorsdk.operator.api.reconciler.UpdateControl} patch resource or status can + * either use simple patches or SSA. Setting this to {@code true}, controllers will use SSA for + * adding finalizers, managing observed generation, patching resources and status. * - * @return true by default + * @return {@code true} by default + * @since 5.0.0 + * @see ConfigurationServiceOverrider#withUseSSAToPatchPrimaryResource(boolean) */ - default boolean useSSAForResourceStatusPatch() { + default boolean useSSAToPatchPrimaryResource() { return true; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java index d4362df615..7a5c098986 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java @@ -40,7 +40,7 @@ public class ConfigurationServiceOverrider { private Set> defaultNonSSAResource; private Boolean previousAnnotationForDependentResources; private Boolean parseResourceVersions; - private Boolean useSSAForResourceStatusPatch; + private Boolean useSSAToPatchPrimaryResource; @SuppressWarnings("rawtypes") private DependentResourceFactory dependentResourceFactory; @@ -198,8 +198,8 @@ public ConfigurationServiceOverrider wihtParseResourceVersions( return this; } - public ConfigurationServiceOverrider withUseSSAForResourceStatusPatch(boolean value) { - this.useSSAForResourceStatusPatch = value; + public ConfigurationServiceOverrider withUseSSAToPatchPrimaryResource(boolean value) { + this.useSSAToPatchPrimaryResource = value; return this; } @@ -341,10 +341,10 @@ public boolean parseResourceVersionsForEventFilteringAndCaching() { } @Override - public boolean useSSAForResourceStatusPatch() { - return useSSAForResourceStatusPatch != null - ? useSSAForResourceStatusPatch - : super.useSSAForResourceStatusPatch(); + public boolean useSSAToPatchPrimaryResource() { + return useSSAToPatchPrimaryResource != null + ? useSSAToPatchPrimaryResource + : super.useSSAToPatchPrimaryResource(); } }; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusUpdateControl.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusUpdateControl.java index 48c0e32946..7236d5898b 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusUpdateControl.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusUpdateControl.java @@ -9,24 +9,18 @@ public class ErrorStatusUpdateControl

extends BaseControl> { private final P resource; - private final boolean patch; private boolean noRetry = false; public static ErrorStatusUpdateControl patchStatus(T resource) { - return new ErrorStatusUpdateControl<>(resource, true); - } - - public static ErrorStatusUpdateControl updateStatus(T resource) { - return new ErrorStatusUpdateControl<>(resource, false); + return new ErrorStatusUpdateControl<>(resource); } public static ErrorStatusUpdateControl noStatusUpdate() { - return new ErrorStatusUpdateControl<>(null, true); + return new ErrorStatusUpdateControl<>(null); } - private ErrorStatusUpdateControl(P resource, boolean patch) { + private ErrorStatusUpdateControl(P resource) { this.resource = resource; - this.patch = patch; } /** @@ -47,10 +41,6 @@ public boolean isNoRetry() { return noRetry; } - public boolean isPatch() { - return patch; - } - /** * If re-scheduled using this method, it is not considered as retry, it effectively cancels retry. * diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java index 7eb7d2ae84..a8ae1331d7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java @@ -1,51 +1,35 @@ package io.javaoperatorsdk.operator.api.reconciler; +import java.util.Optional; + import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.CustomResource; public class UpdateControl

extends BaseControl> { private final P resource; - private final boolean updateStatus; - private final boolean updateResource; + private final boolean patchResource; private final boolean patchStatus; private UpdateControl( - P resource, boolean updateStatus, boolean updateResource, boolean patchStatus) { - if ((updateResource || updateStatus) && resource == null) { + P resource, boolean patchResource, boolean patchStatus) { + if ((patchResource || patchStatus) && resource == null) { throw new IllegalArgumentException("CustomResource cannot be null in case of update"); } this.resource = resource; - this.updateStatus = updateStatus; - this.updateResource = updateResource; + this.patchResource = patchResource; this.patchStatus = patchStatus; } - /** - * Creates an update control instance that instructs the framework to do an update on resource - * itself, not on the status. Note that usually as a results of a reconciliation should be a - * status update not an update to the resource itself. - * - * Using this update makes sure that the resource in the next reconciliation is the updated one - - * this is not guaranteed by default if you do an update on a resource by the Kubernetes client. - * - * @param custom resource type - * @param customResource customResource to use for update - * @return initialized update control - */ - public static UpdateControl updateResource(T customResource) { - return new UpdateControl<>(customResource, false, true, false); - } - /** * Preferred way to update the status. It does not do optimistic locking. Uses JSON Patch to patch * the resource. *

- * Note that this does not work, if the {@link CustomResource#initStatus() initStatus} is - * implemented, since it breaks the diffing process. Don't implement it if using this method. + * Note that this does not work, if the {@link CustomResource#initStatus()} is implemented, since + * it breaks the diffing process. Don't implement it if using this method. *

- * There is also an issue with setting value to null with older Kubernetes versions (1.19 and - * below). See: https://github.com/fabric8io/kubernetes-client/issues/4158 * * @param resource type @@ -53,86 +37,32 @@ public static UpdateControl updateResource(T customRe * @return UpdateControl instance */ public static UpdateControl patchStatus(T customResource) { - return new UpdateControl<>(customResource, true, false, true); - } - - /** - * Note that usually "patchStatus" is advised to be used instead of this method. - *

- * Updates the status with optimistic locking regarding current resource version reconciled. Note - * that this also ensures that on next reconciliation is the most up-to-date custom resource is - * used. - *

- * - * @param resource type - * @param customResource the custom resource with target status - * @return UpdateControl instance - */ - public static UpdateControl updateStatus(T customResource) { - return new UpdateControl<>(customResource, true, false, false); - } - - /** - * As a results of this there will be two call to K8S API. First the custom resource will be - * updates then the status sub-resource. - * - * Using this update makes sure that the resource in the next reconciliation is the updated one - - * this is not guaranteed by default if you do an update on a resource by the Kubernetes client. - * - * @param resource type - * @param customResource - custom resource to use in both API calls - * @return UpdateControl instance - */ - public static UpdateControl updateResourceAndStatus( - T customResource) { - return new UpdateControl<>(customResource, true, true, false); + return new UpdateControl<>(customResource, false, true); } - /** - * Updates the resource - with optimistic locking - and patches the status without optimistic - * locking in place. - * - * Note that using this method, it is not guaranteed that the most recent updated resource will be - * in case for next reconciliation. - * - * @param customResource to update - * @return UpdateControl instance - * @param resource type - */ - public static UpdateControl updateResourceAndPatchStatus( - T customResource) { - return new UpdateControl<>(customResource, true, true, true); + public static UpdateControl patchResource(T customResource) { + return new UpdateControl<>(customResource, true, false); } /** - * Marked for removal, because of confusing name. It does not patch the resource but rather - * updates it. - * - * @deprecated use {@link UpdateControl#updateResourceAndPatchStatus(HasMetadata)} - * * @param customResource to update * @return UpdateControl instance * @param resource type */ - @Deprecated(forRemoval = true) public static UpdateControl patchResourceAndStatus(T customResource) { - return updateResourceAndStatus(customResource); + return new UpdateControl<>(customResource, true, true); } public static UpdateControl noUpdate() { - return new UpdateControl<>(null, false, false, false); - } - - public P getResource() { - return resource; + return new UpdateControl<>(null, false, false); } - public boolean isUpdateStatus() { - return updateStatus; + public Optional

getResource() { + return Optional.ofNullable(resource); } - public boolean isUpdateResource() { - return updateResource; + public boolean isPatchResource() { + return patchResource; } public boolean isPatchStatus() { @@ -140,11 +70,11 @@ public boolean isPatchStatus() { } public boolean isNoUpdate() { - return !updateResource && !updateStatus; + return !patchResource && !patchStatus; } - public boolean isUpdateResourceAndStatus() { - return updateResource && updateStatus; + public boolean isPatchResourceAndStatus() { + return patchResource && patchStatus; } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 5421ef75d0..9481634ed3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -121,10 +121,10 @@ public String controllerName() { @Override public String successTypeName(UpdateControl

result) { String successType = RESOURCE; - if (result.isUpdateStatus()) { + if (result.isPatchStatus()) { successType = STATUS; } - if (result.isUpdateResourceAndStatus()) { + if (result.isPatchResourceAndStatus()) { successType = BOTH; } return successType; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java index 95755c33f0..ea8d494c9c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java @@ -245,17 +245,6 @@ synchronized void eventProcessingFinished( state.markProcessedMarkForDeletion(); metrics.cleanupDoneFor(resourceID, metricsMetadata); } else { - postExecutionControl - .getUpdatedCustomResource() - .ifPresent( - p -> { - if (!postExecutionControl.updateIsStatusPatch()) { - eventSourceManager - .getControllerResourceEventSource() - .handleRecentResourceUpdate( - ResourceID.fromResource(p), p, executionScope.getResource()); - } - }); if (state.eventPresent()) { submitReconciliationExecution(state); } else { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/PostExecutionControl.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/PostExecutionControl.java index 6fddd5ad93..3343cff80a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/PostExecutionControl.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/PostExecutionControl.java @@ -37,7 +37,7 @@ public static PostExecutionControl customResourceStat return new PostExecutionControl<>(false, updatedCustomResource, true, null); } - public static PostExecutionControl customResourceUpdated( + public static PostExecutionControl customResourcePatched( R updatedCustomResource) { return new PostExecutionControl<>(false, updatedCustomResource, false, null); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java index 8ba1f2c606..a20fb2e36a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.processing.event; +import java.lang.reflect.InvocationTargetException; import java.util.function.Function; import org.slf4j.Logger; @@ -8,6 +9,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.MixedOperation; @@ -44,14 +46,17 @@ class ReconciliationDispatcher

{ // Usually for testing purposes. private final boolean retryConfigurationHasZeroAttempts; private final Cloner cloner; + private final boolean useSSA; ReconciliationDispatcher(Controller

controller, CustomResourceFacade

customResourceFacade) { this.controller = controller; this.customResourceFacade = customResourceFacade; - this.cloner = controller.getConfiguration().getConfigurationService().getResourceCloner(); + final var configuration = controller.getConfiguration(); + this.cloner = configuration.getConfigurationService().getResourceCloner(); - var retry = controller.getConfiguration().getRetry(); + var retry = configuration.getRetry(); retryConfigurationHasZeroAttempts = retry == null || retry.initExecution().isLastAttempt(); + useSSA = configuration.getConfigurationService().useSSAToPatchPrimaryResource(); } public ReconciliationDispatcher(Controller

controller) { @@ -86,7 +91,7 @@ private PostExecutionControl

handleDispatch(ExecutionScope

executionScope) Context

context = new DefaultContext<>(executionScope.getRetryInfo(), controller, originalResource); if (markedForDeletion) { - return handleCleanup(resourceForExecution, context); + return handleCleanup(resourceForExecution, originalResource, context); } else { return handleReconcile(executionScope, resourceForExecution, originalResource, context); } @@ -109,8 +114,13 @@ private PostExecutionControl

handleReconcile( * finalizer add. This will make sure that the resources are not created before there is a * finalizer. */ - var updatedResource = - updateCustomResourceWithFinalizer(resourceForExecution, originalResource); + P updatedResource; + if (useSSA) { + updatedResource = addFinalizerWithSSA(originalResource); + } else { + updatedResource = + updateCustomResourceWithFinalizer(resourceForExecution, originalResource); + } return PostExecutionControl.onlyFinalizerAdded(updatedResource); } else { try { @@ -134,26 +144,35 @@ private PostExecutionControl

reconcileExecution(ExecutionScope

executionSc executionScope); UpdateControl

updateControl = controller.reconcile(resourceForExecution, context); + + final P toUpdate; P updatedCustomResource = null; - final var toUpdate = - updateControl.isNoUpdate() ? originalResource : updateControl.getResource(); - if (updateControl.isUpdateResourceAndStatus()) { - updatedCustomResource = updateCustomResource(toUpdate); - toUpdate - .getMetadata() - .setResourceVersion(updatedCustomResource.getMetadata().getResourceVersion()); - } else if (updateControl.isUpdateResource()) { - updatedCustomResource = updateCustomResource(toUpdate); + if (useSSA) { + if (updateControl.isNoUpdate()) { + return createPostExecutionControl(null, updateControl); + } else { + toUpdate = updateControl.getResource().orElseThrow(); + } + } else { + toUpdate = + updateControl.isNoUpdate() ? originalResource : updateControl.getResource().orElseThrow(); + } + + if (updateControl.isPatchResource()) { + updatedCustomResource = patchResource(toUpdate, originalResource); + if (!useSSA) { + toUpdate.getMetadata() + .setResourceVersion(updatedCustomResource.getMetadata().getResourceVersion()); + } } // check if status also needs to be updated final var updateObservedGeneration = updateControl.isNoUpdate() ? shouldUpdateObservedGenerationAutomatically(resourceForExecution) : shouldUpdateObservedGenerationAutomatically(updatedCustomResource); - if (updateControl.isUpdateResourceAndStatus() || updateControl.isUpdateStatus() - || updateObservedGeneration) { - updatedCustomResource = - updateStatusGenerationAware(toUpdate, originalResource, updateControl.isPatchStatus()); + // if using SSA the observed generation is updated only if user instructs patching the status + if (updateControl.isPatchStatus() || (updateObservedGeneration && !useSSA)) { + updatedCustomResource = patchStatusGenerationAware(toUpdate, originalResource); } return createPostExecutionControl(updatedCustomResource, updateControl); } @@ -183,17 +202,15 @@ public boolean isLastAttempt() { P updatedResource = null; if (errorStatusUpdateControl.getResource().isPresent()) { - updatedResource = errorStatusUpdateControl.isPatch() ? customResourceFacade - .patchStatus(errorStatusUpdateControl.getResource().orElseThrow(), originalResource) - : customResourceFacade - .updateStatus(errorStatusUpdateControl.getResource().orElseThrow()); + updatedResource = + patchStatusGenerationAware(errorStatusUpdateControl.getResource().orElseThrow(), + originalResource); } if (errorStatusUpdateControl.isNoRetry()) { PostExecutionControl

postExecutionControl; if (updatedResource != null) { - postExecutionControl = errorStatusUpdateControl.isPatch() - ? PostExecutionControl.customResourceStatusPatched(updatedResource) - : PostExecutionControl.customResourceUpdated(updatedResource); + postExecutionControl = + PostExecutionControl.customResourceStatusPatched(updatedResource); } else { postExecutionControl = PostExecutionControl.defaultDispatch(); } @@ -212,13 +229,9 @@ private boolean isErrorStatusHandlerPresent() { return controller.getReconciler() instanceof ErrorStatusHandler; } - private P updateStatusGenerationAware(P resource, P originalResource, boolean patch) { + private P patchStatusGenerationAware(P resource, P originalResource) { updateStatusObservedGenerationIfRequired(resource); - if (patch) { - return customResourceFacade.patchStatus(resource, originalResource); - } else { - return customResourceFacade.updateStatus(resource); - } + return customResourceFacade.patchStatus(resource, originalResource); } @SuppressWarnings("rawtypes") @@ -253,12 +266,8 @@ private PostExecutionControl

createPostExecutionControl(P updatedCustomResour UpdateControl

updateControl) { PostExecutionControl

postExecutionControl; if (updatedCustomResource != null) { - if (updateControl.isUpdateStatus() && updateControl.isPatchStatus()) { - postExecutionControl = - PostExecutionControl.customResourceStatusPatched(updatedCustomResource); - } else { - postExecutionControl = PostExecutionControl.customResourceUpdated(updatedCustomResource); - } + postExecutionControl = + PostExecutionControl.customResourceStatusPatched(updatedCustomResource); } else { postExecutionControl = PostExecutionControl.defaultDispatch(); } @@ -273,7 +282,7 @@ private void updatePostExecutionControlWithReschedule( } private PostExecutionControl

handleCleanup(P resource, - Context

context) { + P originalResource, Context

context) { if (log.isDebugEnabled()) { log.debug( "Executing delete for resource: {} with version: {}", @@ -287,7 +296,7 @@ private PostExecutionControl

handleCleanup(P resource, // cleanup is finished, nothing left to done final var finalizerName = configuration().getFinalizerName(); if (deleteControl.isRemoveFinalizer() && resource.hasFinalizer(finalizerName)) { - P customResource = conflictRetryingUpdate(resource, r -> { + P customResource = conflictRetryingPatch(resource, originalResource, r -> { // the operator might not be allowed to retrieve the resource on a retry, e.g. when its // permissions are removed by deleting the namespace concurrently if (r == null) { @@ -298,7 +307,7 @@ private PostExecutionControl

handleCleanup(P resource, return false; } return r.removeFinalizer(finalizerName); - }); + }, true); return PostExecutionControl.customResourceFinalizerRemoved(customResource); } } @@ -313,27 +322,56 @@ private PostExecutionControl

handleCleanup(P resource, return postExecutionControl; } + @SuppressWarnings("unchecked") + private P addFinalizerWithSSA(P originalResource) { + log.debug( + "Adding finalizer (using SSA) for resource: {} version: {}", + getUID(originalResource), getVersion(originalResource)); + try { + P resource = (P) originalResource.getClass().getConstructor().newInstance(); + ObjectMeta objectMeta = new ObjectMeta(); + objectMeta.setName(originalResource.getMetadata().getName()); + objectMeta.setNamespace(originalResource.getMetadata().getNamespace()); + resource.setMetadata(objectMeta); + resource.addFinalizer(configuration().getFinalizerName()); + return customResourceFacade.patchResourceWithSSA(resource); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException + | NoSuchMethodException e) { + throw new RuntimeException("Issue with creating custom resource instance with reflection." + + " Custom Resources must provide a no-arg constructor. Class: " + + originalResource.getClass().getName(), + e); + } + } + private P updateCustomResourceWithFinalizer(P resourceForExecution, P originalResource) { log.debug( "Adding finalizer for resource: {} version: {}", getUID(originalResource), getVersion(originalResource)); - return conflictRetryingUpdate(resourceForExecution, - r -> r.addFinalizer(configuration().getFinalizerName())); + return conflictRetryingPatch(resourceForExecution, originalResource, + r -> r.addFinalizer(configuration().getFinalizerName()), false); } - private P updateCustomResource(P resource) { + private P patchResource(P resource, P originalResource) { log.debug("Updating resource: {} with version: {}", getUID(resource), getVersion(resource)); log.trace("Resource before update: {}", resource); - return customResourceFacade.updateResource(resource); + // todo unit test + final var finalizerName = configuration().getFinalizerName(); + if (useSSA && controller.useFinalizer()) { + // addFinalizer already prevents adding an already present finalizer so no need to check + resource.addFinalizer(finalizerName); + } + return customResourceFacade.patchResource(resource, originalResource); } ControllerConfiguration

configuration() { return controller.getConfiguration(); } - public P conflictRetryingUpdate(P resource, Function modificationFunction) { + public P conflictRetryingPatch(P resource, P originalResource, + Function modificationFunction, boolean forceNotUseSSA) { if (log.isDebugEnabled()) { log.debug("Conflict retrying update for: {}", ResourceID.fromResource(resource)); } @@ -344,7 +382,11 @@ public P conflictRetryingUpdate(P resource, Function modificationFun if (Boolean.FALSE.equals(modified)) { return resource; } - return customResourceFacade.updateResource(resource); + if (forceNotUseSSA) { + return customResourceFacade.patchResourceWithoutSSA(resource, originalResource); + } else { + return customResourceFacade.patchResource(resource, originalResource); + } } catch (KubernetesClientException e) { log.trace("Exception during patch for resource: {}", resource); retryIndex++; @@ -368,15 +410,15 @@ public P conflictRetryingUpdate(P resource, Function modificationFun static class CustomResourceFacade { private final MixedOperation, Resource> resourceOperation; - private final boolean useSSAToUpdateStatus; + private final boolean useSSA; private final String fieldManager; public CustomResourceFacade( MixedOperation, Resource> resourceOperation, ControllerConfiguration configuration) { this.resourceOperation = resourceOperation; - this.useSSAToUpdateStatus = - configuration.getConfigurationService().useSSAForResourceStatusPatch(); + this.useSSA = + configuration.getConfigurationService().useSSAToPatchPrimaryResource(); this.fieldManager = configuration.fieldManager(); } @@ -388,35 +430,33 @@ public R getResource(String namespace, String name) { } } - public R updateResource(R resource) { + public R patchResourceWithoutSSA(R resource, R originalResource) { + return resource(originalResource).edit(r -> resource); + } + + public R patchResource(R resource, R originalResource) { if (log.isDebugEnabled()) { log.debug( "Trying to replace resource {}, version: {}", ResourceID.fromResource(resource), resource.getMetadata().getResourceVersion()); } - return resource(resource).lockResourceVersion(resource.getMetadata().getResourceVersion()) - .update(); - } - - public R updateStatus(R resource) { - log.trace("Updating status for resource: {}", resource); - return resource(resource) - .lockResourceVersion() - .updateStatus(); + if (useSSA) { + return patchResourceWithSSA(resource); + } else { + return resource(originalResource).edit(r -> resource); + } } public R patchStatus(R resource, R originalResource) { - log.trace("Patching status for resource: {} with ssa: {}", resource, useSSAToUpdateStatus); + log.trace("Patching status for resource: {} with ssa: {}", resource, useSSA); String resourceVersion = resource.getMetadata().getResourceVersion(); - // don't do optimistic locking on patch originalResource.getMetadata().setResourceVersion(null); resource.getMetadata().setResourceVersion(null); try { - if (useSSAToUpdateStatus) { + if (useSSA) { var managedFields = resource.getMetadata().getManagedFields(); try { - resource.getMetadata().setManagedFields(null); var res = resource(resource); return res.subresource("status").patch(new PatchContext.Builder() @@ -438,6 +478,14 @@ public R patchStatus(R resource, R originalResource) { } } + public R patchResourceWithSSA(R resource) { + return resource(resource).patch(new PatchContext.Builder() + .withFieldManager(fieldManager) + .withForce(true) + .withPatchType(PatchType.SERVER_SIDE_APPLY) + .build()); + } + private Resource resource(R resource) { return resource instanceof Namespaced ? resourceOperation .inNamespace(resource.getMetadata().getNamespace()) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java index 664c50c045..44bdf8c85b 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java @@ -287,21 +287,6 @@ void startProcessedMarkedEventReceivedBefore() { verify(metricsMock, times(1)).reconcileCustomResource(any(HasMetadata.class), isNull(), any()); } - @Test - void updatesEventSourceHandlerIfResourceUpdated() { - TestCustomResource customResource = testCustomResource(); - ExecutionScope executionScope = - new ExecutionScope(null).setResource(customResource); - PostExecutionControl postExecutionControl = - PostExecutionControl.customResourceUpdated(customResource); - - eventProcessorWithRetry.eventProcessingFinished(executionScope, postExecutionControl); - - - verify(controllerResourceEventSourceMock, times(1)).handleRecentResourceUpdate(any(), any(), - any()); - } - @Test void notUpdatesEventSourceHandlerIfResourceUpdated() { TestCustomResource customResource = testCustomResource(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java index d2e4cd52dc..bf4e5a8f27 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java @@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -60,8 +59,16 @@ class ReconciliationDispatcherTest { mock(ReconciliationDispatcher.CustomResourceFacade.class); private static ConfigurationService configurationService; - @BeforeAll - static void classSetup() { + @BeforeEach + void setup() { + initConfigService(true); + testCustomResource = TestUtils.testCustomResource(); + reconciler = spy(new TestReconciler()); + reconciliationDispatcher = + init(testCustomResource, reconciler, null, customResourceFacade, true); + } + + static void initConfigService(boolean useSSA) { /* * We need this for mock reconcilers to properly generate the expected UpdateControl: without * this, calls such as `when(reconciler.reconcile(eq(testCustomResource), @@ -77,15 +84,8 @@ static void classSetup() { public R clone(R object) { return object; } - })); - } - - @BeforeEach - void setup() { - testCustomResource = TestUtils.testCustomResource(); - reconciler = spy(new TestReconciler()); - reconciliationDispatcher = - init(testCustomResource, reconciler, null, customResourceFacade, true); + }) + .withUseSSAToPatchPrimaryResource(useSSA)); } private ReconciliationDispatcher init(R customResource, @@ -127,43 +127,47 @@ void addFinalizerOnNewResource() { verify(reconciler, never()) .reconcile(ArgumentMatchers.eq(testCustomResource), any()); verify(customResourceFacade, times(1)) - .updateResource( + .patchResourceWithSSA( argThat(testCustomResource -> testCustomResource.hasFinalizer(DEFAULT_FINALIZER))); - assertThat(testCustomResource.hasFinalizer(DEFAULT_FINALIZER)).isTrue(); } @Test - void callCreateOrUpdateOnNewResourceIfFinalizerSet() { - testCustomResource.addFinalizer(DEFAULT_FINALIZER); - reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); - verify(reconciler, times(1)) + void addFinalizerOnNewResourceWithoutSSA() { + initConfigService(false); + final ReconciliationDispatcher dispatcher = + init(testCustomResource, reconciler, null, customResourceFacade, true); + + assertFalse(testCustomResource.hasFinalizer(DEFAULT_FINALIZER)); + dispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); + verify(reconciler, never()) .reconcile(ArgumentMatchers.eq(testCustomResource), any()); + verify(customResourceFacade, times(1)) + .patchResource( + argThat(testCustomResource -> testCustomResource.hasFinalizer(DEFAULT_FINALIZER)), + any()); + assertThat(testCustomResource.hasFinalizer(DEFAULT_FINALIZER)).isTrue(); } @Test - void updatesOnlyStatusSubResourceIfFinalizerSet() { + void callCreateOrUpdateOnNewResourceIfFinalizerSet() { testCustomResource.addFinalizer(DEFAULT_FINALIZER); - - reconciler.reconcile = (r, c) -> UpdateControl.patchStatus(testCustomResource); - reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); - - verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); - verify(customResourceFacade, never()).updateResource(any()); + verify(reconciler, times(1)) + .reconcile(ArgumentMatchers.eq(testCustomResource), any()); } @Test - void updatesBothResourceAndStatusIfFinalizerSet() { + void patchesBothResourceAndStatusIfFinalizerSet() { testCustomResource.addFinalizer(DEFAULT_FINALIZER); - reconciler.reconcile = (r, c) -> UpdateControl.updateResourceAndStatus(testCustomResource); - when(customResourceFacade.updateResource(testCustomResource)) + reconciler.reconcile = (r, c) -> UpdateControl.patchResourceAndStatus(testCustomResource); + when(customResourceFacade.patchResource(eq(testCustomResource), any())) .thenReturn(testCustomResource); reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); - verify(customResourceFacade, times(1)).updateResource(testCustomResource); - verify(customResourceFacade, times(1)).updateStatus(testCustomResource); + verify(customResourceFacade, times(1)).patchResource(eq(testCustomResource), any()); + verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); } @Test @@ -175,8 +179,7 @@ void patchesStatus() { reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); - verify(customResourceFacade, never()).updateStatus(any()); - verify(customResourceFacade, never()).updateResource(any()); + verify(customResourceFacade, never()).patchResource(any(), any()); } @Test @@ -208,7 +211,7 @@ void removesDefaultFinalizerOnDeleteIfSet() { reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); assertThat(postExecControl.isFinalizerRemoved()).isTrue(); - verify(customResourceFacade, times(1)).updateResource(testCustomResource); + verify(customResourceFacade, times(1)).patchResourceWithoutSSA(eq(testCustomResource), any()); } @Test @@ -217,7 +220,7 @@ void retriesFinalizerRemovalWithFreshResource() { markForDeletion(testCustomResource); var resourceWithFinalizer = TestUtils.testCustomResource(); resourceWithFinalizer.addFinalizer(DEFAULT_FINALIZER); - when(customResourceFacade.updateResource(testCustomResource)) + when(customResourceFacade.patchResourceWithoutSSA(eq(testCustomResource), any())) .thenThrow(new KubernetesClientException(null, 409, null)) .thenReturn(testCustomResource); when(customResourceFacade.getResource(any(), any())).thenReturn(resourceWithFinalizer); @@ -226,7 +229,7 @@ void retriesFinalizerRemovalWithFreshResource() { reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); assertThat(postExecControl.isFinalizerRemoved()).isTrue(); - verify(customResourceFacade, times(2)).updateResource(any()); + verify(customResourceFacade, times(2)).patchResourceWithoutSSA(any(), any()); verify(customResourceFacade, times(1)).getResource(any(), any()); } @@ -236,7 +239,7 @@ void nullResourceIsGracefullyHandledOnFinalizerRemovalRetry() { // of the finalizer removal testCustomResource.addFinalizer(DEFAULT_FINALIZER); markForDeletion(testCustomResource); - when(customResourceFacade.updateResource(any())) + when(customResourceFacade.patchResourceWithoutSSA(any(), any())) .thenThrow(new KubernetesClientException(null, 409, null)); when(customResourceFacade.getResource(any(), any())).thenReturn(null); @@ -244,7 +247,7 @@ void nullResourceIsGracefullyHandledOnFinalizerRemovalRetry() { reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); assertThat(postExecControl.isFinalizerRemoved()).isTrue(); - verify(customResourceFacade, times(1)).updateResource(testCustomResource); + verify(customResourceFacade, times(1)).patchResourceWithoutSSA(eq(testCustomResource), any()); verify(customResourceFacade, times(1)).getResource(any(), any()); } @@ -252,7 +255,7 @@ void nullResourceIsGracefullyHandledOnFinalizerRemovalRetry() { void throwsExceptionIfFinalizerRemovalRetryExceeded() { testCustomResource.addFinalizer(DEFAULT_FINALIZER); markForDeletion(testCustomResource); - when(customResourceFacade.updateResource(any())) + when(customResourceFacade.patchResourceWithoutSSA(any(), any())) .thenThrow(new KubernetesClientException(null, 409, null)); when(customResourceFacade.getResource(any(), any())) .thenAnswer((Answer) invocationOnMock -> createResourceWithFinalizer()); @@ -264,7 +267,7 @@ void throwsExceptionIfFinalizerRemovalRetryExceeded() { assertThat(postExecControl.getRuntimeException()).isPresent(); assertThat(postExecControl.getRuntimeException().get()) .isInstanceOf(OperatorException.class); - verify(customResourceFacade, times(MAX_UPDATE_RETRY)).updateResource(any()); + verify(customResourceFacade, times(MAX_UPDATE_RETRY)).patchResourceWithoutSSA(any(), any()); verify(customResourceFacade, times(MAX_UPDATE_RETRY - 1)).getResource(any(), any()); } @@ -273,7 +276,7 @@ void throwsExceptionIfFinalizerRemovalRetryExceeded() { void throwsExceptionIfFinalizerRemovalClientExceptionIsNotConflict() { testCustomResource.addFinalizer(DEFAULT_FINALIZER); markForDeletion(testCustomResource); - when(customResourceFacade.updateResource(any())) + when(customResourceFacade.patchResourceWithoutSSA(any(), any())) .thenThrow(new KubernetesClientException(null, 400, null)); var res = @@ -281,7 +284,7 @@ void throwsExceptionIfFinalizerRemovalClientExceptionIsNotConflict() { assertThat(res.getRuntimeException()).isPresent(); assertThat(res.getRuntimeException().get()).isInstanceOf(KubernetesClientException.class); - verify(customResourceFacade, times(1)).updateResource(any()); + verify(customResourceFacade, times(1)).patchResourceWithoutSSA(any(), any()); verify(customResourceFacade, never()).getResource(any(), any()); } @@ -325,7 +328,7 @@ void doesNotRemovesTheSetFinalizerIfTheDeleteNotMethodInstructsIt() { reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); assertEquals(1, testCustomResource.getMetadata().getFinalizers().size()); - verify(customResourceFacade, never()).updateResource(any()); + verify(customResourceFacade, never()).patchResource(any(), any()); } @Test @@ -335,22 +338,22 @@ void doesNotUpdateTheResourceIfNoUpdateUpdateControlIfFinalizerSet() { reconciler.reconcile = (r, c) -> UpdateControl.noUpdate(); reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); - verify(customResourceFacade, never()).updateResource(any()); - verify(customResourceFacade, never()).updateStatus(testCustomResource); + verify(customResourceFacade, never()).patchResource(any(), any()); + verify(customResourceFacade, never()).patchStatus(eq(testCustomResource), any()); } @Test void addsFinalizerIfNotMarkedForDeletionAndEmptyCustomResourceReturned() { removeFinalizers(testCustomResource); reconciler.reconcile = (r, c) -> UpdateControl.noUpdate(); - when(customResourceFacade.updateResource(any())) + when(customResourceFacade.patchResourceWithSSA(any())) .thenReturn(testCustomResource); var postExecControl = reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); - assertEquals(1, testCustomResource.getMetadata().getFinalizers().size()); - verify(customResourceFacade, times(1)).updateResource(any()); + verify(customResourceFacade, times(1)) + .patchResourceWithSSA(argThat(a -> !a.getMetadata().getFinalizers().isEmpty())); assertThat(postExecControl.updateIsStatusPatch()).isFalse(); assertThat(postExecControl.getUpdatedCustomResource()).isPresent(); } @@ -362,7 +365,7 @@ void doesNotCallDeleteIfMarkedForDeletionButNotOurFinalizer() { reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); - verify(customResourceFacade, never()).updateResource(any()); + verify(customResourceFacade, never()).patchResource(any(), any()); verify(reconciler, never()).cleanup(eq(testCustomResource), any()); } @@ -456,7 +459,7 @@ void setObservedGenerationForStatusIfNeeded() throws Exception { } @Test - void updatesObservedGenerationOnNoUpdateUpdateControl() throws Exception { + void doesNotUpdatesObservedGenerationIfStatusIsNotPatchedWhenUsingSSA() throws Exception { var observedGenResource = createObservedGenCustomResource(); Reconciler reconciler = mock(Reconciler.class); @@ -465,18 +468,16 @@ void updatesObservedGenerationOnNoUpdateUpdateControl() throws Exception { when(config.isGenerationAware()).thenReturn(true); when(reconciler.reconcile(any(), any())) .thenReturn(UpdateControl.noUpdate()); - when(facade.updateStatus(observedGenResource)).thenReturn(observedGenResource); + when(facade.patchStatus(any(), any())).thenReturn(observedGenResource); var dispatcher = init(observedGenResource, reconciler, config, facade, true); PostExecutionControl control = dispatcher.handleExecution( executionScopeWithCREvent(observedGenResource)); - assertThat(control.getUpdatedCustomResource().orElseGet(() -> fail("Missing optional")) - .getStatus().getObservedGeneration()) - .isEqualTo(1L); + assertThat(control.getUpdatedCustomResource()).isEmpty(); } @Test - void updateObservedGenerationOnCustomResourceUpdate() throws Exception { + void patchObservedGenerationOnCustomResourcePatchIfNoSSA() throws Exception { var observedGenResource = createObservedGenCustomResource(); Reconciler reconciler = mock(Reconciler.class); @@ -484,9 +485,10 @@ void updateObservedGenerationOnCustomResourceUpdate() throws Exception { CustomResourceFacade facade = mock(CustomResourceFacade.class); when(config.isGenerationAware()).thenReturn(true); when(reconciler.reconcile(any(), any())) - .thenReturn(UpdateControl.updateResource(observedGenResource)); - when(facade.updateResource(any())).thenReturn(observedGenResource); - when(facade.updateStatus(observedGenResource)).thenReturn(observedGenResource); + .thenReturn(UpdateControl.patchResource(observedGenResource)); + when(facade.patchResource(any(), any())).thenReturn(observedGenResource); + when(facade.patchStatus(eq(observedGenResource), any())).thenReturn(observedGenResource); + initConfigService(false); var dispatcher = init(observedGenResource, reconciler, config, facade, true); PostExecutionControl control = dispatcher.handleExecution( @@ -496,6 +498,25 @@ void updateObservedGenerationOnCustomResourceUpdate() throws Exception { .isEqualTo(1L); } + @Test + void doesNotPatchObservedGenerationOnCustomResourcePatch() throws Exception { + var observedGenResource = createObservedGenCustomResource(); + + Reconciler reconciler = mock(Reconciler.class); + final var config = MockControllerConfiguration.forResource(ObservedGenCustomResource.class); + CustomResourceFacade facade = mock(CustomResourceFacade.class); + when(config.isGenerationAware()).thenReturn(true); + when(reconciler.reconcile(any(), any())) + .thenReturn(UpdateControl.patchResource(observedGenResource)); + when(facade.patchResource(any(), any())).thenReturn(observedGenResource); + var dispatcher = init(observedGenResource, reconciler, config, facade, false); + + dispatcher.handleExecution( + executionScopeWithCREvent(observedGenResource)); + + verify(facade, never()).patchStatus(any(), any()); + } + @Test void callErrorStatusHandlerIfImplemented() { testCustomResource.addFinalizer(DEFAULT_FINALIZER); @@ -505,7 +526,7 @@ void callErrorStatusHandlerIfImplemented() { }; reconciler.errorHandler = (r, ri, e) -> { testCustomResource.getStatus().setConfigMapStatus(ERROR_MESSAGE); - return ErrorStatusUpdateControl.updateStatus(testCustomResource); + return ErrorStatusUpdateControl.patchStatus(testCustomResource); }; reconciliationDispatcher.handleExecution( @@ -522,7 +543,7 @@ public boolean isLastAttempt() { } }).setResource(testCustomResource)); - verify(customResourceFacade, times(1)).updateStatus(testCustomResource); + verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); verify(((ErrorStatusHandler) reconciler), times(1)).updateErrorStatus(eq(testCustomResource), any(), any()); } @@ -536,12 +557,12 @@ void callErrorStatusHandlerEvenOnFirstError() { }; reconciler.errorHandler = (r, ri, e) -> { testCustomResource.getStatus().setConfigMapStatus(ERROR_MESSAGE); - return ErrorStatusUpdateControl.updateStatus(testCustomResource); + return ErrorStatusUpdateControl.patchStatus(testCustomResource); }; var postExecControl = reconciliationDispatcher.handleExecution( new ExecutionScope(null).setResource(testCustomResource)); - verify(customResourceFacade, times(1)).updateStatus(testCustomResource); + verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); verify(((ErrorStatusHandler) reconciler), times(1)).updateErrorStatus(eq(testCustomResource), any(), any()); assertThat(postExecControl.exceptionDuringExecution()).isTrue(); @@ -555,7 +576,7 @@ void errorHandlerCanInstructNoRetryWithUpdate() { }; reconciler.errorHandler = (r, ri, e) -> { testCustomResource.getStatus().setConfigMapStatus(ERROR_MESSAGE); - return ErrorStatusUpdateControl.updateStatus(testCustomResource).withNoRetry(); + return ErrorStatusUpdateControl.patchStatus(testCustomResource).withNoRetry(); }; var postExecControl = reconciliationDispatcher.handleExecution( @@ -563,7 +584,7 @@ void errorHandlerCanInstructNoRetryWithUpdate() { verify(((ErrorStatusHandler) reconciler), times(1)).updateErrorStatus(eq(testCustomResource), any(), any()); - verify(customResourceFacade, times(1)).updateStatus(testCustomResource); + verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); assertThat(postExecControl.exceptionDuringExecution()).isFalse(); } @@ -583,7 +604,7 @@ void errorHandlerCanInstructNoRetryNoUpdate() { verify(((ErrorStatusHandler) reconciler), times(1)).updateErrorStatus(eq(testCustomResource), any(), any()); - verify(customResourceFacade, times(0)).updateStatus(testCustomResource); + verify(customResourceFacade, times(0)).patchStatus(eq(testCustomResource), any()); assertThat(postExecControl.exceptionDuringExecution()).isFalse(); } @@ -646,10 +667,14 @@ void canSkipSchedulingMaxDelayIf() { } @Test - void retriesAddingFinalizer() { + void retriesAddingFinalizerWithoutSSA() { + initConfigService(false); + reconciliationDispatcher = + init(testCustomResource, reconciler, null, customResourceFacade, true); + removeFinalizers(testCustomResource); reconciler.reconcile = (r, c) -> UpdateControl.noUpdate(); - when(customResourceFacade.updateResource(any())) + when(customResourceFacade.patchResource(any(), any())) .thenThrow(new KubernetesClientException(null, 409, null)) .thenReturn(testCustomResource); when(customResourceFacade.getResource(any(), any())) @@ -660,7 +685,7 @@ void retriesAddingFinalizer() { reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); - verify(customResourceFacade, times(2)).updateResource(any()); + verify(customResourceFacade, times(2)).patchResource(any(), any()); } @Test @@ -681,6 +706,12 @@ void reSchedulesFromErrorHandler() { assertThat(res.getRuntimeException()).isEmpty(); } + @Test + void addsFinalizerToPatchWithSSA() { + + } + + private ObservedGenCustomResource createObservedGenCustomResource() { ObservedGenCustomResource observedGenCustomResource = new ObservedGenCustomResource(); observedGenCustomResource.setMetadata(new ObjectMeta()); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomReconciler.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomReconciler.java index 748b76b72d..be2c80667e 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomReconciler.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomReconciler.java @@ -104,7 +104,7 @@ public UpdateControl reconcile( } resource.getStatus().setConfigMapStatus("ConfigMap Ready"); } - return UpdateControl.updateResource(resource); + return UpdateControl.patchResource(resource); } private Map configMapData(TestCustomResource resource) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdatingResAndSubResIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusNoSSAIT.java similarity index 51% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdatingResAndSubResIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusNoSSAIT.java index 3d7d27b4c3..9583629a7c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdatingResAndSubResIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusNoSSAIT.java @@ -7,44 +7,47 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.doubleupdate.DoubleUpdateTestCustomReconciler; -import io.javaoperatorsdk.operator.sample.doubleupdate.DoubleUpdateTestCustomResource; -import io.javaoperatorsdk.operator.sample.doubleupdate.DoubleUpdateTestCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.doubleupdate.DoubleUpdateTestCustomResourceStatus; +import io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa.PatchResourceAndStatusNoSSACustomResource; +import io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa.PatchResourceAndStatusNoSSAReconciler; +import io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa.PatchResourceAndStatusNoSSASpec; +import io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa.PatchResourceAndStatusNoSSAStatus; import io.javaoperatorsdk.operator.support.TestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -class UpdatingResAndSubResIT { +class PatchResourceAndStatusNoSSAIT { @RegisterExtension LocallyRunOperatorExtension operator = - LocallyRunOperatorExtension.builder().withReconciler(DoubleUpdateTestCustomReconciler.class) + + LocallyRunOperatorExtension.builder() + .withConfigurationService(o -> o.withUseSSAToPatchPrimaryResource(false)) + .withReconciler(PatchResourceAndStatusNoSSAReconciler.class) .build(); @Test void updatesSubResourceStatus() { - DoubleUpdateTestCustomResource resource = createTestCustomResource("1"); + PatchResourceAndStatusNoSSACustomResource resource = createTestCustomResource("1"); operator.create(resource); awaitStatusUpdated(resource.getMetadata().getName()); // wait for sure, there are no more events TestUtils.waitXms(300); - DoubleUpdateTestCustomResource customResource = + PatchResourceAndStatusNoSSACustomResource customResource = operator - .get(DoubleUpdateTestCustomResource.class, + .get(PatchResourceAndStatusNoSSACustomResource.class, resource.getMetadata().getName()); assertThat(TestUtils.getNumberOfExecutions(operator)) .isEqualTo(1); assertThat(customResource.getStatus().getState()) - .isEqualTo(DoubleUpdateTestCustomResourceStatus.State.SUCCESS); + .isEqualTo(PatchResourceAndStatusNoSSAStatus.State.SUCCESS); assertThat( customResource .getMetadata() .getAnnotations() - .get(DoubleUpdateTestCustomReconciler.TEST_ANNOTATION)) + .get(PatchResourceAndStatusNoSSAReconciler.TEST_ANNOTATION)) .isNotNull(); } @@ -53,21 +56,22 @@ void awaitStatusUpdated(String name) { .atMost(5, TimeUnit.SECONDS) .untilAsserted( () -> { - DoubleUpdateTestCustomResource cr = - operator.get(DoubleUpdateTestCustomResource.class, name); + PatchResourceAndStatusNoSSACustomResource cr = + operator.get(PatchResourceAndStatusNoSSACustomResource.class, name); assertThat(cr) .isNotNull(); assertThat(cr.getStatus()) .isNotNull(); assertThat(cr.getStatus().getState()) - .isEqualTo(DoubleUpdateTestCustomResourceStatus.State.SUCCESS); + .isEqualTo(PatchResourceAndStatusNoSSAStatus.State.SUCCESS); }); } - public DoubleUpdateTestCustomResource createTestCustomResource(String id) { - DoubleUpdateTestCustomResource resource = new DoubleUpdateTestCustomResource(); + public PatchResourceAndStatusNoSSACustomResource createTestCustomResource(String id) { + PatchResourceAndStatusNoSSACustomResource resource = + new PatchResourceAndStatusNoSSACustomResource(); resource.setMetadata(new ObjectMetaBuilder().withName("doubleupdateresource-" + id).build()); - resource.setSpec(new DoubleUpdateTestCustomResourceSpec()); + resource.setSpec(new PatchResourceAndStatusNoSSASpec()); resource.getSpec().setValue(id); return resource; } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusWithSSAIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusWithSSAIT.java new file mode 100644 index 0000000000..644316faf2 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusWithSSAIT.java @@ -0,0 +1,13 @@ +package io.javaoperatorsdk.operator; + +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceAndStatusWithSSAReconciler; + +public class PatchResourceAndStatusWithSSAIT extends PatchWithSSAITBase { + + @Override + protected Reconciler reconciler() { + return new PatchResourceAndStatusWithSSAReconciler(); + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceWithSSAIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceWithSSAIT.java new file mode 100644 index 0000000000..80f81f78d1 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceWithSSAIT.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator; + + +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceWithSSAReconciler; + + +public class PatchResourceWithSSAIT extends PatchWithSSAITBase { + + @Override + protected Reconciler reconciler() { + return new PatchResourceWithSSAReconciler(); + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchWithSSAITBase.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchWithSSAITBase.java new file mode 100644 index 0000000000..b3b6b4fc32 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchWithSSAITBase.java @@ -0,0 +1,59 @@ +package io.javaoperatorsdk.operator; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceWithSSACustomResource; +import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceWithSSAReconciler; +import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceWithSSASpec; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public abstract class PatchWithSSAITBase { + + public static final String RESOURCE_NAME = "test1"; + public static final String INIT_VALUE = "init value"; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(reconciler()) + .build(); + + @Test + void reconcilerPatchesResourceWithSSA() { + extension.create(testResource()); + + await().untilAsserted(() -> { + var actualResource = extension.get(PatchResourceWithSSACustomResource.class, RESOURCE_NAME); + + assertThat(actualResource.getSpec().getInitValue()).isEqualTo(INIT_VALUE); + assertThat(actualResource.getSpec().getControllerManagedValue()) + .isEqualTo(PatchResourceWithSSAReconciler.ADDED_VALUE); + // finalizer is added to the SSA patch in the background by the framework + assertThat(actualResource.getMetadata().getFinalizers()).isNotEmpty(); + assertThat(actualResource.getStatus().isSuccessfullyReconciled()).isTrue(); + // one for resource, one for subresource + assertThat(actualResource.getMetadata().getManagedFields().stream() + .filter(mf -> mf.getManager() + .equals(reconciler().getClass().getSimpleName().toLowerCase())) + .toList()).hasSize(2); + }); + } + + protected abstract Reconciler reconciler(); + + PatchResourceWithSSACustomResource testResource() { + var res = new PatchResourceWithSSACustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(RESOURCE_NAME) + .build()); + res.setSpec(new PatchResourceWithSSASpec()); + res.getSpec().setInitValue(INIT_VALUE); + return res; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReconcilerExecutorIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReconcilerExecutorIT.java index 07a022adb1..476bd842a5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReconcilerExecutorIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReconcilerExecutorIT.java @@ -35,7 +35,6 @@ void configMapGetsCreatedForTestCustomResource() { @Test void patchesStatusForTestCustomResource() { - operator.getReconcilerOfType(TestReconciler.class).setPatchStatus(true); operator.getReconcilerOfType(TestReconciler.class).setUpdateStatus(true); TestCustomResource resource = TestUtils.testCustomResource(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java index 01702a5400..fba39cc03f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java @@ -129,7 +129,7 @@ void workaroundMigratingFromToSSA() { private Operator startOperator(boolean patchStatusWithSSA) { var operator = new Operator(o -> o.withCloseClientOnStop(false) - .withUseSSAForResourceStatusPatch(patchStatusWithSSA)); + .withUseSSAToPatchPrimaryResource(patchStatusWithSSA)); operator.register(new StatusPatchLockingReconciler(), o -> o.settingNamespaces(testNamespace)); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java index 147c0403c3..e03883d8db 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java @@ -21,23 +21,27 @@ class StatusUpdateLockingIT { @RegisterExtension LocallyRunOperatorExtension operator = - LocallyRunOperatorExtension.builder().withReconciler(StatusUpdateLockingReconciler.class) + LocallyRunOperatorExtension.builder() + .withConfigurationService(o -> o.withUseSSAToPatchPrimaryResource(false)) + .withReconciler(StatusUpdateLockingReconciler.class) .build(); @Test - void optimisticLockingDoneOnStatusUpdate() throws InterruptedException { + void noOptimisticLockingDoneOnStatusPatch() throws InterruptedException { var resource = operator.create(createResource()); Thread.sleep(WAIT_TIME / 2); resource.getMetadata().setAnnotations(Map.of("key", "value")); operator.replace(resource); - await().pollDelay(Duration.ofMillis(WAIT_TIME)).untilAsserted(() -> { - assertThat( - operator.getReconcilerOfType(StatusUpdateLockingReconciler.class).getNumberOfExecutions()) - .isEqualTo(2); - assertThat(operator.get(StatusUpdateLockingCustomResource.class, TEST_RESOURCE_NAME) - .getStatus().getValue()).isEqualTo(1); - }); + await().pollDelay(Duration.ofMillis(WAIT_TIME)).timeout(Duration.ofSeconds(460)) + .untilAsserted(() -> { + assertThat( + operator.getReconcilerOfType(StatusUpdateLockingReconciler.class) + .getNumberOfExecutions()) + .isEqualTo(1); + assertThat(operator.get(StatusUpdateLockingCustomResource.class, TEST_RESOURCE_NAME) + .getStatus().getValue()).isEqualTo(1); + }); } StatusUpdateLockingCustomResource createResource() { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.java index ce9637af9e..a7365c19b9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.java @@ -33,7 +33,7 @@ public void generateCorrectDoneableClassIfThereIsAbstractBaseController() { } @Test - public void generateDoneableClasswithMultilevelHierarchy() { + public void generateDoneableClassWithMultilevelHierarchy() { Compilation compilation = Compiler.javac() .withProcessors(new ControllerConfigurationAnnotationProcessor()) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java index 81bcb7e153..2f1c272ce9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java @@ -47,7 +47,7 @@ public UpdateControl reconcile( status.setStatus(ready ? RECONCILE_STATUS.READY : RECONCILE_STATUS.NOT_READY); resource.setStatus(status); - return UpdateControl.updateStatus(resource); + return UpdateControl.patchStatus(resource); } @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResourceSpec.java deleted file mode 100644 index 02212957a9..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResourceSpec.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.javaoperatorsdk.operator.sample.doubleupdate; - -public class DoubleUpdateTestCustomResourceSpec { - - private String value; - - public String getValue() { - return value; - } - - public DoubleUpdateTestCustomResourceSpec setValue(String value) { - this.value = value; - return this; - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResourceStatus.java deleted file mode 100644 index 3c7b694853..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResourceStatus.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.javaoperatorsdk.operator.sample.doubleupdate; - -public class DoubleUpdateTestCustomResourceStatus { - - private State state; - - public State getState() { - return state; - } - - public DoubleUpdateTestCustomResourceStatus setState(State state) { - this.state = state; - return this; - } - - public enum State { - SUCCESS, ERROR - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java index 412a784b7c..4abf982e0f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java @@ -51,6 +51,6 @@ public ErrorStatusUpdateControl updateErro ensureStatusExists(resource); resource.getStatus().getMessages() .add(ERROR_STATUS_MESSAGE + context.getRetryInfo().orElseThrow().getAttemptCount()); - return ErrorStatusUpdateControl.updateStatus(resource); + return ErrorStatusUpdateControl.patchStatus(resource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java similarity index 66% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java index 11c543e388..d5273d4e1d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.doubleupdate; +package io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -11,7 +11,7 @@ @Version("v1") @Kind("DoubleUpdateSample") @ShortNames("du") -public class DoubleUpdateTestCustomResource - extends CustomResource +public class PatchResourceAndStatusNoSSACustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java similarity index 58% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java index 11f0a54f3e..ecbceb8f65 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/doubleupdate/DoubleUpdateTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.doubleupdate; +package io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa; import java.util.HashMap; import java.util.concurrent.atomic.AtomicInteger; @@ -13,18 +13,19 @@ import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @ControllerConfiguration -public class DoubleUpdateTestCustomReconciler - implements Reconciler, TestExecutionInfoProvider { +public class PatchResourceAndStatusNoSSAReconciler + implements Reconciler, TestExecutionInfoProvider { private static final Logger log = - LoggerFactory.getLogger(DoubleUpdateTestCustomReconciler.class); + LoggerFactory.getLogger(PatchResourceAndStatusNoSSAReconciler.class); public static final String TEST_ANNOTATION = "TestAnnotation"; public static final String TEST_ANNOTATION_VALUE = "TestAnnotationValue"; private final AtomicInteger numberOfExecutions = new AtomicInteger(0); @Override - public UpdateControl reconcile( - DoubleUpdateTestCustomResource resource, Context context) { + public UpdateControl reconcile( + PatchResourceAndStatusNoSSACustomResource resource, + Context context) { numberOfExecutions.addAndGet(1); log.info("Value: " + resource.getSpec().getValue()); @@ -32,15 +33,15 @@ public UpdateControl reconcile( resource.getMetadata().setAnnotations(new HashMap<>()); resource.getMetadata().getAnnotations().put(TEST_ANNOTATION, TEST_ANNOTATION_VALUE); ensureStatusExists(resource); - resource.getStatus().setState(DoubleUpdateTestCustomResourceStatus.State.SUCCESS); + resource.getStatus().setState(PatchResourceAndStatusNoSSAStatus.State.SUCCESS); - return UpdateControl.updateResourceAndStatus(resource); + return UpdateControl.patchResourceAndStatus(resource); } - private void ensureStatusExists(DoubleUpdateTestCustomResource resource) { - DoubleUpdateTestCustomResourceStatus status = resource.getStatus(); + private void ensureStatusExists(PatchResourceAndStatusNoSSACustomResource resource) { + PatchResourceAndStatusNoSSAStatus status = resource.getStatus(); if (status == null) { - status = new DoubleUpdateTestCustomResourceStatus(); + status = new PatchResourceAndStatusNoSSAStatus(); resource.setStatus(status); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java new file mode 100644 index 0000000000..ebc58bc862 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa; + +public class PatchResourceAndStatusNoSSASpec { + + private String value; + + public String getValue() { + return value; + } + + public PatchResourceAndStatusNoSSASpec setValue(String value) { + this.value = value; + return this; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java new file mode 100644 index 0000000000..f31031cbcc --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java @@ -0,0 +1,19 @@ +package io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa; + +public class PatchResourceAndStatusNoSSAStatus { + + private State state; + + public State getState() { + return state; + } + + public PatchResourceAndStatusNoSSAStatus setState(State state) { + this.state = state; + return this; + } + + public enum State { + SUCCESS, ERROR + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java new file mode 100644 index 0000000000..0c9cbf0456 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java @@ -0,0 +1,37 @@ +package io.javaoperatorsdk.operator.sample.patchresourcewithssa; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.*; + +@ControllerConfiguration +public class PatchResourceAndStatusWithSSAReconciler + implements Reconciler, + Cleaner { + + public static final String ADDED_VALUE = "Added Value"; + + @Override + public UpdateControl reconcile( + PatchResourceWithSSACustomResource resource, + Context context) { + + var res = new PatchResourceWithSSACustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(resource.getMetadata().getName()) + .withNamespace(resource.getMetadata().getNamespace()) + .build()); + + res.setSpec(new PatchResourceWithSSASpec()); + res.getSpec().setControllerManagedValue(ADDED_VALUE); + res.setStatus(new PatchResourceWithSSAStatus()); + res.getStatus().setSuccessfullyReconciled(true); + + return UpdateControl.patchResourceAndStatus(res); + } + + @Override + public DeleteControl cleanup(PatchResourceWithSSACustomResource resource, + Context context) { + return DeleteControl.defaultDelete(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSACustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSACustomResource.java new file mode 100644 index 0000000000..602776f3cb --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSACustomResource.java @@ -0,0 +1,16 @@ +package io.javaoperatorsdk.operator.sample.patchresourcewithssa; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("prs") +public class PatchResourceWithSSACustomResource + extends CustomResource + implements Namespaced { + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAReconciler.java new file mode 100644 index 0000000000..5e3929a163 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAReconciler.java @@ -0,0 +1,41 @@ +package io.javaoperatorsdk.operator.sample.patchresourcewithssa; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.*; + +@ControllerConfiguration +public class PatchResourceWithSSAReconciler + implements Reconciler, + Cleaner { + + public static final String ADDED_VALUE = "Added Value"; + + @Override + public UpdateControl reconcile( + PatchResourceWithSSACustomResource resource, + Context context) { + + var res = new PatchResourceWithSSACustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(resource.getMetadata().getName()) + .withNamespace(resource.getMetadata().getNamespace()) + .build()); + + // first update the spec with missing value, then status in next reconciliation + if (resource.getSpec().getControllerManagedValue() == null) { + res.setSpec(new PatchResourceWithSSASpec()); + res.getSpec().setControllerManagedValue(ADDED_VALUE); + return UpdateControl.patchResource(res); + } else { + res.setStatus(new PatchResourceWithSSAStatus()); + res.getStatus().setSuccessfullyReconciled(true); + return UpdateControl.patchStatus(res); + } + } + + @Override + public DeleteControl cleanup(PatchResourceWithSSACustomResource resource, + Context context) { + return DeleteControl.defaultDelete(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSASpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSASpec.java new file mode 100644 index 0000000000..77d4fe0428 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSASpec.java @@ -0,0 +1,23 @@ +package io.javaoperatorsdk.operator.sample.patchresourcewithssa; + +public class PatchResourceWithSSASpec { + + private String initValue; + private String controllerManagedValue; + + public String getInitValue() { + return initValue; + } + + public void setInitValue(String initValue) { + this.initValue = initValue; + } + + public String getControllerManagedValue() { + return controllerManagedValue; + } + + public void setControllerManagedValue(String controllerManagedValue) { + this.controllerManagedValue = controllerManagedValue; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAStatus.java new file mode 100644 index 0000000000..982ef83129 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAStatus.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.sample.patchresourcewithssa; + +public class PatchResourceWithSSAStatus { + + private boolean successfullyReconciled; + + public boolean isSuccessfullyReconciled() { + return successfullyReconciled; + } + + public void setSuccessfullyReconciled(boolean successfullyReconciled) { + this.successfullyReconciled = successfullyReconciled; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestReconciler.java index fea06bba93..4ff4521d00 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestReconciler.java @@ -27,20 +27,10 @@ public class TestReconciler private final AtomicInteger numberOfExecutions = new AtomicInteger(0); private final AtomicInteger numberOfCleanupExecutions = new AtomicInteger(0); private volatile boolean updateStatus; - private volatile boolean patchStatus; - public TestReconciler(boolean updateStatus) { - this(updateStatus, false); - } - public TestReconciler(boolean updateStatus, boolean patchStatus) { + public TestReconciler(boolean updateStatus) { this.updateStatus = updateStatus; - this.patchStatus = patchStatus; - } - - public TestReconciler setPatchStatus(boolean patchStatus) { - this.patchStatus = patchStatus; - return this; } public void setUpdateStatus(boolean updateStatus) { @@ -114,16 +104,16 @@ public UpdateControl reconcile( .createOrReplace(); } if (updateStatus) { - if (resource.getStatus() == null) { - resource.setStatus(new TestCustomResourceStatus()); - } + var statusUpdateResource = new TestCustomResource(); + statusUpdateResource.setMetadata(new ObjectMetaBuilder() + .withName(resource.getMetadata().getName()) + .withNamespace(resource.getMetadata().getNamespace()) + .build()); + resource.setStatus(new TestCustomResourceStatus()); resource.getStatus().setConfigMapStatus("ConfigMap Ready"); - } - if (patchStatus) { return UpdateControl.patchStatus(resource); - } else { - return UpdateControl.updateStatus(resource); } + return UpdateControl.noUpdate(); } private Map configMapData(TestCustomResource resource) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResource.java index df832aaed0..0f95ccd824 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResource.java @@ -15,8 +15,4 @@ public class StatusUpdateLockingCustomResource extends CustomResource implements Namespaced { - @Override - protected StatusUpdateLockingCustomResourceStatus initStatus() { - return new StatusUpdateLockingCustomResourceStatus(); - } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingReconciler.java index e21897cf38..fc007f5dfa 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingReconciler.java @@ -18,8 +18,9 @@ public UpdateControl reconcile( throws InterruptedException { numberOfExecutions.addAndGet(1); Thread.sleep(WAIT_TIME); + resource.setStatus(new StatusUpdateLockingCustomResourceStatus()); resource.getStatus().setValue(resource.getStatus().getValue() + 1); - return UpdateControl.updateStatus(resource); + return UpdateControl.patchStatus(resource); } public int getNumberOfExecutions() { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomReconciler.java index 1e76681f25..b50b9fc4b5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomReconciler.java @@ -33,7 +33,7 @@ public UpdateControl reconcile( ensureStatusExists(resource); resource.getStatus().setState(SubResourceTestCustomResourceStatus.State.SUCCESS); waitXms(RECONCILER_MIN_EXEC_TIME); - return UpdateControl.updateStatus(resource); + return UpdateControl.patchStatus(resource); } private void ensureStatusExists(SubResourceTestCustomResource resource) { diff --git a/operator-framework/src/test/resources/compile-fixtures/MultilevelReconciler.java b/operator-framework/src/test/resources/compile-fixtures/MultilevelReconciler.java index acea0a0db2..254d211bd0 100644 --- a/operator-framework/src/test/resources/compile-fixtures/MultilevelReconciler.java +++ b/operator-framework/src/test/resources/compile-fixtures/MultilevelReconciler.java @@ -17,7 +17,7 @@ public static class MyCustomResource extends CustomResource { public UpdateControl reconcile( MultilevelReconciler.MyCustomResource customResource, Context context) { - return UpdateControl.updateResource(null); + return UpdateControl.patchResource(null); } public DeleteControl cleanup(MultilevelReconciler.MyCustomResource customResource, diff --git a/operator-framework/src/test/resources/compile-fixtures/ReconcilerImplemented2Interfaces.java b/operator-framework/src/test/resources/compile-fixtures/ReconcilerImplemented2Interfaces.java index 0adc9aee09..bd1ba773be 100644 --- a/operator-framework/src/test/resources/compile-fixtures/ReconcilerImplemented2Interfaces.java +++ b/operator-framework/src/test/resources/compile-fixtures/ReconcilerImplemented2Interfaces.java @@ -14,7 +14,7 @@ public static class MyCustomResource extends CustomResource { @Override public UpdateControl reconcile(MyCustomResource customResource, Context context) { - return UpdateControl.updateResource(null); + return UpdateControl.patchResource(null); } @Override diff --git a/operator-framework/src/test/resources/compile-fixtures/ReconcilerImplementedIntermediateAbstractClass.java b/operator-framework/src/test/resources/compile-fixtures/ReconcilerImplementedIntermediateAbstractClass.java index b95495a614..ee291cf9ce 100644 --- a/operator-framework/src/test/resources/compile-fixtures/ReconcilerImplementedIntermediateAbstractClass.java +++ b/operator-framework/src/test/resources/compile-fixtures/ReconcilerImplementedIntermediateAbstractClass.java @@ -13,7 +13,7 @@ public class ReconcilerImplementedIntermediateAbstractClass extends public UpdateControl reconcile( AbstractReconciler.MyCustomResource customResource, Context context) { - return UpdateControl.updateResource(null); + return UpdateControl.patchResource(null); } public DeleteControl cleanup(AbstractReconciler.MyCustomResource customResource, diff --git a/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java b/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java index 36fb3f2ef8..1e54ddd915 100644 --- a/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java +++ b/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestReconciler.java @@ -34,7 +34,7 @@ public UpdateControl reconcile( resource.getStatus().getReconciledBy().add(reconcilerName); // update status is with optimistic locking - return UpdateControl.updateStatus(resource).rescheduleAfter(Duration.ofSeconds(1)); + return UpdateControl.patchStatus(resource).rescheduleAfter(Duration.ofSeconds(1)); } } diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java index 1a4b704591..f75ac32ee7 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java @@ -50,7 +50,7 @@ public ErrorStatusUpdateControl updateErrorStatus(MySQLSchema schem status.setSecretName(null); status.setStatus("ERROR: " + e.getMessage()); schema.setStatus(status); - return ErrorStatusUpdateControl.updateStatus(schema); + return ErrorStatusUpdateControl.patchStatus(schema); } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/Utils.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/Utils.java index b37b98aa52..72d04b42ed 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/Utils.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/Utils.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.sample; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; import io.javaoperatorsdk.operator.sample.customresource.WebPage; @@ -11,6 +12,16 @@ public class Utils { private Utils() {} + public static WebPage createWebPageForStatusUpdate(WebPage webPage, String configMapName) { + WebPage res = new WebPage(); + res.setMetadata(new ObjectMetaBuilder() + .withName(webPage.getMetadata().getName()) + .withNamespace(webPage.getMetadata().getNamespace()) + .build()); + res.setStatus(createStatus(configMapName)); + return res; + } + public static WebPageStatus createStatus(String configMapName) { WebPageStatus status = new WebPageStatus(); status.setHtmlConfigMap(configMapName); @@ -33,7 +44,7 @@ public static String serviceName(WebPage webPage) { public static ErrorStatusUpdateControl handleError(WebPage resource, Exception e) { resource.getStatus().setErrorMessage("Error: " + e.getMessage()); - return ErrorStatusUpdateControl.updateStatus(resource); + return ErrorStatusUpdateControl.patchStatus(resource); } public static void simulateErrorIfRequested(WebPage webPage) throws ErrorSimulationException { diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index 3d3b583659..06c4ae8721 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -61,10 +61,10 @@ public UpdateControl reconcile(WebPage webPage, Context contex workflow.reconcile(webPage, context); - webPage.setStatus( - createStatus( - context.getSecondaryResource(ConfigMap.class).orElseThrow().getMetadata().getName())); - return UpdateControl.patchStatus(webPage); + return UpdateControl + .patchStatus( + createWebPageForStatusUpdate(webPage, context.getSecondaryResource(ConfigMap.class) + .orElseThrow().getMetadata().getName())); } @Override diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java index 44149aed4d..32811251d7 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java @@ -6,9 +6,7 @@ import io.javaoperatorsdk.operator.sample.customresource.WebPage; import io.javaoperatorsdk.operator.sample.dependentresource.*; -import static io.javaoperatorsdk.operator.sample.Utils.createStatus; -import static io.javaoperatorsdk.operator.sample.Utils.handleError; -import static io.javaoperatorsdk.operator.sample.Utils.simulateErrorIfRequested; +import static io.javaoperatorsdk.operator.sample.Utils.*; /** * Shows how to implement a reconciler with managed dependent resources. @@ -39,8 +37,7 @@ public UpdateControl reconcile(WebPage webPage, Context contex final var name = context.getSecondaryResource(ConfigMap.class).orElseThrow() .getMetadata().getName(); - webPage.setStatus(createStatus(name)); - return UpdateControl.patchStatus(webPage); + return UpdateControl.patchStatus(createWebPageForStatusUpdate(webPage, name)); } @Override diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index df6ba7ddb8..46bc3dd392 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -132,8 +132,9 @@ public UpdateControl reconcile(WebPage webPage, Context contex log.info("Restarting pods because HTML has changed in {}", ns); kubernetesClient.pods().inNamespace(ns).withLabel("app", deploymentName(webPage)).delete(); } - webPage.setStatus(createStatus(desiredHtmlConfigMap.getMetadata().getName())); - return UpdateControl.patchStatus(webPage); + + return UpdateControl.patchStatus( + createWebPageForStatusUpdate(webPage, desiredHtmlConfigMap.getMetadata().getName())); } private boolean match(Ingress desiredIngress, Ingress existingIngress) { diff --git a/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorAbstractTest.java b/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorAbstractTest.java index 040b3b2f8f..6c9a5512bb 100644 --- a/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorAbstractTest.java +++ b/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorAbstractTest.java @@ -37,7 +37,7 @@ public abstract class WebPageOperatorAbstractTest { public static final String TEST_PAGE = "test-page"; public static final String TITLE1 = "Hello Operator World"; public static final String TITLE2 = "Hello Operator World Title 2"; - public static final int WAIT_SECONDS = 20; + public static final int WAIT_SECONDS = 360; public static final int LONG_WAIT_SECONDS = 120; public static final Duration POLL_INTERVAL = Duration.ofSeconds(1); From 1daf201113610bb268ecb77674c0c07d1ad82082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 8 Apr 2024 18:47:48 +0200 Subject: [PATCH 31/96] fix: error with java docs validation (#2336) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/api/ObservedGenerationAware.java | 10 ++++++---- .../operator/api/config/ConfigurationService.java | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java index 069953a32d..eafe51e6f4 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java @@ -2,6 +2,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.CustomResource; +import io.javaoperatorsdk.operator.api.config.ConfigurationService; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; /** @@ -11,10 +12,11 @@ * In order for this automatic handling to work the status object returned by * {@link CustomResource#getStatus()} should not be null. *

- * The observed generation is updated even when {@link UpdateControl#noUpdate()} or - * {@link UpdateControl#updateResource(HasMetadata)} is called. Although those results call normally - * does not result in a status update, there will be a subsequent status update Kubernetes API call - * in this case. + * The observed generation is updated with SSA mode only if + * {@link UpdateControl#patchStatus(HasMetadata)} or + * {@link UpdateControl#patchResourceAndStatus(HasMetadata)} is called. In non-SSA mode (see + * {@link ConfigurationService#useSSAToPatchPrimaryResource()}) observed generation is update even + * if patch is not called. * * @see ObservedGenerationAwareStatus */ diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index 83acf0566d..ef6797cbf3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -340,6 +340,8 @@ default ExecutorServiceManager getExecutorServiceManager() { * method of Kubernetes Dependent Resource. * * @since 4.4.0 + * + * @return if SSA should be used for dependent resources */ default boolean ssaBasedCreateUpdateMatchForDependentResources() { return true; @@ -425,6 +427,8 @@ default Set> defaultNonSSAResource() { * Disable this if you want to react to your own dependent resource updates * * @since 4.5.0 + * + * @return if special annotation should be used for dependent resource to filter events */ default boolean previousAnnotationForDependentResourcesEventFiltering() { return true; @@ -436,10 +440,12 @@ default boolean previousAnnotationForDependentResourcesEventFiltering() { *

* Disabled by default as Kubernetes does not support, and discourages, this interpretation of * resourceVersions. Enable only if your api server event processing seems to lag the operator - * logic and you want to further minimize the amount of work done / updates issued by the + * logic, and you want to further minimize the amount of work done / updates issued by the * operator. * * @since 4.5.0 + * + * @return if resource version should be parsed (as integer) */ default boolean parseResourceVersionsForEventFilteringAndCaching() { return false; From 50385b0e69f0185db651da1c1b41bfbcbf7b6884 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 29 Aug 2024 21:41:14 +0200 Subject: [PATCH 32/96] chore: reformat, minor fixes Signed-off-by: Chris Laprun --- .../KubernetesDependentResource.java | 5 +- pom.xml | 831 +++++++++--------- 2 files changed, 411 insertions(+), 425 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 3d4693daef..0af41b58eb 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -40,14 +40,11 @@ public abstract class KubernetesDependentResource updaterMatcher = this instanceof ResourceUpdaterMatcher - ? (ResourceUpdaterMatcher) this - : GenericResourceUpdaterMatcher.updaterMatcherFor(resourceType()); + private final ResourceUpdaterMatcher updaterMatcher = this instanceof ResourceUpdaterMatcher ? (ResourceUpdaterMatcher) this : GenericResourceUpdaterMatcher.updaterMatcherFor(resourceType()); private final boolean clustered; private KubernetesDependentResourceConfig kubernetesDependentResourceConfig; private volatile Boolean useSSA; - @SuppressWarnings("unchecked") public KubernetesDependentResource(Class resourceType) { this(resourceType, null); } diff --git a/pom.xml b/pom.xml index 8d825704e8..856c1132fa 100644 --- a/pom.xml +++ b/pom.xml @@ -1,64 +1,65 @@ - - 4.0.0 + + 4.0.0 - io.javaoperatorsdk - java-operator-sdk - 5.0.0-SNAPSHOT - pom - Operator SDK for Java - Java SDK for implementing Kubernetes operators - https://github.com/operator-framework/java-operator-sdk + io.javaoperatorsdk + java-operator-sdk + 5.0.0-SNAPSHOT + pom + Operator SDK for Java + Java SDK for implementing Kubernetes operators + https://github.com/operator-framework/java-operator-sdk - - - Apache 2 License - https://www.apache.org/licenses/LICENSE-2.0.html - - - - - Adam Sandor - adam.sandor@container-solutions.com - - - Attila Meszaros - csviri@gmail.com - - + + + Apache 2 License + https://www.apache.org/licenses/LICENSE-2.0.html + + + + + Adam Sandor + adam.sandor@container-solutions.com + + + Attila Meszaros + csviri@gmail.com + + - - operator-framework-bom - operator-framework-core - operator-framework-junit5 - operator-framework - micrometer-support - sample-operators - caffeine-bounded-cache-support - bootstrapper-maven-plugin - + + operator-framework-bom + operator-framework-core + operator-framework-junit5 + operator-framework + micrometer-support + sample-operators + caffeine-bounded-cache-support + bootstrapper-maven-plugin + - - scm:git:git://github.com/operator-framework/java-operator-sdk.git - scm:git:git@github.com/operator-framework/java-operator-sdk.git - https://github.com/operator-framework/java-operator-sdk/tree/main - + + scm:git:git://github.com/operator-framework/java-operator-sdk.git + scm:git:git@github.com/operator-framework/java-operator-sdk.git + https://github.com/operator-framework/java-operator-sdk/tree/main + - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + - - UTF-8 - 17 - ${java.version} - ${java.version} - java-operator-sdk - https://sonarcloud.io - jdk + + UTF-8 + 17 + ${java.version} + ${java.version} + java-operator-sdk + https://sonarcloud.io + jdk 5.10.1 6.13.4 @@ -77,35 +78,23 @@ 0.9.11 2.16.1 - 2.11 - 3.12.1 - 3.5.0 - 3.10.0 - 3.3.1 - 3.3.1 - 3.4.2 - 3.4.0 - 3.2.5 - 1.7.0 - 3.0.0 - 3.1.3 - 9.0.1 8.0.0 - 3.4.1 - 2.43.0 + 2.11 + 3.12.1 + 3.5.0 + 3.10.0 + 3.3.1 + 3.3.1 + 3.4.2 + 3.4.0 + 3.2.5 + 1.7.0 + 3.0.0 + 3.1.3 + 9.0.1 + 3.4.1 + 2.43.0 - - operator-framework-bom - operator-framework-core - operator-framework-junit5 - operator-framework - micrometer-support - sample-operators - caffeine-bounded-cache-support - bootstrapper-maven-plugin - - - @@ -174,349 +163,349 @@ ${mokito.version} - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} - - - org.apache.logging.log4j - log4j-core - ${log4j.version} - test - - - org.apache.logging.log4j - log4j2-core - ${log4j.version} - - - com.github.spullara.mustache.java - compiler - ${mustache.version} - - - io.javaoperatorsdk - operator-framework-core - ${project.version} - - - io.javaoperatorsdk - operator-framework - ${project.version} - - - - com.squareup.okhttp3 - okhttp - ${okhttp.version} - - - com.squareup.okhttp3 - logging-interceptor - ${okhttp.version} - - - com.squareup.okhttp3 - mockwebserver - ${okhttp.version} - - - com.github.ben-manes.caffeine - caffeine - ${caffeine.version} - - - io.javaoperatorsdk - jenvtest - ${jenvtest.version} - test - - - - io.fabric8 - kubernetes-httpclient-okhttp - ${fabric8-client.version} - - - io.fabric8 - kubernetes-httpclient-vertx - ${fabric8-client.version} - - - - io.fabric8 - kubernetes-httpclient-jdk - ${fabric8-client.version} - - - io.fabric8 - kubernetes-httpclient-jetty - ${fabric8-client.version} - - - + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + test + + + org.apache.logging.log4j + log4j2-core + ${log4j.version} + + + com.github.spullara.mustache.java + compiler + ${mustache.version} + + + io.javaoperatorsdk + operator-framework-core + ${project.version} + + + io.javaoperatorsdk + operator-framework + ${project.version} + + + + com.squareup.okhttp3 + okhttp + ${okhttp.version} + + + com.squareup.okhttp3 + logging-interceptor + ${okhttp.version} + + + com.squareup.okhttp3 + mockwebserver + ${okhttp.version} + + + com.github.ben-manes.caffeine + caffeine + ${caffeine.version} + + + io.javaoperatorsdk + jenvtest + ${jenvtest.version} + test + + + + io.fabric8 + kubernetes-httpclient-okhttp + ${fabric8-client.version} + + + io.fabric8 + kubernetes-httpclient-vertx + ${fabric8-client.version} + + + + io.fabric8 + kubernetes-httpclient-jdk + ${fabric8-client.version} + + + io.fabric8 + kubernetes-httpclient-jetty + ${fabric8-client.version} + + + - - - - true - always - - ossrh - https://oss.sonatype.org/content/repositories/snapshots/ - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - - org.apache.maven.plugins - maven-resources-plugin - ${maven-resources-plugin.version} - - - org.apache.maven.plugins - maven-jar-plugin - ${maven-jar-plugin.version} - - - org.apache.maven.plugins - maven-clean-plugin - ${maven-clean-plugin.version} - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - - org.apache.maven.plugins - maven-install-plugin - ${maven-install-plugin.version} - - - com.diffplug.spotless - spotless-maven-plugin - ${spotless.version} - - - - - - com.diffplug.spotless - spotless-maven-plugin - - - - pom.xml - ./**/pom.xml - - - - - - contributing/eclipse-google-style.xml - - - contributing/eclipse.importorder - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*Test.java - - - **/*IT.java - **/*E2E.java - - WatchPermissionAwareTest - - - - - - - all-tests - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*Test.java - **/*IT.java - **/*E2E.java - - - - - - - - no-unit-tests - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IT.java - - - **/*Test.java - **/*E2E.java - - - - - - - - - minimal-watch-timeout-dependent-it - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*ITS.java - - - **/*Test.java - **/*E2E.java - **/*IT.java - - - - - - - - end-to-end-tests - + + + + true + always + + ossrh + https://oss.sonatype.org/content/repositories/snapshots/ + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + org.apache.maven.plugins + maven-install-plugin + ${maven-install-plugin.version} + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*E2E.java - - - **/*Test.java - **/*IT.java - - - - - - - - release - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IT.java - **/*E2E.java - **/InformerRelatedBehaviorTest.java - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - - - sign-artifacts - - sign - - verify + + com.diffplug.spotless + spotless-maven-plugin + + + + pom.xml + ./**/pom.xml + + + + + + contributing/eclipse-google-style.xml + + + contributing/eclipse.importorder + + + + + + + org.apache.maven.plugins + maven-surefire-plugin - - --pinentry-mode - loopback - + + **/*Test.java + + + **/*IT.java + **/*E2E.java + + WatchPermissionAwareTest - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-maven-plugin.version} - true - - ossrh - https://oss.sonatype.org/ - true - - + - - - + + + + all-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Test.java + **/*IT.java + **/*E2E.java + + + + + + + + no-unit-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IT.java + + + **/*Test.java + **/*E2E.java + + + + + + + + + minimal-watch-timeout-dependent-it + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*ITS.java + + + **/*Test.java + **/*E2E.java + **/*IT.java + + + + + + + + end-to-end-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*E2E.java + + + **/*Test.java + **/*IT.java + + + + + + + + release + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IT.java + **/*E2E.java + **/InformerRelatedBehaviorTest.java + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + + sign + + verify + + + --pinentry-mode + loopback + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + true + + + + + + From d6ba441092be4325fa507fc7e0e2cf4f5f4a65ea Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 11 Apr 2024 18:32:47 +0200 Subject: [PATCH 33/96] fix: remove now unneeded okhttp dependency override, wrong comment (#2331) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chris Laprun Co-authored-by: Attila Mészáros Signed-off-by: Attila Mészáros --- pom.xml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 856c1132fa..0d2a30baed 100644 --- a/pom.xml +++ b/pom.xml @@ -199,15 +199,6 @@ operator-framework ${project.version} - - - com.squareup.okhttp3 - okhttp - ${okhttp.version} - com.squareup.okhttp3 logging-interceptor @@ -230,6 +221,7 @@ test + io.fabric8 kubernetes-httpclient-okhttp @@ -240,7 +232,6 @@ kubernetes-httpclient-vertx ${fabric8-client.version} - io.fabric8 kubernetes-httpclient-jdk From 4f199979493004a54c1c8c680463533bf607ba77 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 12 Apr 2024 09:49:24 +0200 Subject: [PATCH 34/96] feat: run spotless on compile (#2330) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chris Laprun Co-authored-by: Attila Mészáros Signed-off-by: Attila Mészáros --- .github/workflows/e2e-test.yml | 8 +++----- pom.xml | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 5d6ec78c5f..df2d6ca584 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -19,7 +19,7 @@ jobs: sample_operators_tests: strategy: matrix: - sample_dir: + sample: - "sample-operators/mysql-schema" - "sample-operators/tomcat-operator" - "sample-operators/webpage" @@ -48,12 +48,10 @@ jobs: run: mvn install -DskipTests - name: Run integration tests in local mode - working-directory: ${{ matrix.sample_dir }} run: | - mvn test -P end-to-end-tests + mvn test -P end-to-end-tests -pl ${{ matrix.sample }} - name: Run E2E tests as a deployment - working-directory: ${{ matrix.sample_dir }} run: | eval $(minikube -p minikube docker-env) - mvn jib:dockerBuild test -P end-to-end-tests -Dtest.deployment=remote + mvn jib:dockerBuild test -P end-to-end-tests -Dtest.deployment=remote -pl ${{ matrix.sample }} diff --git a/pom.xml b/pom.xml index 0d2a30baed..aa53a9d859 100644 --- a/pom.xml +++ b/pom.xml @@ -313,9 +313,11 @@ pom.xml - ./**/pom.xml + ./**/pom.xml - + + false + @@ -324,9 +326,17 @@ contributing/eclipse.importorder - + + + + + apply + + compile + + org.apache.maven.plugins From f6117c9251c4cf115fa2a1437605fd6d7dc8187a Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 12 Apr 2024 09:49:47 +0200 Subject: [PATCH 35/96] refactor: clean-up (#2325) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chris Laprun Co-authored-by: Attila Mészáros Signed-off-by: Attila Mészáros --- .../boostrapper/Bootstrapper.java | 2 +- .../operator/BuilderUtils.java | 2 +- .../operator/ReconcilerUtils.java | 12 ++++------ .../api/config/BaseConfigurationService.java | 3 +-- .../ControllerConfigurationOverrider.java | 3 --- .../LeaderElectionConfigurationBuilder.java | 3 ++- .../ResolvedControllerConfiguration.java | 6 +++-- ...ependentResourceConfigurationResolver.java | 6 ++--- .../operator/processing/Controller.java | 3 +-- ...BasedGenericKubernetesResourceMatcher.java | 11 +++++---- .../processing/event/EventProcessor.java | 7 +++--- .../processing/event/EventSourceManager.java | 13 ++++++---- .../processing/event/NamedEventSource.java | 6 ++--- .../event/rate/LinearRateLimiter.java | 3 +-- .../ExternalResourceCachingEventSource.java | 24 +++++++++---------- .../informer/ManagedInformerEventSource.java | 11 +++++++-- .../operator/MockKubernetesClient.java | 19 ++++++++++----- .../ControllerConfigurationOverriderTest.java | 15 +++++++----- ...dentResourceConfigurationResolverTest.java | 12 ++++++---- .../event/EventSourceManagerTest.java | 2 +- .../informer/PrimaryToSecondaryIndexTest.java | 8 +++---- .../operator/MultiVersionCRDIT.java | 3 +-- .../config/BaseConfigurationServiceTest.java | 7 +++++- ...CreateUpdateEventFilterTestReconciler.java | 14 +++++++---- ...stomMappingConfigMapDependentResource.java | 2 +- .../dependentssa/DependentSSAReconciler.java | 7 +++++- ...cKubernetesDependentManagedReconciler.java | 8 +++++-- ...bernetesDependentStandaloneReconciler.java | 9 +++++-- ...tatusInCleanupAndRescheduleReconciler.java | 15 ++++++------ .../operator/sample/WebappReconciler.java | 17 +++++++++---- 30 files changed, 150 insertions(+), 103 deletions(-) diff --git a/bootstrapper-maven-plugin/src/main/java/io/javaoperatorsdk/boostrapper/Bootstrapper.java b/bootstrapper-maven-plugin/src/main/java/io/javaoperatorsdk/boostrapper/Bootstrapper.java index ad7bc3cc79..ed12e7619d 100644 --- a/bootstrapper-maven-plugin/src/main/java/io/javaoperatorsdk/boostrapper/Bootstrapper.java +++ b/bootstrapper-maven-plugin/src/main/java/io/javaoperatorsdk/boostrapper/Bootstrapper.java @@ -21,7 +21,7 @@ public class Bootstrapper { private static final Logger log = LoggerFactory.getLogger(Bootstrapper.class); - private MustacheFactory mustacheFactory = new DefaultMustacheFactory(); + private final MustacheFactory mustacheFactory = new DefaultMustacheFactory(); // .gitignore gets excluded from resource, using here a prefixed version private static final Map TOP_LEVEL_STATIC_FILES = diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/BuilderUtils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/BuilderUtils.java index 1cb46bafab..8f33036b74 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/BuilderUtils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/BuilderUtils.java @@ -10,7 +10,7 @@ public final class BuilderUtils { // prevent instantiation of util class private BuilderUtils() {} - public static final B newBuilder(Class builderType, T item) { + public static B newBuilder(Class builderType, T item) { Class builderTargetType = builderTargetType(builderType); try { Constructor constructor = builderType.getDeclaredConstructor(builderTargetType); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ReconcilerUtils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ReconcilerUtils.java index fec5c4e61e..c2241e4bbb 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ReconcilerUtils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ReconcilerUtils.java @@ -9,7 +9,6 @@ import java.util.Objects; import java.util.function.Predicate; import java.util.regex.Pattern; -import java.util.stream.Collectors; import io.fabric8.kubernetes.api.builder.Builder; import io.fabric8.kubernetes.api.model.GenericKubernetesResource; @@ -126,8 +125,7 @@ public static boolean specsEqual(HasMetadata r1, HasMetadata r2) { // will be replaced with: https://github.com/fabric8io/kubernetes-client/issues/3816 public static Object getSpec(HasMetadata resource) { // optimize CustomResource case - if (resource instanceof CustomResource) { - CustomResource cr = (CustomResource) resource; + if (resource instanceof CustomResource cr) { return cr.getSpec(); } @@ -142,8 +140,7 @@ public static Object getSpec(HasMetadata resource) { @SuppressWarnings("unchecked") public static Object setSpec(HasMetadata resource, Object spec) { // optimize CustomResource case - if (resource instanceof CustomResource) { - CustomResource cr = (CustomResource) resource; + if (resource instanceof CustomResource cr) { cr.setSpec(spec); return null; } @@ -191,8 +188,7 @@ public static void handleKubernetesClientException(Exception e, String resourceT throw ((MissingCRDException) e); } - if (e instanceof KubernetesClientException) { - KubernetesClientException ke = (KubernetesClientException) e; + if (e instanceof KubernetesClientException ke) { // only throw MissingCRDException if the 404 error occurs on the target CRD if (404 == ke.getCode() && (resourceTypeName.equals(ke.getFullResourceName()) @@ -217,7 +213,7 @@ private static boolean matchesResourceType(String resourceTypeName, group = group.substring(0, group.length() - 1); } final var segments = Arrays.stream(group.split("/")).filter(Predicate.not(String::isEmpty)) - .collect(Collectors.toUnmodifiableList()); + .toList(); if (segments.size() != 3) { return false; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index af9930d00c..488f3dc9ce 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -260,8 +260,7 @@ private static Configurator configuratorFor(Class instanceType, @SuppressWarnings({"unchecked", "rawtypes"}) private static void configureFromAnnotatedReconciler(Object instance, Reconciler reconciler) { - if (instance instanceof AnnotationConfigurable) { - AnnotationConfigurable configurable = (AnnotationConfigurable) instance; + if (instance instanceof AnnotationConfigurable configurable) { final Class configurationClass = (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface( instance.getClass(), AnnotationConfigurable.class); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java index 9f98214b91..ad66b8b563 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java @@ -10,7 +10,6 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; -import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; @@ -39,7 +38,6 @@ public class ControllerConfigurationOverrider { private String name; private String fieldManager; private Long informerListLimit; - private WorkflowSpec workflowSpec; private ControllerConfigurationOverrider(ControllerConfiguration original) { this.finalizer = original.getFinalizerName(); @@ -57,7 +55,6 @@ private ControllerConfigurationOverrider(ControllerConfiguration original) { this.fieldManager = original.fieldManager(); this.informerListLimit = original.getInformerListLimit().orElse(null); this.itemStore = original.getItemStore().orElse(null); - this.workflowSpec = original.getWorkflowSpec().orElse(null); } public ControllerConfigurationOverrider withFinalizer(String finalizer) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfigurationBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfigurationBuilder.java index 4b21dd9d2d..494c9d8e66 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfigurationBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfigurationBuilder.java @@ -6,9 +6,10 @@ import static io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration.*; +@SuppressWarnings("unused") public final class LeaderElectionConfigurationBuilder { - private String leaseName; + private final String leaseName; private String leaseNamespace; private String identity; private Duration leaseDuration = LEASE_DURATION_DEFAULT_VALUE; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java index 9a94d5d667..af96604591 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java @@ -1,7 +1,10 @@ package io.javaoperatorsdk.operator.api.config; import java.time.Duration; -import java.util.*; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.TimeUnit; import io.fabric8.kubernetes.api.model.HasMetadata; @@ -105,7 +108,6 @@ protected ResolvedControllerConfiguration(Class

resourceClass, String name, this.finalizer = ControllerConfiguration.ensureValidFinalizerName(finalizer, getResourceTypeName()); this.fieldManager = fieldManager; - this.workflowSpec = workflowSpec; } protected ResolvedControllerConfiguration(Class

resourceClass, String name, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java index ebe8b2ad0e..06ae7ec683 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java @@ -22,8 +22,7 @@ private DependentResourceConfigurationResolver() {} public static > void configure( DependentResource dependentResource, DependentResourceSpec spec, C parentConfiguration) { - if (dependentResource instanceof DependentResourceConfigurator) { - final var configurator = (DependentResourceConfigurator) dependentResource; + if (dependentResource instanceof DependentResourceConfigurator configurator) { final var config = configurationFor(spec, parentConfiguration); configurator.configureWith(config); } @@ -33,8 +32,7 @@ public static > Object DependentResourceSpec spec, C parentConfiguration) { // first check if the parent configuration has potentially already resolved the configuration - if (parentConfiguration instanceof DependentResourceConfigurationProvider) { - final var provider = (DependentResourceConfigurationProvider) parentConfiguration; + if (parentConfiguration instanceof DependentResourceConfigurationProvider provider) { final var configuration = provider.getConfigurationFor(spec); if (configuration != null) { return configuration; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 9481634ed3..88d8d34894 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -237,8 +237,7 @@ public void initAndRegisterEventSources(EventSourceContext

context) { final var size = dependentResourcesByName.size(); if (size > 0) { dependentResourcesByName.forEach((key, dependentResource) -> { - if (dependentResource instanceof EventSourceProvider) { - final var provider = (EventSourceProvider) dependentResource; + if (dependentResource instanceof EventSourceProvider provider) { final var source = provider.initEventSource(context); eventSourceManager.registerEventSource(key, source); } else { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java index 5987352960..24b9a8f4a4 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java @@ -11,7 +11,10 @@ import java.util.Optional; import java.util.Set; import java.util.TreeMap; -import java.util.stream.Collectors; +import java.util.Optional; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -332,12 +335,12 @@ private static Map.Entry> selectListEntryBasedOnKey } if (possibleTargets.isEmpty()) { throw new IllegalStateException("Cannot find list element for key: " + key + ", in map: " - + values.stream().map(Map::keySet).collect(Collectors.toList())); + + values.stream().map(Map::keySet).toList()); } if (possibleTargets.size() > 1) { throw new IllegalStateException( "More targets found in list element for key: " + key + " in map: " - + values.stream().map(Map::keySet).collect(Collectors.toList())); + + values.stream().map(Map::keySet).toList()); } return new AbstractMap.SimpleEntry<>(lastIndex, possibleTargets.get(0)); } @@ -349,7 +352,7 @@ private Optional checkIfFieldManagerExists(R actual, String // field manager name. .filter( f -> f.getManager().equals(fieldManager) && f.getOperation().equals(APPLY_OPERATION)) - .collect(Collectors.toList()); + .toList(); if (targetManagedFields.isEmpty()) { log.debug("No field manager exists for resource: {} with name: {} and operation {}", actual.getKind(), diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java index ea8d494c9c..cc06c347d0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java @@ -166,8 +166,7 @@ private void submitReconciliationExecution(ResourceState state) { private void handleEventMarking(Event event, ResourceState state) { final var relatedCustomResourceID = event.getRelatedCustomResourceID(); - if (event instanceof ResourceEvent) { - var resourceEvent = (ResourceEvent) event; + if (event instanceof ResourceEvent resourceEvent) { if (resourceEvent.getAction() == ResourceAction.DELETED) { log.debug("Marking delete event received for: {}", relatedCustomResourceID); state.markDeleteEventReceived(); @@ -331,8 +330,8 @@ private void handleRetryOnException( private void retryAwareErrorLogging(RetryExecution retry, boolean eventPresent, Exception exception, ExecutionScope

executionScope) { - if (!eventPresent && !retry.isLastAttempt() && exception instanceof KubernetesClientException) { - KubernetesClientException ex = (KubernetesClientException) exception; + if (!eventPresent && !retry.isLastAttempt() + && exception instanceof KubernetesClientException ex) { if (ex.getCode() == HttpURLConnection.HTTP_CONFLICT) { log.debug("Full client conflict error during event processing {}", executionScope, exception); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java index 9772c9edd5..2b1005af4a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java @@ -1,6 +1,11 @@ package io.javaoperatorsdk.operator.processing.event; -import java.util.*; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -104,8 +109,7 @@ public synchronized void stop() { @SuppressWarnings("rawtypes") private void logEventSourceEvent(NamedEventSource eventSource, String event) { if (log.isDebugEnabled()) { - if (eventSource.original() instanceof ResourceEventSource) { - ResourceEventSource source = (ResourceEventSource) eventSource.original(); + if (eventSource.original() instanceof ResourceEventSource source) { log.debug("{} event source {} for {}", event, eventSource.isNameSet() ? eventSource.name() : eventSource, source.resourceType()); @@ -152,8 +156,7 @@ public final synchronized void registerEventSource(String name, EventSource even if (name == null || name.isBlank()) { name = EventSourceUtils.generateNameFor(eventSource); } - if (eventSource instanceof ManagedInformerEventSource) { - var managedInformerEventSource = ((ManagedInformerEventSource) eventSource); + if (eventSource instanceof ManagedInformerEventSource managedInformerEventSource) { managedInformerEventSource.setConfigurationService( controller.getConfiguration().getConfigurationService()); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java index a4e4ead83a..1ad6efa929 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java @@ -49,8 +49,7 @@ public Class type() { @Override @SuppressWarnings({"rawtypes", "unchecked"}) public Optional> resourceType() { - if (original instanceof ResourceEventSource) { - ResourceEventSource resourceEventSource = (ResourceEventSource) original; + if (original instanceof ResourceEventSource resourceEventSource) { return Optional.of(resourceEventSource.resourceType()); } return Optional.empty(); @@ -59,8 +58,7 @@ public Optional> resourceType() { @Override @SuppressWarnings("rawtypes") public Optional configuration() { - if (original instanceof Configurable) { - Configurable configurable = (Configurable) original; + if (original instanceof Configurable configurable) { return Optional.ofNullable(configurable.configuration()); } return Optional.empty(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiter.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiter.java index 02a919f547..2692b60bd0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiter.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiter.java @@ -36,11 +36,10 @@ public LinearRateLimiter(Duration refreshPeriod, int limitForPeriod) { @Override public Optional isLimited(RateLimitState rateLimitState) { - if (!isActivated() || !(rateLimitState instanceof RateState)) { + if (!isActivated() || !(rateLimitState instanceof RateState actualState)) { return Optional.empty(); } - var actualState = (RateState) rateLimitState; if (actualState.getCount() < limitForPeriod) { actualState.increaseCount(); return Optional.empty(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java index 58778edbdf..3ccc41a77d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java @@ -1,6 +1,13 @@ package io.javaoperatorsdk.operator.processing.event.source; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -90,8 +97,7 @@ protected synchronized void handleResources(ResourceID primaryID, Set newReso } protected synchronized void handleResources(Map> allNewResources) { - var toDelete = cache.keySet().stream().filter(k -> !allNewResources.containsKey(k)) - .collect(Collectors.toList()); + var toDelete = cache.keySet().stream().filter(k -> !allNewResources.containsKey(k)).toList(); toDelete.forEach(this::handleDelete); allNewResources.forEach(this::handleResources); } @@ -153,21 +159,15 @@ private boolean acceptedByFiler(Map cachedResourceMap, .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); if (onUpdateFilter != null || genericFilter != null) { - var anyUpdated = possibleUpdatedResources.entrySet().stream() + return possibleUpdatedResources.entrySet().stream() .anyMatch( entry -> { var newResource = newResourcesMap.get(entry.getKey()); return acceptedByGenericFiler(newResource) && onUpdateFilter.accept(newResource, entry.getValue()); }); - if (anyUpdated) { - return true; - } - } else if (!possibleUpdatedResources.isEmpty()) { - return true; - } - - return false; + } else + return !possibleUpdatedResources.isEmpty(); } private boolean acceptedByGenericFiler(R resource) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java index 7139395e76..f5efd0a68c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java @@ -1,6 +1,10 @@ package io.javaoperatorsdk.operator.processing.event.source.informer; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Stream; @@ -25,6 +29,7 @@ import io.javaoperatorsdk.operator.processing.event.source.Configurable; import io.javaoperatorsdk.operator.processing.event.source.IndexerResourceCache; +@SuppressWarnings("rawtypes") public abstract class ManagedInformerEventSource> extends AbstractResourceEventSource implements ResourceEventHandler, Cache, IndexerResourceCache, @@ -36,7 +41,7 @@ public abstract class ManagedInformerEventSource>> indexers = new HashMap<>(); + private final Map>> indexers = new HashMap<>(); protected TemporaryResourceCache temporaryResourceCache; protected MixedOperation client; @@ -75,6 +80,7 @@ public void changeNamespaces(Set namespaces) { } } + @SuppressWarnings("unchecked") @Override public synchronized void start() { if (isRunning()) { @@ -124,6 +130,7 @@ public Optional get(ResourceID resourceID) { } } + @SuppressWarnings("unused") public Optional getCachedValue(ResourceID resourceID) { return get(resourceID); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/MockKubernetesClient.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/MockKubernetesClient.java index c9bff4a3d6..31fec8b924 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/MockKubernetesClient.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/MockKubernetesClient.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator; -import java.util.Arrays; +import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; @@ -13,7 +13,14 @@ import io.fabric8.kubernetes.api.model.authorization.v1.SubjectRulesReviewStatus; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.V1ApiextensionAPIGroupDSL; -import io.fabric8.kubernetes.client.dsl.*; +import io.fabric8.kubernetes.client.dsl.AnyNamespaceOperation; +import io.fabric8.kubernetes.client.dsl.ApiextensionsAPIGroupDSL; +import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; +import io.fabric8.kubernetes.client.dsl.Informable; +import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.NamespaceableResource; +import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; +import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElectorBuilder; import io.fabric8.kubernetes.client.informers.SharedIndexInformer; import io.fabric8.kubernetes.client.informers.cache.Indexer; @@ -119,10 +126,10 @@ private static Object allowSelfSubjectReview() { SelfSubjectRulesReview review = new SelfSubjectRulesReview(); review.setStatus(new SubjectRulesReviewStatus()); var resourceRule = new ResourceRule(); - resourceRule.setApiGroups(Arrays.asList(COORDINATION_GROUP)); - resourceRule.setResources(Arrays.asList(LEASES_RESOURCE)); - resourceRule.setVerbs(Arrays.asList(UNIVERSAL_VALUE)); - review.getStatus().setResourceRules(Arrays.asList(resourceRule)); + resourceRule.setApiGroups(List.of(COORDINATION_GROUP)); + resourceRule.setResources(List.of(LEASES_RESOURCE)); + resourceRule.setVerbs(List.of(UNIVERSAL_VALUE)); + review.getStatus().setResourceRules(List.of(resourceRule)); return review; } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java index d8caf50868..e280009da2 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java @@ -11,8 +11,12 @@ 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.*; +import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; @@ -93,8 +97,7 @@ public MyItemStore() { private static class WatchCurrentReconciler implements Reconciler { @Override - public UpdateControl reconcile(ConfigMap resource, Context context) - throws Exception { + public UpdateControl reconcile(ConfigMap resource, Context context) { return null; } } @@ -265,7 +268,7 @@ void alreadyOverriddenDependentNamespacesShouldNotBePropagated() { assertEquals(Set.of(OverriddenNSDependent.DEP_NS), config.namespaces()); } - @SuppressWarnings({"rawtypes", "unchecked"}) + @SuppressWarnings("rawtypes") @Test void replaceNamedDependentResourceConfigShouldWork() { var configuration = createConfiguration(new OneDepReconciler()); @@ -283,7 +286,7 @@ void replaceNamedDependentResourceConfigShouldWork() { var maybeConfig = DependentResourceConfigurationResolver.configurationFor(dependentSpec, configuration); assertNotNull(maybeConfig); - assertTrue(maybeConfig instanceof KubernetesDependentResourceConfig); + assertInstanceOf(KubernetesDependentResourceConfig.class, maybeConfig); var config = (KubernetesDependentResourceConfig) maybeConfig; // check that the DependentResource inherits the controller's configuration if applicable @@ -311,7 +314,7 @@ void replaceNamedDependentResourceConfigShouldWork() { assertEquals(labelSelector, config.labelSelector()); assertEquals(Set.of(overriddenNS), config.namespaces()); // check that we still have the proper workflow configuration - assertTrue(dependentSpec.getReadyCondition() instanceof TestCondition); + assertInstanceOf(TestCondition.class, dependentSpec.getReadyCondition()); } @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class)) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java index 0b7dcd53a1..702a12d124 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java @@ -12,7 +12,11 @@ import io.fabric8.kubernetes.api.model.Service; import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; @@ -48,7 +52,7 @@ void controllerConfigurationProvidedShouldBeReturnedIfAvailable() { final var cfg = configFor(new CustomAnnotationReconciler()); final var customConfig = DependentResourceConfigurationResolver .extractConfigurationFromConfigured(CustomAnnotatedDep.class, cfg); - assertTrue(customConfig instanceof CustomConfig); + assertInstanceOf(CustomConfig.class, customConfig); assertEquals(CustomAnnotatedDep.PROVIDED_VALUE, ((CustomConfig) customConfig).getValue()); final var newConfig = new CustomConfig(72); final var overridden = ControllerConfigurationOverrider.override(cfg) @@ -96,7 +100,7 @@ void registerConverterShouldWork() { DependentResourceConfigurationResolver.extractConfigurationFromConfigured(ConfigMapDep.class, cfg); converter = DependentResourceConfigurationResolver.getConverter(ConfigMapDep.class); - assertTrue(converter instanceof KubernetesDependentConverter); + assertInstanceOf(KubernetesDependentConverter.class, converter); final var overriddenConverter = new ConfigurationConverter() { @Override public Object configFrom(Annotation configAnnotation, @@ -110,7 +114,7 @@ public Object configFrom(Annotation configAnnotation, // already resolved converters are kept unchanged converter = DependentResourceConfigurationResolver.getConverter(ConfigMapDep.class); - assertTrue(converter instanceof KubernetesDependentConverter); + assertInstanceOf(KubernetesDependentConverter.class, converter); // but new converters should use the overridden version DependentResourceConfigurationResolver.extractConfigurationFromConfigured(ServiceDep.class, diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java index b56d79e6ed..39a3192d95 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java @@ -107,7 +107,7 @@ void shouldNotBePossibleToAddEventSourcesForSameTypeAndName() { final var exception = assertThrows(OperatorException.class, () -> manager.registerEventSource(name, source)); final var cause = exception.getCause(); - assertTrue(cause instanceof IllegalArgumentException); + assertInstanceOf(IllegalArgumentException.class, cause); assertThat(cause.getMessage()).contains( "is already registered for the (io.javaoperatorsdk.operator.sample.simple.TestCustomResource, " + name + ") class/name combination"); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/PrimaryToSecondaryIndexTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/PrimaryToSecondaryIndexTest.java index 62f395f2d6..6793b09550 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/PrimaryToSecondaryIndexTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/PrimaryToSecondaryIndexTest.java @@ -23,10 +23,10 @@ class PrimaryToSecondaryIndexTest { private final PrimaryToSecondaryIndex primaryToSecondaryIndex = new DefaultPrimaryToSecondaryIndex<>(secondaryToPrimaryMapperMock); - private ResourceID primaryID1 = new ResourceID("id1", "default"); - private ResourceID primaryID2 = new ResourceID("id2", "default"); - private ConfigMap secondary1 = secondary("secondary1"); - private ConfigMap secondary2 = secondary("secondary2"); + private final ResourceID primaryID1 = new ResourceID("id1", "default"); + private final ResourceID primaryID2 = new ResourceID("id2", "default"); + private final ConfigMap secondary1 = secondary("secondary1"); + private final ConfigMap secondary2 = secondary("secondary2"); @BeforeEach void setup() { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiVersionCRDIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiVersionCRDIT.java index dbb393fec0..de6cc681b6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiVersionCRDIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiVersionCRDIT.java @@ -60,8 +60,7 @@ public void reset() { @Override @SuppressWarnings("rawtypes") public void onStop(SharedIndexInformer informer, Throwable ex) { - if (ex instanceof WatcherException) { - WatcherException watcherEx = (WatcherException) ex; + if (ex instanceof WatcherException watcherEx) { watcherEx.getRawWatchMessage().ifPresent(raw -> { try { // extract the resource at which the version is attempted to be created (i.e. the stored diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java index 276e90d3ed..c39a2b68ea 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java @@ -23,7 +23,12 @@ import io.javaoperatorsdk.operator.api.config.dependent.Configured; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index d59c87236c..c3ec3b70a1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -8,7 +8,12 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; @@ -42,8 +47,7 @@ public void setEventSource( public static final String CONFIG_MAP_TEST_DATA_KEY = "key"; private final AtomicInteger numberOfExecutions = new AtomicInteger(0); - private InformerEventSource informerEventSource; - private DirectConfigMapDependentResource configMapDR = + private final DirectConfigMapDependentResource configMapDR = new DirectConfigMapDependentResource(ConfigMap.class); @Override @@ -93,7 +97,9 @@ public Map prepareEventSources( InformerConfiguration.from(ConfigMap.class) .withLabelSelector("integrationtest = " + this.getClass().getSimpleName()) .build(); - informerEventSource = new InformerEventSource<>(informerConfiguration, context.getClient()); + final var informerEventSource = + new InformerEventSource( + informerConfiguration, context.getClient()); this.configMapDR.setEventSource(informerEventSource); return EventSourceUtils.nameEventSources(informerEventSource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java index 123d360068..e17fdb8099 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java @@ -20,7 +20,7 @@ public class CustomMappingConfigMapDependentResource public static final String CUSTOM_NAMESPACE_KEY = "customNamespaceKey"; public static final String KEY = "key"; - private SecondaryToPrimaryMapper mapper = + private final SecondaryToPrimaryMapper mapper = Mappers.fromAnnotation(CUSTOM_NAME_KEY, CUSTOM_NAMESPACE_KEY); public CustomMappingConfigMapDependentResource() { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java index e40ba9c0c0..f0acce64b3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java @@ -4,7 +4,12 @@ import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java index bab120cfac..40d0454eb7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java @@ -1,6 +1,10 @@ package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentresourcemanaged; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; @Workflow(dependents = {@Dependent(type = ConfigMapGenericKubernetesDependent.class)}) @@ -13,7 +17,7 @@ public UpdateControl reconcile( GenericKubernetesDependentManagedCustomResource resource, Context context) { - return UpdateControl.noUpdate(); + return UpdateControl.noUpdate(); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java index 1cb1372abe..3f38e12a8d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java @@ -2,7 +2,12 @@ import java.util.Map; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @ControllerConfiguration @@ -21,7 +26,7 @@ public UpdateControl reconci dependent.reconcile(resource, context); - return UpdateControl.noUpdate(); + return UpdateControl.noUpdate(); } @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java index 9fcceca851..762948d1c1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java @@ -3,7 +3,12 @@ import java.time.LocalTime; import java.time.temporal.ChronoUnit; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Cleaner; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; @ControllerConfiguration public class UpdateStatusInCleanupAndRescheduleReconciler @@ -38,14 +43,10 @@ public DeleteControl cleanup(UpdateStatusInCleanupAndRescheduleCustomResource re resource.getStatus().setCleanupAttempt(currentAttempt + 1); if (!Boolean.FALSE.equals(rescheduleDelayWorked)) { var diff = ChronoUnit.MILLIS.between(lastCleanupExecution, LocalTime.now()); - if (diff < DELAY) { - rescheduleDelayWorked = false; - } else { - rescheduleDelayWorked = true; - } + rescheduleDelayWorked = diff >= DELAY; } } - var res = context.getClient().resource(resource).updateStatus(); + context.getClient().resource(resource).updateStatus(); if (resource.getStatus().getCleanupAttempt() > 5) { return DeleteControl.defaultDelete(); diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java index 0329350fdb..2dbddbf286 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java @@ -20,7 +20,14 @@ import io.fabric8.kubernetes.client.dsl.ExecListener; import io.fabric8.kubernetes.client.dsl.ExecWatch; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Cleaner; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; @@ -150,14 +157,14 @@ private String[] executeCommandInAllPods( CompletableFuture data = new CompletableFuture<>(); try (ExecWatch execWatch = execCmd(pod, data, command)) { - status[i] = "" + pod.getMetadata().getName() + ":" + data.get(30, TimeUnit.SECONDS); + status[i] = pod.getMetadata().getName() + ":" + data.get(30, TimeUnit.SECONDS); } catch (ExecutionException e) { - status[i] = "" + pod.getMetadata().getName() + ": ExecutionException - " + e.getMessage(); + status[i] = pod.getMetadata().getName() + ": ExecutionException - " + e.getMessage(); } catch (InterruptedException e) { status[i] = - "" + pod.getMetadata().getName() + ": InterruptedException - " + e.getMessage(); + pod.getMetadata().getName() + ": InterruptedException - " + e.getMessage(); } catch (TimeoutException e) { - status[i] = "" + pod.getMetadata().getName() + ": TimeoutException - " + e.getMessage(); + status[i] = pod.getMetadata().getName() + ": TimeoutException - " + e.getMessage(); } } } From d729ae81bf8460aaad05187c47949535a2aa16e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 25 Apr 2024 19:58:40 +0200 Subject: [PATCH 36/96] improve: samples correctly create status object for SSA (#2365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../sample/MySQLSchemaReconciler.java | 16 +++++++++++---- .../operator/sample/TomcatReconciler.java | 16 ++++++++++----- .../operator/sample/WebappReconciler.java | 20 +++++++++++++------ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java index f75ac32ee7..4a6f4f4d45 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java @@ -3,6 +3,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; @@ -33,10 +34,10 @@ public UpdateControl reconcile(MySQLSchema schema, Context { - updateStatusPojo(schema, s, secret.getMetadata().getName(), + var statusUpdateResource = createForStatusUpdate(schema, s, secret.getMetadata().getName(), decode(secret.getData().get(MYSQL_SECRET_USERNAME))); log.info("Schema {} created - updating CR status", s.getName()); - return UpdateControl.patchStatus(schema); + return UpdateControl.patchStatus(statusUpdateResource); }).orElseGet(UpdateControl::noUpdate); } @@ -54,8 +55,14 @@ public ErrorStatusUpdateControl updateErrorStatus(MySQLSchema schem } - private void updateStatusPojo(MySQLSchema mySQLSchema, Schema schema, String secretName, + private MySQLSchema createForStatusUpdate(MySQLSchema mySQLSchema, Schema schema, + String secretName, String userName) { + MySQLSchema res = new MySQLSchema(); + res.setMetadata(new ObjectMetaBuilder() + .withName(mySQLSchema.getMetadata().getName()) + .withNamespace(mySQLSchema.getMetadata().getNamespace()) + .build()); SchemaStatus status = new SchemaStatus(); status.setUrl( format( @@ -64,6 +71,7 @@ private void updateStatusPojo(MySQLSchema mySQLSchema, Schema schema, String sec status.setUserName(userName); status.setSecretName(secretName); status.setStatus("CREATED"); - mySQLSchema.setStatus(status); + res.setStatus(status); + return res; } } diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatReconciler.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatReconciler.java index 796da31d5d..f89a5f22e0 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatReconciler.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatReconciler.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.DeploymentStatus; import io.javaoperatorsdk.operator.api.reconciler.*; @@ -26,23 +27,28 @@ public class TomcatReconciler implements Reconciler { @Override public UpdateControl reconcile(Tomcat tomcat, Context context) { return context.getSecondaryResource(Deployment.class).map(deployment -> { - Tomcat updatedTomcat = updateTomcatStatus(tomcat, deployment); + Tomcat updatedTomcat = createTomcatForStatusUpdate(tomcat, deployment); log.info( "Updating status of Tomcat {} in namespace {} to {} ready replicas", tomcat.getMetadata().getName(), tomcat.getMetadata().getNamespace(), - tomcat.getStatus().getReadyReplicas()); + tomcat.getStatus() == null ? 0 : tomcat.getStatus().getReadyReplicas()); return UpdateControl.patchStatus(updatedTomcat); }).orElseGet(UpdateControl::noUpdate); } - private Tomcat updateTomcatStatus(Tomcat tomcat, Deployment deployment) { + private Tomcat createTomcatForStatusUpdate(Tomcat tomcat, Deployment deployment) { + Tomcat res = new Tomcat(); + res.setMetadata(new ObjectMetaBuilder() + .withName(tomcat.getMetadata().getName()) + .withNamespace(tomcat.getMetadata().getNamespace()) + .build()); DeploymentStatus deploymentStatus = Objects.requireNonNullElse(deployment.getStatus(), new DeploymentStatus()); int readyReplicas = Objects.requireNonNullElse(deploymentStatus.getReadyReplicas(), 0); TomcatStatus status = new TomcatStatus(); status.setReadyReplicas(readyReplicas); - tomcat.setStatus(status); - return tomcat; + res.setStatus(status); + return res; } } diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java index 2dbddbf286..e1c1ddc71a 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java @@ -14,6 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.client.KubernetesClient; @@ -101,12 +102,7 @@ public UpdateControl reconcile(Webapp webapp, Context context) { String[] commandStatusInAllPods = executeCommandInAllPods(kubernetesClient, webapp, command); - if (webapp.getStatus() == null) { - webapp.setStatus(new WebappStatus()); - } - webapp.getStatus().setDeployedArtifact(webapp.getSpec().getUrl()); - webapp.getStatus().setDeploymentStatus(commandStatusInAllPods); - return UpdateControl.patchStatus(webapp); + return UpdateControl.patchStatus(createWebAppForStatusUpdate(webapp, commandStatusInAllPods)); } else { log.info("WebappController invoked but Tomcat not ready yet ({}/{})", tomcat.getStatus() != null ? tomcat.getStatus().getReadyReplicas() : 0, @@ -115,6 +111,18 @@ public UpdateControl reconcile(Webapp webapp, Context context) { } } + private Webapp createWebAppForStatusUpdate(Webapp actual, String[] commandStatusInAllPods) { + var webapp = new Webapp(); + webapp.setMetadata(new ObjectMetaBuilder() + .withName(actual.getMetadata().getName()) + .withNamespace(actual.getMetadata().getNamespace()) + .build()); + webapp.setStatus(new WebappStatus()); + webapp.getStatus().setDeployedArtifact(actual.getSpec().getUrl()); + webapp.getStatus().setDeploymentStatus(commandStatusInAllPods); + return webapp; + } + @Override public DeleteControl cleanup(Webapp webapp, Context context) { From 2f30de372a5b46742dd1831ea7235910248f9bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 28 Apr 2024 10:20:49 +0200 Subject: [PATCH 37/96] improve: named event sources and related changes (#2340) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun Signed-off-by: Attila Mészáros --- .../cache/sample/AbstractTestReconciler.java | 5 +- docs/documentation/v5-0-migration.md | 33 +++- .../config/DefaultResourceConfiguration.java | 1 + .../operator/api/reconciler/Context.java | 1 - .../api/reconciler/EventSourceUtils.java | 63 +----- .../operator/api/reconciler/Reconciler.java | 7 +- .../dependent/EventSourceProvider.java | 18 -- .../operator/health/ControllerHealthInfo.java | 29 +-- .../operator/processing/Controller.java | 16 +- .../AbstractPollingDependentResource.java | 12 +- .../PerResourcePollingDependentResource.java | 12 +- .../external/PollingDependentResource.java | 8 +- .../KubernetesDependentResource.java | 2 +- .../workflow/AbstractWorkflowExecutor.java | 3 +- .../dependent/workflow/DefaultWorkflow.java | 14 +- .../dependent/workflow/Workflow.java | 5 +- .../processing/event/EventSourceManager.java | 79 +++----- .../event/EventSourceRetriever.java | 22 ++- .../processing/event/EventSources.java | 78 +++----- .../processing/event/NamedEventSource.java | 103 ---------- .../event/ReconciliationDispatcher.java | 1 - .../event/source/AbstractEventSource.java | 16 ++ .../source/AbstractResourceEventSource.java | 5 + .../processing/event/source/EventSource.java | 9 + .../ExternalResourceCachingEventSource.java | 7 +- .../event/source/ResourceEventSource.java | 1 + .../ControllerResourceEventSource.java | 10 +- .../inbound/SimpleInboundEventSource.java | 6 + .../source/informer/InformerEventSource.java | 17 +- .../informer/ManagedInformerEventSource.java | 10 +- .../PerResourcePollingConfiguration.java | 30 +++ ...erResourcePollingConfigurationBuilder.java | 49 +++++ .../PerResourcePollingEventSource.java | 146 ++------------ .../source/polling/PollingConfiguration.java | 18 ++ .../polling/PollingConfigurationBuilder.java | 26 +++ .../source/polling/PollingEventSource.java | 34 ++-- .../event/source/timer/TimerEventSource.java | 6 + .../api/reconciler/EventSourceUtilsTest.java | 24 --- .../processing/event/EventProcessorTest.java | 2 +- .../event/EventSourceManagerTest.java | 22 ++- .../processing/event/EventSourcesTest.java | 185 +++++++----------- .../PerResourcePollingEventSourceTest.java | 29 +-- .../polling/PollingEventSourceTest.java | 9 +- .../operator/InformerRelatedBehaviorITS.java | 3 +- .../StandaloneBulkDependentReconciler.java | 7 +- .../ChangeNamespaceTestReconciler.java | 5 +- ...ClusterScopedCustomResourceReconciler.java | 5 +- .../ComplexDependentReconciler.java | 13 +- ...CreateUpdateEventFilterTestReconciler.java | 7 +- .../DependentReInitializationReconciler.java | 6 +- .../dependentssa/DependentSSAReconciler.java | 6 +- ...ericEventSourceRegistrationReconciler.java | 6 +- .../ExternalStateDependentReconciler.java | 6 +- .../ExternalStateReconciler.java | 40 ++-- .../ExternalWithStateDependentResource.java | 3 +- ...ulkDependentResourceExternalWithState.java | 3 +- .../ExternalStateBulkDependentReconciler.java | 6 +- .../sample/filter/FilterTestReconciler.java | 5 +- ...bernetesDependentStandaloneReconciler.java | 8 +- ...cKubernetesResourceHandlingReconciler.java | 5 +- ...formerEventSourceTestCustomReconciler.java | 7 +- ...InformerRelatedBehaviorTestReconciler.java | 2 - ...endentGarbageCollectionTestReconciler.java | 6 +- .../MultipleDependentResourceReconciler.java | 6 +- ...ntResourceWithDiscriminatorReconciler.java | 6 +- ...dentSameTypeNoDiscriminatorReconciler.java | 12 +- ...pleManagedDependentResourceReconciler.java | 13 +- ...edExternalDependentResourceReconciler.java | 47 +++-- ...ultipleSecondaryEventSourceReconciler.java | 7 +- ...ourcePollingEventSourceTestReconciler.java | 26 ++- .../PrimaryIndexerTestReconciler.java | 8 +- .../primarytosecondary/JobReconciler.java | 6 +- ...PrimaryToSecondaryDependentReconciler.java | 7 +- .../StandaloneDependentTestReconciler.java | 6 +- .../operator/sample/MySQLSchemaOperator.java | 4 +- .../dependent/ResourcePollerConfig.java | 8 +- .../dependent/SchemaDependentResource.java | 7 +- .../operator/sample/WebappReconciler.java | 7 +- .../WebPageDependentsWorkflowReconciler.java | 6 +- .../operator/sample/WebPageReconciler.java | 5 +- ...WebPageStandaloneDependentsReconciler.java | 5 +- 81 files changed, 676 insertions(+), 832 deletions(-) delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/EventSourceProvider.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfiguration.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfigurationBuilder.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfiguration.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfigurationBuilder.java delete mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtilsTest.java diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java index 7a53db8bd9..c3743ef409 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java @@ -1,6 +1,7 @@ package io.javaoperatorsdk.operator.processing.event.source.cache.sample; import java.time.Duration; +import java.util.List; import java.util.Map; import org.slf4j.Logger; @@ -69,7 +70,7 @@ protected void createConfigMap(P resource, Context

context) { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext

context) { var boundedItemStore = @@ -82,7 +83,7 @@ public Map prepareEventSources( Mappers.fromOwnerReference(this instanceof BoundedCacheClusterScopeTestReconciler)) .build(), context); - return EventSourceUtils.nameEventSources(es); + return List.of(es); } private void ensureStatus(P resource) { diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index 36748ea1dc..a76b191851 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -17,8 +17,22 @@ permalink: /docs/v5-0-migration [`EventSourceUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java#L11-L11) now contains all the utility methods used for event sources naming that were previously defined in the `EventSourceInitializer` interface. -3. Updates through `UpdateControl` now use [Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/server-side-apply/) by default to add the finalizer and for all - the patch operations in `UpdateControl`. The update operations were removed. If you do not wish to use SSA, you can deactivate the feature using `ConfigurationService.useSSAToPatchPrimaryResource` and related `ConfigurationServiceOverrider.withUseSSAToPatchPrimaryResource`. +3. Event sources are now explicitly named (via the `name` method of the `EventSource` interface). Built-in event sources + implementation have been updated to allow you to specify a name when instantiating them. If you don't provide a name + for your `EventSource` implementation (for example, by using its default, no-arg constructor), one will be + automatically generated. This simplifies the API to define event source to + `List prepareEventSources(EventSourceContext

context)`. + !!! IMPORTANT !!! + If you use dynamic registration of event sources, be sure to name your event sources explicitly as letting JOSDK name + them automatically might result in duplicated event sources being registered as JOSDK relies on the name to identify + event sources and concurrent, dynamic registration might lead to identical event sources having different generated + names, thus leading JOSDK to consider them as different and hence, register them multiple times. +4. Updates through `UpdateControl` now + use [Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/server-side-apply/) by default to add + the finalizer and for all + the patch operations in `UpdateControl`. The update operations were removed. If you do not wish to use SSA, you can + deactivate the feature using `ConfigurationService.useSSAToPatchPrimaryResource` and + related `ConfigurationServiceOverrider.withUseSSAToPatchPrimaryResource`. !!! IMPORTANT !!! @@ -27,15 +41,16 @@ permalink: /docs/v5-0-migration where it is demonstrated. Also, the related part of a [workaround](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L110-L116). - Related automatic observed generation handling changes: + Related automatic observed generation handling changes: Automated Observed Generation (see features in docs), is automatically handled for non-SSA, even if - the status sub-resource is not instructed to be updated. This is not true for SSA, observed generation is updated + the status sub-resource is not instructed to be updated. This is not true for SSA, observed generation is updated only when patch status is instructed by `UpdateControl`. -4. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed +5. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. -5. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should - work without it by default. To optimize and handle special cases see the relevant section in [Dependent Resource documentation](/docs/dependent-resources#multiple-dependent-resources-of-same-type). -6. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed, +6. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should + work without it by default. To optimize and handle special cases see the relevant section + in [Dependent Resource documentation](/docs/dependent-resources#multiple-dependent-resources-of-same-type). +7. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed, use `Operator.stop(Duration)` instead. -7. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead +8. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java index f8ee9f4e84..61ec044694 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java @@ -88,4 +88,5 @@ public Optional> getItemStore() { public Optional getInformerListLimit() { return Optional.ofNullable(informerListLimit); } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java index 27547703b7..0134ea0a04 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java @@ -26,7 +26,6 @@ default Stream getSecondaryResourcesAsStream(Class expectedType) { return getSecondaryResources(expectedType).stream(); } - @Deprecated(forRemoval = true) Optional getSecondaryResource(Class expectedType, String eventSourceName); ControllerConfiguration

getControllerConfiguration(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java index 8b89d95b71..4294fee405 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java @@ -6,66 +6,21 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow; import io.javaoperatorsdk.operator.processing.event.source.EventSource; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; public class EventSourceUtils { - /** - * Utility method to easily create map with generated name for event sources. This is for the use - * case when the event sources are not access explicitly by name in the reconciler. - * - * @param eventSources to name - * @return even source with default names - */ - public static Map nameEventSources(EventSource... eventSources) { - Map eventSourceMap = new HashMap<>(eventSources.length); - for (EventSource eventSource : eventSources) { - eventSourceMap.put(generateNameFor(eventSource), eventSource); - } - return eventSourceMap; + + @SuppressWarnings("unchecked") + public static List dependentEventSources( + EventSourceContext eventSourceContext, DependentResource... dependentResources) { + return Arrays.stream(dependentResources) + .flatMap(dr -> dr.eventSource(eventSourceContext).stream()).toList(); } @SuppressWarnings("unchecked") - public static Map eventSourcesFromWorkflow( + public static List eventSourcesFromWorkflow( EventSourceContext context, Workflow workflow) { - Map result = new HashMap<>(); - for (var e : workflow.getDependentResourcesByNameWithoutActivationCondition().entrySet()) { - var eventSource = e.getValue().eventSource(context); - eventSource.ifPresent(es -> result.put(e.getKey(), (EventSource) es)); - } - return result; - } - - @SuppressWarnings("rawtypes") - public static Map nameEventSourcesFromDependentResource( - EventSourceContext context, DependentResource... dependentResources) { - return nameEventSourcesFromDependentResource(context, Arrays.asList(dependentResources)); - } - - @SuppressWarnings("unchecked,rawtypes") - public static Map nameEventSourcesFromDependentResource( - EventSourceContext context, Collection dependentResources) { - - if (dependentResources != null) { - Map eventSourceMap = new HashMap<>(dependentResources.size()); - for (DependentResource dependentResource : dependentResources) { - Optional es = dependentResource.eventSource(context); - es.ifPresent(e -> eventSourceMap.put(generateNameFor(e), e)); - } - return eventSourceMap; - } else { - return Collections.emptyMap(); - } - } - - /** - * Used when event sources are not explicitly named when created/registered. - * - * @param eventSource EventSource - * @return generated name - */ - public static String generateNameFor(EventSource eventSource) { - // we can have multiple event sources for the same class - return eventSource.getClass().getName() + "#" + eventSource.hashCode(); + return workflow.getDependentResourcesWithoutActivationCondition().stream() + .flatMap(dr -> dr.eventSource(context).stream()).toList(); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java index 2047762c35..40a8a3b407 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java @@ -19,17 +19,16 @@ public interface Reconciler

{ */ UpdateControl

reconcile(P resource, Context

context) throws Exception; - /** * Prepares a map of {@link EventSource} implementations keyed by the name with which they need to * be registered by the SDK. * * @param context a {@link EventSourceContext} providing access to information useful to event * sources - * @return a map of event sources to register + * @return a list of event sources */ - default Map prepareEventSources(EventSourceContext

context) { - return Map.of(); + default List prepareEventSources(EventSourceContext

context) { + return Collections.emptyList(); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/EventSourceProvider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/EventSourceProvider.java deleted file mode 100644 index c83af1270a..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/EventSourceProvider.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.javaoperatorsdk.operator.api.reconciler.dependent; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.processing.event.source.EventSource; - -/** - * @deprecated now event source related methods are directly on {@link DependentResource} - * @param

primary resource - */ -@Deprecated(forRemoval = true) -public interface EventSourceProvider

{ - /** - * @param context - event source context where the event source is initialized - * @return the initiated event source. - */ - EventSource initEventSource(EventSourceContext

context); -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/ControllerHealthInfo.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/ControllerHealthInfo.java index fe90b99ef3..f873a6d870 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/ControllerHealthInfo.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/ControllerHealthInfo.java @@ -4,6 +4,7 @@ import java.util.stream.Collectors; import io.javaoperatorsdk.operator.processing.event.EventSourceManager; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; @SuppressWarnings("rawtypes") public class ControllerHealthInfo { @@ -15,21 +16,21 @@ public ControllerHealthInfo(EventSourceManager eventSourceManager) { } public Map eventSourceHealthIndicators() { - return eventSourceManager.allEventSources().entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + return eventSourceManager.allEventSources().stream() + .collect(Collectors.toMap(EventSource::name, e -> e)); } public Map unhealthyEventSources() { - return eventSourceManager.allEventSources().entrySet().stream() - .filter(e -> e.getValue().getStatus() == Status.UNHEALTHY) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + return eventSourceManager.allEventSources().stream() + .filter(e -> e.getStatus() == Status.UNHEALTHY) + .collect(Collectors.toMap(EventSource::name, e -> e)); } public Map informerEventSourceHealthIndicators() { - return eventSourceManager.allEventSources().entrySet().stream() - .filter(e -> e.getValue() instanceof InformerWrappingEventSourceHealthIndicator) - .collect(Collectors.toMap(Map.Entry::getKey, - e -> (InformerWrappingEventSourceHealthIndicator) e.getValue())); + return eventSourceManager.allEventSources().stream() + .filter(e -> e instanceof InformerWrappingEventSourceHealthIndicator) + .collect(Collectors.toMap(EventSource::name, + e -> (InformerWrappingEventSourceHealthIndicator) e)); } @@ -40,11 +41,11 @@ public Map informerEventSour * {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}. */ public Map unhealthyInformerEventSourceHealthIndicators() { - return eventSourceManager.allEventSources().entrySet().stream() - .filter(e -> e.getValue().getStatus() == Status.UNHEALTHY) - .filter(e -> e.getValue() instanceof InformerWrappingEventSourceHealthIndicator) - .collect(Collectors.toMap(Map.Entry::getKey, - e -> (InformerWrappingEventSourceHealthIndicator) e.getValue())); + return eventSourceManager.allEventSources().stream() + .filter(e -> e.getStatus() == Status.UNHEALTHY) + .filter(e -> e instanceof InformerWrappingEventSourceHealthIndicator) + .collect(Collectors.toMap(EventSource::name, + e -> (InformerWrappingEventSourceHealthIndicator) e)); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 88d8d34894..c42e6b783b 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -36,7 +36,6 @@ import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceNotFoundException; -import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceProvider; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceReferencer; import io.javaoperatorsdk.operator.health.ControllerHealthInfo; import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow; @@ -233,22 +232,17 @@ public void initAndRegisterEventSources(EventSourceContext

context) { // register created event sources final var dependentResourcesByName = - managedWorkflow.getDependentResourcesByNameWithoutActivationCondition(); + managedWorkflow.getDependentResourcesWithoutActivationCondition(); final var size = dependentResourcesByName.size(); if (size > 0) { - dependentResourcesByName.forEach((key, dependentResource) -> { - if (dependentResource instanceof EventSourceProvider provider) { - final var source = provider.initEventSource(context); - eventSourceManager.registerEventSource(key, source); - } else { - Optional eventSource = dependentResource.eventSource(context); - eventSource.ifPresent(es -> eventSourceManager.registerEventSource(key, es)); - } + dependentResourcesByName.forEach(dependentResource -> { + Optional eventSource = dependentResource.eventSource(context); + eventSource.ifPresent(eventSourceManager::registerEventSource); }); // resolve event sources referenced by name for dependents that reuse an existing event source final Map> unresolvable = new HashMap<>(size); - dependentResourcesByName.values().stream() + dependentResourcesByName.stream() .filter(EventSourceReferencer.class::isInstance) .map(EventSourceReferencer.class::cast) .forEach(dr -> { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/AbstractPollingDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/AbstractPollingDependentResource.java index 6355ec39c7..659b8b4720 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/AbstractPollingDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/AbstractPollingDependentResource.java @@ -1,5 +1,7 @@ package io.javaoperatorsdk.operator.processing.dependent.external; +import java.time.Duration; + import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.Ignore; import io.javaoperatorsdk.operator.processing.dependent.AbstractExternalDependentResource; @@ -11,23 +13,23 @@ public abstract class AbstractPollingDependentResource extends AbstractExternalDependentResource> implements CacheKeyMapper { - public static final int DEFAULT_POLLING_PERIOD = 5000; - private long pollingPeriod; + public static final Duration DEFAULT_POLLING_PERIOD = Duration.ofMillis(5000); + private Duration pollingPeriod; protected AbstractPollingDependentResource(Class resourceType) { this(resourceType, DEFAULT_POLLING_PERIOD); } - public AbstractPollingDependentResource(Class resourceType, long pollingPeriod) { + public AbstractPollingDependentResource(Class resourceType, Duration pollingPeriod) { super(resourceType); this.pollingPeriod = pollingPeriod; } - public void setPollingPeriod(long pollingPeriod) { + public void setPollingPeriod(Duration pollingPeriod) { this.pollingPeriod = pollingPeriod; } - public long getPollingPeriod() { + public Duration getPollingPeriod() { return pollingPeriod; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PerResourcePollingDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PerResourcePollingDependentResource.java index affc63cfd3..581698ffd6 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PerResourcePollingDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PerResourcePollingDependentResource.java @@ -6,6 +6,7 @@ import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.Ignore; import io.javaoperatorsdk.operator.processing.event.source.ExternalResourceCachingEventSource; +import io.javaoperatorsdk.operator.processing.event.source.polling.PerResourcePollingConfigurationBuilder; import io.javaoperatorsdk.operator.processing.event.source.polling.PerResourcePollingEventSource; @Ignore @@ -18,15 +19,18 @@ public PerResourcePollingDependentResource(Class resourceType) { super(resourceType); } - public PerResourcePollingDependentResource(Class resourceType, long pollingPeriod) { + public PerResourcePollingDependentResource(Class resourceType, Duration pollingPeriod) { super(resourceType, pollingPeriod); } @Override protected ExternalResourceCachingEventSource createEventSource( EventSourceContext

context) { - return new PerResourcePollingEventSource<>(this, context, - Duration.ofMillis(getPollingPeriod()), resourceType(), this); - } + return new PerResourcePollingEventSource<>(name(), resourceType(), context, + new PerResourcePollingConfigurationBuilder<>( + this, getPollingPeriod()) + .withCacheKeyMapper(this) + .build()); + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PollingDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PollingDependentResource.java index 3df1390d69..519771d82d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PollingDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PollingDependentResource.java @@ -1,10 +1,13 @@ package io.javaoperatorsdk.operator.processing.dependent.external; +import java.time.Duration; + import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.Ignore; import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; import io.javaoperatorsdk.operator.processing.event.source.ExternalResourceCachingEventSource; +import io.javaoperatorsdk.operator.processing.event.source.polling.PollingConfiguration; import io.javaoperatorsdk.operator.processing.event.source.polling.PollingEventSource; @Ignore @@ -19,7 +22,7 @@ public PollingDependentResource(Class resourceType, CacheKeyMapper cacheKe this.cacheKeyMapper = cacheKeyMapper; } - public PollingDependentResource(Class resourceType, long pollingPeriod, + public PollingDependentResource(Class resourceType, Duration pollingPeriod, CacheKeyMapper cacheKeyMapper) { super(resourceType, pollingPeriod); this.cacheKeyMapper = cacheKeyMapper; @@ -28,7 +31,8 @@ public PollingDependentResource(Class resourceType, long pollingPeriod, @Override protected ExternalResourceCachingEventSource createEventSource( EventSourceContext

context) { - return new PollingEventSource<>(this, getPollingPeriod(), resourceType(), cacheKeyMapper); + return new PollingEventSource<>(name(), resourceType(), + new PollingConfiguration<>(this, getPollingPeriod(), cacheKeyMapper)); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 0af41b58eb..de5770bb1f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -84,7 +84,7 @@ private void configureWith(String labelSelector, Set namespaces, .withNamespaces(namespaces, inheritNamespacesOnChange) .build(); - configureWith(new InformerEventSource<>(ic, context)); + configureWith(new InformerEventSource<>(name(), ic, context)); } // just to seamlessly handle GenericKubernetesDependentResource diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java index 05b546553c..c22bf9d666 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java @@ -139,8 +139,7 @@ protected void registerOrDeregisterEventSourceBasedOnActivation( var eventSource = dr.eventSource(eventSourceRetriever.eventSourceContextForDynamicRegistration()); var es = eventSource.orElseThrow(); - eventSourceRetriever.dynamicallyRegisterEventSource(dr.name(), es); - + eventSourceRetriever.dynamicallyRegisterEventSource(es); } else { eventSourceRetriever.dynamicallyDeRegisterEventSource(dr.name()); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java index e52823b4f8..bf186f01ca 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java @@ -153,14 +153,10 @@ public Map getDependentResourcesByName() { return resources; } - public Map getDependentResourcesByNameWithoutActivationCondition() { - final var resources = new HashMap(dependentResourceNodes.size()); - dependentResourceNodes - .forEach((name, node) -> { - if (node.getActivationCondition().isEmpty()) { - resources.put(name, node.getDependentResource()); - } - }); - return resources; + public List getDependentResourcesWithoutActivationCondition() { + return dependentResourceNodes.values().stream() + .filter(n -> n.getActivationCondition().isEmpty()) + .map(DependentResourceNode::getDependentResource) + .toList(); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java index 839844256e..7f30ba6c9e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java @@ -1,6 +1,7 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Set; @@ -44,7 +45,7 @@ default Map getDependentResourcesByName() { } @SuppressWarnings("rawtypes") - default Map getDependentResourcesByNameWithoutActivationCondition() { - return Collections.emptyMap(); + default List getDependentResourcesWithoutActivationCondition() { + return Collections.emptyList(); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java index 2b1005af4a..512ab3bde1 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java @@ -2,13 +2,11 @@ import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,7 +17,6 @@ import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager; import io.javaoperatorsdk.operator.api.config.NamespaceChangeable; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.LifecycleAware; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -70,27 +67,23 @@ public void postProcessDefaultEventSourcesAfterProcessorInitializer() { */ @Override public synchronized void start() { - startEventSource(eventSources.namedControllerResourceEventSource()); + startEventSource(eventSources.controllerResourceEventSource()); executorServiceManager.boundedExecuteAndWaitForAllToComplete( - eventSources.additionalNamedEventSources() + eventSources.additionalEventSources() .filter(es -> es.priority().equals(EventSourceStartPriority.RESOURCE_STATE_LOADER)), this::startEventSource, getThreadNamer("start")); executorServiceManager.boundedExecuteAndWaitForAllToComplete( - eventSources.additionalNamedEventSources() + eventSources.additionalEventSources() .filter(es -> es.priority().equals(EventSourceStartPriority.DEFAULT)), this::startEventSource, getThreadNamer("start")); } - private static Function getThreadNamer(String stage) { - return es -> { - final var name = es.name(); - return es.priority() + " " + stage + " -> " - + (es.isNameSet() ? name + " " + es.original().getClass() : es.original()); - }; + private static Function getThreadNamer(String stage) { + return es -> es.priority() + " " + stage + " -> " + es.name(); } private static Function getEventSourceThreadNamer(String stage) { @@ -99,28 +92,26 @@ private static Function getEventSourceThreadNamer(S @Override public synchronized void stop() { - stopEventSource(eventSources.namedControllerResourceEventSource()); + stopEventSource(eventSources.controllerResourceEventSource()); executorServiceManager.boundedExecuteAndWaitForAllToComplete( - eventSources.additionalNamedEventSources(), + eventSources.additionalEventSources(), this::stopEventSource, getThreadNamer("stop")); } @SuppressWarnings("rawtypes") - private void logEventSourceEvent(NamedEventSource eventSource, String event) { + private void logEventSourceEvent(EventSource eventSource, String event) { if (log.isDebugEnabled()) { - if (eventSource.original() instanceof ResourceEventSource source) { - log.debug("{} event source {} for {}", event, - eventSource.isNameSet() ? eventSource.name() : eventSource, + if (eventSource instanceof ResourceEventSource source) { + log.debug("{} event source {} for {}", event, eventSource.name(), source.resourceType()); } else { - log.debug("{} event source {}", event, - eventSource.isNameSet() ? eventSource.name() : eventSource); + log.debug("{} event source {}", event, eventSource.name()); } } } - private Void startEventSource(NamedEventSource eventSource) { + private Void startEventSource(EventSource eventSource) { try { logEventSourceEvent(eventSource, "Starting"); eventSource.start(); @@ -133,7 +124,7 @@ private Void startEventSource(NamedEventSource eventSource) { return null; } - private Void stopEventSource(NamedEventSource eventSource) { + private Void stopEventSource(EventSource eventSource) { try { logEventSourceEvent(eventSource, "Stopping"); eventSource.stop(); @@ -144,37 +135,28 @@ private Void stopEventSource(NamedEventSource eventSource) { return null; } - public final void registerEventSource(EventSource eventSource) throws OperatorException { - registerEventSource(null, eventSource); - } - @SuppressWarnings("rawtypes") - public final synchronized void registerEventSource(String name, EventSource eventSource) + public final synchronized void registerEventSource(EventSource eventSource) throws OperatorException { Objects.requireNonNull(eventSource, "EventSource must not be null"); try { - if (name == null || name.isBlank()) { - name = EventSourceUtils.generateNameFor(eventSource); - } if (eventSource instanceof ManagedInformerEventSource managedInformerEventSource) { managedInformerEventSource.setConfigurationService( controller.getConfiguration().getConfigurationService()); } - final var named = new NamedEventSource(eventSource, name); - eventSources.add(named); - named.setEventHandler(controller.getEventProcessor()); + eventSources.add(eventSource); + eventSource.setEventHandler(controller.getEventProcessor()); } catch (IllegalStateException | MissingCRDException e) { throw e; // leave untouched } catch (Exception e) { - throw new OperatorException("Couldn't register event source: " + name + " for " + throw new OperatorException("Couldn't register event source: " + eventSource.name() + " for " + controller.getConfiguration().getName() + " controller", e); } } @SuppressWarnings("unchecked") public void broadcastOnResourceEvent(ResourceAction action, P resource, P oldResource) { - eventSources.additionalNamedEventSources() - .map(NamedEventSource::original) + eventSources.additionalEventSources() .forEach(source -> { if (source instanceof ResourceEventAware) { var lifecycleAwareES = ((ResourceEventAware

) source); @@ -209,18 +191,12 @@ public void changeNamespaces(Set namespaces) { public Set getRegisteredEventSources() { return eventSources.flatMappedSources() - .map(NamedEventSource::original) - .collect(Collectors.toCollection(LinkedHashSet::new)); - } - public Map allEventSources() { - return eventSources.allNamedEventSources().collect(Collectors.toMap(NamedEventSource::name, - NamedEventSource::original)); + .collect(Collectors.toCollection(LinkedHashSet::new)); } - @SuppressWarnings("unused") - public Stream getNamedEventSourcesStream() { - return eventSources.flatMappedSources(); + public List allEventSources() { + return eventSources.allEventSources().toList(); } public ControllerResourceEventSource

getControllerResourceEventSource() { @@ -232,14 +208,13 @@ public List> getResourceEventSourcesFor(Class d } @Override - public EventSource dynamicallyRegisterEventSource(String name, - EventSource eventSource) { + public EventSource dynamicallyRegisterEventSource(EventSource eventSource) { synchronized (this) { - var actual = eventSources.existing(name, eventSource); + var actual = eventSources.existingEventSourceOfSameNameAndType(eventSource); if (actual != null) { - eventSource = actual.eventSource(); + eventSource = actual; } else { - registerEventSource(name, eventSource); + registerEventSource(eventSource); } } // The start itself is blocking thus blocking only the threads which are attempt to start the @@ -276,9 +251,9 @@ public List> getEventSourcesFor(Class dependent @Override public ResourceEventSource getResourceEventSourceFor( - Class dependentType, String qualifier) { + Class dependentType, String name) { Objects.requireNonNull(dependentType, "dependentType is Mandatory"); - return eventSources.get(dependentType, qualifier); + return eventSources.get(dependentType, name); } TimerEventSource

retryEventSource() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java index 7ed2777998..c687c93acd 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java @@ -19,10 +19,11 @@ default ResourceEventSource getResourceEventSourceFor(Class depende List> getResourceEventSourcesFor(Class dependentType); /** + *

* Registers (and starts) the specified {@link EventSource} dynamically during the reconciliation. * If an EventSource is already registered with the specified name, the registration will be - * ignored. It is the user's responsibility to handle the naming correctly, thus to not try to - * register different event source with same name that is already registered. + * ignored. It is the user's responsibility to handle the naming correctly. + *

*

* This is only needed when your operator needs to adapt dynamically based on optional resources * that may or may not be present on the target cluster. Even in this situation, it should be @@ -31,20 +32,25 @@ default ResourceEventSource getResourceEventSourceFor(Class depende * activation conditions of dependents, for example. *

*

- * This method will block until the event source is synced, if needed (as is the case for + * This method will block until the event source is synced (if needed, as it is the case for * {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}). *

*

- * Should multiple reconciliations happen concurrently, only one EventSource with the specified - * name will ever be registered. + * IMPORTANT: Should multiple reconciliations happen concurrently, only one + * EventSource with the specified name will ever be registered. It is therefore important to + * explicitly name the event sources that you want to reuse because the name will be used to + * identify which event sources need to be created or not. If you let JOSDK implicitly name event + * sources, then you might end up with duplicated event sources because concurrent registration of + * event sources will lead to 2 (or more) event sources for the same resource type to be attempted + * to be registered under different, automatically generated names. If you clearly identify your + * event sources with names, then, if the concurrent process determines that an event source with + * the specified name, it won't register it again. *

* - * @param name of the event source * @param eventSource to register * @return the actual event source registered. Might not be the same as the parameter. */ - EventSource dynamicallyRegisterEventSource(String name, EventSource eventSource); - + EventSource dynamicallyRegisterEventSource(EventSource eventSource); /** * De-registers (and stops) the {@link EventSource} associated with the specified name. If no such diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java index f827b04a6d..c6b5a83377 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java @@ -1,10 +1,10 @@ package io.javaoperatorsdk.operator.processing.event; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.stream.Collectors; @@ -19,14 +19,10 @@ class EventSources { - public static final String CONTROLLER_RESOURCE_EVENT_SOURCE_NAME = - "ControllerResourceEventSource"; - public static final String RETRY_RESCHEDULE_TIMER_EVENT_SOURCE_NAME = - "RetryAndRescheduleTimerEventSource"; - - private final ConcurrentNavigableMap> sources = + private final ConcurrentNavigableMap> sources = new ConcurrentSkipListMap<>(); - private final TimerEventSource retryAndRescheduleTimerEventSource = new TimerEventSource<>(); + private final TimerEventSource retryAndRescheduleTimerEventSource = + new TimerEventSource<>("RetryAndRescheduleTimerEventSource"); private ControllerResourceEventSource controllerResourceEventSource; @@ -42,32 +38,19 @@ TimerEventSource retryEventSource() { return retryAndRescheduleTimerEventSource; } - public Stream additionalNamedEventSources() { - return Stream.concat(Stream.of( - new NamedEventSource(retryAndRescheduleTimerEventSource, - RETRY_RESCHEDULE_TIMER_EVENT_SOURCE_NAME)), - flatMappedSources()); - } - - public Stream allNamedEventSources() { - return Stream.concat(Stream.of(namedControllerResourceEventSource(), - new NamedEventSource(retryAndRescheduleTimerEventSource, - RETRY_RESCHEDULE_TIMER_EVENT_SOURCE_NAME)), + public Stream allEventSources() { + return Stream.concat( + Stream.of(controllerResourceEventSource(), retryAndRescheduleTimerEventSource), flatMappedSources()); } Stream additionalEventSources() { return Stream.concat( Stream.of(retryEventSource()).filter(Objects::nonNull), - flatMappedSources().map(NamedEventSource::original)); - } - - NamedEventSource namedControllerResourceEventSource() { - return new NamedEventSource(controllerResourceEventSource, - CONTROLLER_RESOURCE_EVENT_SOURCE_NAME); + flatMappedSources()); } - Stream flatMappedSources() { + Stream flatMappedSources() { return sources.values().stream().flatMap(c -> c.values().stream()); } @@ -75,26 +58,23 @@ public void clear() { sources.clear(); } - public NamedEventSource existing(String name, EventSource source) { - final var eventSources = sources.get(keyFor(source)); - if (eventSources == null || eventSources.isEmpty()) { - return null; - } - return eventSources.get(name); + public EventSource existingEventSourceOfSameNameAndType(EventSource source) { + return existingEventSourceOfSameType(source).get(source.name()); + } + + public Map existingEventSourceOfSameType(EventSource source) { + return sources.getOrDefault(keyFor(source), Collections.emptyMap()); } - public void add(NamedEventSource eventSource) { + public void add(EventSource eventSource) { final var name = eventSource.name(); - final var original = eventSource.original(); - final var existing = existing(name, original); - if (existing != null && !eventSource.equals(existing)) { - throw new IllegalArgumentException("Event source " + existing.original() - + " is already registered for the " - + keyAsString(getResourceType(original), name) - + " class/name combination"); + final var existing = existingEventSourceOfSameType(eventSource); + if (existing.get(name) != null) { + throw new IllegalArgumentException("Event source " + existing + + " is already registered with name: " + name); } - sources.computeIfAbsent(keyFor(original), k -> new ConcurrentHashMap<>()).put(name, - eventSource); + + sources.computeIfAbsent(keyFor(eventSource), k -> new HashMap<>()).put(name, eventSource); } @SuppressWarnings("rawtypes") @@ -105,10 +85,6 @@ private Class getResourceType(EventSource source) { } private String keyFor(EventSource source) { - if (source instanceof NamedEventSource) { - source = ((NamedEventSource) source).original(); - } - return keyFor(getResourceType(source)); } @@ -129,7 +105,7 @@ public ResourceEventSource get(Class dependentType, String name) { } final var size = sourcesForType.size(); - NamedEventSource source; + EventSource source; if (size == 1 && name == null) { source = sourcesForType.values().stream().findFirst().orElseThrow(); } else { @@ -147,16 +123,15 @@ public ResourceEventSource get(Class dependentType, String name) { } } - EventSource original = source.original(); - if (!(original instanceof ResourceEventSource)) { + if (!(source instanceof ResourceEventSource)) { throw new IllegalArgumentException(source + " associated with " + keyAsString(dependentType, name) + " is not a " + ResourceEventSource.class.getSimpleName()); } - final var res = (ResourceEventSource) original; + final var res = (ResourceEventSource) source; final var resourceClass = res.resourceType(); if (!resourceClass.isAssignableFrom(dependentType)) { - throw new IllegalArgumentException(original + " associated with " + throw new IllegalArgumentException(source + " associated with " + keyAsString(dependentType, name) + " is handling " + resourceClass.getName() + " resources but asked for " + dependentType.getName()); @@ -179,7 +154,6 @@ public List> getEventSources(Class dependentTyp } return sourcesForType.values().stream() - .map(NamedEventSource::original) .filter(ResourceEventSource.class::isInstance) .map(es -> (ResourceEventSource) es) .collect(Collectors.toList()); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java deleted file mode 100644 index 1ad6efa929..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java +++ /dev/null @@ -1,103 +0,0 @@ -package io.javaoperatorsdk.operator.processing.event; - -import java.util.Objects; -import java.util.Optional; - -import io.javaoperatorsdk.operator.OperatorException; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; -import io.javaoperatorsdk.operator.processing.event.source.Configurable; -import io.javaoperatorsdk.operator.processing.event.source.EventSource; -import io.javaoperatorsdk.operator.processing.event.source.EventSourceStartPriority; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; - -class NamedEventSource implements EventSource, EventSourceMetadata { - - private final EventSource original; - private final String name; - private final boolean nameSet; - - NamedEventSource(EventSource original, String name) { - this.original = original; - this.name = name; - nameSet = !name.equals(EventSourceUtils.generateNameFor(original)); - } - - @Override - public void start() throws OperatorException { - original.start(); - } - - @Override - public void stop() throws OperatorException { - original.stop(); - } - - @Override - public void setEventHandler(EventHandler handler) { - original.setEventHandler(handler); - } - - public String name() { - return name; - } - - @Override - public Class type() { - return original.getClass(); - } - - @Override - @SuppressWarnings({"rawtypes", "unchecked"}) - public Optional> resourceType() { - if (original instanceof ResourceEventSource resourceEventSource) { - return Optional.of(resourceEventSource.resourceType()); - } - return Optional.empty(); - } - - @Override - @SuppressWarnings("rawtypes") - public Optional configuration() { - if (original instanceof Configurable configurable) { - return Optional.ofNullable(configurable.configuration()); - } - return Optional.empty(); - } - - public EventSource eventSource() { - return original; - } - - @Override - public String toString() { - return original + " named: " + name; - } - - public EventSource original() { - return original; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - NamedEventSource that = (NamedEventSource) o; - return Objects.equals(original, that.original) && Objects.equals(name, that.name); - } - - @Override - public int hashCode() { - return Objects.hash(original, name); - } - - @Override - public EventSourceStartPriority priority() { - return original.priority(); - } - - public boolean isNameSet() { - return nameSet; - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java index a20fb2e36a..7b5e25f4bb 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java @@ -357,7 +357,6 @@ private P patchResource(P resource, P originalResource) { getVersion(resource)); log.trace("Resource before update: {}", resource); - // todo unit test final var finalizerName = configuration().getFinalizerName(); if (useSSA && controller.useFinalizer()) { // addFinalizer already prevents adding an already present finalizer so no need to check diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSource.java index 4eaee91add..b2398ab6ff 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSource.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.processing.event.source; + import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.processing.event.EventHandler; @@ -7,6 +8,20 @@ public abstract class AbstractEventSource implements EventSource { private EventHandler handler; private volatile boolean running = false; private EventSourceStartPriority eventSourceStartPriority = EventSourceStartPriority.DEFAULT; + private final String name; + + protected AbstractEventSource() { + this(null); + } + + protected AbstractEventSource(String name) { + this.name = name == null ? EventSource.super.name() : name; + } + + @Override + public String name() { + return name; + } protected EventHandler getEventHandler() { return handler; @@ -41,4 +56,5 @@ public AbstractEventSource setEventSourcePriority( this.eventSourceStartPriority = eventSourceStartPriority; return this; } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractResourceEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractResourceEventSource.java index 65294c1625..73420c0e5e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractResourceEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractResourceEventSource.java @@ -17,6 +17,11 @@ public abstract class AbstractResourceEventSource protected GenericFilter genericFilter; protected AbstractResourceEventSource(Class resourceClass) { + this(resourceClass, resourceClass.getName()); + } + + protected AbstractResourceEventSource(Class resourceClass, String name) { + super(name); this.resourceClass = resourceClass; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java index 05a034a7a7..e368ec3a94 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java @@ -28,4 +28,13 @@ default EventSourceStartPriority priority() { default Status getStatus() { return Status.UNKNOWN; } + + default String name() { + return generateName(this); + } + + static String generateName(EventSource eventSource) { + return eventSource.getClass().getName() + "@" + Integer.toHexString(eventSource.hashCode()); + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java index 3ccc41a77d..b4bb44d957 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java @@ -51,7 +51,12 @@ public abstract class ExternalResourceCachingEventSource resourceClass, CacheKeyMapper cacheKeyMapper) { - super(resourceClass); + this(null, resourceClass, cacheKeyMapper); + } + + protected ExternalResourceCachingEventSource(String name, Class resourceClass, + CacheKeyMapper cacheKeyMapper) { + super(resourceClass, name); this.cacheKeyMapper = cacheKeyMapper; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventSource.java index 722e260878..52215cdcf7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventSource.java @@ -39,4 +39,5 @@ default Optional getSecondaryResource(P primary) { void setOnDeleteFilter(OnDeleteFilter onDeleteFilter); void setGenericFilter(GenericFilter genericFilter); + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java index 614525e970..9a2f51cf37 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java @@ -18,7 +18,7 @@ import io.javaoperatorsdk.operator.processing.event.source.informer.ManagedInformerEventSource; import static io.javaoperatorsdk.operator.ReconcilerUtils.handleKubernetesClientException; -import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.*; +import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion; import static io.javaoperatorsdk.operator.processing.event.source.controller.InternalEventFilters.*; public class ControllerResourceEventSource @@ -26,12 +26,13 @@ public class ControllerResourceEventSource implements ResourceEventHandler { private static final Logger log = LoggerFactory.getLogger(ControllerResourceEventSource.class); + private static final String NAME = "ControllerResourceEventSource"; private final Controller controller; @SuppressWarnings({"unchecked", "rawtypes"}) public ControllerResourceEventSource(Controller controller) { - super(controller.getCRClient(), controller.getConfiguration(), false); + super(NAME, controller.getCRClient(), controller.getConfiguration(), false); this.controller = controller; final var config = controller.getConfiguration(); @@ -130,4 +131,9 @@ public void setOnDeleteFilter(OnDeleteFilter onDeleteFilter) { throw new IllegalStateException( "onDeleteFilter is not supported for controller resource event source"); } + + @Override + public String name() { + return NAME; + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/inbound/SimpleInboundEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/inbound/SimpleInboundEventSource.java index a441684f0f..d13c032f88 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/inbound/SimpleInboundEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/inbound/SimpleInboundEventSource.java @@ -11,6 +11,12 @@ public class SimpleInboundEventSource extends AbstractEventSource { private static final Logger log = LoggerFactory.getLogger(SimpleInboundEventSource.class); + public SimpleInboundEventSource() {} + + public SimpleInboundEventSource(String name) { + super(name); + } + public void propagateEvent(ResourceID resourceID) { if (isRunning()) { getEventHandler().handleEvent(new Event(resourceID)); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java index 81d31f7407..8759410b81 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java @@ -76,20 +76,28 @@ public class InformerEventSource private final PrimaryToSecondaryMapper

primaryToSecondaryMapper; private final String id = UUID.randomUUID().toString(); + public InformerEventSource(String name, + InformerConfiguration configuration, EventSourceContext

context) { + this(name, configuration, context.getClient(), + context.getControllerConfiguration().getConfigurationService() + .parseResourceVersionsForEventFilteringAndCaching()); + } + public InformerEventSource( InformerConfiguration configuration, EventSourceContext

context) { - this(configuration, context.getClient(), + this(null, configuration, context.getClient(), context.getControllerConfiguration().getConfigurationService() .parseResourceVersionsForEventFilteringAndCaching()); } public InformerEventSource(InformerConfiguration configuration, KubernetesClient client) { - this(configuration, client, false); + this(null, configuration, client, false); } - public InformerEventSource(InformerConfiguration configuration, KubernetesClient client, + public InformerEventSource(String name, InformerConfiguration configuration, + KubernetesClient client, boolean parseResourceVersions) { - super( + super(name, configuration.getGroupVersionKind() .map(gvk -> client.genericKubernetesResources(gvk.apiVersion(), gvk.getKind())) .orElseGet(() -> (MixedOperation) client.resources(configuration.getResourceClass())), @@ -316,5 +324,4 @@ public R addPreviousAnnotation(String resourceVersion, R target) { id + Optional.ofNullable(resourceVersion).map(rv -> "," + rv).orElse("")); return target; } - } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java index f5efd0a68c..ec8e980871 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java @@ -24,10 +24,7 @@ import io.javaoperatorsdk.operator.health.InformerWrappingEventSourceHealthIndicator; import io.javaoperatorsdk.operator.health.Status; import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.AbstractResourceEventSource; -import io.javaoperatorsdk.operator.processing.event.source.Cache; -import io.javaoperatorsdk.operator.processing.event.source.Configurable; -import io.javaoperatorsdk.operator.processing.event.source.IndexerResourceCache; +import io.javaoperatorsdk.operator.processing.event.source.*; @SuppressWarnings("rawtypes") public abstract class ManagedInformerEventSource> @@ -45,10 +42,10 @@ public abstract class ManagedInformerEventSource temporaryResourceCache; protected MixedOperation client; - protected ManagedInformerEventSource( + protected ManagedInformerEventSource(String name, MixedOperation client, C configuration, boolean parseResourceVersions) { - super(configuration.getResourceClass()); + super(configuration.getResourceClass(), name); this.parseResourceVersions = parseResourceVersions; this.client = client; this.configuration = configuration; @@ -197,4 +194,5 @@ public String toString() { public void setConfigurationService(ConfigurationService configurationService) { this.configurationService = configurationService; } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfiguration.java new file mode 100644 index 0000000000..23fa9e023a --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfiguration.java @@ -0,0 +1,30 @@ +package io.javaoperatorsdk.operator.processing.event.source.polling; + +import java.time.Duration; +import java.util.Objects; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.function.Predicate; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; + +public record PerResourcePollingConfiguration(ScheduledExecutorService executorService, CacheKeyMapper cacheKeyMapper, + PerResourcePollingEventSource.ResourceFetcher resourceFetcher, + Predicate

registerPredicate, Duration defaultPollingPeriod) { + + public static final int DEFAULT_EXECUTOR_THREAD_NUMBER = 1; + + public PerResourcePollingConfiguration(ScheduledExecutorService executorService, + CacheKeyMapper cacheKeyMapper, + PerResourcePollingEventSource.ResourceFetcher resourceFetcher, + Predicate

registerPredicate, + Duration defaultPollingPeriod) { + this.executorService = executorService == null ? new ScheduledThreadPoolExecutor(DEFAULT_EXECUTOR_THREAD_NUMBER) + : executorService; + this.cacheKeyMapper = cacheKeyMapper == null ? CacheKeyMapper.singleResourceCacheKeyMapper() : cacheKeyMapper; + this.resourceFetcher = Objects.requireNonNull(resourceFetcher); + this.registerPredicate = registerPredicate; + this.defaultPollingPeriod = defaultPollingPeriod; + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfigurationBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfigurationBuilder.java new file mode 100644 index 0000000000..ece10d347e --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfigurationBuilder.java @@ -0,0 +1,49 @@ +package io.javaoperatorsdk.operator.processing.event.source.polling; + +import java.time.Duration; +import java.util.concurrent.ScheduledExecutorService; +import java.util.function.Predicate; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; + +public final class PerResourcePollingConfigurationBuilder { + + private final Duration defaultPollingPeriod; + private final PerResourcePollingEventSource.ResourceFetcher resourceFetcher; + + private Predicate

registerPredicate; + private ScheduledExecutorService executorService; + private CacheKeyMapper cacheKeyMapper; + + public PerResourcePollingConfigurationBuilder( + PerResourcePollingEventSource.ResourceFetcher resourceFetcher, + Duration defaultPollingPeriod) { + this.resourceFetcher = resourceFetcher; + this.defaultPollingPeriod = defaultPollingPeriod; + } + + @SuppressWarnings("unused") + public PerResourcePollingConfigurationBuilder withExecutorService( + ScheduledExecutorService executorService) { + this.executorService = executorService; + return this; + } + + public PerResourcePollingConfigurationBuilder withRegisterPredicate( + Predicate

registerPredicate) { + this.registerPredicate = registerPredicate; + return this; + } + + public PerResourcePollingConfigurationBuilder withCacheKeyMapper( + CacheKeyMapper cacheKeyMapper) { + this.cacheKeyMapper = cacheKeyMapper; + return this; + } + + public PerResourcePollingConfiguration build() { + return new PerResourcePollingConfiguration<>(executorService, cacheKeyMapper, + resourceFetcher, registerPredicate, defaultPollingPeriod); + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java index 6da1ec0e58..2288e7eb75 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java @@ -9,7 +9,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; @@ -21,10 +20,10 @@ import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.Cache; -import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; import io.javaoperatorsdk.operator.processing.event.source.ExternalResourceCachingEventSource; import io.javaoperatorsdk.operator.processing.event.source.ResourceEventAware; + /** * * Polls the supplier for each controlled resource registered. Resource is registered when created @@ -42,138 +41,29 @@ public class PerResourcePollingEventSource private static final Logger log = LoggerFactory.getLogger(PerResourcePollingEventSource.class); - public static final int DEFAULT_EXECUTOR_THREAD_NUMBER = 1; + private final Map> scheduledFutures = new ConcurrentHashMap<>(); + private final Cache

primaryResourceCache; + private final Set fetchedForPrimaries = ConcurrentHashMap.newKeySet(); private final ScheduledExecutorService executorService; - private final Map> scheduledFutures = new ConcurrentHashMap<>(); private final ResourceFetcher resourceFetcher; - private final Cache

resourceCache; private final Predicate

registerPredicate; - private final long period; - private final Set fetchedForPrimaries = ConcurrentHashMap.newKeySet(); - - public PerResourcePollingEventSource(ResourceFetcher resourceFetcher, - EventSourceContext

context, Duration defaultPollingPeriod, - Class resourceClass) { - this(resourceFetcher, context.getPrimaryCache(), defaultPollingPeriod.toMillis(), - null, resourceClass, - CacheKeyMapper.singleResourceCacheKeyMapper()); - } - - /** - * @deprecated use the variant which uses {@link EventSourceContext} instead of {@link Cache} and - * {@link Duration} for period parameter as it provides a more intuitive API. - * - * @param resourceFetcher fetches resource related to a primary resource - * @param resourceCache cache of the primary resource - * @param period default polling period - * @param resourceClass class of the target resource - */ - @Deprecated(forRemoval = true) - public PerResourcePollingEventSource(ResourceFetcher resourceFetcher, - Cache

resourceCache, long period, Class resourceClass) { - this(resourceFetcher, resourceCache, period, null, resourceClass, - CacheKeyMapper.singleResourceCacheKeyMapper()); - } + private final Duration period; - public PerResourcePollingEventSource(ResourceFetcher resourceFetcher, - EventSourceContext

context, - Duration defaultPollingPeriod, - Class resourceClass, - CacheKeyMapper cacheKeyMapper) { - this(resourceFetcher, context.getPrimaryCache(), defaultPollingPeriod.toMillis(), - null, resourceClass, cacheKeyMapper); - } - - /** - * @deprecated use the variant which uses {@link EventSourceContext} instead of {@link Cache} and - * {@link Duration} for period parameter as it provides a more intuitive API. - * - * @param resourceFetcher fetches resource related to a primary resource - * @param resourceCache cache of the primary resource - * @param period default polling period - * @param resourceClass class of the target resource - * @param cacheKeyMapper use to distinguish resource in case more resources are handled for a - * single primary resource - */ - @Deprecated(forRemoval = true) - public PerResourcePollingEventSource(ResourceFetcher resourceFetcher, - Cache

resourceCache, long period, Class resourceClass, - CacheKeyMapper cacheKeyMapper) { - this(resourceFetcher, resourceCache, period, null, resourceClass, cacheKeyMapper); + public PerResourcePollingEventSource(Class resourceClass, EventSourceContext

context, + PerResourcePollingConfiguration config) { + this(null, resourceClass, context, config); } - public PerResourcePollingEventSource(ResourceFetcher resourceFetcher, + public PerResourcePollingEventSource(String name, Class resourceClass, EventSourceContext

context, - Duration defaultPollingPeriod, - Predicate

registerPredicate, - Class resourceClass, - CacheKeyMapper cacheKeyMapper) { - this(resourceFetcher, context.getPrimaryCache(), defaultPollingPeriod.toMillis(), - registerPredicate, resourceClass, cacheKeyMapper, - new ScheduledThreadPoolExecutor(DEFAULT_EXECUTOR_THREAD_NUMBER)); - } - - /** - * @deprecated use the variant which uses {@link EventSourceContext} instead of {@link Cache} and - * {@link Duration} for period parameter as it provides a more intuitive API. - * - * @param resourceFetcher fetches resource related to a primary resource - * @param resourceCache cache of the primary resource - * @param period default polling period - * @param resourceClass class of the target resource - * @param cacheKeyMapper use to distinguish resource in case more resources are handled for a - * single primary resource - * @param registerPredicate used to determine if the related resource for a custom resource should - * be polled or not. - */ - @Deprecated(forRemoval = true) - public PerResourcePollingEventSource(ResourceFetcher resourceFetcher, - Cache

resourceCache, long period, - Predicate

registerPredicate, Class resourceClass, - CacheKeyMapper cacheKeyMapper) { - this(resourceFetcher, resourceCache, period, registerPredicate, resourceClass, cacheKeyMapper, - new ScheduledThreadPoolExecutor(DEFAULT_EXECUTOR_THREAD_NUMBER)); - } - - - public PerResourcePollingEventSource( - ResourceFetcher resourceFetcher, - EventSourceContext

context, Duration defaultPollingPeriod, - Predicate

registerPredicate, Class resourceClass, - CacheKeyMapper cacheKeyMapper, ScheduledExecutorService executorService) { - this(resourceFetcher, context.getPrimaryCache(), defaultPollingPeriod.toMillis(), - registerPredicate, - resourceClass, cacheKeyMapper, executorService); - } - - /** - * @deprecated use the variant which uses {@link EventSourceContext} instead of {@link Cache} and - * {@link Duration} for period parameter as it provides a more intuitive API. - * - * @param resourceFetcher fetches resource related to a primary resource - * @param resourceCache cache of the primary resource - * @param period default polling period - * @param resourceClass class of the target resource - * @param cacheKeyMapper use to distinguish resource in case more resources are handled for a - * single primary resource - * @param registerPredicate used to determine if the related resource for a custom resource should - * be polled or not. - * @param executorService custom executor service - */ - - @Deprecated(forRemoval = true) - public PerResourcePollingEventSource( - ResourceFetcher resourceFetcher, - Cache

resourceCache, long period, - Predicate

registerPredicate, Class resourceClass, - CacheKeyMapper cacheKeyMapper, ScheduledExecutorService executorService) { - super(resourceClass, cacheKeyMapper); - this.resourceFetcher = resourceFetcher; - this.resourceCache = resourceCache; - this.period = period; - this.registerPredicate = registerPredicate; - this.executorService = executorService; + PerResourcePollingConfiguration config) { + super(name, resourceClass, config.cacheKeyMapper()); + this.primaryResourceCache = context.getPrimaryCache(); + this.resourceFetcher = config.resourceFetcher(); + this.registerPredicate = config.registerPredicate(); + this.executorService = config.executorService(); + this.period = config.defaultPollingPeriod(); } private Set getAndCacheResource(P primary, boolean fromGetter) { @@ -187,7 +77,7 @@ private Set getAndCacheResource(P primary, boolean fromGetter) { private void scheduleNextExecution(P primary, Set actualResources) { var primaryID = ResourceID.fromResource(primary); var fetchDelay = resourceFetcher.fetchDelay(actualResources, primary); - var fetchDuration = fetchDelay.orElse(Duration.ofMillis(period)); + var fetchDuration = fetchDelay.orElse(period); ScheduledFuture scheduledFuture = (ScheduledFuture) executorService .schedule(new FetchingExecutor(primaryID), fetchDuration.toMillis(), TimeUnit.MILLISECONDS); @@ -246,7 +136,7 @@ public void run() { return; } // always use up-to-date resource from cache - var primary = resourceCache.get(primaryID); + var primary = primaryResourceCache.get(primaryID); if (primary.isEmpty()) { log.warn("No resource in cache for resource ID: {}", primaryID); // no new execution is scheduled in this case, an on delete event should be received shortly diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfiguration.java new file mode 100644 index 0000000000..516d0546f7 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfiguration.java @@ -0,0 +1,18 @@ +package io.javaoperatorsdk.operator.processing.event.source.polling; + +import java.time.Duration; +import java.util.Objects; + +import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; + +public record PollingConfiguration(PollingEventSource.GenericResourceFetcher genericResourceFetcher, + Duration period, CacheKeyMapper cacheKeyMapper) { + + public PollingConfiguration(PollingEventSource.GenericResourceFetcher genericResourceFetcher, Duration period, + CacheKeyMapper cacheKeyMapper) { + this.genericResourceFetcher = Objects.requireNonNull(genericResourceFetcher); + this.period = period; + this.cacheKeyMapper = + cacheKeyMapper == null ? CacheKeyMapper.singleResourceCacheKeyMapper() : cacheKeyMapper; + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfigurationBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfigurationBuilder.java new file mode 100644 index 0000000000..576f8fdb56 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfigurationBuilder.java @@ -0,0 +1,26 @@ +package io.javaoperatorsdk.operator.processing.event.source.polling; + +import java.time.Duration; + +import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; + +public final class PollingConfigurationBuilder { + private final Duration period; + private final PollingEventSource.GenericResourceFetcher genericResourceFetcher; + private CacheKeyMapper cacheKeyMapper; + + public PollingConfigurationBuilder(PollingEventSource.GenericResourceFetcher fetcher, + Duration period) { + this.genericResourceFetcher = fetcher; + this.period = period; + } + + public PollingConfigurationBuilder withCacheKeyMapper(CacheKeyMapper cacheKeyMapper) { + this.cacheKeyMapper = cacheKeyMapper; + return this; + } + + public PollingConfiguration build() { + return new PollingConfiguration<>(genericResourceFetcher, period, cacheKeyMapper); + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java index 9ef889ecb6..060128576c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java @@ -1,6 +1,10 @@ package io.javaoperatorsdk.operator.processing.event.source.polling; -import java.util.*; +import java.time.Duration; +import java.util.Map; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; import java.util.concurrent.atomic.AtomicBoolean; import org.slf4j.Logger; @@ -10,7 +14,6 @@ import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.health.Status; import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; import io.javaoperatorsdk.operator.processing.event.source.ExternalResourceCachingEventSource; /** @@ -46,26 +49,17 @@ public class PollingEventSource private final Timer timer = new Timer(); private final GenericResourceFetcher genericResourceFetcher; - private final long period; + private final Duration period; private final AtomicBoolean healthy = new AtomicBoolean(true); - public PollingEventSource( - GenericResourceFetcher supplier, - long period, - Class resourceClass) { - super(resourceClass, CacheKeyMapper.singleResourceCacheKeyMapper()); - this.genericResourceFetcher = supplier; - this.period = period; + public PollingEventSource(Class resourceClass, PollingConfiguration config) { + this(null, resourceClass, config); } - public PollingEventSource( - GenericResourceFetcher supplier, - long period, - Class resourceClass, - CacheKeyMapper cacheKeyMapper) { - super(resourceClass, cacheKeyMapper); - this.genericResourceFetcher = supplier; - this.period = period; + public PollingEventSource(String name, Class resourceClass, PollingConfiguration config) { + super(name, resourceClass, config.cacheKeyMapper()); + this.genericResourceFetcher = config.genericResourceFetcher(); + this.period = config.period(); } @Override @@ -89,8 +83,8 @@ public void run() { } } }, - period, - period); + period.toMillis(), + period.toMillis()); } protected synchronized void getStateAndFillCache() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/timer/TimerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/timer/TimerEventSource.java index fe641e0b0b..f228c9935c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/timer/TimerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/timer/TimerEventSource.java @@ -22,6 +22,12 @@ public class TimerEventSource private Timer timer; private final Map onceTasks = new ConcurrentHashMap<>(); + public TimerEventSource() {} + + public TimerEventSource(String name) { + super(name); + } + @SuppressWarnings("unused") public void scheduleOnce(R resource, long delay) { scheduleOnce(ResourceID.fromResource(resource), delay); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtilsTest.java deleted file mode 100644 index b606f1fc1c..0000000000 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtilsTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.javaoperatorsdk.operator.api.reconciler; - -import java.util.HashMap; - -import org.junit.jupiter.api.Test; - -import io.javaoperatorsdk.operator.processing.event.source.polling.PollingEventSource; - -import static org.assertj.core.api.Assertions.assertThat; - -class EventSourceUtilsTest { - - @Test - @SuppressWarnings({"rawtypes", "unchecked"}) - void defaultNameDifferentForOtherInstance() { - var eventSource1 = new PollingEventSource(HashMap::new, 1000, String.class); - var eventSource2 = new PollingEventSource(HashMap::new, 1000, String.class); - var eventSourceName1 = EventSourceUtils.generateNameFor(eventSource1); - var eventSourceName2 = EventSourceUtils.generateNameFor(eventSource2); - - assertThat(eventSourceName1).isNotEqualTo(eventSourceName2); - } - -} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java index 44bdf8c85b..17a61b987b 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java @@ -352,7 +352,7 @@ void newResourceAfterMissedDeleteEvent() { @Test void rateLimitsReconciliationSubmission() { - // the refresh period value does not matter here + // the refresh defaultPollingPeriod value does not matter here var refreshPeriod = Duration.ofMillis(100); var event = prepareCREvent(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java index 39a3192d95..66ccf47e81 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java @@ -92,25 +92,25 @@ void retrievingEventSourceForClassShouldWork() { } @Test - void shouldNotBePossibleToAddEventSourcesForSameTypeAndName() { + void notPossibleAddEventSourcesForSameName() { EventSourceManager manager = initManager(); final var name = "name1"; ManagedInformerEventSource eventSource = mock(ManagedInformerEventSource.class); + when(eventSource.name()).thenReturn(name); when(eventSource.resourceType()).thenReturn(TestCustomResource.class); - manager.registerEventSource(name, eventSource); + manager.registerEventSource(eventSource); eventSource = mock(ManagedInformerEventSource.class); when(eventSource.resourceType()).thenReturn(TestCustomResource.class); + when(eventSource.name()).thenReturn(name); final var source = eventSource; final var exception = assertThrows(OperatorException.class, - () -> manager.registerEventSource(name, source)); + () -> manager.registerEventSource(source)); final var cause = exception.getCause(); assertInstanceOf(IllegalArgumentException.class, cause); - assertThat(cause.getMessage()).contains( - "is already registered for the (io.javaoperatorsdk.operator.sample.simple.TestCustomResource, " - + name + ") class/name combination"); + assertThat(cause.getMessage()).contains("is already registered with name"); } @Test @@ -119,11 +119,14 @@ void retrievingAnEventSourceWhenMultipleAreRegisteredForATypeShouldRequireAQuali ManagedInformerEventSource eventSource = mock(ManagedInformerEventSource.class); when(eventSource.resourceType()).thenReturn(TestCustomResource.class); - manager.registerEventSource("name1", eventSource); + when(eventSource.name()).thenReturn("name1"); + manager.registerEventSource(eventSource); + ManagedInformerEventSource eventSource2 = mock(ManagedInformerEventSource.class); + when(eventSource2.name()).thenReturn("name2"); when(eventSource2.resourceType()).thenReturn(TestCustomResource.class); - manager.registerEventSource("name2", eventSource2); + manager.registerEventSource(eventSource2); final var exception = assertThrows(IllegalArgumentException.class, () -> manager.getResourceEventSourceFor(TestCustomResource.class)); @@ -157,10 +160,11 @@ void changesNamespacesOnControllerAndInformerEventSources() { InformerConfiguration informerConfigurationMock = mock(InformerConfiguration.class); when(informerConfigurationMock.followControllerNamespaceChanges()).thenReturn(true); InformerEventSource informerEventSource = mock(InformerEventSource.class); + when(informerEventSource.name()).thenReturn("ies"); when(informerEventSource.resourceType()).thenReturn(TestCustomResource.class); when(informerEventSource.configuration()).thenReturn(informerConfigurationMock); when(informerEventSource.allowsNamespaceChanges()).thenCallRealMethod(); - manager.registerEventSource("ies", informerEventSource); + manager.registerEventSource(informerEventSource); manager.changeNamespaces(Set.of(newNamespaces)); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java index ad4faecc64..f26f915d00 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java @@ -1,11 +1,5 @@ package io.javaoperatorsdk.operator.processing.event; -import java.util.ConcurrentModificationException; -import java.util.concurrent.Phaser; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -19,7 +13,6 @@ import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; -import static io.javaoperatorsdk.operator.processing.event.EventSources.RETRY_RESCHEDULE_TIMER_EVENT_SOURCE_NAME; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -35,42 +28,46 @@ class EventSourcesTest { @Test void cannotAddTwoDifferentEventSourcesWithSameName() { final var eventSources = new EventSources(); + var es1 = mock(EventSource.class); + when(es1.name()).thenReturn(EVENT_SOURCE_NAME); + var es2 = mock(EventSource.class); + when(es2.name()).thenReturn(EVENT_SOURCE_NAME); + + eventSources.add(es1); assertThrows(IllegalArgumentException.class, () -> { - eventSources.add(new NamedEventSource(mock(EventSource.class), "name")); - eventSources.add(new NamedEventSource(mock(EventSource.class), "name")); + eventSources.add(es2); }); } @Test - void cannotAddTwoEventSourcesWithSameNameUnlessTheyAreEqual() { + void cannotAddTwoEventSourcesWithSame() { final var eventSources = new EventSources(); final var source = mock(EventSource.class); - eventSources.add(new NamedEventSource(source, "name")); - eventSources.add(new NamedEventSource(source, "name")); - assertThat(eventSources.flatMappedSources()) - .containsExactly(new NamedEventSource(source, "name")); - } + when(source.name()).thenReturn("name"); + eventSources.add(source); + assertThrows(IllegalArgumentException.class, () -> eventSources.add(source)); + } @Test void eventSourcesStreamShouldNotReturnControllerEventSource() { final var eventSources = new EventSources(); final var source = mock(EventSource.class); - final var namedEventSource = new NamedEventSource(source, EVENT_SOURCE_NAME); - eventSources.add(namedEventSource); + when(source.name()).thenReturn(EVENT_SOURCE_NAME); - assertThat(eventSources.additionalNamedEventSources()).containsExactly( - new NamedEventSource(eventSources.retryEventSource(), - RETRY_RESCHEDULE_TIMER_EVENT_SOURCE_NAME), - namedEventSource); + eventSources.add(source); + + assertThat(eventSources.additionalEventSources()).containsExactly( + eventSources.retryEventSource(), + source); } @Test void additionalEventSourcesShouldNotContainNamedEventSources() { final var eventSources = new EventSources(); final var source = mock(EventSource.class); - final var namedEventSource = new NamedEventSource(source, EVENT_SOURCE_NAME); - eventSources.add(namedEventSource); + when(source.name()).thenReturn(EVENT_SOURCE_NAME); + eventSources.add(source); assertThat(eventSources.additionalEventSources()).containsExactly( eventSources.retryEventSource(), source); @@ -89,45 +86,37 @@ void checkControllerResourceEventSource() { assertEquals(HasMetadata.class, controllerResourceEventSource.resourceType()); assertEquals(controllerResourceEventSource, - eventSources.namedControllerResourceEventSource().eventSource()); + eventSources.controllerResourceEventSource()); } @Test void flatMappedSourcesShouldReturnOnlyUserRegisteredEventSources() { final var eventSources = new EventSources(); - final var mock1 = mock(ResourceEventSource.class); - when(mock1.resourceType()).thenReturn(HasMetadata.class); - final var mock2 = mock(ResourceEventSource.class); - when(mock2.resourceType()).thenReturn(HasMetadata.class); - final var mock3 = mock(ResourceEventSource.class); - when(mock3.resourceType()).thenReturn(ConfigMap.class); - - final var named1 = new NamedEventSource(mock1, "name1"); - final var named2 = new NamedEventSource(mock2, "name2"); - final var named3 = new NamedEventSource(mock3, "name2"); - eventSources.add(named1); - eventSources.add(named2); - eventSources.add(named3); - - assertThat(eventSources.flatMappedSources()).contains(named1, named2, named3); + final var mock1 = + eventSourceMockWithName(ResourceEventSource.class, "name1", HasMetadata.class); + final var mock2 = + eventSourceMockWithName(ResourceEventSource.class, "name2", HasMetadata.class); + final var mock3 = eventSourceMockWithName(ResourceEventSource.class, "name3", ConfigMap.class); + + eventSources.add(mock1); + eventSources.add(mock2); + eventSources.add(mock3); + + assertThat(eventSources.flatMappedSources()).contains(mock1, mock2, mock3); } @Test void clearShouldWork() { final var eventSources = new EventSources(); - final var mock1 = mock(ResourceEventSource.class); - when(mock1.resourceType()).thenReturn(HasMetadata.class); - final var mock2 = mock(ResourceEventSource.class); - when(mock2.resourceType()).thenReturn(HasMetadata.class); - final var mock3 = mock(ResourceEventSource.class); - when(mock3.resourceType()).thenReturn(ConfigMap.class); - - final var named1 = new NamedEventSource(mock1, "name1"); - final var named2 = new NamedEventSource(mock2, "name2"); - final var named3 = new NamedEventSource(mock3, "name2"); - eventSources.add(named1); - eventSources.add(named2); - eventSources.add(named3); + final var mock1 = + eventSourceMockWithName(ResourceEventSource.class, "name1", HasMetadata.class); + final var mock2 = + eventSourceMockWithName(ResourceEventSource.class, "name2", HasMetadata.class); + final var mock3 = eventSourceMockWithName(ResourceEventSource.class, "name3", ConfigMap.class); + + eventSources.add(mock1); + eventSources.add(mock2); + eventSources.add(mock3); eventSources.clear(); assertThat(eventSources.flatMappedSources()).isEmpty(); @@ -136,19 +125,15 @@ void clearShouldWork() { @Test void getShouldWork() { final var eventSources = new EventSources(); - final var mock1 = mock(ResourceEventSource.class); - when(mock1.resourceType()).thenReturn(HasMetadata.class); - final var mock2 = mock(ResourceEventSource.class); - when(mock2.resourceType()).thenReturn(HasMetadata.class); - final var mock3 = mock(ResourceEventSource.class); - when(mock3.resourceType()).thenReturn(ConfigMap.class); - - final var named1 = new NamedEventSource(mock1, "name1"); - final var named2 = new NamedEventSource(mock2, "name2"); - final var named3 = new NamedEventSource(mock3, "name2"); - eventSources.add(named1); - eventSources.add(named2); - eventSources.add(named3); + final var mock1 = + eventSourceMockWithName(ResourceEventSource.class, "name1", HasMetadata.class); + final var mock2 = + eventSourceMockWithName(ResourceEventSource.class, "name2", HasMetadata.class); + final var mock3 = eventSourceMockWithName(ResourceEventSource.class, "name2", ConfigMap.class); + + eventSources.add(mock1); + eventSources.add(mock2); + eventSources.add(mock3); assertEquals(mock1, eventSources.get(HasMetadata.class, "name1")); assertEquals(mock2, eventSources.get(HasMetadata.class, "name2")); @@ -166,19 +151,15 @@ void getShouldWork() { @Test void getEventSourcesShouldWork() { final var eventSources = new EventSources(); - final var mock1 = mock(ResourceEventSource.class); - when(mock1.resourceType()).thenReturn(HasMetadata.class); - final var mock2 = mock(ResourceEventSource.class); - when(mock2.resourceType()).thenReturn(HasMetadata.class); - final var mock3 = mock(ResourceEventSource.class); - when(mock3.resourceType()).thenReturn(ConfigMap.class); - - final var named1 = new NamedEventSource(mock1, "name1"); - final var named2 = new NamedEventSource(mock2, "name2"); - final var named3 = new NamedEventSource(mock3, "name2"); - eventSources.add(named1); - eventSources.add(named2); - eventSources.add(named3); + final var mock1 = + eventSourceMockWithName(ResourceEventSource.class, "name1", HasMetadata.class); + final var mock2 = + eventSourceMockWithName(ResourceEventSource.class, "name2", HasMetadata.class); + final var mock3 = eventSourceMockWithName(ResourceEventSource.class, "name3", ConfigMap.class); + + eventSources.add(mock1); + eventSources.add(mock2); + eventSources.add(mock3); var sources = eventSources.getEventSources(HasMetadata.class); assertThat(sources.size()).isEqualTo(2); @@ -191,44 +172,14 @@ void getEventSourcesShouldWork() { assertThat(eventSources.getEventSources(Service.class)).isEmpty(); } - @Test - void testConcurrentAddRemoveAndGet() throws InterruptedException { - final var concurrentExceptionFound = new AtomicBoolean(false); - for (int i = 0; i < 1000 && !concurrentExceptionFound.get(); i++) { - final var eventSources = new EventSources(); - var eventSourceList = - IntStream.range(1, 20).mapToObj(n -> { - var mockResES = mock(ResourceEventSource.class); - NamedEventSource eventSource = mock(NamedEventSource.class); - when(eventSource.original()).thenReturn(mockResES); - when(eventSource.name()).thenReturn("name" + n); - when(mockResES.resourceType()).thenReturn(HasMetadata.class); - return eventSource; - }).collect(Collectors.toList()); - - IntStream.range(1, 10).forEach(n -> eventSources.add(eventSourceList.get(n - 1))); - - var phaser = new Phaser(2); - - var t1 = new Thread(() -> { - phaser.arriveAndAwaitAdvance(); - IntStream.range(11, 20).forEach(n -> eventSources.add(eventSourceList.get(n - 1))); - }); - var t2 = new Thread(() -> { - phaser.arriveAndAwaitAdvance(); - try { - eventSources.getEventSources(HasMetadata.class); - } catch (ConcurrentModificationException e) { - concurrentExceptionFound.set(true); - } - }); - t1.start(); - t2.start(); - t1.join(); - t2.join(); - } - assertThat(concurrentExceptionFound) - .withFailMessage("ConcurrentModificationException thrown") - .isFalse(); + + + EventSource eventSourceMockWithName(Class clazz, String name, + Class resourceType) { + var mockedES = mock(clazz); + when(mockedES.name()).thenReturn(name); + when(mockedES.resourceType()).thenReturn(resourceType); + return mockedES; } + } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java index 70249f6125..fd5b85aa16 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java @@ -11,19 +11,17 @@ import io.javaoperatorsdk.operator.TestUtils; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.processing.event.EventHandler; -import io.javaoperatorsdk.operator.processing.event.source.*; +import io.javaoperatorsdk.operator.processing.event.source.AbstractEventSourceTestBase; +import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; +import io.javaoperatorsdk.operator.processing.event.source.IndexerResourceCache; +import io.javaoperatorsdk.operator.processing.event.source.SampleExternalResource; import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; class PerResourcePollingEventSourceTest extends AbstractEventSourceTestBase, EventHandler> { @@ -45,8 +43,10 @@ public void setup() { .thenReturn(Set.of(SampleExternalResource.testResource1())); when(context.getPrimaryCache()).thenReturn(resourceCache); - setUpSource(new PerResourcePollingEventSource<>(supplier, context, Duration.ofMillis(PERIOD), - SampleExternalResource.class, r -> r.getName() + "#" + r.getValue())); + setUpSource(new PerResourcePollingEventSource<>(SampleExternalResource.class, context, + new PerResourcePollingConfigurationBuilder<>(supplier, Duration.ofMillis(PERIOD)) + .withCacheKeyMapper(r -> r.getName() + "#" + r.getValue()) + .build())); } @Test @@ -62,9 +62,14 @@ void pollsTheResourceAfterAwareOfIt() { @Test void registeringTaskOnAPredicate() { - setUpSource(new PerResourcePollingEventSource<>(supplier, context, Duration.ofMillis(PERIOD), - testCustomResource -> testCustomResource.getMetadata().getGeneration() > 1, - SampleExternalResource.class, CacheKeyMapper.singleResourceCacheKeyMapper())); + setUpSource(new PerResourcePollingEventSource<>(SampleExternalResource.class, context, + new PerResourcePollingConfigurationBuilder<>( + supplier, Duration.ofMillis(PERIOD)) + .withRegisterPredicate( + testCustomResource -> testCustomResource.getMetadata().getGeneration() > 1) + .withCacheKeyMapper(CacheKeyMapper.singleResourceCacheKeyMapper()) + .build())); + source.onResourceCreated(testCustomResource); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java index bd0179d4cb..5dffa65ae7 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java @@ -25,14 +25,15 @@ class PollingEventSourceTest AbstractEventSourceTestBase, EventHandler> { public static final int DEFAULT_WAIT_PERIOD = 100; - public static final long POLL_PERIOD = 30L; + public static final Duration POLL_PERIOD = Duration.ofMillis(30L); @SuppressWarnings("unchecked") private final PollingEventSource.GenericResourceFetcher resourceFetcher = mock(PollingEventSource.GenericResourceFetcher.class); private final PollingEventSource pollingEventSource = - new PollingEventSource<>(resourceFetcher, POLL_PERIOD, SampleExternalResource.class, - (SampleExternalResource er) -> er.getName() + "#" + er.getValue()); + new PollingEventSource<>(SampleExternalResource.class, + new PollingConfiguration<>(resourceFetcher, POLL_PERIOD, + (SampleExternalResource er) -> er.getName() + "#" + er.getValue())); @BeforeEach public void setup() { @@ -92,7 +93,7 @@ void updatesHealthIndicatorBasedOnExceptionsInFetcher() throws InterruptedExcept .thenThrow(new RuntimeException("test exception")) .thenReturn(testResponseWithOneValue()); - await().pollInterval(Duration.ofMillis(POLL_PERIOD)).untilAsserted( + await().pollInterval(POLL_PERIOD).untilAsserted( () -> assertThat(pollingEventSource.getStatus()).isEqualTo(Status.UNHEALTHY)); await() diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java index 36e4fd23f6..8b3c7afca8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -22,7 +22,6 @@ import io.javaoperatorsdk.operator.health.InformerHealthIndicator; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource; -import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.ConfigMapDependentResource; import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestCustomResource; import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestReconciler; @@ -151,7 +150,7 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator) InformerHealthIndicator configMapHealthIndicator = (InformerHealthIndicator) unhealthyEventSources - .get(ConfigMapDependentResource.class.getSimpleName()) + .get(InformerRelatedBehaviorTestReconciler.CONFIG_MAP_DEPENDENT_RESOURCE) .informerHealthIndicators().get(additionalNamespace); assertThat(configMapHealthIndicator).isNotNull(); assertThat(configMapHealthIndicator.getTargetNamespace()).isEqualTo(additionalNamespace); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java index ef07bb5520..b8feb5c87e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.bulkdependent; -import java.util.Map; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import io.javaoperatorsdk.operator.api.reconciler.*; @@ -35,9 +35,8 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { - return EventSourceUtils - .nameEventSources(dependent.initEventSource(context)); + return List.of(dependent.initEventSource(context)); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java index 36a46c9da3..00750b30b0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.sample.changenamespace; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -19,14 +20,14 @@ public class ChangeNamespaceTestReconciler new ConcurrentHashMap<>(); @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { InformerEventSource configMapES = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) .build(), context); - return EventSourceUtils.nameEventSources(configMapES); + return List.of(configMapES); } @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java index eedb5ae70b..de5153d540 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.sample.clusterscopedresource; +import java.util.List; import java.util.Map; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -52,12 +53,12 @@ private ConfigMap desired(ClusterScopedCustomResource resource) { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { var ies = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) .withSecondaryToPrimaryMapper(Mappers.fromOwnerReference(true)) .withLabelSelector(TEST_LABEL_KEY + "=" + TEST_LABEL_VALUE) .build(), context); - return EventSourceUtils.nameEventSources(ies); + return List.of(ies); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java index 2f1c272ce9..d2259faeaf 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.complexdependent; -import java.util.Map; +import java.util.List; import java.util.Objects; import io.fabric8.kubernetes.api.model.Service; @@ -51,16 +51,17 @@ public UpdateControl reconcile( } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { InformerEventSource serviceEventSource = - new InformerEventSource<>(InformerConfiguration.from(Service.class, context).build(), + new InformerEventSource<>(SERVICE_EVENT_SOURCE_NAME, + InformerConfiguration.from(Service.class, context).build(), context); InformerEventSource statefulSetEventSource = - new InformerEventSource<>(InformerConfiguration.from(StatefulSet.class, context).build(), + new InformerEventSource<>(STATEFUL_SET_EVENT_SOURCE_NAME, + InformerConfiguration.from(StatefulSet.class, context).build(), context); - return Map.of(SERVICE_EVENT_SOURCE_NAME, serviceEventSource, STATEFUL_SET_EVENT_SOURCE_NAME, - statefulSetEventSource); + return List.of(serviceEventSource, statefulSetEventSource); } public enum RECONCILE_STATUS { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index c3ec3b70a1..dc152d29f6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -1,7 +1,7 @@ package io.javaoperatorsdk.operator.sample.createupdateeventfilter; import java.util.HashMap; -import java.util.Map; +import java.util.List; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; @@ -11,7 +11,6 @@ import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; @@ -91,7 +90,7 @@ private ConfigMap createConfigMap(CreateUpdateEventFilterTestCustomResource reso } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { InformerConfiguration informerConfiguration = InformerConfiguration.from(ConfigMap.class) @@ -102,7 +101,7 @@ public Map prepareEventSources( informerConfiguration, context.getClient()); this.configMapDR.setEventSource(informerEventSource); - return EventSourceUtils.nameEventSources(informerEventSource); + return List.of(informerEventSource); } public int getNumberOfExecutions() { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java index 65916d7a58..75d0a31f41 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.dependentreinitialization; -import java.util.Map; +import java.util.List; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -24,9 +24,9 @@ public UpdateControl reconcile( } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { - return EventSourceUtils.nameEventSourcesFromDependentResource(context, + return EventSourceUtils.dependentEventSources(context, configMapDependentResource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java index f0acce64b3..26720891cb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.dependentssa; -import java.util.Map; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -57,9 +57,9 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { - return EventSourceUtils.nameEventSourcesFromDependentResource(context, + return EventSourceUtils.dependentEventSources(context, ssaConfigMapDependent); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java index a1bc4a80f8..c1f5fc1634 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java @@ -28,9 +28,9 @@ public UpdateControl reconc numberOfExecutions.addAndGet(1); - context.eventSourceRetriever().dynamicallyRegisterEventSource(ConfigMap.class.getSimpleName(), + context.eventSourceRetriever().dynamicallyRegisterEventSource( genericInformerFor(ConfigMap.class, context)); - context.eventSourceRetriever().dynamicallyRegisterEventSource(Secret.class.getSimpleName(), + context.eventSourceRetriever().dynamicallyRegisterEventSource( genericInformerFor(Secret.class, context)); context.getClient().resource(secret(primary)).createOr(NonDeletingOperation::update); @@ -70,7 +70,7 @@ private InformerEventSource clazz, Context context) { - return new InformerEventSource<>( + return new InformerEventSource<>(clazz.getSimpleName(), InformerConfiguration.from(GroupVersionKind.gvkFor(clazz), context.eventSourceRetriever().eventSourceContextForDynamicRegistration()).build(), context.eventSourceRetriever().eventSourceContextForDynamicRegistration()); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java index 9c2b019adc..b9c264ba63 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.externalstate; -import java.util.Map; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -34,11 +34,11 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( InformerConfiguration.from(ConfigMap.class, context).build(), context); - return EventSourceUtils.nameEventSources(configMapEventSource); + return List.of(configMapEventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java index a9c3bb5a28..4f7bb0ce5c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java @@ -1,7 +1,9 @@ package io.javaoperatorsdk.operator.sample.externalstate; import java.time.Duration; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -10,11 +12,18 @@ import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Cleaner; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.EventSourceStartPriority; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; +import io.javaoperatorsdk.operator.processing.event.source.polling.PerResourcePollingConfigurationBuilder; import io.javaoperatorsdk.operator.processing.event.source.polling.PerResourcePollingEventSource; import io.javaoperatorsdk.operator.support.ExternalIDGenServiceMock; import io.javaoperatorsdk.operator.support.ExternalResource; @@ -98,24 +107,29 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { configMapEventSource = new InformerEventSource<>( InformerConfiguration.from(ConfigMap.class, context).build(), context); configMapEventSource.setEventSourcePriority(EventSourceStartPriority.RESOURCE_STATE_LOADER); - externalResourceEventSource = new PerResourcePollingEventSource<>(primaryResource -> { - var configMap = configMapEventSource.getSecondaryResource(primaryResource).orElse(null); - if (configMap == null) { - return Collections.emptySet(); - } - var id = configMap.getData().get(ID_KEY); - var externalResource = externalService.read(id); - return externalResource.map(Set::of).orElseGet(Collections::emptySet); - }, context, Duration.ofMillis(300L), ExternalResource.class); - - return EventSourceUtils.nameEventSources(configMapEventSource, + final PerResourcePollingEventSource.ResourceFetcher fetcher = + (ExternalStateCustomResource primaryResource) -> { + var configMap = + configMapEventSource.getSecondaryResource(primaryResource).orElse(null); + if (configMap == null) { + return Collections.emptySet(); + } + var id = configMap.getData().get(ID_KEY); + var externalResource = externalService.read(id); + return externalResource.map(Set::of).orElseGet(Collections::emptySet); + }; + externalResourceEventSource = + new PerResourcePollingEventSource<>(ExternalResource.class, context, + new PerResourcePollingConfigurationBuilder<>(fetcher, Duration.ofMillis(300L)).build()); + + return Arrays.asList(configMapEventSource, externalResourceEventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java index 0965c49636..b0e0607334 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.sample.externalstate; +import java.time.Duration; import java.util.Collections; import java.util.Map; import java.util.Optional; @@ -27,7 +28,7 @@ public class ExternalWithStateDependentResource extends ExternalIDGenServiceMock externalService = ExternalIDGenServiceMock.getInstance(); public ExternalWithStateDependentResource() { - super(ExternalResource.class, 300); + super(ExternalResource.class, Duration.ofMillis(300)); } @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java index 37684dd39f..29bc6af9aa 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.sample.externalstate.externalstatebulkdependent; +import java.time.Duration; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -31,7 +32,7 @@ public class BulkDependentResourceExternalWithState extends ExternalIDGenServiceMock externalService = ExternalIDGenServiceMock.getInstance(); public BulkDependentResourceExternalWithState() { - super(ExternalResource.class, 300); + super(ExternalResource.class, Duration.ofMillis(300)); } @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java index a69feabb71..0da96c2e32 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.externalstate.externalstatebulkdependent; -import java.util.Map; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -33,11 +33,11 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( InformerConfiguration.from(ConfigMap.class, context).build(), context); - return EventSourceUtils.nameEventSources(configMapEventSource); + return List.of(configMapEventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java index 541e220f4a..e611968766 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.sample.filter; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -48,7 +49,7 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { InformerEventSource configMapES = @@ -58,6 +59,6 @@ public Map prepareEventSources( .equals(CONFIG_MAP_FILTER_VALUE)) .build(), context); - return EventSourceUtils.nameEventSources(configMapES); + return List.of(configMapES); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java index 3f38e12a8d..0d1f5b157a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java @@ -1,11 +1,11 @@ package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentstandalone; -import java.util.Map; +import java.util.List; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -30,8 +30,8 @@ public UpdateControl reconci } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { - return EventSourceUtils.nameEventSources(dependent.eventSource(context).orElseThrow()); + return List.of(dependent.eventSource(context).orElseThrow()); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java index 2b967fa62c..f5c66e8d30 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.HashMap; +import java.util.List; import java.util.Map; import io.fabric8.kubernetes.api.model.GenericKubernetesResource; @@ -64,13 +65,13 @@ GenericKubernetesResource desiredConfigMap( @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { var informerEventSource = new InformerEventSource<>(InformerConfiguration.from( new GroupVersionKind("", VERSION, KIND), context).build(), context); - return EventSourceUtils.nameEventSources(informerEventSource); + return List.of(informerEventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java index d9a44cb027..c7cac63cad 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.informereventsource; -import java.util.Map; +import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; @@ -32,7 +32,7 @@ public class InformerEventSourceTestCustomReconciler private final AtomicInteger numberOfExecutions = new AtomicInteger(0); @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { InformerConfiguration config = @@ -40,8 +40,7 @@ public Map prepareEventSources( .withSecondaryToPrimaryMapper(Mappers.fromAnnotation(RELATED_RESOURCE_NAME)) .build(); - return EventSourceUtils - .nameEventSources(new InformerEventSource<>(config, context)); + return List.of(new InformerEventSource<>(config, context)); } @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java index 8b0511e486..e76d980ef0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java @@ -5,7 +5,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -27,7 +26,6 @@ public class InformerRelatedBehaviorTestReconciler public static final String CONFIG_MAP_DEPENDENT_RESOURCE = "ConfigMapDependentResource"; private final AtomicInteger numberOfExecutions = new AtomicInteger(0); - private KubernetesClient client; @Override public UpdateControl reconcile( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java index 7a033800af..569e2cafb1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.sample.kubernetesdependentgarbagecollection; +import java.util.List; import java.util.Map; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -28,10 +29,9 @@ public DependentGarbageCollectionTestReconciler() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { - return EventSourceUtils.nameEventSourcesFromDependentResource(context, - configMapDependent); + return EventSourceUtils.dependentEventSources(context, configMapDependent); } @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java index 4befd18d87..c61d751079 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.multipledependentresource; -import java.util.Map; +import java.util.List; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; @@ -33,7 +33,7 @@ public UpdateControl reconcile( } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { InformerEventSource eventSource = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) @@ -41,6 +41,6 @@ public Map prepareEventSources( firstDependentResourceConfigMap.configureWith(eventSource); secondDependentResourceConfigMap.configureWith(eventSource); - return EventSourceUtils.nameEventSources(eventSource); + return List.of(eventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java index f82d178bcb..9e04af6d24 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator; -import java.util.Map; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -43,7 +43,7 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { InformerEventSource eventSource = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) @@ -51,6 +51,6 @@ public Map prepareEventSources( firstDependentResourceConfigMap.configureWith(eventSource); secondDependentResourceConfigMap.configureWith(eventSource); - return EventSourceUtils.nameEventSources(eventSource); + return List.of(eventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java index 0e446454da..6377385b6e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; -import java.util.Map; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -46,12 +46,14 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { InformerEventSource ies = - new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) - .build(), context); + new InformerEventSource<>(CONFIG_MAP_EVENT_SOURCE, + InformerConfiguration.from(ConfigMap.class, context) + .build(), + context); - return Map.of(CONFIG_MAP_EVENT_SOURCE, ies); + return List.of(ies); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java index 8651f13fac..63c22436d8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype; -import java.util.Map; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -46,12 +46,13 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { InformerEventSource ies = - new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) - .build(), context); - - return Map.of(CONFIG_MAP_EVENT_SOURCE, ies); + new InformerEventSource<>(CONFIG_MAP_EVENT_SOURCE, + InformerConfiguration.from(ConfigMap.class, context) + .build(), + context); + return List.of(ies); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java index 1e7577302b..614f3a0b59 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java @@ -1,34 +1,42 @@ package io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype; +import java.time.Duration; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; +import io.javaoperatorsdk.operator.processing.event.source.polling.PollingConfigurationBuilder; import io.javaoperatorsdk.operator.processing.event.source.polling.PollingEventSource; import io.javaoperatorsdk.operator.support.ExternalResource; import io.javaoperatorsdk.operator.support.ExternalServiceMock; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -import static io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype.MultipleManagedExternalDependentResourceReconciler.CONFIG_MAP_EVENT_SOURCE; +import static io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype.MultipleManagedExternalDependentResourceReconciler.EVENT_SOURCE_NAME; @Workflow(dependents = { @Dependent(type = ExternalDependentResource1.class, - useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE), + useEventSourceWithName = EVENT_SOURCE_NAME), @Dependent(type = ExternalDependentResource2.class, - useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE) + useEventSourceWithName = EVENT_SOURCE_NAME) }) @ControllerConfiguration() public class MultipleManagedExternalDependentResourceReconciler implements Reconciler, TestExecutionInfoProvider { - public static final String CONFIG_MAP_EVENT_SOURCE = "ConfigMapEventSource"; + public static final String EVENT_SOURCE_NAME = "ConfigMapEventSource"; protected ExternalServiceMock externalServiceMock = ExternalServiceMock.getInstance(); private final AtomicInteger numberOfExecutions = new AtomicInteger(0); @@ -48,21 +56,26 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { + final PollingEventSource.GenericResourceFetcher fetcher = () -> { + var lists = externalServiceMock.listResources(); + final Map> res = new HashMap<>(); + lists.forEach(er -> { + var resourceId = er.toResourceID(); + res.computeIfAbsent(resourceId, rid -> new HashSet<>()); + res.get(resourceId).add(er); + }); + return res; + }; + PollingEventSource pollingEventSource = - new PollingEventSource<>(() -> { - var lists = externalServiceMock.listResources(); - Map> res = new HashMap<>(); - lists.forEach(er -> { - var resourceId = er.toResourceID(); - res.computeIfAbsent(resourceId, rid -> new HashSet<>()); - res.get(resourceId).add(er); - }); - return res; - }, 1000L, ExternalResource.class, ExternalResource::getId); + new PollingEventSource<>(EVENT_SOURCE_NAME, ExternalResource.class, + new PollingConfigurationBuilder<>(fetcher, Duration.ofMillis(1000L)) + .withCacheKeyMapper(ExternalResource::getId) + .build()); - return Map.of(CONFIG_MAP_EVENT_SOURCE, pollingEventSource); + return List.of(pollingEventSource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java index 1c8e1a1c60..62c9ef3b7b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java @@ -1,7 +1,7 @@ package io.javaoperatorsdk.operator.sample.multiplesecondaryeventsource; import java.util.HashMap; -import java.util.Map; +import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -61,10 +61,9 @@ public int getNumberOfExecutions() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { - var config = InformerConfiguration.from(ConfigMap.class) .withNamespaces(context.getControllerConfiguration().getNamespaces()) .withLabelSelector("multisecondary") @@ -75,7 +74,7 @@ public Map prepareEventSources( }).build(); InformerEventSource configMapEventSource = new InformerEventSource<>(config, context); - return EventSourceUtils.nameEventSources(configMapEventSource); + return List.of(configMapEventSource); } ConfigMap configMap(String name, MultipleSecondaryEventSourceCustomResource resource) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java index 6915d89e40..d8dde593ac 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java @@ -1,13 +1,19 @@ package io.javaoperatorsdk.operator.sample.perresourceeventsource; import java.time.Duration; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.source.EventSource; +import io.javaoperatorsdk.operator.processing.event.source.polling.PerResourcePollingConfigurationBuilder; import io.javaoperatorsdk.operator.processing.event.source.polling.PerResourcePollingEventSource; @ControllerConfiguration @@ -28,16 +34,18 @@ public UpdateControl reconcile( } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { PerResourcePollingEventSource eventSource = - new PerResourcePollingEventSource<>(resource -> { - numberOfFetchExecutions.putIfAbsent(resource.getMetadata().getName(), 0); - numberOfFetchExecutions.compute(resource.getMetadata().getName(), (s, v) -> v + 1); - return Set.of(UUID.randomUUID().toString()); - }, - context, Duration.ofMillis(POLL_PERIOD), String.class); - return EventSourceUtils.nameEventSources(eventSource); + new PerResourcePollingEventSource<>(String.class, context, + new PerResourcePollingConfigurationBuilder<>( + (PerResourceEventSourceCustomResource resource) -> { + numberOfFetchExecutions.putIfAbsent(resource.getMetadata().getName(), 0); + numberOfFetchExecutions.compute(resource.getMetadata().getName(), + (s, v) -> v + 1); + return Set.of(UUID.randomUUID().toString()); + }, Duration.ofMillis(POLL_PERIOD)).build()); + return List.of(eventSource); } public int getNumberOfExecutions(String name) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java index bc05a171cf..78af3dbd66 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java @@ -1,13 +1,12 @@ package io.javaoperatorsdk.operator.sample.primaryindexer; -import java.util.Map; +import java.util.List; import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; @@ -17,7 +16,7 @@ public class PrimaryIndexerTestReconciler extends AbstractPrimaryIndexerTestReconciler { @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { context.getPrimaryCache().addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer); @@ -35,7 +34,6 @@ public Map prepareEventSources( .collect(Collectors.toSet())) .build(); - return EventSourceUtils - .nameEventSources(new InformerEventSource<>(informerConfiguration, context)); + return List.of(new InformerEventSource<>(informerConfiguration, context)); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java index f2f975f248..4cf1d8c93b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java @@ -1,7 +1,6 @@ package io.javaoperatorsdk.operator.sample.primarytosecondary; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -61,7 +60,7 @@ public UpdateControl reconcile( } @Override - public Map prepareEventSources(EventSourceContext context) { + public List prepareEventSources(EventSourceContext context) { context.getPrimaryCache().addIndexer(JOB_CLUSTER_INDEX, (job -> List .of(indexKey(job.getSpec().getClusterName(), job.getMetadata().getNamespace())))); @@ -79,8 +78,7 @@ public Map prepareEventSources(EventSourceContext cont primary.getSpec().getClusterName(), primary.getMetadata().getNamespace()))); } - return EventSourceUtils - .nameEventSources(new InformerEventSource<>(informerConfiguration.build(), context)); + return List.of(new InformerEventSource<>(informerConfiguration.build(), context)); } private String indexKey(String clusterName, String namespace) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java index 3283c76a93..a6cf2cef12 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java @@ -1,7 +1,6 @@ package io.javaoperatorsdk.operator.sample.primarytosecondaydependent; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -59,7 +58,7 @@ public int getNumberOfExecutions() { * demand for it. **/ @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { // there is no owner reference in the config map, but we still want to trigger reconciliation if // the config map changes. So first we add an index which custom resource references the config @@ -67,7 +66,7 @@ public Map prepareEventSources( context.getPrimaryCache().addIndexer(CONFIG_MAP_INDEX, (primary -> List .of(indexKey(primary.getSpec().getConfigMapName(), primary.getMetadata().getNamespace())))); - var cmES = new InformerEventSource<>(InformerConfiguration + var es = new InformerEventSource<>(CONFIG_MAP_EVENT_SOURCE, InformerConfiguration .from(ConfigMap.class, context) // if there is a many-to-many relationship (thus no direct owner reference) // PrimaryToSecondaryMapper needs to be added @@ -83,7 +82,7 @@ public Map prepareEventSources( .build(), context); - return Map.of(CONFIG_MAP_EVENT_SOURCE, cmES); + return List.of(es); } private String indexKey(String configMapName, String namespace) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java index 5d852d86b3..b0d48bebfd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java @@ -1,6 +1,6 @@ package io.javaoperatorsdk.operator.sample.standalonedependent; -import java.util.Map; +import java.util.List; import java.util.Optional; import io.fabric8.kubernetes.api.model.apps.Deployment; @@ -31,9 +31,9 @@ public StandaloneDependentTestReconciler() { } @Override - public Map prepareEventSources( + public List prepareEventSources( EventSourceContext context) { - return EventSourceUtils.nameEventSourcesFromDependentResource(context, + return EventSourceUtils.dependentEventSources(context, deploymentDependent); } diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaOperator.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaOperator.java index e9e1ac1d49..ce3595f0c3 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaOperator.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaOperator.java @@ -1,6 +1,7 @@ package io.javaoperatorsdk.operator.sample; import java.io.IOException; +import java.time.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +32,8 @@ public static void main(String[] args) throws IOException { operator.register(schemaReconciler, configOverrider -> configOverrider.replacingNamedDependentResourceConfig( SchemaDependentResource.NAME, - new ResourcePollerConfig(300, MySQLDbConfig.loadFromEnvironmentVars()))); + new ResourcePollerConfig(Duration.ofMillis(300), + MySQLDbConfig.loadFromEnvironmentVars()))); operator.start(); new FtBasic(new TkFork(new FkRegex("/health", "ALL GOOD!")), 8080).start(Exit.NEVER); diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/ResourcePollerConfig.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/ResourcePollerConfig.java index 5e9cc3f964..44de818f88 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/ResourcePollerConfig.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/ResourcePollerConfig.java @@ -1,19 +1,21 @@ package io.javaoperatorsdk.operator.sample.dependent; +import java.time.Duration; + import io.javaoperatorsdk.operator.sample.MySQLDbConfig; public class ResourcePollerConfig { - private final int pollPeriod; + private final Duration pollPeriod; private final MySQLDbConfig mySQLDbConfig; - public ResourcePollerConfig(int pollPeriod, MySQLDbConfig mySQLDbConfig) { + public ResourcePollerConfig(Duration pollPeriod, MySQLDbConfig mySQLDbConfig) { this.pollPeriod = pollPeriod; this.mySQLDbConfig = mySQLDbConfig; } - public int getPollPeriod() { + public Duration getPollPeriod() { return pollPeriod; } diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java index 476898af00..2098b531b3 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java @@ -3,6 +3,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.time.Duration; import java.util.Base64; import java.util.Collections; import java.util.Optional; @@ -52,7 +53,7 @@ public SchemaDependentResource() { @Override public Optional configuration() { - return Optional.of(new ResourcePollerConfig((int) getPollingPeriod(), dbConfig)); + return Optional.of(new ResourcePollerConfig(getPollingPeriod(), dbConfig)); } @Override @@ -127,11 +128,11 @@ public ResourcePollerConfig configFrom(SchemaConfig configAnnotation, ControllerConfiguration parentConfiguration, Class originatingClass) { if (configAnnotation != null) { - return new ResourcePollerConfig(configAnnotation.pollPeriod(), + return new ResourcePollerConfig(Duration.ofMillis(configAnnotation.pollPeriod()), new MySQLDbConfig(configAnnotation.host(), String.valueOf(configAnnotation.port()), configAnnotation.user(), configAnnotation.password())); } - return new ResourcePollerConfig(SchemaConfig.DEFAULT_POLL_PERIOD, + return new ResourcePollerConfig(Duration.ofMillis(SchemaConfig.DEFAULT_POLL_PERIOD), MySQLDbConfig.loadFromEnvironmentVars()); } } diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java index e1c1ddc71a..79194c7990 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java @@ -2,7 +2,6 @@ import java.io.ByteArrayOutputStream; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -26,7 +25,6 @@ import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -47,7 +45,7 @@ public WebappReconciler(KubernetesClient kubernetesClient) { } @Override - public Map prepareEventSources(EventSourceContext context) { + public List prepareEventSources(EventSourceContext context) { /* * To create an event to a related WebApp resource and trigger the reconciliation we need to * find which WebApp this Tomcat custom resource is related to. To find the related @@ -67,8 +65,7 @@ public Map prepareEventSources(EventSourceContext c (Webapp primary) -> Set.of(new ResourceID(primary.getSpec().getTomcat(), primary.getMetadata().getNamespace()))) .build(); - return EventSourceUtils - .nameEventSources(new InformerEventSource<>(configuration, context)); + return List.of(new InformerEventSource<>(configuration, context)); } /** diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index 06c4ae8721..f9664760f5 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -1,7 +1,7 @@ package io.javaoperatorsdk.operator.sample; import java.util.Arrays; -import java.util.Map; +import java.util.List; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.Service; @@ -48,8 +48,8 @@ public WebPageDependentsWorkflowReconciler(KubernetesClient kubernetesClient) { } @Override - public Map prepareEventSources(EventSourceContext context) { - return EventSourceUtils.nameEventSourcesFromDependentResource(context, configMapDR, + public List prepareEventSources(EventSourceContext context) { + return EventSourceUtils.dependentEventSources(context, configMapDR, deploymentDR, serviceDR, ingressDR); } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index 46bc3dd392..be0e26b7d8 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -1,6 +1,7 @@ package io.javaoperatorsdk.operator.sample; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -42,7 +43,7 @@ public WebPageReconciler(KubernetesClient kubernetesClient) { } @Override - public Map prepareEventSources(EventSourceContext context) { + public List prepareEventSources(EventSourceContext context) { var configMapEventSource = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) .withLabelSelector(SELECTOR) @@ -59,7 +60,7 @@ public Map prepareEventSources(EventSourceContext new InformerEventSource<>(InformerConfiguration.from(Ingress.class, context) .withLabelSelector(SELECTOR) .build(), context); - return EventSourceUtils.nameEventSources(configMapEventSource, deploymentEventSource, + return List.of(configMapEventSource, deploymentEventSource, serviceEventSource, ingressEventSource); } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java index 4e4fa22b6b..66f853e841 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java @@ -1,7 +1,7 @@ package io.javaoperatorsdk.operator.sample; import java.util.Arrays; -import java.util.Map; +import java.util.List; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; @@ -41,7 +41,7 @@ public WebPageStandaloneDependentsReconciler() { } @Override - public Map prepareEventSources(EventSourceContext context) { + public List prepareEventSources(EventSourceContext context) { // initializes the dependents' event sources from the given context return EventSourceUtils.eventSourcesFromWorkflow(context, workflow); } @@ -92,6 +92,7 @@ private Workflow createDependentResourcesAndWorkflow() { var serviceDR = new ServiceDependentResource(); var ingressDR = new IngressDependentResource(); + // configure them with our label selector Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR) .forEach(dr -> dr.configureWith(new KubernetesDependentResourceConfigBuilder() From 92d572af1acd6dd02b77879be774ddf0bf9c70f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 29 Apr 2024 13:41:53 +0200 Subject: [PATCH 38/96] feat: silent exception handling in managed workflows (#2363) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun Signed-off-by: Attila Mészáros --- .../api/config/BaseConfigurationService.java | 6 +++ .../api/config/workflow/WorkflowSpec.java | 2 + .../operator/api/reconciler/Workflow.java | 27 ++++++++-- .../operator/processing/Controller.java | 14 +++--- .../workflow/DefaultManagedWorkflow.java | 4 +- .../dependent/workflow/WorkflowResult.java | 4 +- .../workflow/ManagedWorkflowTest.java | 5 ++ .../WorkflowSilentExceptionHandlingIT.java | 47 +++++++++++++++++ .../ConfigMapDependent.java | 28 +++++++++++ ...wExceptionsInReconcilerCustomResource.java | 15 ++++++ ...kflowExceptionsInReconcilerReconciler.java | 50 +++++++++++++++++++ 11 files changed, 188 insertions(+), 14 deletions(-) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowSilentExceptionHandlingIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/ConfigMapDependent.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index 488f3dc9ce..b496a9b1b7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -178,6 +178,12 @@ public List getDependentResourceSpecs() { public boolean isExplicitInvocation() { return workflowAnnotation.explicitInvocation(); } + + @Override + public boolean handleExceptionsInReconciler() { + return workflowAnnotation.handleExceptionsInReconciler(); + } + }; config.setWorkflowSpec(workflowSpec); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java index 1b1c9da668..72d50f8050 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/workflow/WorkflowSpec.java @@ -10,4 +10,6 @@ public interface WorkflowSpec { List getDependentResourceSpecs(); boolean isExplicitInvocation(); + + boolean handleExceptionsInReconciler(); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java index 04a5b21606..a9497a9749 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java @@ -1,6 +1,10 @@ package io.javaoperatorsdk.operator.api.reconciler; -import java.lang.annotation.*; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; @@ -13,10 +17,25 @@ Dependent[] dependents(); /** - * If true, managed workflow should be explicitly invoked within the reconciler implementation. If - * false workflow is invoked just before the {@link Reconciler#reconcile(HasMetadata, Context)} - * method. + * If {@code true}, the managed workflow should be explicitly invoked within the reconciler + * implementation. If {@code false}, the workflow is invoked just before the + * {@link Reconciler#reconcile(HasMetadata, Context)} method. */ boolean explicitInvocation() default false; + /** + * If {@code true} and exceptions are thrown during the workflow's execution, the reconciler won't + * throw an {@link io.javaoperatorsdk.operator.AggregatedOperatorException} at the end of the + * execution as would normally be the case. Instead, it will proceed to its + * {@link Reconciler#reconcile(HasMetadata, Context)} method as if no error occurred. It is then + * up to the developer to decide how to proceed by retrieving the errored dependents (and their + * associated exception) via + * {@link io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowResult#erroredDependents}, + * the workflow result itself being accessed from + * {@link Context#managedWorkflowAndDependentResourceContext()}. If {@code false}, an exception + * will be automatically thrown at the end of the workflow execution, presenting an aggregated + * view of what happened. + */ + boolean handleExceptionsInReconciler() default false; + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index c42e6b783b..ccb8ebbc1f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -70,6 +70,7 @@ public class Controller

private final boolean isCleaner; private final Metrics metrics; private final Workflow

managedWorkflow; + private final boolean explicitWorkflowInvocation; private final GroupVersionKind associatedGVK; private final EventProcessor

eventProcessor; @@ -92,6 +93,9 @@ public Controller(Reconciler

reconciler, final var managed = configurationService.getWorkflowFactory().workflowFor(configuration); managedWorkflow = managed.resolve(kubernetesClient, configuration); + explicitWorkflowInvocation = + configuration.getWorkflowSpec().map(WorkflowSpec::isExplicitInvocation) + .orElse(false); eventSourceManager = new EventSourceManager<>(this); eventProcessor = new EventProcessor<>(eventSourceManager, configurationService); @@ -143,7 +147,7 @@ public Map metadata() { public UpdateControl

execute() throws Exception { initContextIfNeeded(resource, context); configuration.getWorkflowSpec().ifPresent(ws -> { - if (!managedWorkflow.isEmpty() && !isWorkflowExplicitInvocation()) { + if (!managedWorkflow.isEmpty() && !explicitWorkflowInvocation) { managedWorkflow.reconcile(resource, context); } }); @@ -188,7 +192,7 @@ public DeleteControl execute() { WorkflowCleanupResult workflowCleanupResult = null; // The cleanup is called also when explicit invocation is true, but the cleaner is not implemented - if (managedWorkflow.hasCleaner() || !isWorkflowExplicitInvocation()) { + if (managedWorkflow.hasCleaner() || !explicitWorkflowInvocation) { workflowCleanupResult = managedWorkflow.cleanup(resource, context); } @@ -449,7 +453,6 @@ public void reconcileManagedWorkflow(P primary, Context

context) { ((DefaultManagedWorkflowAndDependentResourceContext) context .managedWorkflowAndDependentResourceContext()) .setWorkflowExecutionResult(res); - res.throwAggregateExceptionIfErrorsPresent(); } } @@ -459,7 +462,7 @@ public WorkflowCleanupResult cleanupManagedWorkflow(P resource, Context

conte ((DefaultManagedWorkflowAndDependentResourceContext) context .managedWorkflowAndDependentResourceContext()) .setWorkflowCleanupResult(workflowCleanupResult); - workflowCleanupResult.throwAggregateExceptionIfErrorsPresent(); + return workflowCleanupResult; } else { return null; @@ -467,7 +470,6 @@ public WorkflowCleanupResult cleanupManagedWorkflow(P resource, Context

conte } public boolean isWorkflowExplicitInvocation() { - return configuration.getWorkflowSpec().map(WorkflowSpec::isExplicitInvocation) - .orElse(false); + return explicitWorkflowInvocation; } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java index fb0b733c32..03ed24d6df 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java @@ -16,7 +16,6 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.KubernetesClientAware; import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET; -import static io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow.THROW_EXCEPTION_AUTOMATICALLY_DEFAULT; @SuppressWarnings("rawtypes") public class DefaultManagedWorkflow

implements ManagedWorkflow

{ @@ -96,7 +95,8 @@ public Workflow

resolve(KubernetesClient client, final var top = topLevelResources.stream().map(alreadyResolved::get).collect(Collectors.toSet()); return new DefaultWorkflow<>(alreadyResolved, bottom, top, - THROW_EXCEPTION_AUTOMATICALLY_DEFAULT, hasCleaner); + configuration.getWorkflowSpec().map(w -> !w.handleExceptionsInReconciler()).orElseThrow(), + hasCleaner); } @SuppressWarnings({"rawtypes", "unchecked"}) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java index 75366925bd..d442c75c09 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; +import java.util.Collections; import java.util.Map; import java.util.Map.Entry; import java.util.stream.Collectors; @@ -10,11 +11,10 @@ @SuppressWarnings("rawtypes") class WorkflowResult { - private static final String NUMBER_DELIMITER = "_"; private final Map erroredDependents; WorkflowResult(Map erroredDependents) { - this.erroredDependents = erroredDependents; + this.erroredDependents = erroredDependents != null ? erroredDependents : Collections.emptyMap(); } public Map getErroredDependents() { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java index e618e44e46..e634a368d7 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTest.java @@ -73,6 +73,11 @@ public List getDependentResourceSpecs() { public boolean isExplicitInvocation() { return false; } + + @Override + public boolean handleExceptionsInReconciler() { + return false; + } }; when(configuration.getWorkflowSpec()).thenReturn(Optional.of(ws)); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowSilentExceptionHandlingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowSilentExceptionHandlingIT.java new file mode 100644 index 0000000000..cd79283585 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowSilentExceptionHandlingIT.java @@ -0,0 +1,47 @@ +package io.javaoperatorsdk.operator; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling.HandleWorkflowExceptionsInReconcilerCustomResource; +import io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling.HandleWorkflowExceptionsInReconcilerReconciler; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class WorkflowSilentExceptionHandlingIT { + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(HandleWorkflowExceptionsInReconcilerReconciler.class) + .build(); + + @Test + void handleExceptionsInReconciler() { + extension.create(testResource()); + var reconciler = + extension.getReconcilerOfType(HandleWorkflowExceptionsInReconcilerReconciler.class); + + await().untilAsserted(() -> { + assertThat(reconciler.isErrorsFoundInReconcilerResult()).isTrue(); + }); + + extension.delete(testResource()); + + await().untilAsserted(() -> { + assertThat(reconciler.isErrorsFoundInCleanupResult()).isTrue(); + }); + } + + HandleWorkflowExceptionsInReconcilerCustomResource testResource() { + var res = new HandleWorkflowExceptionsInReconcilerCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName("test1") + .build()); + return res; + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/ConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/ConfigMapDependent.java new file mode 100644 index 0000000000..a418e8787e --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/ConfigMapDependent.java @@ -0,0 +1,28 @@ +package io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling; + + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; + +public class ConfigMapDependent extends + CRUDNoGCKubernetesDependentResource { + + public ConfigMapDependent() { + super(ConfigMap.class); + } + + @Override + public ReconcileResult reconcile( + HandleWorkflowExceptionsInReconcilerCustomResource primary, + Context context) { + throw new RuntimeException("Exception thrown on purpose"); + } + + @Override + public void delete(HandleWorkflowExceptionsInReconcilerCustomResource primary, + Context context) { + throw new RuntimeException("Exception thrown on purpose"); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java new file mode 100644 index 0000000000..3d4283e182 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("hweir") +public class HandleWorkflowExceptionsInReconcilerCustomResource + extends CustomResource + implements Namespaced { +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java new file mode 100644 index 0000000000..2519ccfe8d --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java @@ -0,0 +1,50 @@ +package io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling; + +import io.javaoperatorsdk.operator.api.reconciler.Cleaner; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; + +@Workflow(handleExceptionsInReconciler = true, + dependents = @Dependent(type = ConfigMapDependent.class)) +@ControllerConfiguration +public class HandleWorkflowExceptionsInReconcilerReconciler + implements Reconciler, + Cleaner { + + private volatile boolean errorsFoundInReconcilerResult = false; + private volatile boolean errorsFoundInCleanupResult = false; + + @Override + public UpdateControl reconcile( + HandleWorkflowExceptionsInReconcilerCustomResource resource, + Context context) { + + errorsFoundInReconcilerResult = context.managedWorkflowAndDependentResourceContext() + .getWorkflowReconcileResult().erroredDependentsExist(); + + + return UpdateControl.noUpdate(); + } + + @Override + public DeleteControl cleanup(HandleWorkflowExceptionsInReconcilerCustomResource resource, + Context context) { + + errorsFoundInCleanupResult = context.managedWorkflowAndDependentResourceContext() + .getWorkflowCleanupResult().erroredDependentsExist(); + return DeleteControl.defaultDelete(); + } + + public boolean isErrorsFoundInReconcilerResult() { + return errorsFoundInReconcilerResult; + } + + public boolean isErrorsFoundInCleanupResult() { + return errorsFoundInCleanupResult; + } +} From ff53d994b069e2a45b44c96f0d0bab3f57c5f7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 2 May 2024 08:02:12 +0200 Subject: [PATCH 39/96] feat: feature flag to not clone secondary resource on access (#2364) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../api/config/ConfigurationService.java | 27 +++++- .../config/ConfigurationServiceOverrider.java | 87 +++++++++++-------- .../source/informer/InformerManager.java | 4 +- .../operator/sample/WebPageReconciler.java | 9 +- 4 files changed, 84 insertions(+), 43 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index ef6797cbf3..74b74e4adb 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -20,6 +20,7 @@ import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.utils.KubernetesSerialization; import io.javaoperatorsdk.operator.api.monitoring.Metrics; +import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceFactory; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; @@ -456,7 +457,8 @@ default boolean parseResourceVersionsForEventFilteringAndCaching() { * either use simple patches or SSA. Setting this to {@code true}, controllers will use SSA for * adding finalizers, managing observed generation, patching resources and status. * - * @return {@code true} by default + * @return {@code true} if Server-Side Apply (SSA) should be used when patching the primary + * resources, {@code false} otherwise * @since 5.0.0 * @see ConfigurationServiceOverrider#withUseSSAToPatchPrimaryResource(boolean) */ @@ -464,4 +466,27 @@ default boolean useSSAToPatchPrimaryResource() { return true; } + /** + *

+ * Determines whether resources retrieved from caches such as via calls to + * {@link Context#getSecondaryResource(Class)} should be defensively cloned first. + *

+ * + *

+ * Defensive cloning to prevent problematic cache modifications (modifying the resource would + * otherwise modify the stored copy in the cache) was transparently done in previous JOSDK + * versions. This might have performance consequences and, with the more prevalent use of + * Server-Side Apply, where you should create a new copy of your resource with only modified + * fields, such modifications of these resources are less likely to occur. + *

+ * + * @return {@code true} if resources should be defensively cloned before returning them from + * caches, {@code false} otherwise + * + * @since 5.0.0 + */ + default boolean cloneSecondaryResourcesWhenGettingFromCache() { + return false; + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java index 7a5c098986..eef17100fe 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java @@ -5,6 +5,7 @@ import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.function.Consumer; +import java.util.function.Function; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,6 +42,7 @@ public class ConfigurationServiceOverrider { private Boolean previousAnnotationForDependentResources; private Boolean parseResourceVersions; private Boolean useSSAToPatchPrimaryResource; + private Boolean cloneSecondaryResourcesWhenGettingFromCache; @SuppressWarnings("rawtypes") private DependentResourceFactory dependentResourceFactory; @@ -203,6 +205,12 @@ public ConfigurationServiceOverrider withUseSSAToPatchPrimaryResource(boolean va return this; } + public ConfigurationServiceOverrider withCloneSecondaryResourcesWhenGettingFromCache( + boolean value) { + this.cloneSecondaryResourcesWhenGettingFromCache = value; + return this; + } + public ConfigurationService build() { return new BaseConfigurationService(original.getVersion(), cloner, client) { @Override @@ -210,23 +218,30 @@ public Set getKnownReconcilerNames() { return original.getKnownReconcilerNames(); } + private T overriddenValueOrDefault(T value, + Function defaultValue) { + return value != null ? value : defaultValue.apply(original); + } + @Override public boolean checkCRDAndValidateLocalModel() { - return checkCR != null ? checkCR : original.checkCRDAndValidateLocalModel(); + return overriddenValueOrDefault(checkCR, + ConfigurationService::checkCRDAndValidateLocalModel); } @SuppressWarnings("rawtypes") @Override + @SuppressWarnings("rawtypes") public DependentResourceFactory dependentResourceFactory() { - return dependentResourceFactory != null ? dependentResourceFactory - : DependentResourceFactory.DEFAULT; + return overriddenValueOrDefault(dependentResourceFactory, + ConfigurationService::dependentResourceFactory); } @Override public int concurrentReconciliationThreads() { return Utils.ensureValid( - concurrentReconciliationThreads != null ? concurrentReconciliationThreads - : original.concurrentReconciliationThreads(), + overriddenValueOrDefault(concurrentReconciliationThreads, + ConfigurationService::concurrentReconciliationThreads), "maximum reconciliation threads", minimumMaxValueFor(minConcurrentReconciliationThreads), original.concurrentReconciliationThreads()); @@ -235,8 +250,8 @@ public int concurrentReconciliationThreads() { @Override public int concurrentWorkflowExecutorThreads() { return Utils.ensureValid( - concurrentWorkflowExecutorThreads != null ? concurrentWorkflowExecutorThreads - : original.concurrentWorkflowExecutorThreads(), + overriddenValueOrDefault(concurrentWorkflowExecutorThreads, + ConfigurationService::concurrentWorkflowExecutorThreads), "maximum workflow execution threads", minimumMaxValueFor(minConcurrentWorkflowExecutorThreads), original.concurrentWorkflowExecutorThreads()); @@ -248,8 +263,8 @@ public int concurrentWorkflowExecutorThreads() { @Deprecated(forRemoval = true) @Override public int minConcurrentReconciliationThreads() { - return minConcurrentReconciliationThreads != null ? minConcurrentReconciliationThreads - : original.minConcurrentReconciliationThreads(); + return overriddenValueOrDefault(minConcurrentReconciliationThreads, + ConfigurationService::minConcurrentReconciliationThreads); } /** @@ -258,30 +273,29 @@ public int minConcurrentReconciliationThreads() { @Override @Deprecated(forRemoval = true) public int minConcurrentWorkflowExecutorThreads() { - return minConcurrentWorkflowExecutorThreads != null ? minConcurrentWorkflowExecutorThreads - : original.minConcurrentWorkflowExecutorThreads(); + return overriddenValueOrDefault(minConcurrentWorkflowExecutorThreads, + ConfigurationService::minConcurrentWorkflowExecutorThreads); } @Override public Metrics getMetrics() { - return metrics != null ? metrics : original.getMetrics(); + return overriddenValueOrDefault(metrics, ConfigurationService::getMetrics); } @Override public boolean closeClientOnStop() { - return closeClientOnStop != null ? closeClientOnStop : original.closeClientOnStop(); + return overriddenValueOrDefault(closeClientOnStop, ConfigurationService::closeClientOnStop); } @Override public ExecutorService getExecutorService() { - return executorService != null ? executorService - : super.getExecutorService(); + return overriddenValueOrDefault(executorService, ConfigurationService::getExecutorService); } @Override public ExecutorService getWorkflowExecutorService() { - return workflowExecutorService != null ? workflowExecutorService - : super.getWorkflowExecutorService(); + return overriddenValueOrDefault(workflowExecutorService, + ConfigurationService::getWorkflowExecutorService); } @Override @@ -298,54 +312,55 @@ public Optional getInformerStoppedHandler() { @Override public boolean stopOnInformerErrorDuringStartup() { - return stopOnInformerErrorDuringStartup != null ? stopOnInformerErrorDuringStartup - : super.stopOnInformerErrorDuringStartup(); + return overriddenValueOrDefault(stopOnInformerErrorDuringStartup, + ConfigurationService::stopOnInformerErrorDuringStartup); } @Override public Duration cacheSyncTimeout() { - return cacheSyncTimeout != null ? cacheSyncTimeout : super.cacheSyncTimeout(); + return overriddenValueOrDefault(cacheSyncTimeout, ConfigurationService::cacheSyncTimeout); } @Override public ResourceClassResolver getResourceClassResolver() { - return resourceClassResolver != null ? resourceClassResolver - : super.getResourceClassResolver(); + return overriddenValueOrDefault(resourceClassResolver, + ConfigurationService::getResourceClassResolver); } @Override public boolean ssaBasedCreateUpdateMatchForDependentResources() { - return ssaBasedCreateUpdateMatchForDependentResources != null - ? ssaBasedCreateUpdateMatchForDependentResources - : super.ssaBasedCreateUpdateMatchForDependentResources(); + return overriddenValueOrDefault(ssaBasedCreateUpdateMatchForDependentResources, + ConfigurationService::ssaBasedCreateUpdateMatchForDependentResources); } @Override public Set> defaultNonSSAResources() { - return defaultNonSSAResource != null ? defaultNonSSAResource - : super.defaultNonSSAResources(); + return overriddenValueOrDefault(defaultNonSSAResource, + ConfigurationService::defaultNonSSAResources); } @Override public boolean previousAnnotationForDependentResourcesEventFiltering() { - return previousAnnotationForDependentResources != null - ? previousAnnotationForDependentResources - : super.previousAnnotationForDependentResourcesEventFiltering(); + return overriddenValueOrDefault(previousAnnotationForDependentResources, + ConfigurationService::previousAnnotationForDependentResourcesEventFiltering); } @Override public boolean parseResourceVersionsForEventFilteringAndCaching() { - return parseResourceVersions != null - ? parseResourceVersions - : super.parseResourceVersionsForEventFilteringAndCaching(); + return overriddenValueOrDefault(parseResourceVersions, + ConfigurationService::parseResourceVersionsForEventFilteringAndCaching); } @Override public boolean useSSAToPatchPrimaryResource() { - return useSSAToPatchPrimaryResource != null - ? useSSAToPatchPrimaryResource - : super.useSSAToPatchPrimaryResource(); + return overriddenValueOrDefault(useSSAToPatchPrimaryResource, + ConfigurationService::useSSAToPatchPrimaryResource); + } + @Override + public boolean cloneSecondaryResourcesWhenGettingFromCache() { + return overriddenValueOrDefault(cloneSecondaryResourcesWhenGettingFromCache, + ConfigurationService::cloneSecondaryResourcesWhenGettingFromCache); } }; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java index e68cd3ab25..a97897b1fa 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java @@ -170,7 +170,9 @@ public Stream list(String namespace, Predicate predicate) { public Optional get(ResourceID resourceID) { return getSource(resourceID.getNamespace().orElse(WATCH_ALL_NAMESPACES)) .flatMap(source -> source.get(resourceID)) - .map(r -> configurationService.getResourceCloner().clone(r)); + .map(r -> configurationService.cloneSecondaryResourcesWhenGettingFromCache() + ? configurationService.getResourceCloner().clone(r) + : r); } @Override diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index be0e26b7d8..dfe6a10a71 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -13,7 +13,6 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.fabric8.kubernetes.client.KubernetesClient; -import io.fabric8.kubernetes.client.dsl.Replaceable; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; @@ -91,7 +90,7 @@ public UpdateControl reconcile(WebPage webPage, Context contex desiredHtmlConfigMap.getMetadata().getName(), ns); kubernetesClient.configMaps().inNamespace(ns).resource(desiredHtmlConfigMap) - .createOr(Replaceable::update); + .serverSideApply(); } var existingDeployment = context.getSecondaryResource(Deployment.class).orElse(null); @@ -101,7 +100,7 @@ public UpdateControl reconcile(WebPage webPage, Context contex desiredDeployment.getMetadata().getName(), ns); kubernetesClient.apps().deployments().inNamespace(ns).resource(desiredDeployment) - .createOr(Replaceable::update); + .serverSideApply(); } var existingService = context.getSecondaryResource(Service.class).orElse(null); @@ -111,14 +110,14 @@ public UpdateControl reconcile(WebPage webPage, Context contex desiredDeployment.getMetadata().getName(), ns); kubernetesClient.services().inNamespace(ns).resource(desiredService) - .createOr(Replaceable::update); + .serverSideApply(); } var existingIngress = context.getSecondaryResource(Ingress.class); if (Boolean.TRUE.equals(webPage.getSpec().getExposed())) { var desiredIngress = makeDesiredIngress(webPage); if (existingIngress.isEmpty() || !match(desiredIngress, existingIngress.get())) { - kubernetesClient.resource(desiredIngress).inNamespace(ns).createOr(Replaceable::update); + kubernetesClient.resource(desiredIngress).inNamespace(ns).serverSideApply(); } } else existingIngress.ifPresent( From 1fb539258aee1cf4834394f5fb2957c015a9da8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 2 May 2024 09:11:34 +0200 Subject: [PATCH 40/96] fix: unit test for event processor stopping (#2373) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/processing/event/EventProcessorTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java index 17a61b987b..f38bcce1cc 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java @@ -426,8 +426,8 @@ void executionOfReconciliationShouldNotStartIfProcessorStopped() throws Interrup eventSourceManagerMock, null)); eventProcessor.start(); - eventProcessor.handleEvent(prepareCREvent()); - eventProcessor.handleEvent(prepareCREvent()); + eventProcessor.handleEvent(prepareCREvent(new ResourceID("test1","default"))); + eventProcessor.handleEvent(prepareCREvent(new ResourceID("test1","default"))); eventProcessor.stop(); // wait until both event should be handled From d72a9e7d03696e9af5549e3f6e38bbc2388e5262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 2 May 2024 19:57:09 +0200 Subject: [PATCH 41/96] feat: all event source is resource event source (#2367) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun Signed-off-by: Attila Mészáros --- docs/documentation/v5-0-migration.md | 15 ++-- .../javaoperatorsdk/operator/RuntimeInfo.java | 5 +- .../api/config/ConfigurationService.java | 4 +- .../api/reconciler/DefaultContext.java | 6 +- .../dependent/DependentResource.java | 11 +-- .../operator/health/ControllerHealthInfo.java | 4 +- .../operator/processing/Controller.java | 6 +- ...actEventSourceHolderDependentResource.java | 6 +- .../AbstractExternalDependentResource.java | 6 +- .../processing/event/EventProcessor.java | 4 +- .../processing/event/EventSourceManager.java | 67 ++++++++-------- .../processing/event/EventSourceMetadata.java | 13 ---- .../event/EventSourceRetriever.java | 13 ++-- .../processing/event/EventSources.java | 76 ++++++++----------- .../event/source/AbstractEventSource.java | 45 ++++++++++- .../source/AbstractResourceEventSource.java | 50 ------------ .../processing/event/source/EventSource.java | 50 ++++++++++-- .../ExternalResourceCachingEventSource.java | 2 +- .../event/source/ResourceEventSource.java | 43 ----------- ...Source.java => ControllerEventSource.java} | 8 +- .../inbound/SimpleInboundEventSource.java | 15 +++- .../informer/ManagedInformerEventSource.java | 2 +- .../event/source/timer/TimerEventSource.java | 14 +++- .../processing/event/EventProcessorTest.java | 20 ++--- .../event/EventSourceManagerTest.java | 27 ++++--- .../processing/event/EventSourcesTest.java | 45 ++++++----- ...st.java => ControllerEventSourceTest.java} | 12 +-- .../operator/InformerRelatedBehaviorITS.java | 8 +- ...ericEventSourceRegistrationReconciler.java | 2 +- .../MultipleOwnerDependentConfigMap.java | 2 +- .../primarytosecondary/JobReconciler.java | 2 +- 31 files changed, 281 insertions(+), 302 deletions(-) delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceMetadata.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractResourceEventSource.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventSource.java rename operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/{ControllerResourceEventSource.java => ControllerEventSource.java} (95%) rename operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/{ControllerResourceEventSourceTest.java => ControllerEventSourceTest.java} (94%) diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index a76b191851..b051e2018f 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -17,7 +17,10 @@ permalink: /docs/v5-0-migration [`EventSourceUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java#L11-L11) now contains all the utility methods used for event sources naming that were previously defined in the `EventSourceInitializer` interface. -3. Event sources are now explicitly named (via the `name` method of the `EventSource` interface). Built-in event sources +3. Similarly, the `EventSourceProvider` interface has been remove, replaced by explicit initialization of the associated + event source on `DependentResource` via the ` + Optional> eventSource(EventSourceContext

eventSourceContext)` method. +4. Event sources are now explicitly named (via the `name` method of the `EventSource` interface). Built-in event sources implementation have been updated to allow you to specify a name when instantiating them. If you don't provide a name for your `EventSource` implementation (for example, by using its default, no-arg constructor), one will be automatically generated. This simplifies the API to define event source to @@ -27,7 +30,7 @@ permalink: /docs/v5-0-migration them automatically might result in duplicated event sources being registered as JOSDK relies on the name to identify event sources and concurrent, dynamic registration might lead to identical event sources having different generated names, thus leading JOSDK to consider them as different and hence, register them multiple times. -4. Updates through `UpdateControl` now +5. Updates through `UpdateControl` now use [Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/server-side-apply/) by default to add the finalizer and for all the patch operations in `UpdateControl`. The update operations were removed. If you do not wish to use SSA, you can @@ -46,11 +49,11 @@ permalink: /docs/v5-0-migration the status sub-resource is not instructed to be updated. This is not true for SSA, observed generation is updated only when patch status is instructed by `UpdateControl`. -5. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed +6. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. -6. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should +7. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should work without it by default. To optimize and handle special cases see the relevant section in [Dependent Resource documentation](/docs/dependent-resources#multiple-dependent-resources-of-same-type). -7. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed, +8. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed, use `Operator.stop(Duration)` instead. -8. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead +9. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/RuntimeInfo.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/RuntimeInfo.java index 961e519d62..ee2f4d447e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/RuntimeInfo.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/RuntimeInfo.java @@ -7,6 +7,7 @@ import io.javaoperatorsdk.operator.health.EventSourceHealthIndicator; import io.javaoperatorsdk.operator.health.InformerWrappingEventSourceHealthIndicator; +import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; /** * RuntimeInfo in general is available when operator is fully started. You can use "isStarted" to @@ -64,9 +65,7 @@ public Map> unhealthyEventSource /** * @return Aggregated Map with controller related event sources that wraps an informer. Thus, - * either a - * {@link io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource} - * or an + * either a {@link ControllerEventSource} or an * {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}. */ public Map> unhealthyInformerWrappingEventSourceHealthIndicator() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index 74b74e4adb..b402f60d7d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -28,6 +28,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.ResourceUpdaterMatcher; import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflowFactory; +import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; /** An interface from which to retrieve configuration information. */ public interface ConfigurationService { @@ -215,8 +216,7 @@ default Optional getLeaderElectionConfiguration() { *

* if true, operator stops if there are some issues with informers * {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource} or - * {@link io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource} - * on startup. Other event sources may also respect this flag. + * {@link ControllerEventSource} on startup. Other event sources may also respect this flag. *

*

* if false, the startup will ignore recoverable errors, caused for example by RBAC issues, and diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java index 86f29e6878..e8f6d475cb 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java @@ -44,7 +44,7 @@ public Set getSecondaryResources(Class expectedType) { @Override public IndexedResourceCache

getPrimaryCache() { - return controller.getEventSourceManager().getControllerResourceEventSource(); + return controller.getEventSourceManager().getControllerEventSource(); } @Override @@ -55,7 +55,7 @@ public boolean isNextReconciliationImminent() { @Override public Stream getSecondaryResourcesAsStream(Class expectedType) { - return controller.getEventSourceManager().getResourceEventSourcesFor(expectedType).stream() + return controller.getEventSourceManager().getEventSourcesFor(expectedType).stream() .map(es -> es.getSecondaryResources(primaryResource)) .flatMap(Set::stream); } @@ -64,7 +64,7 @@ public Stream getSecondaryResourcesAsStream(Class expectedType) { public Optional getSecondaryResource(Class expectedType, String eventSourceName) { return controller .getEventSourceManager() - .getResourceEventSourceFor(expectedType, eventSourceName) + .getEventSourceFor(expectedType, eventSourceName) .getSecondaryResource(primaryResource); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java index eec011e5e8..2b75b0d969 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java @@ -5,7 +5,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; /** * An interface to implement and provide dependent resource support. @@ -32,8 +32,8 @@ public interface DependentResource { Class resourceType(); /** - * Dependent resources are designed to by default provide event sources. There are cases where - * they might not: + * Dependent resources are designed to provide event sources by default. There are, however, cases + * where they might not: *

    *
  • If an event source is shared between multiple dependent resources. In this case only one or * none of the dependent resources sharing the event source should provide one, if any.
  • @@ -42,9 +42,10 @@ public interface DependentResource { *
* * @param eventSourceContext context of event source initialization - * @return an optional event source + * @return an optional event source initialized from the specified context + * @since 5.0.0 */ - default Optional> eventSource( + default Optional> eventSource( EventSourceContext

eventSourceContext) { return Optional.empty(); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/ControllerHealthInfo.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/ControllerHealthInfo.java index f873a6d870..1d65922f11 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/ControllerHealthInfo.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/ControllerHealthInfo.java @@ -5,6 +5,7 @@ import io.javaoperatorsdk.operator.processing.event.EventSourceManager; import io.javaoperatorsdk.operator.processing.event.source.EventSource; +import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; @SuppressWarnings("rawtypes") public class ControllerHealthInfo { @@ -36,8 +37,7 @@ public Map informerEventSour /** * @return Map with event sources that wraps an informer. Thus, either a - * {@link io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource} - * or an + * {@link ControllerEventSource} or an * {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}. */ public Map unhealthyInformerEventSourceHealthIndicators() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index ccb8ebbc1f..f24cf61afc 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -43,7 +43,7 @@ import io.javaoperatorsdk.operator.processing.event.EventProcessor; import io.javaoperatorsdk.operator.processing.event.EventSourceManager; import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE; @@ -102,7 +102,7 @@ public Controller(Reconciler

reconciler, eventSourceManager.postProcessDefaultEventSourcesAfterProcessorInitializer(); controllerHealthInfo = new ControllerHealthInfo(eventSourceManager); eventSourceContext = new EventSourceContext<>( - eventSourceManager.getControllerResourceEventSource(), configuration, kubernetesClient); + eventSourceManager.getControllerEventSource(), configuration, kubernetesClient); initAndRegisterEventSources(eventSourceContext); configurationService.getMetrics().controllerRegistered(this); } @@ -240,7 +240,7 @@ public void initAndRegisterEventSources(EventSourceContext

context) { final var size = dependentResourcesByName.size(); if (size > 0) { dependentResourcesByName.forEach(dependentResource -> { - Optional eventSource = dependentResource.eventSource(context); + Optional eventSource = dependentResource.eventSource(context); eventSource.ifPresent(eventSourceManager::registerEventSource); }); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java index 0b9f2ae897..6de936a5f8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java @@ -11,14 +11,14 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.RecentOperationCacheFiller; import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; @Ignore -public abstract class AbstractEventSourceHolderDependentResource> +public abstract class AbstractEventSourceHolderDependentResource> extends AbstractDependentResource implements EventSourceReferencer

{ private T eventSource; @@ -67,7 +67,7 @@ public synchronized Optional eventSource(EventSourceContext

context) { public void resolveEventSource(EventSourceRetriever

eventSourceRetriever) { if (eventSourceNameToUse != null && eventSource == null) { final var source = - eventSourceRetriever.getResourceEventSourceFor(resourceType(), eventSourceNameToUse); + eventSourceRetriever.getEventSourceFor(resourceType(), eventSourceNameToUse); if (source == null) { throw new EventSourceNotFoundException(eventSourceNameToUse); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractExternalDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractExternalDependentResource.java index ef825ef71f..acb6cb99d3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractExternalDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractExternalDependentResource.java @@ -5,10 +5,10 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.RecentOperationCacheFiller; import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; -public abstract class AbstractExternalDependentResource> +public abstract class AbstractExternalDependentResource> extends AbstractEventSourceHolderDependentResource { private final boolean isDependentResourceWithExplicitState = @@ -34,7 +34,7 @@ public void resolveEventSource(EventSourceRetriever

eventSourceRetriever) { final var eventSourceName = (String) dependentResourceWithExplicitState .eventSourceName().orElse(null); externalStateEventSource = (InformerEventSource) eventSourceRetriever - .getResourceEventSourceFor(dependentResourceWithExplicitState.stateResourceClass(), + .getEventSourceFor(dependentResourceWithExplicitState.stateResourceClass(), eventSourceName); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java index cc06c347d0..e05ea4830f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java @@ -52,7 +52,7 @@ public EventProcessor(EventSourceManager

eventSourceManager, this( eventSourceManager.getController().getConfiguration(), new ReconciliationDispatcher<>(eventSourceManager.getController()), eventSourceManager, - configurationService.getMetrics(), eventSourceManager.getControllerResourceEventSource()); + configurationService.getMetrics(), eventSourceManager.getControllerEventSource()); } @SuppressWarnings("rawtypes") @@ -64,7 +64,7 @@ public EventProcessor(EventSourceManager

eventSourceManager, this( controllerConfiguration, reconciliationDispatcher, eventSourceManager, metrics, - eventSourceManager.getControllerResourceEventSource()); + eventSourceManager.getControllerEventSource()); } @SuppressWarnings({"rawtypes", "unchecked"}) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java index 512ab3bde1..a17328e7d7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java @@ -7,6 +7,7 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,8 +23,7 @@ import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.EventSourceStartPriority; import io.javaoperatorsdk.operator.processing.event.source.ResourceEventAware; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; -import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource; +import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceAction; import io.javaoperatorsdk.operator.processing.event.source.informer.ManagedInformerEventSource; import io.javaoperatorsdk.operator.processing.event.source.timer.TimerEventSource; @@ -51,7 +51,7 @@ public EventSourceManager(Controller

controller) { } public void postProcessDefaultEventSourcesAfterProcessorInitializer() { - eventSources.controllerResourceEventSource().setEventHandler(controller.getEventProcessor()); + eventSources.controllerEventSource().setEventHandler(controller.getEventProcessor()); eventSources.retryEventSource().setEventHandler(controller.getEventProcessor()); } @@ -63,11 +63,11 @@ public void postProcessDefaultEventSourcesAfterProcessorInitializer() { * {@link io.javaoperatorsdk.operator.processing.event.source.polling.PerResourcePollingEventSource}). *

* Now the event sources are also started sequentially, mainly because others might depend on - * {@link ControllerResourceEventSource} , which is started first. + * {@link ControllerEventSource} , which is started first. */ @Override public synchronized void start() { - startEventSource(eventSources.controllerResourceEventSource()); + startEventSource(eventSources.controllerEventSource()); executorServiceManager.boundedExecuteAndWaitForAllToComplete( eventSources.additionalEventSources() @@ -82,6 +82,7 @@ public synchronized void start() { getThreadNamer("start")); } + @SuppressWarnings("rawtypes") private static Function getThreadNamer(String stage) { return es -> es.priority() + " " + stage + " -> " + es.name(); } @@ -92,7 +93,7 @@ private static Function getEventSourceThreadNamer(S @Override public synchronized void stop() { - stopEventSource(eventSources.controllerResourceEventSource()); + stopEventSource(eventSources.controllerEventSource()); executorServiceManager.boundedExecuteAndWaitForAllToComplete( eventSources.additionalEventSources(), this::stopEventSource, @@ -102,16 +103,12 @@ public synchronized void stop() { @SuppressWarnings("rawtypes") private void logEventSourceEvent(EventSource eventSource, String event) { if (log.isDebugEnabled()) { - if (eventSource instanceof ResourceEventSource source) { - log.debug("{} event source {} for {}", event, eventSource.name(), - source.resourceType()); - } else { - log.debug("{} event source {}", event, eventSource.name()); - } + log.debug("{} event source {} for {}", event, eventSource.name(), + eventSource.resourceType()); } } - private Void startEventSource(EventSource eventSource) { + private Void startEventSource(EventSource eventSource) { try { logEventSourceEvent(eventSource, "Starting"); eventSource.start(); @@ -124,7 +121,7 @@ private Void startEventSource(EventSource eventSource) { return null; } - private Void stopEventSource(EventSource eventSource) { + private Void stopEventSource(EventSource eventSource) { try { logEventSourceEvent(eventSource, "Stopping"); eventSource.stop(); @@ -136,7 +133,7 @@ private Void stopEventSource(EventSource eventSource) { } @SuppressWarnings("rawtypes") - public final synchronized void registerEventSource(EventSource eventSource) + public final synchronized void registerEventSource(EventSource eventSource) throws OperatorException { Objects.requireNonNull(eventSource, "EventSource must not be null"); try { @@ -176,7 +173,7 @@ public void broadcastOnResourceEvent(ResourceAction action, P resource, P oldRes } public void changeNamespaces(Set namespaces) { - eventSources.controllerResourceEventSource() + eventSources.controllerEventSource() .changeNamespaces(namespaces); executorServiceManager.boundedExecuteAndWaitForAllToComplete(eventSources .additionalEventSources() @@ -189,26 +186,32 @@ public void changeNamespaces(Set namespaces) { getEventSourceThreadNamer("changeNamespace")); } - public Set getRegisteredEventSources() { + public Set> getRegisteredEventSources() { return eventSources.flatMappedSources() - .collect(Collectors.toCollection(LinkedHashSet::new)); } + @SuppressWarnings("rawtypes") public List allEventSources() { return eventSources.allEventSources().toList(); } - public ControllerResourceEventSource

getControllerResourceEventSource() { - return eventSources.controllerResourceEventSource(); + + @SuppressWarnings("unused") + public Stream> getEventSourcesStream() { + return eventSources.flatMappedSources(); + } + + public ControllerEventSource

getControllerEventSource() { + return eventSources.controllerEventSource(); } - public List> getResourceEventSourcesFor(Class dependentType) { + public List> getEventSourcesFor(Class dependentType) { return eventSources.getEventSources(dependentType); } @Override - public EventSource dynamicallyRegisterEventSource(EventSource eventSource) { + public EventSource dynamicallyRegisterEventSource(EventSource eventSource) { synchronized (this) { var actual = eventSources.existingEventSourceOfSameNameAndType(eventSource); if (actual != null) { @@ -224,8 +227,10 @@ public EventSource dynamicallyRegisterEventSource(EventSource eventSource) { } @Override - public synchronized Optional dynamicallyDeRegisterEventSource(String name) { - EventSource es = eventSources.remove(name); + public synchronized Optional> dynamicallyDeRegisterEventSource( + String name) { + @SuppressWarnings("unchecked") + EventSource es = eventSources.remove(name); if (es != null) { es.stop(); } @@ -237,20 +242,8 @@ public EventSourceContext

eventSourceContextForDynamicRegistration() { return controller.eventSourceContext(); } - /** - * @deprecated Use {@link #getResourceEventSourceFor(Class)} instead - * - * @param target resource type - * @param dependentType target resource class - * @return list of related event sources - */ - @Deprecated - public List> getEventSourcesFor(Class dependentType) { - return getResourceEventSourcesFor(dependentType); - } - @Override - public ResourceEventSource getResourceEventSourceFor( + public EventSource getEventSourceFor( Class dependentType, String name) { Objects.requireNonNull(dependentType, "dependentType is Mandatory"); return eventSources.get(dependentType, name); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceMetadata.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceMetadata.java deleted file mode 100644 index 2fd913d481..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceMetadata.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.javaoperatorsdk.operator.processing.event; - -import java.util.Optional; - -public interface EventSourceMetadata { - String name(); - - Class type(); - - Optional> resourceType(); - - Optional configuration(); -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java index c687c93acd..16b03303a4 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java @@ -6,17 +6,16 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.processing.event.source.EventSource; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; public interface EventSourceRetriever

{ - default ResourceEventSource getResourceEventSourceFor(Class dependentType) { - return getResourceEventSourceFor(dependentType, null); + default EventSource getEventSourceFor(Class dependentType) { + return getEventSourceFor(dependentType, null); } - ResourceEventSource getResourceEventSourceFor(Class dependentType, String name); + EventSource getEventSourceFor(Class dependentType, String name); - List> getResourceEventSourcesFor(Class dependentType); + List> getEventSourcesFor(Class dependentType); /** *

@@ -50,7 +49,7 @@ default ResourceEventSource getResourceEventSourceFor(Class depende * @param eventSource to register * @return the actual event source registered. Might not be the same as the parameter. */ - EventSource dynamicallyRegisterEventSource(EventSource eventSource); + EventSource dynamicallyRegisterEventSource(EventSource eventSource); /** * De-registers (and stops) the {@link EventSource} associated with the specified name. If no such @@ -68,7 +67,7 @@ default ResourceEventSource getResourceEventSourceFor(Class depende * @param name of the event source * @return the actual event source deregistered if there is one. */ - Optional dynamicallyDeRegisterEventSource(String name); + Optional> dynamicallyDeRegisterEventSource(String name); EventSourceContext

eventSourceContextForDynamicRegistration(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java index c6b5a83377..79091de0d3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java @@ -7,50 +7,50 @@ import java.util.Objects; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; -import java.util.stream.Collectors; import java.util.stream.Stream; import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.event.source.EventSource; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; -import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource; +import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; import io.javaoperatorsdk.operator.processing.event.source.timer.TimerEventSource; -class EventSources { +class EventSources

{ - private final ConcurrentNavigableMap> sources = + private final ConcurrentNavigableMap>> sources = new ConcurrentSkipListMap<>(); - private final TimerEventSource retryAndRescheduleTimerEventSource = + private final TimerEventSource

retryAndRescheduleTimerEventSource = new TimerEventSource<>("RetryAndRescheduleTimerEventSource"); - private ControllerResourceEventSource controllerResourceEventSource; + private ControllerEventSource

controllerEventSource; - void createControllerEventSource(Controller controller) { - controllerResourceEventSource = new ControllerResourceEventSource<>(controller); + void createControllerEventSource(Controller

controller) { + controllerEventSource = new ControllerEventSource<>(controller); } - ControllerResourceEventSource controllerResourceEventSource() { - return controllerResourceEventSource; + public ControllerEventSource

controllerEventSource() { + return controllerEventSource; } - TimerEventSource retryEventSource() { + TimerEventSource

retryEventSource() { return retryAndRescheduleTimerEventSource; } + @SuppressWarnings("rawtypes") public Stream allEventSources() { return Stream.concat( - Stream.of(controllerResourceEventSource(), retryAndRescheduleTimerEventSource), + Stream.of(controllerEventSource(), retryAndRescheduleTimerEventSource), flatMappedSources()); } + @SuppressWarnings("rawtypes") Stream additionalEventSources() { return Stream.concat( Stream.of(retryEventSource()).filter(Objects::nonNull), flatMappedSources()); } - Stream flatMappedSources() { + Stream> flatMappedSources() { return sources.values().stream().flatMap(c -> c.values().stream()); } @@ -58,17 +58,19 @@ public void clear() { sources.clear(); } - public EventSource existingEventSourceOfSameNameAndType(EventSource source) { - return existingEventSourceOfSameType(source).get(source.name()); + @SuppressWarnings("unchecked") + public EventSource existingEventSourceOfSameNameAndType(EventSource source) { + return (EventSource) existingEventSourcesOfSameType(source).get(source.name()); } - public Map existingEventSourceOfSameType(EventSource source) { + private Map> existingEventSourcesOfSameType( + EventSource source) { return sources.getOrDefault(keyFor(source), Collections.emptyMap()); } - public void add(EventSource eventSource) { + public void add(EventSource eventSource) { final var name = eventSource.name(); - final var existing = existingEventSourceOfSameType(eventSource); + final var existing = existingEventSourcesOfSameType(eventSource); if (existing.get(name) != null) { throw new IllegalArgumentException("Event source " + existing + " is already registered with name: " + name); @@ -77,15 +79,8 @@ public void add(EventSource eventSource) { sources.computeIfAbsent(keyFor(eventSource), k -> new HashMap<>()).put(name, eventSource); } - @SuppressWarnings("rawtypes") - private Class getResourceType(EventSource source) { - return source instanceof ResourceEventSource - ? ((ResourceEventSource) source).resourceType() - : source.getClass(); - } - - private String keyFor(EventSource source) { - return keyFor(getResourceType(source)); + private String keyFor(EventSource source) { + return keyFor(source.resourceType()); } private String keyFor(Class dependentType) { @@ -93,7 +88,7 @@ private String keyFor(Class dependentType) { } @SuppressWarnings("unchecked") - public ResourceEventSource get(Class dependentType, String name) { + public EventSource get(Class dependentType, String name) { if (dependentType == null) { throw new IllegalArgumentException("Must pass a dependent type to retrieve event sources"); } @@ -105,9 +100,9 @@ public ResourceEventSource get(Class dependentType, String name) { } final var size = sourcesForType.size(); - EventSource source; + EventSource source; if (size == 1 && name == null) { - source = sourcesForType.values().stream().findFirst().orElseThrow(); + source = (EventSource) sourcesForType.values().stream().findFirst().orElseThrow(); } else { if (name == null || name.isBlank()) { throw new IllegalArgumentException("There are multiple EventSources registered for type " @@ -115,7 +110,7 @@ public ResourceEventSource get(Class dependentType, String name) { + ", you need to provide a name to specify which EventSource you want to query. Known names: " + String.join(",", sourcesForType.keySet())); } - source = sourcesForType.get(name); + source = (EventSource) sourcesForType.get(name); if (source == null) { throw new IllegalArgumentException("There is no event source found for class:" + @@ -123,20 +118,14 @@ public ResourceEventSource get(Class dependentType, String name) { } } - if (!(source instanceof ResourceEventSource)) { - throw new IllegalArgumentException(source + " associated with " - + keyAsString(dependentType, name) + " is not a " - + ResourceEventSource.class.getSimpleName()); - } - final var res = (ResourceEventSource) source; - final var resourceClass = res.resourceType(); + final var resourceClass = source.resourceType(); if (!resourceClass.isAssignableFrom(dependentType)) { throw new IllegalArgumentException(source + " associated with " + keyAsString(dependentType, name) + " is handling " + resourceClass.getName() + " resources but asked for " + dependentType.getName()); } - return res; + return source; } @SuppressWarnings("rawtypes") @@ -147,18 +136,17 @@ private String keyAsString(Class dependentType, String name) { } @SuppressWarnings("unchecked") - public List> getEventSources(Class dependentType) { + public List> getEventSources(Class dependentType) { final var sourcesForType = sources.get(keyFor(dependentType)); if (sourcesForType == null) { return Collections.emptyList(); } return sourcesForType.values().stream() - .filter(ResourceEventSource.class::isInstance) - .map(es -> (ResourceEventSource) es) - .collect(Collectors.toList()); + .map(es -> (EventSource) es).toList(); } + @SuppressWarnings("rawtypes") public EventSource remove(String name) { var optionalMap = sources.values().stream().filter(m -> m.containsKey(name)).findFirst(); return optionalMap.map(m -> m.remove(name)).orElse(null); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSource.java index b2398ab6ff..a2306378d4 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSource.java @@ -1,21 +1,35 @@ package io.javaoperatorsdk.operator.processing.event.source; +import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.processing.event.EventHandler; +import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; + +public abstract class AbstractEventSource implements EventSource { + + private final Class resourceClass; + + protected OnAddFilter onAddFilter; + protected OnUpdateFilter onUpdateFilter; + protected OnDeleteFilter onDeleteFilter; + protected GenericFilter genericFilter; -public abstract class AbstractEventSource implements EventSource { private EventHandler handler; private volatile boolean running = false; private EventSourceStartPriority eventSourceStartPriority = EventSourceStartPriority.DEFAULT; private final String name; - protected AbstractEventSource() { - this(null); + protected AbstractEventSource(Class resourceClass) { + this(resourceClass, null); } - protected AbstractEventSource(String name) { + protected AbstractEventSource(Class resourceClass, String name) { this.name = name == null ? EventSource.super.name() : name; + this.resourceClass = resourceClass; } @Override @@ -57,4 +71,27 @@ public AbstractEventSource setEventSourcePriority( return this; } + @Override + public Class resourceType() { + return resourceClass; + } + + public void setOnAddFilter(OnAddFilter onAddFilter) { + this.onAddFilter = onAddFilter; + } + + public void setOnUpdateFilter( + OnUpdateFilter onUpdateFilter) { + this.onUpdateFilter = onUpdateFilter; + } + + public void setOnDeleteFilter( + OnDeleteFilter onDeleteFilter) { + this.onDeleteFilter = onDeleteFilter; + } + + public void setGenericFilter(GenericFilter genericFilter) { + this.genericFilter = genericFilter; + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractResourceEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractResourceEventSource.java deleted file mode 100644 index 73420c0e5e..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/AbstractResourceEventSource.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.javaoperatorsdk.operator.processing.event.source; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; - -public abstract class AbstractResourceEventSource - extends AbstractEventSource - implements ResourceEventSource { - private final Class resourceClass; - - protected OnAddFilter onAddFilter; - protected OnUpdateFilter onUpdateFilter; - protected OnDeleteFilter onDeleteFilter; - protected GenericFilter genericFilter; - - protected AbstractResourceEventSource(Class resourceClass) { - this(resourceClass, resourceClass.getName()); - } - - protected AbstractResourceEventSource(Class resourceClass, String name) { - super(name); - this.resourceClass = resourceClass; - } - - @Override - public Class resourceType() { - return resourceClass; - } - - public void setOnAddFilter(OnAddFilter onAddFilter) { - this.onAddFilter = onAddFilter; - } - - public void setOnUpdateFilter( - OnUpdateFilter onUpdateFilter) { - this.onUpdateFilter = onUpdateFilter; - } - - public void setOnDeleteFilter( - OnDeleteFilter onDeleteFilter) { - this.onDeleteFilter = onDeleteFilter; - } - - public void setGenericFilter(GenericFilter genericFilter) { - this.genericFilter = genericFilter; - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java index e368ec3a94..11b884bb73 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java @@ -1,16 +1,25 @@ package io.javaoperatorsdk.operator.processing.event.source; +import java.util.Optional; +import java.util.Set; + +import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.health.EventSourceHealthIndicator; import io.javaoperatorsdk.operator.health.Status; import io.javaoperatorsdk.operator.processing.LifecycleAware; import io.javaoperatorsdk.operator.processing.event.EventHandler; +import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; /** * Creates an event source to trigger your reconciler whenever something happens to a secondary or * external resource that should cause a reconciliation of the primary resource. EventSource * generalizes the concept of Informers and extends it to external (i.e. non Kubernetes) resources. */ -public interface EventSource extends LifecycleAware, EventSourceHealthIndicator { +public interface EventSource + extends LifecycleAware, EventSourceHealthIndicator { /** * Sets the {@link EventHandler} that is linked to your reconciler when this EventSource is @@ -20,21 +29,48 @@ public interface EventSource extends LifecycleAware, EventSourceHealthIndicator */ void setEventHandler(EventHandler handler); + default String name() { + return generateName(this); + } + default EventSourceStartPriority priority() { return EventSourceStartPriority.DEFAULT; } + /** + * Retrieves the resource type associated with this ResourceEventSource + * + * @return the resource type associated with this ResourceEventSource + */ + Class resourceType(); + + default Optional getSecondaryResource(P primary) { + var resources = getSecondaryResources(primary); + if (resources.isEmpty()) { + return Optional.empty(); + } else if (resources.size() == 1) { + return Optional.of(resources.iterator().next()); + } else { + throw new IllegalStateException("More than 1 secondary resource related to primary"); + } + } + + Set getSecondaryResources(P primary); + + void setOnAddFilter(OnAddFilter onAddFilter); + + void setOnUpdateFilter(OnUpdateFilter onUpdateFilter); + + void setOnDeleteFilter(OnDeleteFilter onDeleteFilter); + + void setGenericFilter(GenericFilter genericFilter); + @Override default Status getStatus() { return Status.UNKNOWN; } - default String name() { - return generateName(this); - } - - static String generateName(EventSource eventSource) { + static String generateName(EventSource eventSource) { return eventSource.getClass().getName() + "@" + Integer.toHexString(eventSource.hashCode()); } - } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java index b4bb44d957..130e3db179 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java @@ -40,7 +40,7 @@ * @param

primary resource */ public abstract class ExternalResourceCachingEventSource - extends AbstractResourceEventSource implements RecentOperationCacheFiller { + extends AbstractEventSource implements RecentOperationCacheFiller { private static final Logger log = LoggerFactory.getLogger(ExternalResourceCachingEventSource.class); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventSource.java deleted file mode 100644 index 52215cdcf7..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ResourceEventSource.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.javaoperatorsdk.operator.processing.event.source; - -import java.util.Optional; -import java.util.Set; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; - -public interface ResourceEventSource extends EventSource { - - /** - * Retrieves the resource type associated with this ResourceEventSource - * - * @return the resource type associated with this ResourceEventSource - */ - Class resourceType(); - - default Optional getSecondaryResource(P primary) { - var resources = getSecondaryResources(primary); - if (resources.isEmpty()) { - return Optional.empty(); - } else if (resources.size() == 1) { - return Optional.of(resources.iterator().next()); - } else { - throw new IllegalStateException("More than 1 secondary resource related to primary"); - } - - } - - Set getSecondaryResources(P primary); - - void setOnAddFilter(OnAddFilter onAddFilter); - - void setOnUpdateFilter(OnUpdateFilter onUpdateFilter); - - void setOnDeleteFilter(OnDeleteFilter onDeleteFilter); - - void setGenericFilter(GenericFilter genericFilter); - -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java similarity index 95% rename from operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java rename to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java index 9a2f51cf37..3d66051e16 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java @@ -21,17 +21,17 @@ import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion; import static io.javaoperatorsdk.operator.processing.event.source.controller.InternalEventFilters.*; -public class ControllerResourceEventSource +public class ControllerEventSource extends ManagedInformerEventSource> implements ResourceEventHandler { - private static final Logger log = LoggerFactory.getLogger(ControllerResourceEventSource.class); - private static final String NAME = "ControllerResourceEventSource"; + private static final Logger log = LoggerFactory.getLogger(ControllerEventSource.class); + public static final String NAME = "ControllerResourceEventSource"; private final Controller controller; @SuppressWarnings({"unchecked", "rawtypes"}) - public ControllerResourceEventSource(Controller controller) { + public ControllerEventSource(Controller controller) { super(NAME, controller.getCRClient(), controller.getConfiguration(), false); this.controller = controller; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/inbound/SimpleInboundEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/inbound/SimpleInboundEventSource.java index d13c032f88..7d5f2aa446 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/inbound/SimpleInboundEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/inbound/SimpleInboundEventSource.java @@ -1,20 +1,25 @@ package io.javaoperatorsdk.operator.processing.event.source.inbound; +import java.util.Set; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.processing.event.Event; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.AbstractEventSource; -public class SimpleInboundEventSource extends AbstractEventSource { +public class SimpleInboundEventSource

extends AbstractEventSource { private static final Logger log = LoggerFactory.getLogger(SimpleInboundEventSource.class); - public SimpleInboundEventSource() {} + public SimpleInboundEventSource() { + super(Void.class); + } public SimpleInboundEventSource(String name) { - super(name); + super(Void.class, name); } public void propagateEvent(ResourceID resourceID) { @@ -25,4 +30,8 @@ public void propagateEvent(ResourceID resourceID) { } } + @Override + public Set getSecondaryResources(P primary) { + return Set.of(); + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java index ec8e980871..dcf0ab3d7e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java @@ -28,7 +28,7 @@ @SuppressWarnings("rawtypes") public abstract class ManagedInformerEventSource> - extends AbstractResourceEventSource + extends AbstractEventSource implements ResourceEventHandler, Cache, IndexerResourceCache, RecentOperationCacheFiller, NamespaceChangeable, InformerWrappingEventSourceHealthIndicator, Configurable { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/timer/TimerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/timer/TimerEventSource.java index f228c9935c..b909083a00 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/timer/TimerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/timer/TimerEventSource.java @@ -1,6 +1,7 @@ package io.javaoperatorsdk.operator.processing.event.source.timer; import java.util.Map; +import java.util.Set; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.ConcurrentHashMap; @@ -15,17 +16,19 @@ import io.javaoperatorsdk.operator.processing.event.source.ResourceEventAware; public class TimerEventSource - extends AbstractEventSource + extends AbstractEventSource implements ResourceEventAware { private static final Logger log = LoggerFactory.getLogger(TimerEventSource.class); private Timer timer; private final Map onceTasks = new ConcurrentHashMap<>(); - public TimerEventSource() {} + public TimerEventSource() { + super(Void.class); + } public TimerEventSource(String name) { - super(name); + super(Void.class, name); } @SuppressWarnings("unused") @@ -75,6 +78,11 @@ public void stop() { } } + @Override + public Set getSecondaryResources(HasMetadata primary) { + return Set.of(); + } + public class EventProducerTimeTask extends TimerTask { protected final ResourceID customResourceUid; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java index f38bcce1cc..9f7e390c0a 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java @@ -22,7 +22,7 @@ import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter.RateLimitState; -import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource; +import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceAction; import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEvent; import io.javaoperatorsdk.operator.processing.event.source.timer.TimerEventSource; @@ -66,8 +66,8 @@ class EventProcessorTest { mock(ReconciliationDispatcher.class); private final EventSourceManager eventSourceManagerMock = mock(EventSourceManager.class); private final TimerEventSource retryTimerEventSourceMock = mock(TimerEventSource.class); - private final ControllerResourceEventSource controllerResourceEventSourceMock = - mock(ControllerResourceEventSource.class); + private final ControllerEventSource controllerEventSourceMock = + mock(ControllerEventSource.class); private final Metrics metricsMock = mock(Metrics.class); private EventProcessor eventProcessor; private EventProcessor eventProcessorWithRetry; @@ -75,8 +75,8 @@ class EventProcessorTest { @BeforeEach void setup() { - when(eventSourceManagerMock.getControllerResourceEventSource()) - .thenReturn(controllerResourceEventSourceMock); + when(eventSourceManagerMock.getControllerEventSource()) + .thenReturn(controllerEventSourceMock); eventProcessor = spy(new EventProcessor(controllerConfiguration(null, rateLimiterMock), reconciliationDispatcherMock, @@ -103,7 +103,7 @@ void dispatchesEventsIfNoExecutionInProgress() { @Test void skipProcessingIfLatestCustomResourceNotInCache() { Event event = prepareCREvent(); - when(controllerResourceEventSourceMock.get(event.getRelatedCustomResourceID())) + when(controllerEventSourceMock.get(event.getRelatedCustomResourceID())) .thenReturn(Optional.empty()); eventProcessor.handleEvent(event); @@ -275,7 +275,7 @@ void startProcessedMarkedEventReceivedBefore() { LinearRateLimiter.deactivatedRateLimiter()), reconciliationDispatcherMock, eventSourceManagerMock, metricsMock)); - when(controllerResourceEventSourceMock.get(eq(crID))) + when(controllerEventSourceMock.get(eq(crID))) .thenReturn(Optional.of(testCustomResource())); eventProcessor.handleEvent(new Event(crID)); @@ -297,7 +297,7 @@ void notUpdatesEventSourceHandlerIfResourceUpdated() { eventProcessorWithRetry.eventProcessingFinished(executionScope, postExecutionControl); - verify(controllerResourceEventSourceMock, times(0)).handleRecentResourceUpdate(any(), any(), + verify(controllerEventSourceMock, times(0)).handleRecentResourceUpdate(any(), any(), any()); } @@ -468,7 +468,7 @@ private ResourceEvent prepareCREvent() { } private ResourceEvent prepareCREvent(HasMetadata hasMetadata) { - when(controllerResourceEventSourceMock.get(eq(ResourceID.fromResource(hasMetadata)))) + when(controllerEventSourceMock.get(eq(ResourceID.fromResource(hasMetadata)))) .thenReturn(Optional.of(hasMetadata)); return new ResourceEvent(ResourceAction.UPDATED, ResourceID.fromResource(hasMetadata), hasMetadata); @@ -476,7 +476,7 @@ private ResourceEvent prepareCREvent(HasMetadata hasMetadata) { private ResourceEvent prepareCREvent(ResourceID resourceID) { TestCustomResource customResource = testCustomResource(resourceID); - when(controllerResourceEventSourceMock.get(eq(resourceID))) + when(controllerEventSourceMock.get(eq(resourceID))) .thenReturn(Optional.of(customResource)); return new ResourceEvent(ResourceAction.UPDATED, ResourceID.fromResource(customResource), customResource); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java index 66ccf47e81..b5ff379dd6 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java @@ -13,9 +13,10 @@ import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.processing.Controller; +import io.javaoperatorsdk.operator.processing.event.source.AbstractEventSource; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.EventSourceStartPriority; -import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource; +import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.ManagedInformerEventSource; import io.javaoperatorsdk.operator.processing.event.source.timer.TimerEventSource; @@ -34,10 +35,11 @@ class EventSourceManagerTest { @Test public void registersEventSource() { EventSource eventSource = mock(EventSource.class); + when(eventSource.resourceType()).thenReturn(EventSource.class); eventSourceManager.registerEventSource(eventSource); - Set registeredSources = eventSourceManager.getRegisteredEventSources(); + final var registeredSources = eventSourceManager.getRegisteredEventSources(); assertThat(registeredSources).contains(eventSource); verify(eventSource, times(1)).setEventHandler(any()); @@ -46,7 +48,9 @@ public void registersEventSource() { @Test public void closeShouldCascadeToEventSources() { EventSource eventSource = mock(EventSource.class); + when(eventSource.resourceType()).thenReturn(EventSource.class); EventSource eventSource2 = mock(TimerEventSource.class); + when(eventSource2.resourceType()).thenReturn(AbstractEventSource.class); eventSourceManager.registerEventSource(eventSource); eventSourceManager.registerEventSource(eventSource2); @@ -61,8 +65,11 @@ public void closeShouldCascadeToEventSources() { public void startCascadesToEventSources() { EventSource eventSource = mock(EventSource.class); when(eventSource.priority()).thenReturn(EventSourceStartPriority.DEFAULT); + when(eventSource.resourceType()).thenReturn(EventSource.class); EventSource eventSource2 = mock(TimerEventSource.class); when(eventSource2.priority()).thenReturn(EventSourceStartPriority.DEFAULT); + when(eventSource2.resourceType()).thenReturn(AbstractEventSource.class); + eventSourceManager.registerEventSource(eventSource); eventSourceManager.registerEventSource(eventSource2); @@ -75,18 +82,18 @@ public void startCascadesToEventSources() { @Test void retrievingEventSourceForClassShouldWork() { assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> eventSourceManager.getResourceEventSourceFor(Class.class)); + .isThrownBy(() -> eventSourceManager.getEventSourceFor(Class.class)); // manager is initialized with a controller configured to handle HasMetadata EventSourceManager manager = initManager(); assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> manager.getResourceEventSourceFor(HasMetadata.class, "unknown_name")); + .isThrownBy(() -> manager.getEventSourceFor(HasMetadata.class, "unknown_name")); ManagedInformerEventSource eventSource = mock(ManagedInformerEventSource.class); when(eventSource.resourceType()).thenReturn(String.class); manager.registerEventSource(eventSource); - var source = manager.getResourceEventSourceFor(String.class); + var source = manager.getEventSourceFor(String.class); assertThat(source).isNotNull(); assertEquals(eventSource, source); } @@ -129,13 +136,13 @@ void retrievingAnEventSourceWhenMultipleAreRegisteredForATypeShouldRequireAQuali manager.registerEventSource(eventSource2); final var exception = assertThrows(IllegalArgumentException.class, - () -> manager.getResourceEventSourceFor(TestCustomResource.class)); + () -> manager.getEventSourceFor(TestCustomResource.class)); assertTrue(exception.getMessage().contains("name1")); assertTrue(exception.getMessage().contains("name2")); - assertEquals(manager.getResourceEventSourceFor(TestCustomResource.class, "name2"), + assertEquals(manager.getEventSourceFor(TestCustomResource.class, "name2"), eventSource2); - assertEquals(manager.getResourceEventSourceFor(TestCustomResource.class, "name1"), + assertEquals(manager.getEventSourceFor(TestCustomResource.class, "name1"), eventSource); } @@ -152,8 +159,8 @@ void changesNamespacesOnControllerAndInformerEventSources() { MockKubernetesClient.client(HasMetadata.class)); EventSources eventSources = spy(new EventSources()); - var controllerResourceEventSourceMock = mock(ControllerResourceEventSource.class); - doReturn(controllerResourceEventSourceMock).when(eventSources).controllerResourceEventSource(); + var controllerResourceEventSourceMock = mock(ControllerEventSource.class); + doReturn(controllerResourceEventSourceMock).when(eventSources).controllerEventSource(); when(controllerResourceEventSourceMock.allowsNamespaceChanges()).thenCallRealMethod(); var manager = new EventSourceManager(controller, eventSources); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java index f26f915d00..9c2d09bac4 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java @@ -11,7 +11,6 @@ import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.event.source.EventSource; -import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -30,8 +29,10 @@ void cannotAddTwoDifferentEventSourcesWithSameName() { final var eventSources = new EventSources(); var es1 = mock(EventSource.class); when(es1.name()).thenReturn(EVENT_SOURCE_NAME); + when(es1.resourceType()).thenReturn(EventSource.class); var es2 = mock(EventSource.class); when(es2.name()).thenReturn(EVENT_SOURCE_NAME); + when(es2.resourceType()).thenReturn(EventSource.class); eventSources.add(es1); assertThrows(IllegalArgumentException.class, () -> { @@ -44,6 +45,7 @@ void cannotAddTwoEventSourcesWithSame() { final var eventSources = new EventSources(); final var source = mock(EventSource.class); when(source.name()).thenReturn("name"); + when(source.resourceType()).thenReturn(EventSource.class); eventSources.add(source); assertThrows(IllegalArgumentException.class, () -> eventSources.add(source)); @@ -54,6 +56,7 @@ void eventSourcesStreamShouldNotReturnControllerEventSource() { final var eventSources = new EventSources(); final var source = mock(EventSource.class); when(source.name()).thenReturn(EVENT_SOURCE_NAME); + when(source.resourceType()).thenReturn(EventSource.class); eventSources.add(source); @@ -67,36 +70,38 @@ void additionalEventSourcesShouldNotContainNamedEventSources() { final var eventSources = new EventSources(); final var source = mock(EventSource.class); when(source.name()).thenReturn(EVENT_SOURCE_NAME); + when(source.resourceType()).thenReturn(EventSource.class); eventSources.add(source); + assertThat(eventSources.additionalEventSources()).containsExactly( eventSources.retryEventSource(), source); } @Test - void checkControllerResourceEventSource() { + void checkControllerEventSource() { final var eventSources = new EventSources(); final var configuration = MockControllerConfiguration.forResource(HasMetadata.class); when(configuration.getConfigurationService()).thenReturn(new BaseConfigurationService()); final var controller = new Controller(mock(Reconciler.class), configuration, MockKubernetesClient.client(HasMetadata.class)); eventSources.createControllerEventSource(controller); - final var controllerResourceEventSource = eventSources.controllerResourceEventSource(); - assertNotNull(controllerResourceEventSource); - assertEquals(HasMetadata.class, controllerResourceEventSource.resourceType()); + final var controllerEventSource = eventSources.controllerEventSource(); + assertNotNull(controllerEventSource); + assertEquals(HasMetadata.class, controllerEventSource.resourceType()); - assertEquals(controllerResourceEventSource, - eventSources.controllerResourceEventSource()); + assertEquals(controllerEventSource, + eventSources.controllerEventSource()); } @Test void flatMappedSourcesShouldReturnOnlyUserRegisteredEventSources() { final var eventSources = new EventSources(); final var mock1 = - eventSourceMockWithName(ResourceEventSource.class, "name1", HasMetadata.class); + eventSourceMockWithName(EventSource.class, "name1", HasMetadata.class); final var mock2 = - eventSourceMockWithName(ResourceEventSource.class, "name2", HasMetadata.class); - final var mock3 = eventSourceMockWithName(ResourceEventSource.class, "name3", ConfigMap.class); + eventSourceMockWithName(EventSource.class, "name2", HasMetadata.class); + final var mock3 = eventSourceMockWithName(EventSource.class, "name3", ConfigMap.class); eventSources.add(mock1); eventSources.add(mock2); @@ -109,10 +114,10 @@ void flatMappedSourcesShouldReturnOnlyUserRegisteredEventSources() { void clearShouldWork() { final var eventSources = new EventSources(); final var mock1 = - eventSourceMockWithName(ResourceEventSource.class, "name1", HasMetadata.class); + eventSourceMockWithName(EventSource.class, "name1", HasMetadata.class); final var mock2 = - eventSourceMockWithName(ResourceEventSource.class, "name2", HasMetadata.class); - final var mock3 = eventSourceMockWithName(ResourceEventSource.class, "name3", ConfigMap.class); + eventSourceMockWithName(EventSource.class, "name2", HasMetadata.class); + final var mock3 = eventSourceMockWithName(EventSource.class, "name3", ConfigMap.class); eventSources.add(mock1); eventSources.add(mock2); @@ -126,10 +131,10 @@ void clearShouldWork() { void getShouldWork() { final var eventSources = new EventSources(); final var mock1 = - eventSourceMockWithName(ResourceEventSource.class, "name1", HasMetadata.class); + eventSourceMockWithName(EventSource.class, "name1", HasMetadata.class); final var mock2 = - eventSourceMockWithName(ResourceEventSource.class, "name2", HasMetadata.class); - final var mock3 = eventSourceMockWithName(ResourceEventSource.class, "name2", ConfigMap.class); + eventSourceMockWithName(EventSource.class, "name2", HasMetadata.class); + final var mock3 = eventSourceMockWithName(EventSource.class, "name2", ConfigMap.class); eventSources.add(mock1); eventSources.add(mock2); @@ -152,10 +157,10 @@ void getShouldWork() { void getEventSourcesShouldWork() { final var eventSources = new EventSources(); final var mock1 = - eventSourceMockWithName(ResourceEventSource.class, "name1", HasMetadata.class); + eventSourceMockWithName(EventSource.class, "name1", HasMetadata.class); final var mock2 = - eventSourceMockWithName(ResourceEventSource.class, "name2", HasMetadata.class); - final var mock3 = eventSourceMockWithName(ResourceEventSource.class, "name3", ConfigMap.class); + eventSourceMockWithName(EventSource.class, "name2", HasMetadata.class); + final var mock3 = eventSourceMockWithName(EventSource.class, "name3", ConfigMap.class); eventSources.add(mock1); eventSources.add(mock2); @@ -174,7 +179,7 @@ void getEventSourcesShouldWork() { - EventSource eventSourceMockWithName(Class clazz, String name, + EventSource eventSourceMockWithName(Class clazz, String name, Class resourceType) { var mockedES = mock(clazz); when(mockedES.name()).thenReturn(name); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java similarity index 94% rename from operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSourceTest.java rename to operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java index 04e0bc0aff..ca6c030a88 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java @@ -29,8 +29,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -class ControllerResourceEventSourceTest extends - AbstractEventSourceTestBase, EventHandler> { +class ControllerEventSourceTest extends + AbstractEventSourceTestBase, EventHandler> { public static final String FINALIZER = ReconcilerUtils.getDefaultFinalizerName(TestCustomResource.class); @@ -39,7 +39,7 @@ class ControllerResourceEventSourceTest extends @BeforeEach public void setup() { - setUpSource(new ControllerResourceEventSource<>(testController), true, + setUpSource(new ControllerEventSource<>(testController), true, new BaseConfigurationService()); } @@ -87,7 +87,7 @@ void normalExecutionIfGenerationChanges() { @Test void handlesAllEventIfNotGenerationAware() { source = - new ControllerResourceEventSource<>(new TestController(false)); + new ControllerEventSource<>(new TestController(false)); setup(); TestCustomResource customResource1 = TestUtils.testCustomResource(); @@ -126,7 +126,7 @@ void filtersOutEventsOnAddAndUpdate() { OnAddFilter onAddFilter = (res) -> false; OnUpdateFilter onUpdatePredicate = (res, res2) -> false; source = - new ControllerResourceEventSource<>( + new ControllerEventSource<>( new TestController(onAddFilter, onUpdatePredicate, null)); setUpSource(source); @@ -141,7 +141,7 @@ void genericFilterFiltersOutAddUpdateAndDeleteEvents() { TestCustomResource cr = TestUtils.testCustomResource(); source = - new ControllerResourceEventSource<>(new TestController(null, null, res -> false)); + new ControllerEventSource<>(new TestController(null, null, res -> false)); setUpSource(source); source.eventReceived(ResourceAction.ADDED, cr, null); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java index 8b3c7afca8..427b2b54b5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -21,7 +21,7 @@ import io.javaoperatorsdk.jenvtest.junit.EnableKubeAPIServer; import io.javaoperatorsdk.operator.health.InformerHealthIndicator; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource; +import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestCustomResource; import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestReconciler; @@ -142,7 +142,7 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator) InformerHealthIndicator controllerHealthIndicator = (InformerHealthIndicator) unhealthyEventSources - .get(ControllerResourceEventSource.class.getSimpleName()) + .get(ControllerEventSource.NAME) .informerHealthIndicators().get(additionalNamespace); assertThat(controllerHealthIndicator).isNotNull(); assertThat(controllerHealthIndicator.getTargetNamespace()).isEqualTo(additionalNamespace); @@ -269,13 +269,13 @@ private void assertRuntimeInfoNoCRPermission(Operator operator) { operator.getRuntimeInfo().unhealthyEventSources() .get(INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER); assertThat(unhealthyEventSources).isNotEmpty(); - assertThat(unhealthyEventSources.get(ControllerResourceEventSource.class.getSimpleName())) + assertThat(unhealthyEventSources.get(ControllerEventSource.NAME)) .isNotNull(); var informerHealthIndicators = operator.getRuntimeInfo() .unhealthyInformerWrappingEventSourceHealthIndicator() .get(INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER); assertThat(informerHealthIndicators).isNotEmpty(); - assertThat(informerHealthIndicators.get(ControllerResourceEventSource.class.getSimpleName()) + assertThat(informerHealthIndicators.get(ControllerEventSource.NAME) .informerHealthIndicators()) .hasSize(1); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java index c1f5fc1634..94744e30de 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java @@ -37,7 +37,7 @@ public UpdateControl reconc context.getClient().resource(configMap(primary)).createOr(NonDeletingOperation::update); numberOfEventSources.set(context.eventSourceRetriever() - .getResourceEventSourcesFor(GenericKubernetesResource.class).size()); + .getEventSourcesFor(GenericKubernetesResource.class).size()); return UpdateControl.noUpdate(); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentConfigMap.java index 698cec88af..a3387477d5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentConfigMap.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentConfigMap.java @@ -49,7 +49,7 @@ public Optional getSecondaryResource(MultipleOwnerDependentCustomReso Context context) { InformerEventSource ies = (InformerEventSource) context - .eventSourceRetriever().getResourceEventSourceFor(ConfigMap.class); + .eventSourceRetriever().getEventSourceFor(ConfigMap.class); return ies.get(new ResourceID(RESOURCE_NAME, primary.getMetadata().getNamespace())); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java index 4cf1d8c93b..eaeb86cfe2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java @@ -48,7 +48,7 @@ public UpdateControl reconcile( } else { // reading the resource from cache as alternative, works without primary to secondary mapper var informerEventSource = (InformerEventSource) context.eventSourceRetriever() - .getResourceEventSourceFor(Cluster.class); + .getEventSourceFor(Cluster.class); informerEventSource .get(new ResourceID(resource.getSpec().getClusterName(), resource.getMetadata().getNamespace())) From d506116a0febac2726f27cba46992aad873b98fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 14 May 2024 14:49:28 +0200 Subject: [PATCH 42/96] feat: read-only bulk dependent (#2372) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../dependent/AbstractDependentResource.java | 12 ++- .../dependent/BulkDependentResource.java | 8 +- .../BulkDependentResourceReconciler.java | 54 ++++++++------ .../dependent/CRUDBulkDependentResource.java | 11 +++ .../operator/ReadOnlyBulkDependentIT.java | 73 +++++++++++++++++++ ...ConfigMapDeleterBulkDependentResource.java | 10 +-- .../ExternalBulkDependentResource.java | 4 + .../ReadOnlyBulkDependentResource.java | 53 ++++++++++++++ .../ReadOnlyBulkReadyPostCondition.java | 23 ++++++ .../readonly/ReadOnlyBulkReconciler.java | 33 +++++++++ ...ulkDependentResourceExternalWithState.java | 9 +-- 11 files changed, 247 insertions(+), 43 deletions(-) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/CRUDBulkDependentResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/ReadOnlyBulkDependentIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReconciler.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java index e9ef90f6dd..24ea12ed0b 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java @@ -60,7 +60,7 @@ public ReconcileResult reconcile(P primary, Context

context) { } protected ReconcileResult reconcile(P primary, R actualResource, Context

context) { - if (creatable || updatable) { + if (creatable() || updatable()) { if (actualResource == null) { if (creatable) { var desired = desired(primary, context); @@ -70,7 +70,7 @@ protected ReconcileResult reconcile(P primary, R actualResource, Context

c return ReconcileResult.resourceCreated(createdResource); } } else { - if (updatable) { + if (updatable()) { final Matcher.Result match = match(actualResource, primary, context); if (!match.matched()) { final var desired = match.computedDesired().orElseGet(() -> desired(primary, context)); @@ -223,4 +223,12 @@ public String name() { public void setName(String name) { this.name = name; } + + protected boolean creatable() { + return creatable; + } + + protected boolean updatable() { + return updatable; + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java index a86b6ee0e8..313d7115c9 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java @@ -13,8 +13,7 @@ * {@link Creator} and {@link Deleter} interfaces out of the box. A concrete dependent resource can * implement additionally also {@link Updater}. */ -public interface BulkDependentResource - extends Creator, Deleter

{ +public interface BulkDependentResource { /** * Retrieves a map of desired secondary resources associated with the specified primary resource, @@ -26,7 +25,10 @@ public interface BulkDependentResource * @return a Map associating desired secondary resources with the specified primary via arbitrary * identifiers */ - Map desiredResources(P primary, Context

context); + default Map desiredResources(P primary, Context

context) { + throw new IllegalStateException( + "Implement desiredResources in case a non read-only bulk dependent resource"); + } /** * Retrieves the actual secondary resources currently existing on the server and associated with diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResourceReconciler.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResourceReconciler.java index e740ef3773..1ed36edaa2 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResourceReconciler.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResourceReconciler.java @@ -24,18 +24,26 @@ class BulkDependentResourceReconciler @Override public ReconcileResult reconcile(P primary, Context

context) { - final var desiredResources = bulkDependentResource.desiredResources(primary, context); + Map actualResources = bulkDependentResource.getSecondaryResources(primary, context); + if (!(bulkDependentResource instanceof Creator) + && !(bulkDependentResource instanceof Deleter) + && !(bulkDependentResource instanceof Updater)) { + return ReconcileResult + .aggregatedResult(actualResources.values().stream().map(ReconcileResult::noOperation) + .toList()); + } - // remove existing resources that are not needed anymore according to the primary state - deleteExtraResources(desiredResources.keySet(), actualResources, primary, context); + final var desiredResources = bulkDependentResource.desiredResources(primary, context); + + if (bulkDependentResource instanceof Deleter) { + // remove existing resources that are not needed anymore according to the primary state + deleteExtraResources(desiredResources.keySet(), actualResources, primary, context); + } final List> results = new ArrayList<>(desiredResources.size()); - final var updatable = bulkDependentResource instanceof Updater; desiredResources.forEach((key, value) -> { - final var instance = - updatable ? new UpdatableBulkDependentResourceInstance<>(bulkDependentResource, value) - : new BulkDependentResourceInstance<>(bulkDependentResource, value); + final var instance = new BulkDependentResourceInstance<>(bulkDependentResource, value); results.add(instance.reconcile(primary, actualResources.get(key), context)); }); @@ -67,7 +75,7 @@ private void deleteExtraResources(Set expectedKeys, @Ignore private static class BulkDependentResourceInstance extends AbstractDependentResource - implements Creator, Deleter

{ + implements Creator, Deleter

, Updater { private final BulkDependentResource bulkDependentResource; private final R desired; @@ -112,26 +120,24 @@ public Class resourceType() { return asAbstractDependentResource().resourceType(); } - @Override + @SuppressWarnings("unchecked") public R create(R desired, P primary, Context

context) { - return bulkDependentResource.create(desired, primary, context); + return ((Creator) bulkDependentResource).create(desired, primary, context); } - } - /** - * Makes sure that the instance implements Updater if its precursor does as well. - * - * @param - * @param

- */ - @Ignore - private static class UpdatableBulkDependentResourceInstance - extends BulkDependentResourceInstance implements Updater { + @Override + protected boolean isCreatable() { + return bulkDependentResource instanceof Creator; + } - private UpdatableBulkDependentResourceInstance( - BulkDependentResource bulkDependentResource, - R desired) { - super(bulkDependentResource, desired); + @Override + protected boolean isUpdatable() { + return bulkDependentResource instanceof Updater; + } + + @Override + public boolean isDeletable() { + return bulkDependentResource instanceof Deleter; } } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/CRUDBulkDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/CRUDBulkDependentResource.java new file mode 100644 index 0000000000..aa650bf1b5 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/CRUDBulkDependentResource.java @@ -0,0 +1,11 @@ +package io.javaoperatorsdk.operator.processing.dependent; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; + +public interface CRUDBulkDependentResource + extends BulkDependentResource, + Creator, + BulkUpdater, + Deleter

{ +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReadOnlyBulkDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReadOnlyBulkDependentIT.java new file mode 100644 index 0000000000..265eb98e4e --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReadOnlyBulkDependentIT.java @@ -0,0 +1,73 @@ +package io.javaoperatorsdk.operator; + +import java.time.Duration; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestSpec; +import io.javaoperatorsdk.operator.sample.bulkdependent.readonly.ReadOnlyBulkDependentResource; +import io.javaoperatorsdk.operator.sample.bulkdependent.readonly.ReadOnlyBulkReconciler; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class ReadOnlyBulkDependentIT { + + public static final int EXPECTED_NUMBER_OF_RESOURCES = 2; + public static final String TEST = "test"; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(new ReadOnlyBulkReconciler()) + .build(); + + @Test + void readOnlyBulkDependent() { + var primary = extension.create(testCustomResource()); + + await().pollDelay(Duration.ofMillis(150)).untilAsserted(() -> { + var actualPrimary = extension.get(BulkDependentTestCustomResource.class, TEST); + + assertThat(actualPrimary.getStatus()).isNotNull(); + assertThat(actualPrimary.getStatus().getReady()).isFalse(); + }); + + var configMap1 = createConfigMap(1, primary); + extension.create(configMap1); + var configMap2 = createConfigMap(2, primary); + extension.create(configMap2); + + await().untilAsserted(() -> { + var actualPrimary = extension.get(BulkDependentTestCustomResource.class, TEST); + assertThat(actualPrimary.getStatus().getReady()).isTrue(); + }); + } + + private ConfigMap createConfigMap(int i, BulkDependentTestCustomResource primary) { + ConfigMap configMap = new ConfigMap(); + configMap.setMetadata(new ObjectMetaBuilder() + .withName(TEST + ReadOnlyBulkDependentResource.INDEX_DELIMITER + i) + .withNamespace(primary.getMetadata().getNamespace()) + .build()); + configMap.addOwnerReference(primary); + return configMap; + } + + BulkDependentTestCustomResource testCustomResource() { + BulkDependentTestCustomResource customResource = new BulkDependentTestCustomResource(); + customResource.setMetadata(new ObjectMetaBuilder() + .withName(TEST) + .build()); + customResource.setSpec(new BulkDependentTestSpec()); + customResource.getSpec().setNumberOfResources(EXPECTED_NUMBER_OF_RESOURCES); + + return customResource; + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java index cb52ebdd05..1ee4e3ef24 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java @@ -8,10 +8,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; -import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.Creator; -import io.javaoperatorsdk.operator.processing.dependent.Updater; +import io.javaoperatorsdk.operator.processing.dependent.*; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; /** @@ -20,10 +17,7 @@ public class ConfigMapDeleterBulkDependentResource extends KubernetesDependentResource - implements Creator, - Updater, - Deleter, - BulkDependentResource { + implements CRUDBulkDependentResource { public static final String LABEL_KEY = "bulk"; public static final String LABEL_VALUE = "true"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkDependentResource.java index dbad6dcfb8..7dee7ae962 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkDependentResource.java @@ -7,8 +7,10 @@ import java.util.stream.Collectors; import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; import io.javaoperatorsdk.operator.processing.dependent.BulkUpdater; +import io.javaoperatorsdk.operator.processing.dependent.Creator; import io.javaoperatorsdk.operator.processing.dependent.external.PollingDependentResource; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; @@ -16,6 +18,8 @@ public class ExternalBulkDependentResource extends PollingDependentResource implements BulkDependentResource, + Creator, + Deleter, BulkUpdater { public static final String EXTERNAL_RESOURCE_NAME_DELIMITER = "#"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java new file mode 100644 index 0000000000..b812b82ef1 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java @@ -0,0 +1,53 @@ +package io.javaoperatorsdk.operator.sample.bulkdependent.readonly; + +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.event.ResourceID; +import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; +import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; +import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; + + +public class ReadOnlyBulkDependentResource + extends + KubernetesDependentResource + implements BulkDependentResource, + SecondaryToPrimaryMapper { + + public static final String INDEX_DELIMITER = "-"; + + public ReadOnlyBulkDependentResource() { + super(ConfigMap.class); + } + + @Override + protected Class getPrimaryResourceType() { + return BulkDependentTestCustomResource.class; + } + + @Override + public Map getSecondaryResources(BulkDependentTestCustomResource primary, + Context context) { + return context.getSecondaryResourcesAsStream(ConfigMap.class) + .filter(cm -> getName(cm).startsWith(primary.getMetadata().getName())) + .collect(Collectors.toMap( + cm -> getName(cm).substring(getName(cm).lastIndexOf(INDEX_DELIMITER) + 1), + Function.identity())); + } + + private static String getName(ConfigMap cm) { + return cm.getMetadata().getName(); + } + + @Override + public Set toPrimaryResourceIDs(ConfigMap resource) { + return Mappers.fromOwnerReferences(false).toPrimaryResourceIDs(resource); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java new file mode 100644 index 0000000000..9d036d74bd --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java @@ -0,0 +1,23 @@ +package io.javaoperatorsdk.operator.sample.bulkdependent.readonly; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; +import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; + +public class ReadOnlyBulkReadyPostCondition + implements Condition { + @Override + public boolean isMet( + DependentResource dependentResource, + BulkDependentTestCustomResource primary, Context context) { + var minResourceNumber = primary.getSpec().getNumberOfResources(); + @SuppressWarnings("unchecked") + var secondaryResources = + ((BulkDependentResource) dependentResource) + .getSecondaryResources(primary, context); + return minResourceNumber <= secondaryResources.size(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReconciler.java new file mode 100644 index 0000000000..df3366c115 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReconciler.java @@ -0,0 +1,33 @@ +package io.javaoperatorsdk.operator.sample.bulkdependent.readonly; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestStatus; + +@Workflow(dependents = @Dependent(type = ReadOnlyBulkDependentResource.class, + readyPostcondition = ReadOnlyBulkReadyPostCondition.class)) +@ControllerConfiguration +public class ReadOnlyBulkReconciler implements Reconciler { + @Override + public UpdateControl reconcile( + BulkDependentTestCustomResource resource, Context context) { + + var nonReadyDependents = + context.managedWorkflowAndDependentResourceContext().getWorkflowReconcileResult() + .getNotReadyDependents(); + + + BulkDependentTestCustomResource customResource = new BulkDependentTestCustomResource(); + customResource.setMetadata(new ObjectMetaBuilder() + .withName(resource.getMetadata().getName()) + .withNamespace(resource.getMetadata().getNamespace()) + .build()); + var status = new BulkDependentTestStatus(); + status.setReady(nonReadyDependents.isEmpty()); + customResource.setStatus(status); + + return UpdateControl.patchStatus(customResource); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java index 29bc6af9aa..48e207616d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java @@ -11,10 +11,7 @@ import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.BulkUpdater; -import io.javaoperatorsdk.operator.processing.dependent.DependentResourceWithExplicitState; -import io.javaoperatorsdk.operator.processing.dependent.Matcher; +import io.javaoperatorsdk.operator.processing.dependent.*; import io.javaoperatorsdk.operator.processing.dependent.external.PerResourcePollingDependentResource; import io.javaoperatorsdk.operator.support.ExternalIDGenServiceMock; import io.javaoperatorsdk.operator.support.ExternalResource; @@ -25,8 +22,8 @@ public class BulkDependentResourceExternalWithState extends PerResourcePollingDependentResource implements BulkDependentResource, - DependentResourceWithExplicitState, - BulkUpdater { + CRUDBulkDependentResource, + DependentResourceWithExplicitState { public static final String DELIMITER = "-"; ExternalIDGenServiceMock externalService = ExternalIDGenServiceMock.getInstance(); From 0c8ed9e1706ecf1e005e0773f0e8ddcca9e1cdfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 14 May 2024 16:22:48 +0200 Subject: [PATCH 43/96] feat: remove automatic observed generation handling (#2382) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun Signed-off-by: Attila Mészáros --- README.md | 1 - .../src/main/resources/templates/Status.java | 4 +- .../BoundedCacheTestStatus.java | 4 +- docs/documentation/v5-0-migration.md | 11 ++-- .../operator/api/ObservedGenerationAware.java | 29 ---------- .../api/ObservedGenerationAwareStatus.java | 19 ------- .../api/config/ConfigurationService.java | 2 +- .../event/ReconciliationDispatcher.java | 45 ++-------------- .../event/ReconciliationDispatcherTest.java | 45 ---------------- .../observedgeneration/ObservedGenStatus.java | 4 +- .../operator/ManualObservedGenerationIT.java | 54 +++++++++++++++++++ .../ObservedGenerationHandlingIT.java | 37 ------------- ...teUpdateEventFilterTestCustomResource.java | 7 +-- ...teEventFilterTestCustomResourceStatus.java | 4 +- .../GracefulStopTestCustomResourceStatus.java | 11 +++- .../GracefulStopTestReconciler.java | 1 + ...nualObservedGenerationCustomResource.java} | 11 ++-- .../ManualObservedGenerationReconciler.java | 48 +++++++++++++++++ .../ManualObservedGenerationSpec.java | 14 +++++ .../ManualObservedGenerationStatus.java | 14 +++++ ...vedGenerationTestCustomResourceStatus.java | 7 --- .../ObservedGenerationTestReconciler.java | 28 ---------- .../RateLimitCustomResourceStatus.java | 4 +- .../operator/sample/SchemaStatus.java | 4 +- .../sample/customresource/WebPageStatus.java | 4 +- 25 files changed, 163 insertions(+), 249 deletions(-) delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAwareStatus.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/ManualObservedGenerationIT.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/ObservedGenerationHandlingIT.java rename operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/{observedgeneration/ObservedGenerationTestCustomResource.java => manualobservedgeneration/ManualObservedGenerationCustomResource.java} (53%) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationSpec.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestCustomResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestReconciler.java diff --git a/README.md b/README.md index b932fe1e96..435ead4967 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,6 @@ It makes it easy to implement best practices and patterns for an Operator. Featu * Handling dependent resources, related events, and caching. * Automatic Retries * Smart event scheduling -* Handling Observed Generations automatically * Easy to use Error Handling * ... and everything that a batteries included framework needs diff --git a/bootstrapper-maven-plugin/src/main/resources/templates/Status.java b/bootstrapper-maven-plugin/src/main/resources/templates/Status.java index 4c37b99947..52bd0fd4d2 100644 --- a/bootstrapper-maven-plugin/src/main/resources/templates/Status.java +++ b/bootstrapper-maven-plugin/src/main/resources/templates/Status.java @@ -1,7 +1,5 @@ package {{groupId}}; -import io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus; - -public class {{artifactClassId}}Status extends ObservedGenerationAwareStatus { +public class {{artifactClassId}}Status { } diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/namespacescope/BoundedCacheTestStatus.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/namespacescope/BoundedCacheTestStatus.java index 03a311529e..2bdd434d23 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/namespacescope/BoundedCacheTestStatus.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/namespacescope/BoundedCacheTestStatus.java @@ -1,6 +1,4 @@ package io.javaoperatorsdk.operator.processing.event.source.cache.sample.namespacescope; -import io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus; - -public class BoundedCacheTestStatus extends ObservedGenerationAwareStatus { +public class BoundedCacheTestStatus { } diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index b051e2018f..f338d97381 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -44,11 +44,6 @@ permalink: /docs/v5-0-migration where it is demonstrated. Also, the related part of a [workaround](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L110-L116). - Related automatic observed generation handling changes: - Automated Observed Generation (see features in docs), is automatically handled for non-SSA, even if - the status sub-resource is not instructed to be updated. This is not true for SSA, observed generation is updated - only when patch status is instructed by `UpdateControl`. - 6. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. 7. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should @@ -57,3 +52,9 @@ permalink: /docs/v5-0-migration 8. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed, use `Operator.stop(Duration)` instead. 9. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead +10. Automated observed generation handling feature was removed (`ObservedGenerationAware` interface + and `ObservedGenerationAwareStatus` class were deleted). Manually handling observed generation is fairly easy to do + in your reconciler, however, it cannot be done automatically when using SSA. We therefore removed the feature since + it would have been confusing to have a different behavior for SSA and non-SSA cases. For an example of how to do + observed generation handling manually in your reconciler, see + [this sample](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java). \ No newline at end of file diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java deleted file mode 100644 index eafe51e6f4..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.javaoperatorsdk.operator.api; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.CustomResource; -import io.javaoperatorsdk.operator.api.config.ConfigurationService; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; - -/** - * If the custom resource's status implements this interface, the observed generation will be - * automatically handled. The last observed generation will be updated on status. - *

- * In order for this automatic handling to work the status object returned by - * {@link CustomResource#getStatus()} should not be null. - *

- * The observed generation is updated with SSA mode only if - * {@link UpdateControl#patchStatus(HasMetadata)} or - * {@link UpdateControl#patchResourceAndStatus(HasMetadata)} is called. In non-SSA mode (see - * {@link ConfigurationService#useSSAToPatchPrimaryResource()}) observed generation is update even - * if patch is not called. - * - * @see ObservedGenerationAwareStatus - */ -public interface ObservedGenerationAware { - - void setObservedGeneration(Long generation); - - Long getObservedGeneration(); - -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAwareStatus.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAwareStatus.java deleted file mode 100644 index d2048c9513..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAwareStatus.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.javaoperatorsdk.operator.api; - -/** - * A helper base class for status sub-resources classes to extend to support generate awareness. - */ -public class ObservedGenerationAwareStatus implements ObservedGenerationAware { - - private Long observedGeneration; - - @Override - public void setObservedGeneration(Long generation) { - this.observedGeneration = generation; - } - - @Override - public Long getObservedGeneration() { - return observedGeneration; - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index b402f60d7d..ff335f40fa 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -455,7 +455,7 @@ default boolean parseResourceVersionsForEventFilteringAndCaching() { /** * {@link io.javaoperatorsdk.operator.api.reconciler.UpdateControl} patch resource or status can * either use simple patches or SSA. Setting this to {@code true}, controllers will use SSA for - * adding finalizers, managing observed generation, patching resources and status. + * adding finalizers, patching resources and status. * * @return {@code true} if Server-Side Apply (SSA) should be used when patching the primary * resources, {@code false} otherwise diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java index 7b5e25f4bb..2b33133ae4 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java @@ -10,14 +10,12 @@ import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.PatchContext; import io.fabric8.kubernetes.client.dsl.base.PatchType; import io.javaoperatorsdk.operator.OperatorException; -import io.javaoperatorsdk.operator.api.ObservedGenerationAware; import io.javaoperatorsdk.operator.api.config.Cloner; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.BaseControl; @@ -166,13 +164,8 @@ private PostExecutionControl

reconcileExecution(ExecutionScope

executionSc } } - // check if status also needs to be updated - final var updateObservedGeneration = updateControl.isNoUpdate() - ? shouldUpdateObservedGenerationAutomatically(resourceForExecution) - : shouldUpdateObservedGenerationAutomatically(updatedCustomResource); - // if using SSA the observed generation is updated only if user instructs patching the status - if (updateControl.isPatchStatus() || (updateObservedGeneration && !useSSA)) { - updatedCustomResource = patchStatusGenerationAware(toUpdate, originalResource); + if (updateControl.isPatchStatus()) { + customResourceFacade.patchStatus(toUpdate, originalResource); } return createPostExecutionControl(updatedCustomResource, updateControl); } @@ -202,9 +195,8 @@ public boolean isLastAttempt() { P updatedResource = null; if (errorStatusUpdateControl.getResource().isPresent()) { - updatedResource = - patchStatusGenerationAware(errorStatusUpdateControl.getResource().orElseThrow(), - originalResource); + updatedResource = customResourceFacade + .patchStatus(errorStatusUpdateControl.getResource().orElseThrow(), originalResource); } if (errorStatusUpdateControl.isNoRetry()) { PostExecutionControl

postExecutionControl; @@ -230,38 +222,9 @@ private boolean isErrorStatusHandlerPresent() { } private P patchStatusGenerationAware(P resource, P originalResource) { - updateStatusObservedGenerationIfRequired(resource); return customResourceFacade.patchStatus(resource, originalResource); } - @SuppressWarnings("rawtypes") - private boolean shouldUpdateObservedGenerationAutomatically(P resource) { - if (configuration().isGenerationAware() && resource instanceof CustomResource) { - var customResource = (CustomResource) resource; - var status = customResource.getStatus(); - // Note that if status is null we won't update the observed generation. - if (status instanceof ObservedGenerationAware) { - var observedGen = ((ObservedGenerationAware) status).getObservedGeneration(); - var currentGen = resource.getMetadata().getGeneration(); - return !currentGen.equals(observedGen); - } - } - return false; - } - - @SuppressWarnings("rawtypes") - private void updateStatusObservedGenerationIfRequired(P resource) { - if (configuration().isGenerationAware() && resource instanceof CustomResource) { - var customResource = (CustomResource) resource; - var status = customResource.getStatus(); - // Note that if status is null we won't update the observed generation. - if (status instanceof ObservedGenerationAware) { - ((ObservedGenerationAware) status) - .setObservedGeneration(resource.getMetadata().getGeneration()); - } - } - } - private PostExecutionControl

createPostExecutionControl(P updatedCustomResource, UpdateControl

updateControl) { PostExecutionControl

postExecutionControl; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java index bf4e5a8f27..7e80f4aedc 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java @@ -435,29 +435,6 @@ void reScheduleOnDeleteWithoutFinalizerRemoval() { .isEqualTo(1000L); } - @Test - void setObservedGenerationForStatusIfNeeded() throws Exception { - var observedGenResource = createObservedGenCustomResource(); - - Reconciler reconciler = mock(Reconciler.class); - ControllerConfiguration config = - MockControllerConfiguration.forResource(ObservedGenCustomResource.class); - CustomResourceFacade facade = mock(CustomResourceFacade.class); - var dispatcher = init(observedGenResource, reconciler, config, facade, true); - - when(config.isGenerationAware()).thenReturn(true); - - when(reconciler.reconcile(any(), any())) - .thenReturn(UpdateControl.patchStatus(observedGenResource)); - when(facade.patchStatus(eq(observedGenResource), any())).thenReturn(observedGenResource); - - PostExecutionControl control = dispatcher.handleExecution( - executionScopeWithCREvent(observedGenResource)); - assertThat(control.getUpdatedCustomResource().orElseGet(() -> fail("Missing optional")) - .getStatus().getObservedGeneration()) - .isEqualTo(1L); - } - @Test void doesNotUpdatesObservedGenerationIfStatusIsNotPatchedWhenUsingSSA() throws Exception { var observedGenResource = createObservedGenCustomResource(); @@ -476,28 +453,6 @@ void doesNotUpdatesObservedGenerationIfStatusIsNotPatchedWhenUsingSSA() throws E assertThat(control.getUpdatedCustomResource()).isEmpty(); } - @Test - void patchObservedGenerationOnCustomResourcePatchIfNoSSA() throws Exception { - var observedGenResource = createObservedGenCustomResource(); - - Reconciler reconciler = mock(Reconciler.class); - final var config = MockControllerConfiguration.forResource(ObservedGenCustomResource.class); - CustomResourceFacade facade = mock(CustomResourceFacade.class); - when(config.isGenerationAware()).thenReturn(true); - when(reconciler.reconcile(any(), any())) - .thenReturn(UpdateControl.patchResource(observedGenResource)); - when(facade.patchResource(any(), any())).thenReturn(observedGenResource); - when(facade.patchStatus(eq(observedGenResource), any())).thenReturn(observedGenResource); - initConfigService(false); - var dispatcher = init(observedGenResource, reconciler, config, facade, true); - - PostExecutionControl control = dispatcher.handleExecution( - executionScopeWithCREvent(observedGenResource)); - assertThat(control.getUpdatedCustomResource().orElseGet(() -> fail("Missing optional")) - .getStatus().getObservedGeneration()) - .isEqualTo(1L); - } - @Test void doesNotPatchObservedGenerationOnCustomResourcePatch() throws Exception { var observedGenResource = createObservedGenCustomResource(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenStatus.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenStatus.java index d4ffee5416..81ce9a435d 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenStatus.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenStatus.java @@ -1,7 +1,5 @@ package io.javaoperatorsdk.operator.sample.observedgeneration; -import io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus; - -public class ObservedGenStatus extends ObservedGenerationAwareStatus { +public class ObservedGenStatus { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManualObservedGenerationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManualObservedGenerationIT.java new file mode 100644 index 0000000000..ddfb2370d6 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManualObservedGenerationIT.java @@ -0,0 +1,54 @@ +package io.javaoperatorsdk.operator; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.manualobservedgeneration.ManualObservedGenerationCustomResource; +import io.javaoperatorsdk.operator.sample.manualobservedgeneration.ManualObservedGenerationReconciler; +import io.javaoperatorsdk.operator.sample.manualobservedgeneration.ManualObservedGenerationSpec; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class ManualObservedGenerationIT { + + public static final String RESOURCE_NAME = "test1"; + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder().withReconciler(new ManualObservedGenerationReconciler()) + .build(); + + @Test + void observedGenerationUpdated() { + extension.create(testResource()); + + await().untilAsserted(() -> { + var r = extension.get(ManualObservedGenerationCustomResource.class, RESOURCE_NAME); + assertThat(r).isNotNull(); + assertThat(r.getStatus().getObservedGeneration()).isEqualTo(1); + assertThat(r.getStatus().getObservedGeneration()).isEqualTo(r.getMetadata().getGeneration()); + }); + + var changed = testResource(); + changed.getSpec().setValue("changed value"); + extension.replace(changed); + + await().untilAsserted(() -> { + var r = extension.get(ManualObservedGenerationCustomResource.class, RESOURCE_NAME); + assertThat(r.getStatus().getObservedGeneration()).isEqualTo(2); + assertThat(r.getStatus().getObservedGeneration()).isEqualTo(r.getMetadata().getGeneration()); + }); + } + + ManualObservedGenerationCustomResource testResource() { + var res = new ManualObservedGenerationCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(RESOURCE_NAME) + .build()); + res.setSpec(new ManualObservedGenerationSpec()); + res.getSpec().setValue("Initial Value"); + return res; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ObservedGenerationHandlingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ObservedGenerationHandlingIT.java deleted file mode 100644 index 0e28ddec4c..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ObservedGenerationHandlingIT.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.javaoperatorsdk.operator; - -import java.util.concurrent.TimeUnit; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.observedgeneration.ObservedGenerationTestCustomResource; -import io.javaoperatorsdk.operator.sample.observedgeneration.ObservedGenerationTestReconciler; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; - -class ObservedGenerationHandlingIT { - @RegisterExtension - LocallyRunOperatorExtension operator = - LocallyRunOperatorExtension.builder().withReconciler(new ObservedGenerationTestReconciler()) - .build(); - - @Test - void testReconciliationOfNonCustomResourceAndStatusUpdate() { - var resource = new ObservedGenerationTestCustomResource(); - resource.setMetadata(new ObjectMeta()); - resource.getMetadata().setName("observed-gen1"); - - var createdResource = operator.create(resource); - - await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> { - var d = operator.get(ObservedGenerationTestCustomResource.class, - createdResource.getMetadata().getName()); - assertThat(d.getStatus().getObservedGeneration()).isNotNull(); - assertThat(d.getStatus().getObservedGeneration()).isEqualTo(1); - }); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java index 5797a44d9d..8a0ee77474 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java @@ -11,12 +11,7 @@ @ShortNames("cue") public class CreateUpdateEventFilterTestCustomResource extends - CustomResource + CustomResource implements Namespaced { - @Override - protected CreateUpdateEventFilterTestCustomResourceStatus initStatus() { - return new CreateUpdateEventFilterTestCustomResourceStatus(); - } - } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceStatus.java index 6733e1a7cd..e8f8da78f4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceStatus.java @@ -1,7 +1,5 @@ package io.javaoperatorsdk.operator.sample.createupdateeventfilter; -import io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus; - -public class CreateUpdateEventFilterTestCustomResourceStatus extends ObservedGenerationAwareStatus { +public class CreateUpdateEventFilterTestCustomResourceStatus { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceStatus.java index f59f5b1163..fa80e79c19 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceStatus.java @@ -1,7 +1,14 @@ package io.javaoperatorsdk.operator.sample.gracefulstop; -import io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus; +public class GracefulStopTestCustomResourceStatus { -public class GracefulStopTestCustomResourceStatus extends ObservedGenerationAwareStatus { + private long observedGeneration; + public long getObservedGeneration() { + return observedGeneration; + } + + public void setObservedGeneration(long observedGeneration) { + this.observedGeneration = observedGeneration; + } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestReconciler.java index cf266c0b48..7ff0d9d246 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestReconciler.java @@ -22,6 +22,7 @@ public UpdateControl reconcile( numberOfExecutions.addAndGet(1); resource.setStatus(new GracefulStopTestCustomResourceStatus()); + resource.getStatus().setObservedGeneration(resource.getMetadata().getGeneration()); Thread.sleep(RECONCILER_SLEEP); return UpdateControl.patchStatus(resource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationCustomResource.java similarity index 53% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationCustomResource.java index 8a0ede3a5d..10b54fe79d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationCustomResource.java @@ -1,18 +1,15 @@ -package io.javaoperatorsdk.operator.sample.observedgeneration; +package io.javaoperatorsdk.operator.sample.manualobservedgeneration; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; -import io.fabric8.kubernetes.model.annotation.Kind; import io.fabric8.kubernetes.model.annotation.ShortNames; import io.fabric8.kubernetes.model.annotation.Version; @Group("sample.javaoperatorsdk") @Version("v1") -@Kind("ObservedGenerationTestCustomResource") -@ShortNames("og") -public class ObservedGenerationTestCustomResource - extends CustomResource +@ShortNames("mog") +public class ManualObservedGenerationCustomResource + extends CustomResource implements Namespaced { - } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java new file mode 100644 index 0000000000..6e3aa15dce --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java @@ -0,0 +1,48 @@ +package io.javaoperatorsdk.operator.sample.manualobservedgeneration; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.*; + +@ControllerConfiguration +public class ManualObservedGenerationReconciler + implements Reconciler { + + private final AtomicInteger numberOfExecutions = new AtomicInteger(0); + + @Override + public UpdateControl reconcile( + ManualObservedGenerationCustomResource resource, + Context context) { + numberOfExecutions.addAndGet(1); + var resourceForStatusPatch = resourceForStatusPatch(resource); + if (!Objects.equals(resource.getMetadata().getGeneration(), + resourceForStatusPatch.getStatus().getObservedGeneration())) { + resourceForStatusPatch.getStatus() + .setObservedGeneration(resource.getMetadata().getGeneration()); + return UpdateControl.patchStatus(resourceForStatusPatch); + } else { + return UpdateControl.noUpdate(); + } + } + + private ManualObservedGenerationCustomResource resourceForStatusPatch( + ManualObservedGenerationCustomResource original) { + var res = new ManualObservedGenerationCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(original.getMetadata().getName()) + .withNamespace(original.getMetadata().getNamespace()) + .build()); + res.setStatus(original.getStatus()); + if (res.getStatus() == null) { + res.setStatus(new ManualObservedGenerationStatus()); + } + return res; + } + + public int getNumberOfExecutions() { + return numberOfExecutions.get(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationSpec.java new file mode 100644 index 0000000000..35b04685aa --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationSpec.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.sample.manualobservedgeneration; + +public class ManualObservedGenerationSpec { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationStatus.java new file mode 100644 index 0000000000..cdb6d56b2e --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationStatus.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.sample.manualobservedgeneration; + +public class ManualObservedGenerationStatus { + + private long observedGeneration; + + public long getObservedGeneration() { + return observedGeneration; + } + + public void setObservedGeneration(long observedGeneration) { + this.observedGeneration = observedGeneration; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestCustomResourceStatus.java deleted file mode 100644 index 14071775f3..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestCustomResourceStatus.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.javaoperatorsdk.operator.sample.observedgeneration; - -import io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus; - -public class ObservedGenerationTestCustomResourceStatus extends ObservedGenerationAwareStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestReconciler.java deleted file mode 100644 index 7e2127ec7c..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/observedgeneration/ObservedGenerationTestReconciler.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.javaoperatorsdk.operator.sample.observedgeneration; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; - -@ControllerConfiguration -public class ObservedGenerationTestReconciler - implements Reconciler { - - private static final Logger log = LoggerFactory.getLogger(ObservedGenerationTestReconciler.class); - - @Override - public UpdateControl reconcile( - ObservedGenerationTestCustomResource resource, - Context context) { - log.info("Reconcile ObservedGenerationTestCustomResource: {}", - resource.getMetadata().getName()); - if (resource.getStatus() == null) { - resource.setStatus(new ObservedGenerationTestCustomResourceStatus()); - } - return UpdateControl.patchStatus(resource); - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceStatus.java index 087408fc16..975728c18c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceStatus.java @@ -1,7 +1,5 @@ package io.javaoperatorsdk.operator.sample.ratelimit; -import io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus; - -public class RateLimitCustomResourceStatus extends ObservedGenerationAwareStatus { +public class RateLimitCustomResourceStatus { } diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/SchemaStatus.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/SchemaStatus.java index 92ddb67a63..168cd8db15 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/SchemaStatus.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/SchemaStatus.java @@ -1,8 +1,6 @@ package io.javaoperatorsdk.operator.sample; -import io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus; - -public class SchemaStatus extends ObservedGenerationAwareStatus { +public class SchemaStatus { private String url; diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/customresource/WebPageStatus.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/customresource/WebPageStatus.java index 7ab20c76be..36409ac7f9 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/customresource/WebPageStatus.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/customresource/WebPageStatus.java @@ -1,8 +1,6 @@ package io.javaoperatorsdk.operator.sample.customresource; -import io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus; - -public class WebPageStatus extends ObservedGenerationAwareStatus { +public class WebPageStatus { private String htmlConfigMap; From 78a90fed5752c0e6ef72664b7b6b658829be50a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 15 May 2024 14:37:14 +0200 Subject: [PATCH 44/96] docs: bulk dependent resource migration (#2383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- docs/documentation/v5-0-migration.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md index f338d97381..a1c1b66120 100644 --- a/docs/documentation/v5-0-migration.md +++ b/docs/documentation/v5-0-migration.md @@ -57,4 +57,9 @@ permalink: /docs/v5-0-migration in your reconciler, however, it cannot be done automatically when using SSA. We therefore removed the feature since it would have been confusing to have a different behavior for SSA and non-SSA cases. For an example of how to do observed generation handling manually in your reconciler, see - [this sample](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java). \ No newline at end of file + [this sample](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java). +11. `BulkDependentResource` now supports [read-only mode](https://github.com/operator-framework/java-operator-sdk/issues/2233). + This also means, that `BulkDependentResource` now does not automatically implement `Creator` and `Deleter` as before. + Make sure to implement those interfaces in your bulk dependent resources. You can use also the new helper interface, the + [`CRUDBulkDependentResource`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/CRUDBulkDependentResource.java) + what also implement `BulkUpdater` interface. \ No newline at end of file From c7922d073f892e7d0421649ccebd3b4cadfd8167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 15 May 2024 23:37:17 +0200 Subject: [PATCH 45/96] fix: correct default secondary to primary mapper (#2386) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/api/config/informer/InformerConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java index bca39b189c..f5ebf284de 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java @@ -52,7 +52,7 @@ protected DefaultInformerConfiguration(String labelSelector, this.primaryToSecondaryMapper = primaryToSecondaryMapper; this.secondaryToPrimaryMapper = Objects.requireNonNullElse(secondaryToPrimaryMapper, - Mappers.fromOwnerReference()); + Mappers.fromOwnerReferences(false)); this.onDeleteFilter = onDeleteFilter; } From 5a81fefb861eec6208d4aea6617f13ac64f0a537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 16 May 2024 09:39:55 +0200 Subject: [PATCH 46/96] improve: secondaryToPrimary check type of owner reference (#2371) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../cache/sample/AbstractTestReconciler.java | 3 +- .../informer/InformerConfiguration.java | 52 +++++++++-------- .../api/reconciler/EventSourceContext.java | 9 ++- .../operator/processing/Controller.java | 3 +- .../GenericKubernetesDependentResource.java | 2 +- .../KubernetesDependentResource.java | 4 +- .../operator/processing/event/ResourceID.java | 14 ----- .../event/source/informer/Mappers.java | 37 ++++++++---- .../event/source/informer/MappersTest.java | 56 +++++++++++++++++++ .../simple/TestCustomResourceOtherV1.java | 2 +- .../ReadOnlyBulkDependentResource.java | 3 +- ...ClusterScopedCustomResourceReconciler.java | 3 +- ...CreateUpdateEventFilterTestReconciler.java | 2 +- ...formerEventSourceTestCustomReconciler.java | 2 +- ...ultipleSecondaryEventSourceReconciler.java | 2 +- .../PrimaryIndexerTestReconciler.java | 2 +- 16 files changed, 134 insertions(+), 62 deletions(-) create mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/MappersTest.java diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java index c3743ef409..18cd486fb2 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java @@ -80,7 +80,8 @@ public List prepareEventSources( var es = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) .withItemStore(boundedItemStore) .withSecondaryToPrimaryMapper( - Mappers.fromOwnerReference(this instanceof BoundedCacheClusterScopeTestReconciler)) + Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), + this instanceof BoundedCacheClusterScopeTestReconciler)) .build(), context); return List.of(es); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java index f5ebf284de..5371975ec5 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java @@ -50,9 +50,7 @@ protected DefaultInformerConfiguration(String labelSelector, this.followControllerNamespaceChanges = followControllerNamespaceChanges; this.groupVersionKind = groupVersionKind; this.primaryToSecondaryMapper = primaryToSecondaryMapper; - this.secondaryToPrimaryMapper = - Objects.requireNonNullElse(secondaryToPrimaryMapper, - Mappers.fromOwnerReferences(false)); + this.secondaryToPrimaryMapper = secondaryToPrimaryMapper; this.onDeleteFilter = onDeleteFilter; } @@ -135,16 +133,24 @@ class InformerConfigurationBuilder { private boolean inheritControllerNamespacesOnChange = false; private ItemStore itemStore; private Long informerListLimit; + private final Class primaryResourceClass; - private InformerConfigurationBuilder(Class resourceClass) { - this.resourceClass = resourceClass; - this.groupVersionKind = null; + private InformerConfigurationBuilder(Class resourceClass, + Class primaryResourceClass) { + this(resourceClass, primaryResourceClass, null); } @SuppressWarnings("unchecked") - private InformerConfigurationBuilder(GroupVersionKind groupVersionKind) { - this.resourceClass = (Class) GenericKubernetesResource.class; + private InformerConfigurationBuilder(GroupVersionKind groupVersionKind, + Class primaryResourceClass) { + this((Class) GenericKubernetesResource.class, primaryResourceClass, groupVersionKind); + } + + private InformerConfigurationBuilder(Class resourceClass, + Class primaryResourceClass, GroupVersionKind groupVersionKind) { + this.resourceClass = resourceClass; this.groupVersionKind = groupVersionKind; + this.primaryResourceClass = primaryResourceClass; } public

InformerConfigurationBuilder withPrimaryToSecondaryMapper( @@ -264,23 +270,17 @@ public InformerConfigurationBuilder withInformerListLimit(Long informerListLi public InformerConfiguration build() { return new DefaultInformerConfiguration<>(labelSelector, resourceClass, groupVersionKind, primaryToSecondaryMapper, - secondaryToPrimaryMapper, + Objects.requireNonNullElse(secondaryToPrimaryMapper, + Mappers.fromOwnerReferences(HasMetadata.getApiVersion(primaryResourceClass), + HasMetadata.getKind(primaryResourceClass), false)), namespaces, inheritControllerNamespacesOnChange, onAddFilter, onUpdateFilter, onDeleteFilter, genericFilter, itemStore, informerListLimit); } } static InformerConfigurationBuilder from( - Class resourceClass) { - return new InformerConfigurationBuilder<>(resourceClass); - } - - /** - * * For the case when want to use {@link GenericKubernetesResource} - */ - static InformerConfigurationBuilder from( - GroupVersionKind groupVersionKind) { - return new InformerConfigurationBuilder<>(groupVersionKind); + Class resourceClass, Class primaryResourceClass) { + return new InformerConfigurationBuilder<>(resourceClass, primaryResourceClass); } /** @@ -294,20 +294,26 @@ static InformerConfigurationBuilder from( */ static InformerConfigurationBuilder from( Class resourceClass, EventSourceContext eventSourceContext) { - return new InformerConfigurationBuilder<>(resourceClass) + return new InformerConfigurationBuilder<>(resourceClass, + eventSourceContext.getPrimaryResourceClass()) .withNamespacesInheritedFromController(eventSourceContext); } /** - * * For the case when want to use {@link GenericKubernetesResource} + * For the case when want to use {@link GenericKubernetesResource} */ - @SuppressWarnings("unchecked") static InformerConfigurationBuilder from( GroupVersionKind groupVersionKind, EventSourceContext eventSourceContext) { - return new InformerConfigurationBuilder(groupVersionKind) + return new InformerConfigurationBuilder(groupVersionKind, + eventSourceContext.getPrimaryResourceClass()) .withNamespacesInheritedFromController(eventSourceContext); } + static InformerConfigurationBuilder from( + GroupVersionKind groupVersionKind, Class primaryResourceClass) { + return new InformerConfigurationBuilder<>(groupVersionKind, primaryResourceClass); + } + @SuppressWarnings("unchecked") @Override default Class getResourceClass() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceContext.java index e8062e9651..4f0f08b3b8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceContext.java @@ -16,13 +16,16 @@ public class EventSourceContext

{ private final IndexerResourceCache

primaryCache; private final ControllerConfiguration

controllerConfiguration; private final KubernetesClient client; + private final Class

primaryResourceClass; public EventSourceContext(IndexerResourceCache

primaryCache, ControllerConfiguration

controllerConfiguration, - KubernetesClient client) { + KubernetesClient client, + Class

primaryResourceClass) { this.primaryCache = primaryCache; this.controllerConfiguration = controllerConfiguration; this.client = client; + this.primaryResourceClass = primaryResourceClass; } /** @@ -54,4 +57,8 @@ public ControllerConfiguration

getControllerConfiguration() { public KubernetesClient getClient() { return client; } + + public Class

getPrimaryResourceClass() { + return primaryResourceClass; + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index f24cf61afc..40fb23def8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -102,7 +102,8 @@ public Controller(Reconciler

reconciler, eventSourceManager.postProcessDefaultEventSourcesAfterProcessorInitializer(); controllerHealthInfo = new ControllerHealthInfo(eventSourceManager); eventSourceContext = new EventSourceContext<>( - eventSourceManager.getControllerEventSource(), configuration, kubernetesClient); + eventSourceManager.getControllerEventSource(), configuration, kubernetesClient, + configuration.getResourceClass()); initAndRegisterEventSources(eventSourceContext); configurationService.getMetrics().controllerRegistered(this); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java index 591b357f31..0714aaa83c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java @@ -21,7 +21,7 @@ public GenericKubernetesDependentResource(GroupVersionKindPlural groupVersionKin } protected InformerConfiguration.InformerConfigurationBuilder informerConfigurationBuilder() { - return InformerConfiguration.from(groupVersionKind); + return InformerConfiguration.from(groupVersionKind, getPrimaryResourceType()); } @SuppressWarnings("unchecked") diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index de5770bb1f..cc2c2f82a8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -89,7 +89,7 @@ private void configureWith(String labelSelector, Set namespaces, // just to seamlessly handle GenericKubernetesDependentResource protected InformerConfiguration.InformerConfigurationBuilder informerConfigurationBuilder() { - return InformerConfiguration.from(resourceType()); + return InformerConfiguration.from(resourceType(), getPrimaryResourceType()); } @SuppressWarnings("unchecked") @@ -97,7 +97,7 @@ private SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { if (this instanceof SecondaryToPrimaryMapper) { return (SecondaryToPrimaryMapper) this; } else if (garbageCollected) { - return Mappers.fromOwnerReferences(clustered); + return Mappers.fromOwnerReferences(getPrimaryResourceType(), clustered); } else if (useNonOwnerRefBasedSecondaryToPrimaryMapping()) { return Mappers.fromDefaultAnnotations(); } else { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ResourceID.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ResourceID.java index 39374cb433..071dd49f29 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ResourceID.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ResourceID.java @@ -14,20 +14,6 @@ public static ResourceID fromResource(HasMetadata resource) { resource.getMetadata().getNamespace()); } - public static Optional fromFirstOwnerReference(HasMetadata resource) { - return fromFirstOwnerReference(resource, false); - } - - public static Optional fromFirstOwnerReference(HasMetadata resource, - boolean clusterScoped) { - var ownerReferences = resource.getMetadata().getOwnerReferences(); - if (!ownerReferences.isEmpty()) { - return Optional.of(fromOwnerReference(resource, ownerReferences.get(0), clusterScoped)); - } else { - return Optional.empty(); - } - } - public static ResourceID fromOwnerReference(HasMetadata resource, OwnerReference ownerReference, boolean clusterScoped) { return new ResourceID(ownerReference.getName(), diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java index 65f9c86cb8..24c4d18837 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java @@ -42,24 +42,37 @@ public static SecondaryToPrimaryMapper fromLabel( return fromMetadata(nameKey, namespaceKey, true); } - public static SecondaryToPrimaryMapper fromOwnerReference() { - return fromOwnerReference(false); + public static SecondaryToPrimaryMapper fromOwnerReferences( + Class primaryResourceType) { + return fromOwnerReferences(primaryResourceType, false); } - /** - * @param clusterScope if the owner is a cluster scoped resource - * @return mapper - * @param type of the secondary resource, where the owner reference is - */ - public static SecondaryToPrimaryMapper fromOwnerReference( - boolean clusterScope) { - return resource -> ResourceID.fromFirstOwnerReference(resource, clusterScope).map(Set::of) - .orElseGet(Collections::emptySet); + public static SecondaryToPrimaryMapper fromOwnerReferences( + Class primaryResourceType, boolean clusterScoped) { + return fromOwnerReferences(HasMetadata.getApiVersion(primaryResourceType), + HasMetadata.getKind(primaryResourceType), + clusterScoped); + } + + public static SecondaryToPrimaryMapper fromOwnerReferences( + HasMetadata primaryResource) { + return fromOwnerReferences(primaryResource, false); + } + + public static SecondaryToPrimaryMapper fromOwnerReferences( + HasMetadata primaryResource, + boolean clusterScoped) { + return fromOwnerReferences(primaryResource.getApiVersion(), primaryResource.getKind(), + clusterScoped); } public static SecondaryToPrimaryMapper fromOwnerReferences( + String apiVersion, String kind, boolean clusterScope) { - return resource -> resource.getMetadata().getOwnerReferences().stream() + return resource -> resource.getMetadata().getOwnerReferences() + .stream() + .filter(r -> r.getKind().equals(kind) + && r.getApiVersion().equals(apiVersion)) .map(or -> ResourceID.fromOwnerReference(resource, or, clusterScope)) .collect(Collectors.toSet()); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/MappersTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/MappersTest.java new file mode 100644 index 0000000000..12e7b54706 --- /dev/null +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/MappersTest.java @@ -0,0 +1,56 @@ +package io.javaoperatorsdk.operator.processing.event.source.informer; + +import java.util.UUID; + +import org.junit.jupiter.api.Test; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.TestUtils; +import io.javaoperatorsdk.operator.processing.event.ResourceID; +import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; +import io.javaoperatorsdk.operator.sample.simple.TestCustomResourceOtherV1; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class MappersTest { + + + @Test + void secondaryToPrimaryMapperFromOwnerReference() { + var primary = TestUtils.testCustomResource(); + primary.getMetadata().setUid(UUID.randomUUID().toString()); + var secondary = getConfigMap(primary); + secondary.addOwnerReference(primary); + + var res = Mappers.fromOwnerReferences(TestCustomResource.class) + .toPrimaryResourceIDs(secondary); + + assertThat(res).contains(ResourceID.fromResource(primary)); + } + + @Test + void secondaryToPrimaryMapperFromOwnerReferenceFiltersByType() { + var primary = TestUtils.testCustomResource(); + primary.getMetadata().setUid(UUID.randomUUID().toString()); + var secondary = getConfigMap(primary); + secondary.addOwnerReference(primary); + + var res = Mappers.fromOwnerReferences(TestCustomResourceOtherV1.class) + .toPrimaryResourceIDs(secondary); + + assertThat(res).isEmpty(); + } + + + private static ConfigMap getConfigMap(TestCustomResource primary) { + return new ConfigMapBuilder() + .withMetadata(new ObjectMetaBuilder() + .withName("test1") + .withNamespace(primary.getMetadata().getNamespace()) + .build()) + .build(); + } +} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceOtherV1.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceOtherV1.java index f768ba491f..90e226abc8 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceOtherV1.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceOtherV1.java @@ -7,7 +7,7 @@ @Group("sample.javaoperatorsdk.io") @Version("v1") -@Kind("TestCustomResource") // this is needed to override the automatically generated kind +@Kind("TestCustomResourceOtherV1") // this is needed to override the automatically generated kind public class TestCustomResourceOtherV1 extends CustomResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java index b812b82ef1..0f4fb80b8a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java @@ -48,6 +48,7 @@ private static String getName(ConfigMap cm) { @Override public Set toPrimaryResourceIDs(ConfigMap resource) { - return Mappers.fromOwnerReferences(false).toPrimaryResourceIDs(resource); + return Mappers.fromOwnerReferences(BulkDependentTestCustomResource.class, false) + .toPrimaryResourceIDs(resource); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java index de5153d540..ec872bd6b2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java @@ -56,7 +56,8 @@ private ConfigMap desired(ClusterScopedCustomResource resource) { public List prepareEventSources( EventSourceContext context) { var ies = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) - .withSecondaryToPrimaryMapper(Mappers.fromOwnerReference(true)) + .withSecondaryToPrimaryMapper( + Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), true)) .withLabelSelector(TEST_LABEL_KEY + "=" + TEST_LABEL_VALUE) .build(), context); return List.of(ies); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index dc152d29f6..8567f49916 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -93,7 +93,7 @@ private ConfigMap createConfigMap(CreateUpdateEventFilterTestCustomResource reso public List prepareEventSources( EventSourceContext context) { InformerConfiguration informerConfiguration = - InformerConfiguration.from(ConfigMap.class) + InformerConfiguration.from(ConfigMap.class, context) .withLabelSelector("integrationtest = " + this.getClass().getSimpleName()) .build(); final var informerEventSource = diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java index c7cac63cad..232426403d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java @@ -36,7 +36,7 @@ public List prepareEventSources( EventSourceContext context) { InformerConfiguration config = - InformerConfiguration.from(ConfigMap.class) + InformerConfiguration.from(ConfigMap.class, context) .withSecondaryToPrimaryMapper(Mappers.fromAnnotation(RELATED_RESOURCE_NAME)) .build(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java index 62c9ef3b7b..88f97a8235 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java @@ -64,7 +64,7 @@ public int getNumberOfExecutions() { public List prepareEventSources( EventSourceContext context) { - var config = InformerConfiguration.from(ConfigMap.class) + var config = InformerConfiguration.from(ConfigMap.class, context) .withNamespaces(context.getControllerConfiguration().getNamespaces()) .withLabelSelector("multisecondary") .withSecondaryToPrimaryMapper(s -> { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java index 78af3dbd66..547c224e55 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java @@ -22,7 +22,7 @@ public List prepareEventSources( context.getPrimaryCache().addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer); var informerConfiguration = - InformerConfiguration.from(ConfigMap.class) + InformerConfiguration.from(ConfigMap.class, context) .withSecondaryToPrimaryMapper( (ConfigMap secondaryResource) -> context .getPrimaryCache() From 2162ee7d648d37530104fb2db37646b8ca2ecc66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 16 May 2024 10:01:46 +0200 Subject: [PATCH 47/96] improve: remove deprecated APIs (#2375) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../micrometer/MicrometerMetrics.java | 14 ----- .../io/javaoperatorsdk/operator/Operator.java | 16 +---- .../api/config/ConfigurationService.java | 32 ---------- .../config/ConfigurationServiceOverrider.java | 56 +----------------- .../api/config/ExecutorServiceManager.java | 1 - .../operator/api/monitoring/Metrics.java | 58 +------------------ .../managed/KubernetesClientAware.java | 15 ----- .../KubernetesDependentResourceConfig.java | 15 ----- .../workflow/DefaultManagedWorkflow.java | 5 -- .../dependent/workflow/WorkflowResult.java | 9 --- .../source/informer/InformerEventSource.java | 12 ---- .../ConfigurationServiceOverriderTest.java | 21 ------- .../junit/AbstractOperatorExtension.java | 15 ----- .../operator/junit/KubernetesClientAware.java | 13 ----- .../junit/LocallyRunOperatorExtension.java | 13 +++-- .../operator/InformerRelatedBehaviorITS.java | 3 +- .../operator/LeaderElectionPermissionIT.java | 3 +- .../PerResourcePollingEventSourceIT.java | 4 +- .../sample/LeaderElectionTestOperator.java | 4 +- .../operator/sample/WebPageOperator.java | 7 +-- .../operator/sample/WebPageReconciler.java | 17 +++--- .../operator/sample/WebPageOperatorE2E.java | 2 +- 22 files changed, 31 insertions(+), 304 deletions(-) delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/KubernetesClientAware.java delete mode 100644 operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/KubernetesClientAware.java diff --git a/micrometer-support/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetrics.java b/micrometer-support/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetrics.java index b819bd0ca3..07106d9b3c 100644 --- a/micrometer-support/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetrics.java +++ b/micrometer-support/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetrics.java @@ -59,20 +59,6 @@ public class MicrometerMetrics implements Metrics { private final Map gauges = new ConcurrentHashMap<>(); private final Cleaner cleaner; - /** - * Creates a default micrometer-based Metrics implementation, collecting metrics on a per resource - * basis and not dealing with cleaning these after these resources are deleted. Note that this - * probably will change in a future release. If you want more control over what the implementation - * actually does, please use the static factory methods instead. - * - * @param registry the {@link MeterRegistry} instance to use for metrics recording - * @deprecated Use the factory methods / builders instead - */ - @Deprecated - public MicrometerMetrics(MeterRegistry registry) { - this(registry, Cleaner.NOOP, true); - } - /** * Creates a MicrometerMetrics instance configured to not collect per-resource metrics, just * aggregates per resource **type** diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java index d3f2f57c6d..d85de6b1e5 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java @@ -35,7 +35,7 @@ public Operator() { } Operator(KubernetesClient kubernetesClient) { - this(kubernetesClient, null); + this(initConfigurationService(kubernetesClient, null)); } /** @@ -63,19 +63,7 @@ public Operator(ConfigurationService configurationService) { * {@link ConfigurationService} values */ public Operator(Consumer overrider) { - this(null, overrider); - } - - /** - * @param client client to use to all Kubernetes related operations - * @param overrider a {@link ConfigurationServiceOverrider} consumer used to override the default - * {@link ConfigurationService} values - * @deprecated Use {@link Operator#Operator(Consumer)} instead, passing your custom client with - * {@link ConfigurationServiceOverrider#withKubernetesClient(KubernetesClient)} - */ - @Deprecated(since = "4.4.0") - public Operator(KubernetesClient client, Consumer overrider) { - this(initConfigurationService(client, overrider)); + this(initConfigurationService(null, overrider)); } private static ConfigurationService initConfigurationService(KubernetesClient client, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index ff335f40fa..3cee8d3cec 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -132,11 +132,6 @@ default boolean checkCRDAndValidateLocalModel() { } int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50; - /** - * @deprecated Not used anymore in the default implementation - */ - @Deprecated(forRemoval = true) - int MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER = 10; /** * The number of threads the operator can spin out to dispatch reconciliation requests to @@ -148,23 +143,7 @@ default int concurrentReconciliationThreads() { return DEFAULT_RECONCILIATION_THREADS_NUMBER; } - /** - * The minimum number of threads the operator starts in the thread pool for reconciliations. - * - * @deprecated not used anymore by default executor implementation - * @return the minimum number of concurrent reconciliation threads - */ - @Deprecated(forRemoval = true) - default int minConcurrentReconciliationThreads() { - return MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER; - } - int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER; - /** - * @deprecated Not used anymore in the default implementation - */ - @Deprecated(forRemoval = true) - int MIN_DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER; /** * Number of threads the operator can spin out to be used in the workflows with the default @@ -176,17 +155,6 @@ default int concurrentWorkflowExecutorThreads() { return DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER; } - /** - * The minimum number of threads the operator starts in the thread pool for workflows. - * - * @deprecated not used anymore by default executor implementation - * @return the minimum number of concurrent workflow threads - */ - @Deprecated(forRemoval = true) - default int minConcurrentWorkflowExecutorThreads() { - return MIN_DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER; - } - default Metrics getMetrics() { return Metrics.NOOP; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java index eef17100fe..edfb7734d8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java @@ -4,7 +4,6 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutorService; -import java.util.function.Consumer; import java.util.function.Function; import org.slf4j.Logger; @@ -24,9 +23,7 @@ public class ConfigurationServiceOverrider { private Metrics metrics; private Boolean checkCR; private Integer concurrentReconciliationThreads; - private Integer minConcurrentReconciliationThreads; private Integer concurrentWorkflowExecutorThreads; - private Integer minConcurrentWorkflowExecutorThreads; private Cloner cloner; private Boolean closeClientOnStop; private KubernetesClient client; @@ -65,24 +62,6 @@ public ConfigurationServiceOverrider withConcurrentWorkflowExecutorThreads(int t return this; } - private int minimumMaxValueFor(Integer minValue) { - return minValue != null ? (minValue < 0 ? 0 : minValue) + 1 : 1; - } - - public ConfigurationServiceOverrider withMinConcurrentReconciliationThreads(int threadNumber) { - this.minConcurrentReconciliationThreads = Utils.ensureValid(threadNumber, - "minimum reconciliation threads", ExecutorServiceManager.MIN_THREAD_NUMBER, - original.minConcurrentReconciliationThreads()); - return this; - } - - public ConfigurationServiceOverrider withMinConcurrentWorkflowExecutorThreads(int threadNumber) { - this.minConcurrentWorkflowExecutorThreads = Utils.ensureValid(threadNumber, - "minimum workflow execution threads", ExecutorServiceManager.MIN_THREAD_NUMBER, - original.minConcurrentWorkflowExecutorThreads()); - return this; - } - @SuppressWarnings("rawtypes") public ConfigurationServiceOverrider withDependentResourceFactory( DependentResourceFactory dependentResourceFactory) { @@ -243,7 +222,7 @@ public int concurrentReconciliationThreads() { overriddenValueOrDefault(concurrentReconciliationThreads, ConfigurationService::concurrentReconciliationThreads), "maximum reconciliation threads", - minimumMaxValueFor(minConcurrentReconciliationThreads), + 1, original.concurrentReconciliationThreads()); } @@ -253,30 +232,10 @@ public int concurrentWorkflowExecutorThreads() { overriddenValueOrDefault(concurrentWorkflowExecutorThreads, ConfigurationService::concurrentWorkflowExecutorThreads), "maximum workflow execution threads", - minimumMaxValueFor(minConcurrentWorkflowExecutorThreads), + 1, original.concurrentWorkflowExecutorThreads()); } - /** - * @deprecated Not used anymore in the default implementation - */ - @Deprecated(forRemoval = true) - @Override - public int minConcurrentReconciliationThreads() { - return overriddenValueOrDefault(minConcurrentReconciliationThreads, - ConfigurationService::minConcurrentReconciliationThreads); - } - - /** - * @deprecated Not used anymore in the default implementation - */ - @Override - @Deprecated(forRemoval = true) - public int minConcurrentWorkflowExecutorThreads() { - return overriddenValueOrDefault(minConcurrentWorkflowExecutorThreads, - ConfigurationService::minConcurrentWorkflowExecutorThreads); - } - @Override public Metrics getMetrics() { return overriddenValueOrDefault(metrics, ConfigurationService::getMetrics); @@ -365,15 +324,4 @@ public boolean cloneSecondaryResourcesWhenGettingFromCache() { }; } - /** - * @deprecated Use - * {@link ConfigurationService#newOverriddenConfigurationService(ConfigurationService, Consumer)} - * instead - * @param original that will be overridden - * @return current overrider - */ - @Deprecated(since = "2.2.0") - public static ConfigurationServiceOverrider override(ConfigurationService original) { - return new ConfigurationServiceOverrider(original); - } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java index 112ab7188a..c35281e822 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java @@ -22,7 +22,6 @@ public class ExecutorServiceManager { private static final Logger log = LoggerFactory.getLogger(ExecutorServiceManager.class); - public static final int MIN_THREAD_NUMBER = 0; private ExecutorService executor; private ExecutorService workflowExecutor; private ExecutorService cachingExecutorService; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/monitoring/Metrics.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/monitoring/Metrics.java index 42fee488d7..bb34e5f760 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/monitoring/Metrics.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/monitoring/Metrics.java @@ -1,6 +1,5 @@ package io.javaoperatorsdk.operator.api.monitoring; -import java.util.Collections; import java.util.Map; import io.fabric8.kubernetes.api.model.HasMetadata; @@ -37,16 +36,6 @@ default void controllerRegistered(Controller controller) */ default void receivedEvent(Event event, Map metadata) {} - /** - * @param metadata additional metadata - * @param resourceID of primary resource - * @param retryInfo for current execution - * @deprecated Use {@link #reconcileCustomResource(HasMetadata, RetryInfo, Map)} instead - */ - @Deprecated(forRemoval = true) - @SuppressWarnings("unused") - default void reconcileCustomResource(ResourceID resourceID, RetryInfo retryInfo, - Map metadata) {} /** * Called right before a resource is dispatched to the ExecutorService for reconciliation. @@ -56,19 +45,6 @@ default void reconcileCustomResource(ResourceID resourceID, RetryInfo retryInfo, * @param metadata metadata associated with the resource being processed */ default void reconcileCustomResource(HasMetadata resource, RetryInfo retryInfo, - Map metadata) { - reconcileCustomResource(ResourceID.fromResource(resource), retryInfo, metadata); - } - - /** - * @param exception actual exception - * @param metadata additional metadata - * @param resourceID of primary resource - * @deprecated Use {@link #failedReconciliation(HasMetadata, Exception, Map)} instead - */ - @Deprecated(forRemoval = true) - @SuppressWarnings("unused") - default void failedReconciliation(ResourceID resourceID, Exception exception, Map metadata) {} /** @@ -81,9 +57,7 @@ default void failedReconciliation(ResourceID resourceID, Exception exception, * @param metadata metadata associated with the resource being processed */ default void failedReconciliation(HasMetadata resource, Exception exception, - Map metadata) { - failedReconciliation(ResourceID.fromResource(resource), exception, metadata); - } + Map metadata) {} default void reconciliationExecutionStarted(HasMetadata resource, Map metadata) {} @@ -91,14 +65,6 @@ default void reconciliationExecutionStarted(HasMetadata resource, Map metadata) {} - /** - * @param resourceID of primary resource - * @deprecated Use (and implement) {@link #cleanupDoneFor(ResourceID, Map)} instead - */ - @Deprecated - default void cleanupDoneFor(ResourceID resourceID) { - cleanupDoneFor(resourceID, Collections.emptyMap()); - } /** * Called when the resource associated with the specified {@link ResourceID} has been successfully @@ -109,24 +75,6 @@ default void cleanupDoneFor(ResourceID resourceID) { */ default void cleanupDoneFor(ResourceID resourceID, Map metadata) {} - /** - * @param resourceID of primary resource - * @deprecated Use (and implement) {@link #finishedReconciliation(ResourceID, Map)} instead - */ - @Deprecated - default void finishedReconciliation(ResourceID resourceID) { - finishedReconciliation(resourceID, Collections.emptyMap()); - } - - /** - * @param resourceID of primary resource - * @param metadata additional metadata - * @deprecated Use {@link #finishedReconciliation(HasMetadata, Map)} instead - */ - @Deprecated(forRemoval = true) - @SuppressWarnings("unused") - default void finishedReconciliation(ResourceID resourceID, Map metadata) {} - /** * Called when the * {@link io.javaoperatorsdk.operator.api.reconciler.Reconciler#reconcile(HasMetadata, Context)} @@ -136,9 +84,7 @@ default void finishedReconciliation(ResourceID resourceID, Map m * @param resource the {@link ResourceID} associated with the resource being processed * @param metadata metadata associated with the resource being processed */ - default void finishedReconciliation(HasMetadata resource, Map metadata) { - finishedReconciliation(ResourceID.fromResource(resource), metadata); - } + default void finishedReconciliation(HasMetadata resource, Map metadata) {} /** * Encapsulates the information about a controller execution i.e. a call to either diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/KubernetesClientAware.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/KubernetesClientAware.java deleted file mode 100644 index d6c743f22b..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/KubernetesClientAware.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.javaoperatorsdk.operator.api.reconciler.dependent.managed; - -import io.fabric8.kubernetes.client.KubernetesClient; -import io.javaoperatorsdk.operator.api.reconciler.Context; - -/** - * @deprecated It shouldn't be needed to pass a {@link KubernetesClient} instance anymore as the - * client should be accessed via {@link Context#getClient()} instead. - */ -@Deprecated(since = "4.5.0", forRemoval = true) -public interface KubernetesClientAware { - void setKubernetesClient(KubernetesClient kubernetesClient); - - KubernetesClient getKubernetesClient(); -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java index b1cb743232..e302ad437a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java @@ -52,21 +52,6 @@ public KubernetesDependentResourceConfig(Set namespaces, this.useSSA = useSSA; } - // use builder instead - @Deprecated(forRemoval = true) - public KubernetesDependentResourceConfig(Set namespaces, String labelSelector) { - this(namespaces, labelSelector, true, DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA, - null, null, - null, null, null); - } - - // use builder instead - @Deprecated(forRemoval = true) - public KubernetesDependentResourceConfig setLabelSelector(String labelSelector) { - this.labelSelector = labelSelector; - return this; - } - public Set namespaces() { return namespaces; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java index 03ed24d6df..43bb807e30 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java @@ -13,7 +13,6 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceReferencer; import io.javaoperatorsdk.operator.api.reconciler.dependent.NameSetter; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.KubernetesClientAware; import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET; @@ -112,10 +111,6 @@ private DependentResource resolve(DependentResourceSpec spec, ((NameSetter) dependentResource).setName(name); } - if (dependentResource instanceof KubernetesClientAware) { - ((KubernetesClientAware) dependentResource).setKubernetesClient(client); - } - spec.getUseEventSourceWithName() .ifPresent(esName -> { if (dependentResource instanceof EventSourceReferencer) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java index d442c75c09..7014ccd5d4 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java @@ -21,15 +21,6 @@ public Map getErroredDependents() { return erroredDependents; } - /** - * @deprecated Use {@link #erroredDependentsExist()} instead - * @return if any dependents are in error state - */ - @Deprecated(forRemoval = true) - public boolean erroredDependentsExists() { - return !erroredDependents.isEmpty(); - } - @SuppressWarnings("unused") public boolean erroredDependentsExist() { return !erroredDependents.isEmpty(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java index 8759410b81..571e02dbc2 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java @@ -255,18 +255,6 @@ public Set getSecondaryResources(P primary) { .collect(Collectors.toSet()); } - /** - * Returns the configuration object for the informer. - * - * @return the informer configuration object - * - * @deprecated Use {@link #configuration()} instead - */ - @Deprecated(forRemoval = true) - public InformerConfiguration getConfiguration() { - return configuration(); - } - @Override public synchronized void handleRecentResourceUpdate(ResourceID resourceID, R resource, R previousVersionOfResource) { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java index 2d8444af68..4c374e09f2 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java @@ -8,7 +8,6 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.monitoring.Metrics; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; class ConfigurationServiceOverriderTest { @@ -80,24 +79,4 @@ public R clone(R object) { overridden.getLeaderElectionConfiguration()); } - @Test - void shouldReplaceInvalidValues() { - final var original = new BaseConfigurationService(); - - final var service = ConfigurationService.newOverriddenConfigurationService(original, - o -> o - .withConcurrentReconciliationThreads(0) - .withMinConcurrentReconciliationThreads(-1) - .withConcurrentWorkflowExecutorThreads(2) - .withMinConcurrentWorkflowExecutorThreads(3)); - - assertEquals(original.minConcurrentReconciliationThreads(), - service.minConcurrentReconciliationThreads()); - assertEquals(original.concurrentReconciliationThreads(), - service.concurrentReconciliationThreads()); - assertEquals(3, service.minConcurrentWorkflowExecutorThreads()); - assertEquals(original.concurrentWorkflowExecutorThreads(), - service.concurrentWorkflowExecutorThreads()); - } - } diff --git a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/AbstractOperatorExtension.java b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/AbstractOperatorExtension.java index eb05fcb5d8..d46987caa6 100644 --- a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/AbstractOperatorExtension.java +++ b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/AbstractOperatorExtension.java @@ -111,30 +111,15 @@ public T create(T resource) { return kubernetesClient.resource(resource).inNamespace(namespace).create(); } - @Deprecated(forRemoval = true) - public T create(Class type, T resource) { - return create(resource); - } - public T replace(T resource) { return kubernetesClient.resource(resource).inNamespace(namespace).replace(); } - @Deprecated(forRemoval = true) - public T replace(Class type, T resource) { - return replace(resource); - } - public boolean delete(T resource) { var res = kubernetesClient.resource(resource).inNamespace(namespace).delete(); return res.size() == 1 && res.get(0).getCauses().isEmpty(); } - @Deprecated(forRemoval = true) - public boolean delete(Class type, T resource) { - return delete(resource); - } - protected void beforeAllImpl(ExtensionContext context) { if (oneNamespacePerClass) { namespace = perClassNamespaceNameSupplier.apply(context); diff --git a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/KubernetesClientAware.java b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/KubernetesClientAware.java deleted file mode 100644 index 8e94e71b53..0000000000 --- a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/KubernetesClientAware.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.javaoperatorsdk.operator.junit; - -import io.fabric8.kubernetes.client.KubernetesClient; -import io.javaoperatorsdk.operator.api.reconciler.Context; - -/** - * @deprecated It shouldn't be needed to pass a {@link KubernetesClient} instance to the reconciler - * anymore as the client should be accessed via {@link Context#getClient()} instead. - */ -@Deprecated(since = "4.5.0", forRemoval = true) -public interface KubernetesClientAware extends HasKubernetesClient { - void setKubernetesClient(KubernetesClient kubernetesClient); -} diff --git a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java index 442e398d83..6b8ef3f622 100644 --- a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java +++ b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java @@ -74,11 +74,14 @@ private LocallyRunOperatorExtension( this.portForwards = portForwards; this.localPortForwards = new ArrayList<>(portForwards.size()); this.additionalCustomResourceDefinitions = additionalCustomResourceDefinitions; - configurationServiceOverrider = configurationServiceOverrider != null - ? configurationServiceOverrider - .andThen(overrider -> overrider.withKubernetesClient(kubernetesClient)) - : overrider -> overrider.withKubernetesClient(kubernetesClient); - this.operator = new Operator(configurationServiceOverrider); + configurationServiceOverrider = configurationServiceOverrider != null + ? configurationServiceOverrider + .andThen(overrider -> overrider.withKubernetesClient(kubernetesClient)) + : overrider -> overrider.withKubernetesClient(kubernetesClient); + this.operator = new Operator( + configurationServiceOverrider == null ? o -> o.withKubernetesClient(getKubernetesClient()) + : configurationServiceOverrider + .andThen(o -> o.withKubernetesClient(getKubernetesClient()))); this.registeredControllers = new HashMap<>(); this.crdMappings = crdMappings; } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java index 427b2b54b5..3a6f4d05e9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -316,8 +316,9 @@ Operator startOperator(boolean stopOnInformerErrorDuringStartup, boolean addStop reconciler = new InformerRelatedBehaviorTestReconciler(); - Operator operator = new Operator(clientUsingServiceAccount(), + Operator operator = new Operator( co -> { + co.withKubernetesClient(clientUsingServiceAccount()); co.withStopOnInformerErrorDuringStartup(stopOnInformerErrorDuringStartup); co.withCacheSyncTimeout(Duration.ofMillis(3000)); if (addStopHandler) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionPermissionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionPermissionIT.java index e1c8435b8a..c1b30277c7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionPermissionIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionPermissionIT.java @@ -32,7 +32,8 @@ void operatorStopsIfNoLeaderElectionPermission() { .withImpersonateUsername("leader-elector-stop-noaccess") .build()).build(); - var operator = new Operator(client, o -> { + var operator = new Operator(o -> { + o.withKubernetesClient(client); o.withLeaderElectionConfiguration( new LeaderElectionConfiguration("lease1", "default")); o.withStopOnInformerErrorDuringStartup(false); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PerResourcePollingEventSourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PerResourcePollingEventSourceIT.java index a4b850b9d4..3a827572e5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PerResourcePollingEventSourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PerResourcePollingEventSourceIT.java @@ -28,8 +28,8 @@ class PerResourcePollingEventSourceIT { **/ @Test void fetchedAndReconciledMultipleTimes() { - operator.create(PerResourceEventSourceCustomResource.class, resource(NAME_1)); - operator.create(PerResourceEventSourceCustomResource.class, resource(NAME_2)); + operator.create(resource(NAME_1)); + operator.create(resource(NAME_2)); var reconciler = operator.getReconcilerOfType(PerResourcePollingEventSourceTestReconciler.class); diff --git a/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestOperator.java b/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestOperator.java index 262c0a7c70..359272e0ef 100644 --- a/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestOperator.java +++ b/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestOperator.java @@ -3,7 +3,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration; @@ -22,9 +21,8 @@ public static void main(String[] args) { ? new LeaderElectionConfiguration("leader-election-test") : new LeaderElectionConfiguration("leader-election-test", namespace, identity); - var client = new KubernetesClientBuilder().build(); Operator operator = - new Operator(client, c -> c.withLeaderElectionConfiguration(leaderElectionConfiguration)); + new Operator(c -> c.withLeaderElectionConfiguration(leaderElectionConfiguration)); operator.register(new LeaderElectionTestReconciler(identity)); operator.start(); diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java index e3ab63dc54..ff80cc5901 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java @@ -6,8 +6,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.fabric8.kubernetes.client.KubernetesClient; -import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.sample.probes.LivenessHandler; import io.javaoperatorsdk.operator.sample.probes.StartupHandler; @@ -28,11 +26,10 @@ public class WebPageOperator { public static void main(String[] args) throws IOException { log.info("WebServer Operator starting!"); - KubernetesClient client = new KubernetesClientBuilder().build(); - Operator operator = new Operator(client, o -> o.withStopOnInformerErrorDuringStartup(false)); + Operator operator = new Operator(o -> o.withStopOnInformerErrorDuringStartup(false)); String reconcilerEnvVar = System.getenv(WEBPAGE_RECONCILER_ENV); if (WEBPAGE_CLASSIC_RECONCILER_ENV_VALUE.equals(reconcilerEnvVar)) { - operator.register(new WebPageReconciler(client)); + operator.register(new WebPageReconciler()); } else if (WEBPAGE_MANAGED_DEPENDENT_RESOURCE_ENV_VALUE .equals(reconcilerEnvVar)) { operator.register(new WebPageManagedDependentsReconciler()); diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index dfe6a10a71..6669d3a1f5 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -12,7 +12,6 @@ import io.fabric8.kubernetes.api.model.*; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; -import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; @@ -35,10 +34,8 @@ public class WebPageReconciler private static final Logger log = LoggerFactory.getLogger(WebPageReconciler.class); - private final KubernetesClient kubernetesClient; + public WebPageReconciler() { - public WebPageReconciler(KubernetesClient kubernetesClient) { - this.kubernetesClient = kubernetesClient; } @Override @@ -89,7 +86,7 @@ public UpdateControl reconcile(WebPage webPage, Context contex "Creating or updating ConfigMap {} in {}", desiredHtmlConfigMap.getMetadata().getName(), ns); - kubernetesClient.configMaps().inNamespace(ns).resource(desiredHtmlConfigMap) + context.getClient().configMaps().inNamespace(ns).resource(desiredHtmlConfigMap) .serverSideApply(); } @@ -99,7 +96,7 @@ public UpdateControl reconcile(WebPage webPage, Context contex "Creating or updating Deployment {} in {}", desiredDeployment.getMetadata().getName(), ns); - kubernetesClient.apps().deployments().inNamespace(ns).resource(desiredDeployment) + context.getClient().apps().deployments().inNamespace(ns).resource(desiredDeployment) .serverSideApply(); } @@ -109,7 +106,7 @@ public UpdateControl reconcile(WebPage webPage, Context contex "Creating or updating Deployment {} in {}", desiredDeployment.getMetadata().getName(), ns); - kubernetesClient.services().inNamespace(ns).resource(desiredService) + context.getClient().services().inNamespace(ns).resource(desiredService) .serverSideApply(); } @@ -117,11 +114,11 @@ public UpdateControl reconcile(WebPage webPage, Context contex if (Boolean.TRUE.equals(webPage.getSpec().getExposed())) { var desiredIngress = makeDesiredIngress(webPage); if (existingIngress.isEmpty() || !match(desiredIngress, existingIngress.get())) { - kubernetesClient.resource(desiredIngress).inNamespace(ns).serverSideApply(); + context.getClient().resource(desiredIngress).inNamespace(ns).serverSideApply(); } } else existingIngress.ifPresent( - ingress -> kubernetesClient.resource(ingress).delete()); + ingress -> context.getClient().resource(ingress).delete()); // not that this is not necessary, eventually mounted config map would be updated, just this way // is much faster; what is handy for demo purposes. @@ -130,7 +127,7 @@ public UpdateControl reconcile(WebPage webPage, Context contex previousConfigMap.getData().get(INDEX_HTML), desiredHtmlConfigMap.getData().get(INDEX_HTML))) { log.info("Restarting pods because HTML has changed in {}", ns); - kubernetesClient.pods().inNamespace(ns).withLabel("app", deploymentName(webPage)).delete(); + context.getClient().pods().inNamespace(ns).withLabel("app", deploymentName(webPage)).delete(); } return UpdateControl.patchStatus( diff --git a/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorE2E.java b/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorE2E.java index 03c3d2c2e0..45fc4cd5ba 100644 --- a/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorE2E.java +++ b/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorE2E.java @@ -27,7 +27,7 @@ public WebPageOperatorE2E() throws FileNotFoundException {} isLocal() ? LocallyRunOperatorExtension.builder() .waitForNamespaceDeletion(false) - .withReconciler(new WebPageReconciler(client)) + .withReconciler(new WebPageReconciler()) .build() : ClusterDeployedOperatorExtension.builder() .waitForNamespaceDeletion(false) From 97d8c48a585d3966a234139d8a3e603a7c5ab93d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 16 May 2024 22:50:14 +0200 Subject: [PATCH 48/96] improve: ensure unique name on event sources (#2370) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * improve: ensure unique name on event sources Signed-off-by: Attila Mészáros * fix Signed-off-by: Attila Mészáros --------- Signed-off-by: Attila Mészáros --- .../processing/event/EventSourceManager.java | 2 +- .../processing/event/EventSources.java | 56 +++++++++---------- .../event/EventSourceManagerTest.java | 6 +- .../processing/event/EventSourcesTest.java | 4 +- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java index a17328e7d7..c65d897734 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java @@ -213,7 +213,7 @@ public List> getEventSourcesFor(Class dependentType) { @Override public EventSource dynamicallyRegisterEventSource(EventSource eventSource) { synchronized (this) { - var actual = eventSources.existingEventSourceOfSameNameAndType(eventSource); + var actual = eventSources.existingEventSourceByName(eventSource.name()); if (actual != null) { eventSource = actual; } else { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java index 79091de0d3..e790ae3c32 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java @@ -19,10 +19,37 @@ class EventSources

{ private final ConcurrentNavigableMap>> sources = new ConcurrentSkipListMap<>(); + private final Map sourceByName = new HashMap<>(); + private final TimerEventSource

retryAndRescheduleTimerEventSource = new TimerEventSource<>("RetryAndRescheduleTimerEventSource"); private ControllerEventSource

controllerEventSource; + public void add(EventSource eventSource) { + final var name = eventSource.name(); + var existing = sourceByName.get(name); + if (existing != null) { + throw new IllegalArgumentException("Event source " + existing + + " is already registered with name: " + name); + } + sourceByName.put(name, eventSource); + sources.computeIfAbsent(keyFor(eventSource), k -> new HashMap<>()).put(name, eventSource); + } + + public EventSource remove(String name) { + var optionalMap = sources.values().stream().filter(m -> m.containsKey(name)).findFirst(); + sourceByName.remove(name); + return optionalMap.map(m -> m.remove(name)).orElse(null); + } + + public void clear() { + sources.clear(); + sourceByName.clear(); + } + + public EventSource existingEventSourceByName(String name) { + return sourceByName.get(name); + } void createControllerEventSource(Controller

controller) { controllerEventSource = new ControllerEventSource<>(controller); @@ -54,30 +81,7 @@ Stream> flatMappedSources() { return sources.values().stream().flatMap(c -> c.values().stream()); } - public void clear() { - sources.clear(); - } - - @SuppressWarnings("unchecked") - public EventSource existingEventSourceOfSameNameAndType(EventSource source) { - return (EventSource) existingEventSourcesOfSameType(source).get(source.name()); - } - - private Map> existingEventSourcesOfSameType( - EventSource source) { - return sources.getOrDefault(keyFor(source), Collections.emptyMap()); - } - public void add(EventSource eventSource) { - final var name = eventSource.name(); - final var existing = existingEventSourcesOfSameType(eventSource); - if (existing.get(name) != null) { - throw new IllegalArgumentException("Event source " + existing - + " is already registered with name: " + name); - } - - sources.computeIfAbsent(keyFor(eventSource), k -> new HashMap<>()).put(name, eventSource); - } private String keyFor(EventSource source) { return keyFor(source.resourceType()); @@ -145,10 +149,4 @@ public List> getEventSources(Class dependentType) { return sourcesForType.values().stream() .map(es -> (EventSource) es).toList(); } - - @SuppressWarnings("rawtypes") - public EventSource remove(String name) { - var optionalMap = sources.values().stream().filter(m -> m.containsKey(name)).findFirst(); - return optionalMap.map(m -> m.remove(name)).orElse(null); - } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java index b5ff379dd6..7e45bda68c 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java @@ -48,8 +48,11 @@ public void registersEventSource() { @Test public void closeShouldCascadeToEventSources() { EventSource eventSource = mock(EventSource.class); + when(eventSource.name()).thenReturn("name1"); when(eventSource.resourceType()).thenReturn(EventSource.class); + EventSource eventSource2 = mock(TimerEventSource.class); + when(eventSource2.name()).thenReturn("name2"); when(eventSource2.resourceType()).thenReturn(AbstractEventSource.class); eventSourceManager.registerEventSource(eventSource); @@ -65,11 +68,12 @@ public void closeShouldCascadeToEventSources() { public void startCascadesToEventSources() { EventSource eventSource = mock(EventSource.class); when(eventSource.priority()).thenReturn(EventSourceStartPriority.DEFAULT); + when(eventSource.name()).thenReturn("name1"); when(eventSource.resourceType()).thenReturn(EventSource.class); EventSource eventSource2 = mock(TimerEventSource.class); when(eventSource2.priority()).thenReturn(EventSourceStartPriority.DEFAULT); + when(eventSource2.name()).thenReturn("name2"); when(eventSource2.resourceType()).thenReturn(AbstractEventSource.class); - eventSourceManager.registerEventSource(eventSource); eventSourceManager.registerEventSource(eventSource2); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java index 9c2d09bac4..3d0d92da4f 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java @@ -134,7 +134,7 @@ void getShouldWork() { eventSourceMockWithName(EventSource.class, "name1", HasMetadata.class); final var mock2 = eventSourceMockWithName(EventSource.class, "name2", HasMetadata.class); - final var mock3 = eventSourceMockWithName(EventSource.class, "name2", ConfigMap.class); + final var mock3 = eventSourceMockWithName(EventSource.class, "name3", ConfigMap.class); eventSources.add(mock1); eventSources.add(mock2); @@ -142,7 +142,7 @@ void getShouldWork() { assertEquals(mock1, eventSources.get(HasMetadata.class, "name1")); assertEquals(mock2, eventSources.get(HasMetadata.class, "name2")); - assertEquals(mock3, eventSources.get(ConfigMap.class, "name2")); + assertEquals(mock3, eventSources.get(ConfigMap.class, "name3")); assertEquals(mock3, eventSources.get(ConfigMap.class, null)); From 2410c2f73cac251ce005499db6d50b47a376adc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 21 May 2024 23:22:57 +0200 Subject: [PATCH 49/96] docs: migrate v5 changes to docsy (#2397) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../en/docs/dependent-resources/_index.md | 251 ++++++------------ docsy/content/en/docs/features/_index.md | 157 +++++------ .../en/docs/migration/v5-0-migration.md | 63 +++++ docsy/content/en/docs/workflows/_index.md | 48 +++- 4 files changed, 248 insertions(+), 271 deletions(-) create mode 100644 docsy/content/en/docs/migration/v5-0-migration.md diff --git a/docsy/content/en/docs/dependent-resources/_index.md b/docsy/content/en/docs/dependent-resources/_index.md index be67ec6ab6..a80bf80822 100644 --- a/docsy/content/en/docs/dependent-resources/_index.md +++ b/docsy/content/en/docs/dependent-resources/_index.md @@ -3,6 +3,8 @@ title: Dependent Resources weight: 60 --- +# Dependent Resources + ## Motivations and Goals Most operators need to deal with secondary resources when trying to realize the desired state @@ -96,13 +98,13 @@ and labels, which are ignored by default: ```java public class MyDependentResource extends KubernetesDependentResource - implements Matcher { - // your implementation + implements Matcher { + // your implementation - public Result match(MyDependent actualResource, MyPrimary primary, - Context context) { - return GenericKubernetesResourceMatcher.match(this, actualResource, primary, context, true); - } + public Result match(MyDependent actualResource, MyPrimary primary, + Context context) { + return GenericKubernetesResourceMatcher.match(this, actualResource, primary, context, true); + } } ``` @@ -136,24 +138,24 @@ Deleted (or set to be garbage collected). The following example shows how to cre @KubernetesDependent(labelSelector = WebPageManagedDependentsReconciler.SELECTOR) class DeploymentDependentResource extends CRUDKubernetesDependentResource { - public DeploymentDependentResource() { - super(Deployment.class); - } - - @Override - protected Deployment desired(WebPage webPage, Context context) { - var deploymentName = deploymentName(webPage); - Deployment deployment = loadYaml(Deployment.class, getClass(), "deployment.yaml"); - deployment.getMetadata().setName(deploymentName); - deployment.getMetadata().setNamespace(webPage.getMetadata().getNamespace()); - deployment.getSpec().getSelector().getMatchLabels().put("app", deploymentName); - - deployment.getSpec().getTemplate().getMetadata().getLabels() - .put("app", deploymentName); - deployment.getSpec().getTemplate().getSpec().getVolumes().get(0) - .setConfigMap(new ConfigMapVolumeSourceBuilder().withName(configMapName(webPage)).build()); - return deployment; - } + public DeploymentDependentResource() { + super(Deployment.class); + } + + @Override + protected Deployment desired(WebPage webPage, Context context) { + var deploymentName = deploymentName(webPage); + Deployment deployment = loadYaml(Deployment.class, getClass(), "deployment.yaml"); + deployment.getMetadata().setName(deploymentName); + deployment.getMetadata().setNamespace(webPage.getMetadata().getNamespace()); + deployment.getSpec().getSelector().getMatchLabels().put("app", deploymentName); + + deployment.getSpec().getTemplate().getMetadata().getLabels() + .put("app", deploymentName); + deployment.getSpec().getTemplate().getSpec().getVolumes().get(0) + .setConfigMap(new ConfigMapVolumeSourceBuilder().withName(configMapName(webPage)).build()); + return deployment; + } } ``` @@ -189,25 +191,25 @@ instances are managed by JOSDK, an example of which can be seen below: ```java @ControllerConfiguration( - labelSelector = SELECTOR, - dependents = { - @Dependent(type = ConfigMapDependentResource.class), - @Dependent(type = DeploymentDependentResource.class), - @Dependent(type = ServiceDependentResource.class) - }) + labelSelector = SELECTOR, + dependents = { + @Dependent(type = ConfigMapDependentResource.class), + @Dependent(type = DeploymentDependentResource.class), + @Dependent(type = ServiceDependentResource.class) + }) public class WebPageManagedDependentsReconciler - implements Reconciler, ErrorStatusHandler { + implements Reconciler, ErrorStatusHandler { - // omitted code + // omitted code - @Override - public UpdateControl reconcile(WebPage webPage, Context context) { + @Override + public UpdateControl reconcile(WebPage webPage, Context context) { - final var name = context.getSecondaryResource(ConfigMap.class).orElseThrow() - .getMetadata().getName(); - webPage.setStatus(createStatus(name)); - return UpdateControl.patchStatus(webPage); - } + final var name = context.getSecondaryResource(ConfigMap.class).orElseThrow() + .getMetadata().getName(); + webPage.setStatus(createStatus(name)); + return UpdateControl.patchStatus(webPage); + } } ``` @@ -222,104 +224,11 @@ It is also possible to wire dependent resources programmatically. In practice th developer is responsible for initializing and managing the dependent resources as well as calling their `reconcile` method. However, this makes it possible for developers to fully customize the reconciliation process. Standalone dependent resources should be used in cases when the managed use -case does not fit. - -Note that [Workflows](https://javaoperatorsdk.io/docs/workflows) also can be invoked from standalone -resources. - -The following sample is similar to the one above, simply performing additional checks, and -conditionally creating an `Ingress`: - -```java - -@ControllerConfiguration -public class WebPageStandaloneDependentsReconciler - implements Reconciler, ErrorStatusHandler, - EventSourceInitializer { - - private KubernetesDependentResource configMapDR; - private KubernetesDependentResource deploymentDR; - private KubernetesDependentResource serviceDR; - private KubernetesDependentResource ingressDR; - - public WebPageStandaloneDependentsReconciler(KubernetesClient kubernetesClient) { - // 1. - createDependentResources(kubernetesClient); - } - - @Override - public List prepareEventSources(EventSourceContext context) { - // 2. - return List.of( - configMapDR.initEventSource(context), - deploymentDR.initEventSource(context), - serviceDR.initEventSource(context)); - } - - @Override - public UpdateControl reconcile(WebPage webPage, Context context) { - - // 3. - if (!isValidHtml(webPage.getHtml())) { - return UpdateControl.patchStatus(setInvalidHtmlErrorMessage(webPage)); - } - - // 4. - configMapDR.reconcile(webPage, context); - deploymentDR.reconcile(webPage, context); - serviceDR.reconcile(webPage, context); - - // 5. - if (Boolean.TRUE.equals(webPage.getSpec().getExposed())) { - ingressDR.reconcile(webPage, context); - } else { - ingressDR.delete(webPage, context); - } +case does not fit. You can, of course, also use [Workflows](https://javaoperatorsdk.io/docs/workflows) when managing +resources programmatically. - // 6. - webPage.setStatus( - createStatus(configMapDR.getResource(webPage).orElseThrow().getMetadata().getName())); - return UpdateControl.patchStatus(webPage); - } - - private void createDependentResources(KubernetesClient client) { - this.configMapDR = new ConfigMapDependentResource(); - this.deploymentDR = new DeploymentDependentResource(); - this.serviceDR = new ServiceDependentResource(); - this.ingressDR = new IngressDependentResource(); - - Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR).forEach(dr -> { - dr.setKubernetesClient(client); - dr.configureWith(new KubernetesDependentResourceConfig() - .setLabelSelector(DEPENDENT_RESOURCE_LABEL_SELECTOR)); - }); - } - - // omitted code -} -``` - -There are multiple things happening here: - -1. Dependent resources are explicitly created and can be access later by reference. -2. Event sources are produced by the dependent resources, but needs to be explicitly registered in - this case by implementing - the [`EventSourceInitializer`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java) - interface. -3. The input html is validated, and error message is set in case it is invalid. -4. Reconciliation of dependent resources is called explicitly, but here the workflow - customization is fully in the hand of the developer. -5. An `Ingress` is created but only in case `exposed` flag set to true on custom resource. Tries to - delete it if not. -6. Status is set in a different way, this is just an alternative way to show, that the actual state - can be read using the reference. This could be written in a same way as in the managed example. - -See the full source code of -sample [here](https://github.com/operator-framework/java-operator-sdk/blob/main/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java) -. - -Note also the Workflows feature makes it possible to also support this conditional creation use -case in managed dependent resources. +You can see a commented example of how to do +so [here](https://github.com/operator-framework/java-operator-sdk/blob/main/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java). ## Creating/Updating Kubernetes Resources @@ -352,17 +261,17 @@ Since SSA is a complex feature, JOSDK implements a feature flag allowing users t these implementations. See in [ConfigurationService](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L332-L358). -It is, however, important to note that these implementations are default, generic -implementations that the framework can provide expected behavior out of the box. In many -situations, these will work just fine but it is also possible to provide matching algorithms +It is, however, important to note that these implementations are default, generic +implementations that the framework can provide expected behavior out of the box. In many +situations, these will work just fine but it is also possible to provide matching algorithms optimized for specific use cases. This is easily done by simply overriding -the `match(...)` [method](https://github.com/java-operator-sdk/java-operator-sdk/blob/e16559fd41bbb8bef6ce9d1f47bffa212a941b09/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java#L156-L156). +the `match(...)` [method](https://github.com/java-operator-sdk/java-operator-sdk/blob/e16559fd41bbb8bef6ce9d1f47bffa212a941b09/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java#L156-L156). -It is also possible to bypass the matching logic altogether to simply rely on the server-side +It is also possible to bypass the matching logic altogether to simply rely on the server-side apply mechanism if always sending potentially unchanged resources to the cluster is not an issue. JOSDK's matching mechanism allows to spare some potentially useless calls to the Kubernetes API -server. To bypass the matching feature completely, simply override the `match` method to always -return `false`, thus telling JOSDK that the actual state never matches the desired one, making +server. To bypass the matching feature completely, simply override the `match` method to always +return `false`, thus telling JOSDK that the actual state never matches the desired one, making it always update the resources using SSA. WARNING: Older versions of Kubernetes before 1.25 would create an additional resource version for every SSA update @@ -389,20 +298,25 @@ tests [here](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/op When dealing with multiple dependent resources of same type, the dependent resource implementation needs to know which specific resource should be targeted when reconciling a given dependent -resource, since there will be multiple instances of that type which could possibly be used, each -associated with the same primary resource. In order to do this, JOSDK relies on the -[resource discriminator](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceDiscriminator.java) -concept. Resource discriminators uniquely identify the target resource of a dependent resource. -In the managed Kubernetes dependent resources case, the discriminator can be declaratively set -using the `@KubernetesDependent` annotation: - -```java - -@KubernetesDependent(resourceDiscriminator = ConfigMap1Discriminator.class) -public class MultipleManagedDependentResourceConfigMap1 { -//... -} -``` +resource, since there could be multiple instances of that type which could possibly be used, each +associated with the same primary resource. In this situation, JOSDK automatically selects the appropriate secondary +resource matching the desired state associated with the primary resource. This makes sense because the desired +state computation already needs to be able to discriminate among multiple related secondary resources to tell JOSDK how +they should be reconciled. + +There might be casees, though, where it might be problematic to call the `desired` method several times (for example, because it is costly to do so), it is always possible to override this automated discrimination using several means: + +- Implement your own `getSecondaryResource` method on your `DependentResource` implementation from scratch. +- Override the `selectManagedSecondaryResource` method, if your `DependentResource` extends `AbstractDependentResource`. + This should be relatively simple to override this method to optimize the matching to your needs. You can see an + example of such an implementation in + the [`ExternalWithStateDependentResource`](https://github.com/operator-framework/java-operator-sdk/blob/6cd0f884a7c9b60c81bd2d52da54adbd64d6e118/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java#L43-L49) + class. +- Override the `managedSecondaryResourceID` method, if your `DependentResource` extends `KubernetesDependentResource`, + where it's very often possible to easily determine the `ResourceID` of the secondary resource. This would probably be + the easiest solution if you're working with Kubernetes resources. + +### Sharing an Event Source Between Dependent Resources Dependent resources usually also provide event sources. When dealing with multiple dependents of the same type, one needs to decide whether these dependent resources should track the same @@ -418,10 +332,10 @@ would look as follows: useEventSourceWithName = "configMapSource") ``` -A sample is provided as an integration test both -for [managed](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentSameTypeIT.java) -and -for [standalone](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java) +A sample is provided as an integration test both: +for [managed](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentNoDiscriminatorIT.java) + +For [standalone](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java) cases. ## Bulk Dependent Resources @@ -484,15 +398,18 @@ also be created, one per dependent resource. See [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java) as a sample. - ## GenericKubernetesResource based Dependent Resources -In rare circumstances resource handling where there is no class representation or just typeless handling might be needed. -Fabric8 Client provides [GenericKubernetesResource](https://github.com/fabric8io/kubernetes-client/blob/main/doc/CHEATSHEET.md#resource-typeless-api) -to support that. +In rare circumstances resource handling where there is no class representation or just typeless handling might be +needed. +Fabric8 Client +provides [GenericKubernetesResource](https://github.com/fabric8io/kubernetes-client/blob/main/doc/CHEATSHEET.md#resource-typeless-api) +to support that. -For dependent resource this is supported by [GenericKubernetesDependentResource](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java#L8-L8) -. See samples [here](https://github.com/java-operator-sdk/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource). +For dependent resource this is supported +by [GenericKubernetesDependentResource](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java#L8-L8) +. See +samples [here](https://github.com/java-operator-sdk/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource). ## Other Dependent Resource Features diff --git a/docsy/content/en/docs/features/_index.md b/docsy/content/en/docs/features/_index.md index 8c775ed4fa..1eaa68b15b 100644 --- a/docsy/content/en/docs/features/_index.md +++ b/docsy/content/en/docs/features/_index.md @@ -3,6 +3,8 @@ title: Features weight: 50 --- +# Features + The Java Operator SDK (JOSDK) is a high level framework and related tooling aimed at facilitating the implementation of Kubernetes operators. The features are by default following the best practices in an opinionated way. However, feature flags and other configuration options @@ -62,7 +64,8 @@ and/or re-schedule a reconciliation with a desired time delay: @Override public UpdateControl reconcile( EventSourceTestCustomResource resource, Context context) { - ... + // omitted code + return UpdateControl.patchStatus(resource).rescheduleAfter(10, TimeUnit.SECONDS); } ``` @@ -73,7 +76,8 @@ without an update: @Override public UpdateControl reconcile( EventSourceTestCustomResource resource, Context context) { - ... + // omitted code + return UpdateControl.noUpdate().rescheduleAfter(10, TimeUnit.SECONDS); } ``` @@ -85,17 +89,31 @@ Those are the typical use cases of resource updates, however in some cases there the controller wants to update the resource itself (for example to add annotations) or not perform any updates, which is also supported. -It is also possible to update both the status and the resource with the -`updateResourceAndStatus` method. In this case, the resource is updated first followed by the -status, using two separate requests to the Kubernetes API. - -You should always state your intent using `UpdateControl` and let the SDK deal with the actual -updates instead of performing these updates yourself using the actual Kubernetes client so that -the SDK can update its internal state accordingly. - -Resource updates are protected using optimistic version control, to make sure that other updates -that might have occurred in the mean time on the server are not overwritten. This is ensured by -setting the `resourceVersion` field on the processed resources. +It is also possible to update both the status and the resource with the `patchResourceAndStatus` method. In this case, +the resource is updated first followed by the status, using two separate requests to the Kubernetes API. + +From v5 `UpdateControl` only supports patching the resources, by default +using [Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/server-side-apply/). +It is important to understand how SSA works in Kubernetes. Mainly, resources applied using SSA +should contain only the fields identifying the resource and those the user is interested in (a 'fully specified intent' +in Kubernetes parlance), thus usually using a resource created from scratch, see +[sample](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAReconciler.java#L18-L22). +To contrast, see the same sample, this time [without SSA](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java#L16-L16). + +Non-SSA based patch is still supported. +You can control whether or not to use SSA +using [`ConfigurationServcice.useSSAToPatchPrimaryResource()`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L385-L385) +and the related `ConfigurationServiceOverrider.withUseSSAToPatchPrimaryResource` method. +Related integration test can be +found [here](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java). + +Handling resources directly using the client, instead of delegating these updates operations to JOSDK by returning +an `UpdateControl` at the end of your reconciliation, should work appropriately. However, we do recommend to +use `UpdateControl` instead since JOSDK makes sure that the operations are handled properly, since there are subtleties +to be aware of. For example, if you are using a finalizer, JOSDK makes sure to include it in your fully specified intent +so that it is not unintentionally removed from the resource (which would happen if you omit it, since your controller is +the designated manager for that field and Kubernetes interprets the finalizer being gone from the specified intent as a +request for removal). [`DeleteControl`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DeleteControl.java) typically instructs the framework to remove the finalizer after the dependent @@ -104,7 +122,8 @@ resource are cleaned up in `cleanup` implementation. ```java public DeleteControl cleanup(MyCustomResource customResource,Context context){ - ... + // omitted code + return DeleteControl.defaultDelete(); } @@ -163,56 +182,7 @@ You can specify the name of the finalizer to use for your `Reconciler` using the [`@ControllerConfiguration`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java) annotation. If you do not specify a finalizer name, one will be automatically generated for you. -## Automatic Observed Generation Handling - -Having an `.observedGeneration` value on your resources' status is a best practice to -indicate the last generation of the resource which was successfully reconciled by the controller. -This helps users / administrators diagnose potential issues. - -In order to have this feature working: - -- the **status class** (not the resource itself) must implement the - [`ObservedGenerationAware`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java) - interface. See also - the [`ObservedGenerationAwareStatus`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAwareStatus.java) - convenience implementation that you can extend in your own status class implementations. -- The other condition is that the `CustomResource.getStatus()` method should not return `null`. - So the status should be instantiated when the object is returned using the `UpdateControl`. - -If these conditions are fulfilled and generation awareness is activated, the observed generation -is automatically set by the framework after the `reconcile` method is called. Note that the -observed generation is also updated even when `UpdateControl.noUpdate()` is returned from the -reconciler. See this feature at work in -the [WebPage example](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStatus.java#L5) -. - -```java -public class WebPageStatus extends ObservedGenerationAwareStatus { - - private String htmlConfigMap; - - ... -} -``` - -Initializing status automatically on custom resource could be done by overriding the `initStatus` method -of `CustomResource`. However, this is NOT advised, since breaks the status patching if you use: -`UpdateControl.patchStatus`. See -also [javadocs](https://github.com/java-operator-sdk/java-operator-sdk/blob/3994f5ffc1fb000af81aa198abf72a5f75fd3e97/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java#L41-L42) -. - -```java -@Group("sample.javaoperatorsdk") -@Version("v1") -public class WebPage extends CustomResource - implements Namespaced { - - @Override - protected WebPageStatus initStatus() { - return new WebPageStatus(); - } -} -``` +From v5 by default finalizer is added using Served Side Apply. See also UpdateControl in docs. ## Generation Awareness and Event Filtering @@ -231,9 +201,7 @@ To turn off this feature, set `generationAwareEventProcessing` to `false` for th ## Support for Well Known (non-custom) Kubernetes Resources A Controller can be registered for a non-custom resource, so well known Kubernetes resources like ( -`Ingress`, `Deployment`,...). Note that automatic observed generation handling is not supported -for these resources, though, in this case, the handling of the observed generation is probably -handled by the primary controller. +`Ingress`, `Deployment`,...). See the [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/deployment/DeploymentReconciler.java) @@ -243,11 +211,12 @@ for reconciling deployments. public class DeploymentReconciler implements Reconciler, TestExecutionInfoProvider { - @Override - public UpdateControl reconcile( - Deployment resource, Context context) { - ... - } + @Override + public UpdateControl reconcile( + Deployment resource, Context context) { + // omitted code + } +} ``` ## Max Interval Between Reconciliations @@ -265,6 +234,7 @@ standard annotation: @ControllerConfiguration(maxReconciliationInterval = @MaxReconciliationInterval( interval = 50, timeUnit = TimeUnit.MILLISECONDS)) +public class MyReconciler implements Reconciler {} ``` The event is not propagated at a fixed rate, rather it's scheduled after each reconciliation. So the @@ -487,9 +457,8 @@ related [method](https://github.com/java-operator-sdk/java-operator-sdk/blob/mai ### Registering Event Sources -To register event sources, your `Reconciler` has to implement the -[`EventSourceInitializer`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java) -interface and initialize a list of event sources to register. One way to see this in action is +To register event sources, your `Reconciler` has to override the `prepareEventSources` and return +list of event sources to register. One way to see this in action is to look at the [tomcat example](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java) (irrelevant details omitted): @@ -499,8 +468,9 @@ to look at the @ControllerConfiguration public class WebappReconciler implements Reconciler, Cleaner, EventSourceInitializer { - - @Override + // ommitted code + + @Override public Map prepareEventSources(EventSourceContext context) { InformerConfiguration configuration = InformerConfiguration.from(Tomcat.class, context) @@ -512,7 +482,7 @@ public class WebappReconciler return EventSourceInitializer .nameEventSources(new InformerEventSource<>(configuration, context)); } - ... + } ``` @@ -656,15 +626,15 @@ registering an associated `Informer` and then calling the `changeNamespaces` met ```java -public static void main(String[]args)throws IOException{ - KubernetesClient client=new DefaultKubernetesClient(); - Operator operator=new Operator(client); - RegisteredController registeredController=operator.register(new WebPageReconciler(client)); - operator.installShutdownHook(); - operator.start(); +public static void main(String[] args) { + KubernetesClient client = new DefaultKubernetesClient(); + Operator operator = new Operator(client); + RegisteredController registeredController = operator.register(new WebPageReconciler(client)); + operator.installShutdownHook(); + operator.start(); - // call registeredController further while operator is running - } + // call registeredController further while operator is running +} ``` @@ -676,8 +646,7 @@ configured appropriately so that the `followControllerNamespaceChanges` method r ```java @ControllerConfiguration -public class MyReconciler - implements Reconciler, EventSourceInitializer { +public class MyReconciler implements Reconciler { @Override public Map prepareEventSources( @@ -688,7 +657,7 @@ public class MyReconciler .withNamespacesInheritedFromController(context) .build(), context); - return EventSourceInitializer.nameEventSources(configMapES); + return EventSourceUtils.nameEventSources(configMapES); } } @@ -767,8 +736,8 @@ You can use a different implementation by overriding the default one provided by follows: ```java -Metrics metrics= …; -Operator operator = new Operator(client, o -> o.withMetrics()); +Metrics metrics; // initialize your metrics implementation +Operator operator = new Operator(client, o -> o.withMetrics(metrics)); ``` ### Micrometer implementation @@ -784,8 +753,8 @@ To create a `MicrometerMetrics` implementation that behaves how it has historica instance via: ```java -MeterRegistry registry= …; -Metrics metrics=new MicrometerMetrics(registry) +MeterRegistry registry; // initialize your registry implementation +Metrics metrics = new MicrometerMetrics(registry); ``` Note, however, that this constructor is deprecated and we encourage you to use the factory methods instead, which either @@ -801,7 +770,7 @@ basis, deleting the associated meters after 5 seconds when a resource is deleted MicrometerMetrics.newPerResourceCollectingMicrometerMetricsBuilder(registry) .withCleanUpDelayInSeconds(5) .withCleaningThreadNumber(2) - .build() + .build(); ``` The micrometer implementation records the following metrics: diff --git a/docsy/content/en/docs/migration/v5-0-migration.md b/docsy/content/en/docs/migration/v5-0-migration.md new file mode 100644 index 0000000000..c766d5c770 --- /dev/null +++ b/docsy/content/en/docs/migration/v5-0-migration.md @@ -0,0 +1,63 @@ +--- +title: Migrating from v4.7 to v5.0 +description: Migrating from v4.7 to v5.0 +--- + +# Migrating from v4.7 to v5.0 + +## API Tweaks + +1. [Result of managed dependent resources](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java#L55-L57) + is not `Optional` anymore. In case you use this result, simply use the result + objects directly. +2. `EventSourceInitializer` is not a separate interface anymore. It is part of the `Reconciler` interface with a + default implementation. You can simply remove this interface from your reconciler. The + [`EventSourceUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java#L11-L11) + now contains all the utility methods used for event sources naming that were previously defined in + the `EventSourceInitializer` interface. +3. Similarly, the `EventSourceProvider` interface has been remove, replaced by explicit initialization of the associated + event source on `DependentResource` via the ` + Optional> eventSource(EventSourceContext

eventSourceContext)` method. +4. Event sources are now explicitly named (via the `name` method of the `EventSource` interface). Built-in event sources + implementation have been updated to allow you to specify a name when instantiating them. If you don't provide a name + for your `EventSource` implementation (for example, by using its default, no-arg constructor), one will be + automatically generated. This simplifies the API to define event source to + `List prepareEventSources(EventSourceContext

context)`. + !!! IMPORTANT !!! + If you use dynamic registration of event sources, be sure to name your event sources explicitly as letting JOSDK name + them automatically might result in duplicated event sources being registered as JOSDK relies on the name to identify + event sources and concurrent, dynamic registration might lead to identical event sources having different generated + names, thus leading JOSDK to consider them as different and hence, register them multiple times. +5. Updates through `UpdateControl` now + use [Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/server-side-apply/) by default to add + the finalizer and for all + the patch operations in `UpdateControl`. The update operations were removed. If you do not wish to use SSA, you can + deactivate the feature using `ConfigurationService.useSSAToPatchPrimaryResource` and + related `ConfigurationServiceOverrider.withUseSSAToPatchPrimaryResource`. + + !!! IMPORTANT !!! + + See known issues with migration from non-SSA to SSA based status updates here: + [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L71-L82) + where it is demonstrated. Also, the related part of + a [workaround](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L110-L116). + +6. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed + via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. +7. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should + work without it by default. To optimize and handle special cases see the relevant section + in [Dependent Resource documentation](/docs/dependent-resources#multiple-dependent-resources-of-same-type). +8. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed, + use `Operator.stop(Duration)` instead. +9. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead +10. Automated observed generation handling feature was removed (`ObservedGenerationAware` interface + and `ObservedGenerationAwareStatus` class were deleted). Manually handling observed generation is fairly easy to do + in your reconciler, however, it cannot be done automatically when using SSA. We therefore removed the feature since + it would have been confusing to have a different behavior for SSA and non-SSA cases. For an example of how to do + observed generation handling manually in your reconciler, see + [this sample](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java). +11. `BulkDependentResource` now supports [read-only mode](https://github.com/operator-framework/java-operator-sdk/issues/2233). + This also means, that `BulkDependentResource` now does not automatically implement `Creator` and `Deleter` as before. + Make sure to implement those interfaces in your bulk dependent resources. You can use also the new helper interface, the + [`CRUDBulkDependentResource`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/CRUDBulkDependentResource.java) + what also implement `BulkUpdater` interface. \ No newline at end of file diff --git a/docsy/content/en/docs/workflows/_index.md b/docsy/content/en/docs/workflows/_index.md index 5f275c2b9a..ea2c53990a 100644 --- a/docsy/content/en/docs/workflows/_index.md +++ b/docsy/content/en/docs/workflows/_index.md @@ -41,10 +41,10 @@ reconciliation process. condition holds or not. This is a very useful feature when your operator needs to handle different flavors of the platform (e.g. OpenShift vs plain Kubernetes) and/or change its behavior based on the availability of optional resources / features (e.g. CertManager, a specific Ingress controller, etc.). - - Activation condition is semi-experimental at the moment, and it has its limitations. - For example event sources cannot be shared between multiple managed dependent resources which use activation condition. - The intention is to further improve and explore the possibilities with this approach. + + Activation condition is semi-experimental at the moment, and it has its limitations. + For example event sources cannot be shared between multiple managed dependent resources which use activation condition. + The intention is to further improve and explore the possibilities with this approach. ## Defining Workflows @@ -120,7 +120,7 @@ page sample): @ControllerConfiguration( labelSelector = WebPageDependentsWorkflowReconciler.DEPENDENT_RESOURCE_LABEL_SELECTOR) public class WebPageDependentsWorkflowReconciler - implements Reconciler, ErrorStatusHandler, EventSourceInitializer { + implements Reconciler, ErrorStatusHandler { public static final String DEPENDENT_RESOURCE_LABEL_SELECTOR = "!low-level"; private static final Logger log = @@ -131,7 +131,7 @@ public class WebPageDependentsWorkflowReconciler private KubernetesDependentResource serviceDR; private KubernetesDependentResource ingressDR; - private Workflow workflow; + private final Workflow workflow; public WebPageDependentsWorkflowReconciler(KubernetesClient kubernetesClient) { initDependentResources(kubernetesClient); @@ -145,7 +145,7 @@ public class WebPageDependentsWorkflowReconciler @Override public Map prepareEventSources(EventSourceContext context) { - return EventSourceInitializer.nameEventSources( + return EventSourceUtils.nameEventSources( configMapDR.initEventSource(context), deploymentDR.initEventSource(context), serviceDR.initEventSource(context), @@ -198,7 +198,7 @@ demonstrated using examples: 2. Root nodes, i.e. nodes in the graph that do not depend on other nodes are reconciled first, in a parallel manner. 3. A DR is reconciled if it does not depend on any other DRs, or *ALL* the DRs it depends on are - reconciled and ready. If a DR defines a reconcile pre-condition and/or an activation condition, + reconciled and ready. If a DR defines a reconcile pre-condition and/or an activation condition, then these condition must become `true` before the DR is reconciled. 4. A DR is considered *ready* if it got successfully reconciled and any ready post-condition it might define is `true`. @@ -328,10 +328,38 @@ provides such a delete post-condition implementation in the form of Also, check usage in an [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java). -In such cases the Kubernetes Dependent Resource should extend `CRUDNoGCKubernetesDependentResource` +In such cases the Kubernetes Dependent Resource should extend `CRUDNoGCKubernetesDependentResource` and NOT `CRUDKubernetesDependentResource` since otherwise the Kubernetes Garbage Collector would delete the resources. In other words if a Kubernetes Dependent Resource depends on another dependent resource, it should not implement -`GargageCollected` interface, otherwise the deletion order won't be guaranteed. +`GargageCollected` interface, otherwise the deletion order won't be guaranteed. + + +## Explicit Managed Workflow Invocation + +Managed workflows, i.e. ones that are declared via annotations and therefore completely managed by JOSDK, are reconciled +before the primary resource. Each dependent resource that can be reconciled (according to the workflow configuration) +will therefore be reconciled before the primary reconciler is called to reconcile the primary resource. There are, +however, situations where it would be be useful to perform additional steps before the workflow is reconciled, for +example to validate the current state, execute arbitrary logic or even skip reconciliation altogether. Explicit +invocation of managed workflow was therefore introduced to solve these issues. + +To use this feature, you need to set the `explicitInvocation` field to `true` on the `@Workflow` annotation and then +call the `reconcileManagedWorkflow` method from the ` +ManagedWorkflowAndDependentResourceContext` retrieved from the reconciliation `Context` provided as part of your primary +resource reconciler `reconcile` method arguments. + +See +related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java) +for more details. + +For `cleanup`, if the `Cleaner` interface is implemented, the `cleanupManageWorkflow()` needs to be called explicitly. +However, if `Cleaner` interface is not implemented, it will be called implicitly. +See +related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitCleanupIT.java). + +While nothing prevents calling the workflow multiple times in a reconciler, it isn't typical or even recommended to do +so. Conversely, if explicit invocation is requested but `reconcileManagedWorkflow` is not called in the primary resource +reconciler, the workflow won't be reconciled at all. ## Notes and Caveats From 31c6a301ca326d2ab38de6f8d4d42ac99cf70327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 12 Jun 2024 10:30:06 +0200 Subject: [PATCH 50/96] docs: @Workflow usage (#2413) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- docsy/content/en/docs/workflows/_index.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docsy/content/en/docs/workflows/_index.md b/docsy/content/en/docs/workflows/_index.md index ea2c53990a..32d93a6157 100644 --- a/docsy/content/en/docs/workflows/_index.md +++ b/docsy/content/en/docs/workflows/_index.md @@ -70,15 +70,16 @@ will only consider the `ConfigMap` deleted until that post-condition becomes `tr ```java -@ControllerConfiguration(dependents = { - @Dependent(name = DEPLOYMENT_NAME, type = DeploymentDependentResource.class, - readyPostcondition = DeploymentReadyCondition.class), - @Dependent(type = ConfigMapDependentResource.class, - reconcilePrecondition = ConfigMapReconcileCondition.class, - deletePostcondition = ConfigMapDeletePostCondition.class, - activationCondition = ConfigMapActivationCondition.class, - dependsOn = DEPLOYMENT_NAME) +@Workflow(dependents = { + @Dependent(name = DEPLOYMENT_NAME, type = DeploymentDependentResource.class, + readyPostcondition = DeploymentReadyCondition.class), + @Dependent(type = ConfigMapDependentResource.class, + reconcilePrecondition = ConfigMapReconcileCondition.class, + deletePostcondition = ConfigMapDeletePostCondition.class, + activationCondition = ConfigMapActivationCondition.class, + dependsOn = DEPLOYMENT_NAME) }) +@ControllerConfiguration public class SampleWorkflowReconciler implements Reconciler, Cleaner { From 57a24333ae6d81c2cdde92ef1ad81f64eced6aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 17 Jun 2024 11:14:39 +0200 Subject: [PATCH 51/96] improve: remove ErrorStatusHandler interface (#2438) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../en/docs/migration/v5-0-migration.md | 3 +- .../api/reconciler/ErrorStatusHandler.java | 28 ------- .../reconciler/ErrorStatusUpdateControl.java | 21 +++++ .../operator/api/reconciler/Reconciler.java | 24 ++++++ .../event/ReconciliationDispatcher.java | 82 ++++++++----------- .../event/ReconciliationDispatcherTest.java | 42 +++++----- .../DependentResourceCrossRefReconciler.java | 3 +- .../ErrorStatusHandlerTestReconciler.java | 3 +- ...endentGarbageCollectionTestReconciler.java | 3 +- .../primarytosecondary/JobReconciler.java | 2 +- .../StandaloneDependentTestReconciler.java | 4 +- .../sample/MySQLSchemaReconciler.java | 2 +- .../WebPageDependentsWorkflowReconciler.java | 2 +- .../WebPageManagedDependentsReconciler.java | 2 +- .../operator/sample/WebPageReconciler.java | 2 +- ...WebPageStandaloneDependentsReconciler.java | 3 +- 16 files changed, 112 insertions(+), 114 deletions(-) delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusHandler.java diff --git a/docsy/content/en/docs/migration/v5-0-migration.md b/docsy/content/en/docs/migration/v5-0-migration.md index c766d5c770..fdf624e29c 100644 --- a/docsy/content/en/docs/migration/v5-0-migration.md +++ b/docsy/content/en/docs/migration/v5-0-migration.md @@ -60,4 +60,5 @@ description: Migrating from v4.7 to v5.0 This also means, that `BulkDependentResource` now does not automatically implement `Creator` and `Deleter` as before. Make sure to implement those interfaces in your bulk dependent resources. You can use also the new helper interface, the [`CRUDBulkDependentResource`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/CRUDBulkDependentResource.java) - what also implement `BulkUpdater` interface. \ No newline at end of file + what also implement `BulkUpdater` interface. +12. `ErrorStatusHandler` is deleted. Just delete the interface from your impl. \ No newline at end of file diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusHandler.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusHandler.java deleted file mode 100644 index c7bd09a930..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.javaoperatorsdk.operator.api.reconciler; - -import io.fabric8.kubernetes.api.model.HasMetadata; - -public interface ErrorStatusHandler

{ - - /** - *

- * Reconciler can implement this interface in order to update the status sub-resource in the case - * an exception in thrown. In that case - * {@link #updateErrorStatus(HasMetadata, Context, Exception)} is called automatically. - *

- * The result of the method call is used to make a status update on the custom resource. This is - * always a sub-resource update request, so no update on custom resource itself (like spec of - * metadata) happens. Note that this update request will also produce an event, and will result in - * a reconciliation if the controller is not generation aware. - *

- * Note that the scope of this feature is only the reconcile method of the reconciler, since there - * should not be updates on custom resource after it is marked for deletion. - * - * @param resource to update the status on - * @param context the current context - * @param e exception thrown from the reconciler - * @return the updated resource - */ - ErrorStatusUpdateControl

updateErrorStatus(P resource, Context

context, Exception e); - -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusUpdateControl.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusUpdateControl.java index 7236d5898b..e9073d613c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusUpdateControl.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusUpdateControl.java @@ -10,6 +10,7 @@ public class ErrorStatusUpdateControl

private final P resource; private boolean noRetry = false; + private final boolean defaultErrorProcessing; public static ErrorStatusUpdateControl patchStatus(T resource) { return new ErrorStatusUpdateControl<>(resource); @@ -19,8 +20,21 @@ public static ErrorStatusUpdateControl noStatusUpdate return new ErrorStatusUpdateControl<>(null); } + /** + * No special processing of the error, the error will be thrown and default error handling will + * apply + */ + public static ErrorStatusUpdateControl defaultErrorProcessing() { + return new ErrorStatusUpdateControl<>(null, true); + } + private ErrorStatusUpdateControl(P resource) { + this(resource, false); + } + + private ErrorStatusUpdateControl(P resource, boolean defaultErrorProcessing) { this.resource = resource; + this.defaultErrorProcessing = defaultErrorProcessing; } /** @@ -29,6 +43,9 @@ private ErrorStatusUpdateControl(P resource) { * @return ErrorStatusUpdateControl */ public ErrorStatusUpdateControl

withNoRetry() { + if (defaultErrorProcessing) { + throw new IllegalStateException("Cannot set no-retry for default error processing"); + } this.noRetry = true; return this; } @@ -41,6 +58,10 @@ public boolean isNoRetry() { return noRetry; } + public boolean isDefaultErrorProcessing() { + return defaultErrorProcessing; + } + /** * If re-scheduled using this method, it is not considered as retry, it effectively cancels retry. * diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java index 40a8a3b407..f271652686 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java @@ -31,4 +31,28 @@ default List prepareEventSources(EventSourceContext

context) { return Collections.emptyList(); } + /** + *

+ * Reconciler can override this method in order to update the status sub-resource in the case an + * exception in thrown. In that case {@link #updateErrorStatus(HasMetadata, Context, Exception)} + * is called automatically. + *

+ * The result of the method call is used to make a status update on the custom resource. This is + * always a sub-resource update request, so no update on custom resource itself (like spec of + * metadata) happens. Note that this update request will also produce an event, and will result in + * a reconciliation if the controller is not generation aware. + *

+ * Note that the scope of this feature is only the reconcile method of the reconciler, since there + * should not be updates on custom resource after it is marked for deletion. + * + * @param resource to update the status on + * @param context the current context + * @param e exception thrown from the reconciler + * @return the updated resource + */ + default ErrorStatusUpdateControl

updateErrorStatus(P resource, Context

context, + Exception e) { + return ErrorStatusUpdateControl.defaultErrorProcessing(); + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java index 2b33133ae4..1ad3b65910 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java @@ -22,7 +22,6 @@ import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.DefaultContext; import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; -import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler; import io.javaoperatorsdk.operator.api.reconciler.RetryInfo; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.Controller; @@ -174,55 +173,46 @@ private PostExecutionControl

reconcileExecution(ExecutionScope

executionSc private PostExecutionControl

handleErrorStatusHandler(P resource, P originalResource, Context

context, Exception e) throws Exception { - if (isErrorStatusHandlerPresent()) { - try { - RetryInfo retryInfo = context.getRetryInfo().orElseGet(() -> new RetryInfo() { - @Override - public int getAttemptCount() { - return 0; - } - @Override - public boolean isLastAttempt() { - // check also if the retry is limited to 0 - return retryConfigurationHasZeroAttempts || - controller.getConfiguration().getRetry() == null; - } - }); - ((DefaultContext

) context).setRetryInfo(retryInfo); - var errorStatusUpdateControl = ((ErrorStatusHandler

) controller.getReconciler()) - .updateErrorStatus(resource, context, e); - - P updatedResource = null; - if (errorStatusUpdateControl.getResource().isPresent()) { - updatedResource = customResourceFacade - .patchStatus(errorStatusUpdateControl.getResource().orElseThrow(), originalResource); - } - if (errorStatusUpdateControl.isNoRetry()) { - PostExecutionControl

postExecutionControl; - if (updatedResource != null) { - postExecutionControl = - PostExecutionControl.customResourceStatusPatched(updatedResource); - } else { - postExecutionControl = PostExecutionControl.defaultDispatch(); - } - errorStatusUpdateControl.getScheduleDelay() - .ifPresent(postExecutionControl::withReSchedule); - return postExecutionControl; - } - } catch (RuntimeException ex) { - log.error("Error during error status handling.", ex); + RetryInfo retryInfo = context.getRetryInfo().orElseGet(() -> new RetryInfo() { + @Override + public int getAttemptCount() { + return 0; } - } - throw e; - } - private boolean isErrorStatusHandlerPresent() { - return controller.getReconciler() instanceof ErrorStatusHandler; - } + @Override + public boolean isLastAttempt() { + // check also if the retry is limited to 0 + return retryConfigurationHasZeroAttempts || + controller.getConfiguration().getRetry() == null; + } + }); + ((DefaultContext

) context).setRetryInfo(retryInfo); + var errorStatusUpdateControl = controller.getReconciler() + .updateErrorStatus(resource, context, e); - private P patchStatusGenerationAware(P resource, P originalResource) { - return customResourceFacade.patchStatus(resource, originalResource); + if (errorStatusUpdateControl.isDefaultErrorProcessing()) { + throw e; + } + + P updatedResource = null; + if (errorStatusUpdateControl.getResource().isPresent()) { + updatedResource = customResourceFacade + .patchStatus(errorStatusUpdateControl.getResource().orElseThrow(), originalResource); + } + if (errorStatusUpdateControl.isNoRetry()) { + PostExecutionControl

postExecutionControl; + if (updatedResource != null) { + postExecutionControl = + PostExecutionControl.customResourceStatusPatched(updatedResource); + } else { + postExecutionControl = PostExecutionControl.defaultDispatch(); + } + errorStatusUpdateControl.getScheduleDelay() + .ifPresent(postExecutionControl::withReSchedule); + return postExecutionControl; + } + throw e; } private PostExecutionControl

createPostExecutionControl(P updatedCustomResource, diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java index 7e80f4aedc..efec8c4228 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java @@ -5,11 +5,11 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; +import java.util.function.Supplier; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatcher; import org.mockito.ArgumentMatchers; import org.mockito.stubbing.Answer; @@ -28,7 +28,6 @@ import io.javaoperatorsdk.operator.api.reconciler.Cleaner; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; -import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler; import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.RetryInfo; @@ -479,7 +478,7 @@ void callErrorStatusHandlerIfImplemented() { reconciler.reconcile = (r, c) -> { throw new IllegalStateException("Error Status Test"); }; - reconciler.errorHandler = (r, ri, e) -> { + reconciler.errorHandler = () -> { testCustomResource.getStatus().setConfigMapStatus(ERROR_MESSAGE); return ErrorStatusUpdateControl.patchStatus(testCustomResource); }; @@ -499,7 +498,7 @@ public boolean isLastAttempt() { }).setResource(testCustomResource)); verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); - verify(((ErrorStatusHandler) reconciler), times(1)).updateErrorStatus(eq(testCustomResource), + verify(reconciler, times(1)).updateErrorStatus(eq(testCustomResource), any(), any()); } @@ -510,7 +509,7 @@ void callErrorStatusHandlerEvenOnFirstError() { reconciler.reconcile = (r, c) -> { throw new IllegalStateException("Error Status Test"); }; - reconciler.errorHandler = (r, ri, e) -> { + reconciler.errorHandler = () -> { testCustomResource.getStatus().setConfigMapStatus(ERROR_MESSAGE); return ErrorStatusUpdateControl.patchStatus(testCustomResource); }; @@ -518,7 +517,7 @@ void callErrorStatusHandlerEvenOnFirstError() { var postExecControl = reconciliationDispatcher.handleExecution( new ExecutionScope(null).setResource(testCustomResource)); verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); - verify(((ErrorStatusHandler) reconciler), times(1)).updateErrorStatus(eq(testCustomResource), + verify(reconciler, times(1)).updateErrorStatus(eq(testCustomResource), any(), any()); assertThat(postExecControl.exceptionDuringExecution()).isTrue(); } @@ -529,7 +528,7 @@ void errorHandlerCanInstructNoRetryWithUpdate() { reconciler.reconcile = (r, c) -> { throw new IllegalStateException("Error Status Test"); }; - reconciler.errorHandler = (r, ri, e) -> { + reconciler.errorHandler = () -> { testCustomResource.getStatus().setConfigMapStatus(ERROR_MESSAGE); return ErrorStatusUpdateControl.patchStatus(testCustomResource).withNoRetry(); }; @@ -537,7 +536,7 @@ void errorHandlerCanInstructNoRetryWithUpdate() { var postExecControl = reconciliationDispatcher.handleExecution( new ExecutionScope(null).setResource(testCustomResource)); - verify(((ErrorStatusHandler) reconciler), times(1)).updateErrorStatus(eq(testCustomResource), + verify(reconciler, times(1)).updateErrorStatus(eq(testCustomResource), any(), any()); verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); assertThat(postExecControl.exceptionDuringExecution()).isFalse(); @@ -549,7 +548,7 @@ void errorHandlerCanInstructNoRetryNoUpdate() { reconciler.reconcile = (r, c) -> { throw new IllegalStateException("Error Status Test"); }; - reconciler.errorHandler = (r, ri, e) -> { + reconciler.errorHandler = () -> { testCustomResource.getStatus().setConfigMapStatus(ERROR_MESSAGE); return ErrorStatusUpdateControl.noStatusUpdate().withNoRetry(); }; @@ -557,7 +556,7 @@ void errorHandlerCanInstructNoRetryNoUpdate() { var postExecControl = reconciliationDispatcher.handleExecution( new ExecutionScope(null).setResource(testCustomResource)); - verify(((ErrorStatusHandler) reconciler), times(1)).updateErrorStatus(eq(testCustomResource), + verify(reconciler, times(1)).updateErrorStatus(eq(testCustomResource), any(), any()); verify(customResourceFacade, times(0)).patchStatus(eq(testCustomResource), any()); assertThat(postExecControl.exceptionDuringExecution()).isFalse(); @@ -570,13 +569,13 @@ void errorStatusHandlerCanPatchResource() { throw new IllegalStateException("Error Status Test"); }; reconciler.errorHandler = - (r, ri, e) -> ErrorStatusUpdateControl.patchStatus(testCustomResource); + () -> ErrorStatusUpdateControl.patchStatus(testCustomResource); reconciliationDispatcher.handleExecution( new ExecutionScope(null).setResource(testCustomResource)); verify(customResourceFacade, times(1)).patchStatus(eq(testCustomResource), any()); - verify(((ErrorStatusHandler) reconciler), times(1)).updateErrorStatus(eq(testCustomResource), + verify(reconciler, times(1)).updateErrorStatus(eq(testCustomResource), any(), any()); } @@ -592,16 +591,14 @@ void ifRetryLimitedToZeroMaxAttemptsErrorHandlerGetsCorrectLastAttempt() { reconciler.reconcile = (r, c) -> { throw new IllegalStateException("Error Status Test"); }; - var mockErrorHandler = mock(ErrorStatusHandler.class); - when(mockErrorHandler.updateErrorStatus(any(), any(), any())) - .thenReturn(ErrorStatusUpdateControl.noStatusUpdate()); - reconciler.errorHandler = mockErrorHandler; + + reconciler.errorHandler = () -> ErrorStatusUpdateControl.noStatusUpdate(); reconciliationDispatcher.handleExecution( new ExecutionScope(null).setResource(testCustomResource)); - verify(mockErrorHandler, times(1)).updateErrorStatus(any(), - ArgumentMatchers.argThat((ArgumentMatcher>) context -> { + verify(reconciler, times(1)).updateErrorStatus(any(), + ArgumentMatchers.argThat(context -> { var retryInfo = context.getRetryInfo().orElseThrow(); return retryInfo.isLastAttempt(); }), any()); @@ -651,7 +648,7 @@ void reSchedulesFromErrorHandler() { throw new IllegalStateException("Error Status Test"); }; reconciler.errorHandler = - (r, ri, e) -> ErrorStatusUpdateControl.noStatusUpdate() + () -> ErrorStatusUpdateControl.noStatusUpdate() .rescheduleAfter(delay); var res = reconciliationDispatcher.handleExecution( @@ -691,12 +688,11 @@ public ExecutionScope executionScopeWithCREvent(T res } private class TestReconciler - implements Reconciler, Cleaner, - ErrorStatusHandler { + implements Reconciler, Cleaner { private BiFunction> reconcile; private BiFunction cleanup; - private ErrorStatusHandler errorHandler; + private Supplier errorHandler; @Override public UpdateControl reconcile(TestCustomResource resource, @@ -719,7 +715,7 @@ public DeleteControl cleanup(TestCustomResource resource, Context context) { public ErrorStatusUpdateControl updateErrorStatus( TestCustomResource resource, Context context, Exception e) { - return errorHandler != null ? errorHandler.updateErrorStatus(resource, context, e) + return errorHandler != null ? errorHandler.get() : ErrorStatusUpdateControl.noStatusUpdate(); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java index 0d6d63024f..c54434cf6a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java @@ -21,8 +21,7 @@ dependsOn = SECRET_NAME)}) @ControllerConfiguration public class DependentResourceCrossRefReconciler - implements Reconciler, - ErrorStatusHandler { + implements Reconciler { public static final String SECRET_NAME = "secret"; private final AtomicInteger numberOfExecutions = new AtomicInteger(0); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java index 4abf982e0f..b0c120dad2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java @@ -10,8 +10,7 @@ @ControllerConfiguration public class ErrorStatusHandlerTestReconciler - implements Reconciler, TestExecutionInfoProvider, - ErrorStatusHandler { + implements Reconciler, TestExecutionInfoProvider { private static final Logger log = LoggerFactory.getLogger(ErrorStatusHandlerTestReconciler.class); private final AtomicInteger numberOfExecutions = new AtomicInteger(0); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java index 569e2cafb1..a4162c09d2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java @@ -16,8 +16,7 @@ @ControllerConfiguration public class DependentGarbageCollectionTestReconciler - implements Reconciler, - ErrorStatusHandler { + implements Reconciler { private KubernetesClient kubernetesClient; private volatile boolean errorOccurred = false; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java index eaeb86cfe2..8cd64b95db 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java @@ -19,7 +19,7 @@ */ @ControllerConfiguration() public class JobReconciler - implements Reconciler, ErrorStatusHandler { + implements Reconciler { private static final String JOB_CLUSTER_INDEX = "job-cluster-index"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java index b0d48bebfd..a2197c48a1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java @@ -9,7 +9,6 @@ import io.javaoperatorsdk.operator.StandaloneDependentResourceIT; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler; import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; @@ -20,8 +19,7 @@ @ControllerConfiguration public class StandaloneDependentTestReconciler - implements Reconciler, - ErrorStatusHandler { + implements Reconciler { private volatile boolean errorOccurred = false; DeploymentDependentResource deploymentDependent; diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java index 4a6f4f4d45..7e229ca4bd 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java @@ -22,7 +22,7 @@ }) @ControllerConfiguration public class MySQLSchemaReconciler - implements Reconciler, ErrorStatusHandler { + implements Reconciler { static final Logger log = LoggerFactory.getLogger(MySQLSchemaReconciler.class); diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index f9664760f5..d8b64db9fd 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -26,7 +26,7 @@ labelSelector = WebPageDependentsWorkflowReconciler.DEPENDENT_RESOURCE_LABEL_SELECTOR) @SuppressWarnings("unused") public class WebPageDependentsWorkflowReconciler - implements Reconciler, ErrorStatusHandler { + implements Reconciler { public static final String DEPENDENT_RESOURCE_LABEL_SELECTOR = "!low-level"; diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java index 32811251d7..df3cae354f 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java @@ -20,7 +20,7 @@ }) @ControllerConfiguration public class WebPageManagedDependentsReconciler - implements Reconciler, ErrorStatusHandler, Cleaner { + implements Reconciler, Cleaner { public static final String SELECTOR = "managed"; diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index 6669d3a1f5..68f55108db 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -28,7 +28,7 @@ @RateLimited(maxReconciliations = 2, within = 3) @ControllerConfiguration public class WebPageReconciler - implements Reconciler, ErrorStatusHandler { + implements Reconciler { public static final String INDEX_HTML = "index.html"; diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java index 66f853e841..4b71f104f6 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java @@ -6,7 +6,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler; import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; @@ -31,7 +30,7 @@ */ @ControllerConfiguration public class WebPageStandaloneDependentsReconciler - implements Reconciler, ErrorStatusHandler { + implements Reconciler { private final Workflow workflow; From bb125775e5cea76a5291886dc55567af78f5d901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 19 Jun 2024 22:03:47 +0200 Subject: [PATCH 52/96] improve: dependent configuration improvements - context independent (#2389) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun --- .../cache/sample/AbstractTestReconciler.java | 5 +- ...oundedCacheClusterScopeTestReconciler.java | 4 + .../BoundedCacheTestReconciler.java | 4 + docs/documentation/v5-0-migration.md | 65 --------- .../api/config/BaseConfigurationService.java | 11 +- .../api/config/ControllerConfiguration.java | 5 +- .../ControllerConfigurationOverrider.java | 2 +- .../ResolvedControllerConfiguration.java | 15 +- .../api/config/ResourceConfiguration.java | 5 +- .../dependent/ConfigurationConverter.java | 7 +- ...ependentResourceConfigurationResolver.java | 35 +---- .../dependent/DependentResourceSpec.java | 21 +-- .../informer/InformerConfiguration.java | 130 ++++++++++------- .../operator/api/reconciler/Constants.java | 12 +- .../dependent/DependentResourceFactory.java | 19 ++- ....java => ConfiguredDependentResource.java} | 3 +- .../operator/processing/GroupVersionKind.java | 22 +++ ...actEventSourceHolderDependentResource.java | 29 +--- .../PerResourcePollingDependentResource.java | 3 +- .../external/PollingDependentResource.java | 4 +- .../CRUDKubernetesDependentResource.java | 4 + .../GenericKubernetesDependentResource.java | 13 +- .../dependent/kubernetes/InformerConfig.java | 86 +++++++++++ .../kubernetes/KubernetesDependent.java | 61 +------- .../KubernetesDependentConverter.java | 102 ++++++++----- .../KubernetesDependentInformerConfig.java | 101 +++++++++++++ ...ernetesDependentInformerConfigBuilder.java | 93 ++++++++++++ .../KubernetesDependentResource.java | 121 +++++---------- .../KubernetesDependentResourceConfig.java | 89 ++--------- ...ernetesDependentResourceConfigBuilder.java | 65 ++------- .../GenericResourceUpdaterMatcher.java | 3 +- .../workflow/AbstractWorkflowExecutor.java | 6 +- .../workflow/DefaultManagedWorkflow.java | 4 +- .../processing/event/EventSourceManager.java | 4 +- .../controller/ControllerEventSource.java | 3 +- .../source/informer/InformerEventSource.java | 15 +- .../source/informer/InformerManager.java | 79 +++++----- .../informer/ManagedInformerEventSource.java | 10 +- .../event/source/informer/Mappers.java | 9 ++ .../PerResourcePollingConfiguration.java | 7 +- ...erResourcePollingConfigurationBuilder.java | 8 +- .../PerResourcePollingEventSource.java | 9 +- .../source/polling/PollingConfiguration.java | 5 +- .../polling/PollingConfigurationBuilder.java | 8 +- .../source/polling/PollingEventSource.java | 8 +- .../ControllerConfigurationOverriderTest.java | 138 +++++++++--------- ...dentResourceConfigurationResolverTest.java | 79 +++++----- .../processing/GroupVersionKindTest.java | 19 +++ .../GenericKubernetesResourceMatcherTest.java | 2 +- .../GenericResourceUpdaterMatcherTest.java | 8 +- .../AbstractWorkflowExecutorTest.java | 19 ++- .../workflow/ManagedWorkflowTestUtils.java | 4 +- .../source/AbstractEventSourceTestBase.java | 11 +- .../controller/ControllerEventSourceTest.java | 18 +-- .../informer/InformerEventSourceTest.java | 11 +- .../polling/PollingEventSourceTest.java | 2 +- .../WorkflowExplicitInvocationIT.java | 4 +- .../config/BaseConfigurationServiceTest.java | 73 +++------ ...ConfigMapDeleterBulkDependentResource.java | 5 - .../ReadOnlyBulkDependentResource.java | 8 +- .../ChangeNamespaceTestReconciler.java | 6 +- ...ClusterScopedCustomResourceReconciler.java | 12 +- .../ComplexDependentReconciler.java | 12 +- .../dependent/BaseDependentResource.java | 5 - ...CreateUpdateEventFilterTestReconciler.java | 2 +- ...stomMappingConfigMapDependentResource.java | 17 ++- .../FilteredDependentConfigMap.java | 3 +- ...ericEventSourceRegistrationReconciler.java | 8 +- .../ExternalStateDependentReconciler.java | 3 +- .../ExternalStateReconciler.java | 3 +- .../ExternalStateBulkDependentReconciler.java | 4 +- .../sample/filter/FilterTestReconciler.java | 2 +- .../ConfigMapGenericKubernetesDependent.java | 2 + ...cKubernetesResourceHandlingReconciler.java | 3 +- ...formerEventSourceTestCustomReconciler.java | 2 +- .../ConfigMapDependentResource.java | 3 +- .../MultipleDependentResourceReconciler.java | 7 +- ...ntResourceWithDiscriminatorReconciler.java | 7 +- ...dentSameTypeNoDiscriminatorReconciler.java | 6 +- ...pleManagedDependentResourceReconciler.java | 6 +- ...edExternalDependentResourceReconciler.java | 3 +- ...ultipleSecondaryEventSourceReconciler.java | 3 +- .../ConfigMapDependentResource1.java | 3 +- .../ConfigMapDependentResource2.java | 3 +- ...DependentPrimaryIndexerTestReconciler.java | 55 ++++--- .../PrimaryIndexerTestReconciler.java | 2 +- .../primarytosecondary/JobReconciler.java | 4 +- ...PrimaryToSecondaryDependentReconciler.java | 5 +- .../sample/readonly/ReadOnlyDependent.java | 2 + .../restart/ConfigMapDependentResource.java | 3 +- .../dependent/SchemaDependentResource.java | 11 +- .../dependent/SecretDependentResource.java | 5 + .../sample/DeploymentDependentResource.java | 4 +- .../sample/ServiceDependentResource.java | 4 +- .../operator/sample/WebappReconciler.java | 2 +- .../WebPageDependentsWorkflowReconciler.java | 6 +- .../operator/sample/WebPageReconciler.java | 8 +- ...WebPageStandaloneDependentsReconciler.java | 5 +- .../ConfigMapDependentResource.java | 3 +- .../DeploymentDependentResource.java | 3 +- .../IngressDependentResource.java | 4 +- .../ServiceDependentResource.java | 3 +- 102 files changed, 1067 insertions(+), 902 deletions(-) delete mode 100644 docs/documentation/v5-0-migration.md rename operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/{DependentResourceConfigurator.java => ConfiguredDependentResource.java} (76%) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfig.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfigBuilder.java diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java index 18cd486fb2..98101d1243 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java @@ -77,7 +77,7 @@ public List prepareEventSources( boundedItemStore(new KubernetesClientBuilder().build(), ConfigMap.class, Duration.ofMinutes(1), 1); // setting max size for testing purposes - var es = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) + var es = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, primaryClass()) .withItemStore(boundedItemStore) .withSecondaryToPrimaryMapper( Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), @@ -104,4 +104,7 @@ public static BoundedItemStore boundedItemStore( .build(); return CaffeineBoundedItemStores.boundedItemStore(client, rClass, cache); } + + protected abstract Class

primaryClass(); + } diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/clusterscope/BoundedCacheClusterScopeTestReconciler.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/clusterscope/BoundedCacheClusterScopeTestReconciler.java index a154659164..84448fc9d8 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/clusterscope/BoundedCacheClusterScopeTestReconciler.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/clusterscope/BoundedCacheClusterScopeTestReconciler.java @@ -7,4 +7,8 @@ public class BoundedCacheClusterScopeTestReconciler extends AbstractTestReconciler { + @Override + protected Class primaryClass() { + return BoundedCacheClusterScopeTestCustomResource.class; + } } diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/namespacescope/BoundedCacheTestReconciler.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/namespacescope/BoundedCacheTestReconciler.java index 211877b361..6b95665585 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/namespacescope/BoundedCacheTestReconciler.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/namespacescope/BoundedCacheTestReconciler.java @@ -7,4 +7,8 @@ public class BoundedCacheTestReconciler extends AbstractTestReconciler { + @Override + protected Class primaryClass() { + return BoundedCacheTestCustomResource.class; + } } diff --git a/docs/documentation/v5-0-migration.md b/docs/documentation/v5-0-migration.md deleted file mode 100644 index a1c1b66120..0000000000 --- a/docs/documentation/v5-0-migration.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: Migrating from v4.7 to v5.0 -description: Migrating from v4.7 to v5.0 -layout: docs -permalink: /docs/v5-0-migration ---- - -# Migrating from v4.7 to v5.0 - -## API Tweaks - -1. [Result of managed dependent resources](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java#L55-L57) - is not `Optional` anymore. In case you use this result, simply use the result - objects directly. -2. `EventSourceInitializer` is not a separate interface anymore. It is part of the `Reconciler` interface with a - default implementation. You can simply remove this interface from your reconciler. The - [`EventSourceUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java#L11-L11) - now contains all the utility methods used for event sources naming that were previously defined in - the `EventSourceInitializer` interface. -3. Similarly, the `EventSourceProvider` interface has been remove, replaced by explicit initialization of the associated - event source on `DependentResource` via the ` - Optional> eventSource(EventSourceContext

eventSourceContext)` method. -4. Event sources are now explicitly named (via the `name` method of the `EventSource` interface). Built-in event sources - implementation have been updated to allow you to specify a name when instantiating them. If you don't provide a name - for your `EventSource` implementation (for example, by using its default, no-arg constructor), one will be - automatically generated. This simplifies the API to define event source to - `List prepareEventSources(EventSourceContext

context)`. - !!! IMPORTANT !!! - If you use dynamic registration of event sources, be sure to name your event sources explicitly as letting JOSDK name - them automatically might result in duplicated event sources being registered as JOSDK relies on the name to identify - event sources and concurrent, dynamic registration might lead to identical event sources having different generated - names, thus leading JOSDK to consider them as different and hence, register them multiple times. -5. Updates through `UpdateControl` now - use [Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/server-side-apply/) by default to add - the finalizer and for all - the patch operations in `UpdateControl`. The update operations were removed. If you do not wish to use SSA, you can - deactivate the feature using `ConfigurationService.useSSAToPatchPrimaryResource` and - related `ConfigurationServiceOverrider.withUseSSAToPatchPrimaryResource`. - - !!! IMPORTANT !!! - - See known issues with migration from non-SSA to SSA based status updates here: - [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L71-L82) - where it is demonstrated. Also, the related part of - a [workaround](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java#L110-L116). - -6. `ManagedDependentResourceContext` has been renamed to `ManagedWorkflowAndDependentResourceContext` and is accessed - via the accordingly renamed `managedWorkflowAndDependentResourceContext` method. -7. `ResourceDiscriminator` was removed. In most of the cases you can just delete the discriminator, everything should - work without it by default. To optimize and handle special cases see the relevant section - in [Dependent Resource documentation](/docs/dependent-resources#multiple-dependent-resources-of-same-type). -8. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed, - use `Operator.stop(Duration)` instead. -9. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead -10. Automated observed generation handling feature was removed (`ObservedGenerationAware` interface - and `ObservedGenerationAwareStatus` class were deleted). Manually handling observed generation is fairly easy to do - in your reconciler, however, it cannot be done automatically when using SSA. We therefore removed the feature since - it would have been confusing to have a different behavior for SSA and non-SSA cases. For an example of how to do - observed generation handling manually in your reconciler, see - [this sample](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java). -11. `BulkDependentResource` now supports [read-only mode](https://github.com/operator-framework/java-operator-sdk/issues/2233). - This also means, that `BulkDependentResource` now does not automatically implement `Creator` and `Deleter` as before. - Make sure to implement those interfaces in your bulk dependent resources. You can use also the new helper interface, the - [`CRUDBulkDependentResource`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/CRUDBulkDependentResource.java) - what also implement `BulkUpdater` interface. \ No newline at end of file diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index b496a9b1b7..70c86a2a94 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -17,6 +17,7 @@ import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.Utils.Configurator; +import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.Constants; @@ -194,7 +195,7 @@ public boolean handleExceptionsInReconciler() { @SuppressWarnings({"unchecked", "rawtypes"}) private static List dependentResources( Workflow annotation, - ControllerConfiguration parent) { + ControllerConfiguration controllerConfiguration) { final var dependents = annotation.dependents(); @@ -213,7 +214,7 @@ private static List dependentResources( "A DependentResource named '" + dependentName + "' already exists: " + spec); } - final var name = parent.getName(); + final var name = controllerConfiguration.getName(); var eventSourceName = dependent.useEventSourceWithName(); eventSourceName = Constants.NO_VALUE_SET.equals(eventSourceName) ? null : eventSourceName; @@ -225,6 +226,12 @@ private static List dependentResources( Utils.instantiate(dependent.deletePostcondition(), Condition.class, context), Utils.instantiate(dependent.activationCondition(), Condition.class, context), eventSourceName); + + // extract potential configuration + DependentResourceConfigurationResolver.configureSpecFromConfigured(spec, + controllerConfiguration, + dependentType); + specsMap.put(dependentName, spec); } return specsMap.values().stream().toList(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java index 2031283f37..aa74d7ea1a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java @@ -6,6 +6,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.ReconcilerUtils; +import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval; import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; @@ -71,7 +72,6 @@ default Optional maxReconciliationInterval() { return Optional.of(Duration.ofHours(MaxReconciliationInterval.DEFAULT_INTERVAL)); } - @SuppressWarnings("unused") ConfigurationService getConfigurationService(); @SuppressWarnings("unchecked") @@ -86,7 +86,7 @@ default Class

getResourceClass() { @SuppressWarnings("unused") default Set getEffectiveNamespaces() { - return ResourceConfiguration.super.getEffectiveNamespaces(getConfigurationService()); + return ResourceConfiguration.super.getEffectiveNamespaces(this); } /** @@ -100,4 +100,5 @@ default String fieldManager() { return getName(); } + C getConfigurationFor(DependentResourceSpec spec); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java index ad66b8b563..315ed29c7b 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java @@ -19,7 +19,7 @@ import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES_SET; import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE_SET; -@SuppressWarnings({"rawtypes", "unused"}) +@SuppressWarnings({"rawtypes", "unused", "UnusedReturnValue"}) public class ControllerConfigurationOverrider { private String finalizer; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java index af96604591..9ecf24adc7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java @@ -9,7 +9,6 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.informers.cache.ItemStore; -import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationProvider; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; @@ -22,8 +21,7 @@ @SuppressWarnings("rawtypes") public class ResolvedControllerConfiguration

extends DefaultResourceConfiguration

- implements io.javaoperatorsdk.operator.api.config.ControllerConfiguration

, - DependentResourceConfigurationProvider { + implements io.javaoperatorsdk.operator.api.config.ControllerConfiguration

{ private final String name; private final boolean generationAware; @@ -168,8 +166,15 @@ public ConfigurationService getConfigurationService() { } @Override - public Object getConfigurationFor(DependentResourceSpec spec) { - return configurations.get(spec); + @SuppressWarnings("unchecked") + public C getConfigurationFor(DependentResourceSpec spec) { + // first check if there's an overridden configuration at the controller level + var config = configurations.get(spec); + if (config == null) { + // if not, check the spec for configuration + config = spec.getConfiguration().orElse(null); + } + return (C) config; } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java index d94504f50f..b4677a8de6 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java @@ -111,11 +111,12 @@ static Set ensureValidNamespaces(Collection namespaces) { * * @return a Set of namespace names the associated controller will watch */ - default Set getEffectiveNamespaces(ConfigurationService configurationService) { + default Set getEffectiveNamespaces(ControllerConfiguration controllerConfiguration) { var targetNamespaces = getNamespaces(); if (watchCurrentNamespace()) { final String namespace = - configurationService.getKubernetesClient().getConfiguration().getNamespace(); + controllerConfiguration.getConfigurationService().getKubernetesClient().getConfiguration() + .getNamespace(); if (namespace == null) { throw new OperatorException( "Couldn't retrieve the currently connected namespace. Make sure it's correctly set in your ~/.kube/config file, using, e.g. 'kubectl config set-context --namespace='"); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/ConfigurationConverter.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/ConfigurationConverter.java index 68e0f521de..f0327514ae 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/ConfigurationConverter.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/ConfigurationConverter.java @@ -3,10 +3,9 @@ import java.lang.annotation.Annotation; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DependentResourceConfigurator; -public interface ConfigurationConverter> { +public interface ConfigurationConverter { - C configFrom(A configAnnotation, ControllerConfiguration parentConfiguration, - Class originatingClass); + C configFrom(A configAnnotation, DependentResourceSpec spec, + ControllerConfiguration parentConfiguration); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java index 06ae7ec683..471b0f6a8e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java @@ -8,7 +8,6 @@ import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DependentResourceConfigurator; @SuppressWarnings({"rawtypes", "unchecked"}) public class DependentResourceConfigurationResolver { @@ -20,39 +19,18 @@ private DependentResourceConfigurationResolver() {} private static final Map, ConfigurationConverter> knownConverters = new HashMap<>(); - public static > void configure( - DependentResource dependentResource, DependentResourceSpec spec, C parentConfiguration) { - if (dependentResource instanceof DependentResourceConfigurator configurator) { - final var config = configurationFor(spec, parentConfiguration); - configurator.configureWith(config); - } - } - - public static > Object configurationFor( - DependentResourceSpec spec, C parentConfiguration) { - // first check if the parent configuration has potentially already resolved the configuration - if (parentConfiguration instanceof DependentResourceConfigurationProvider provider) { - final var configuration = provider.getConfigurationFor(spec); - if (configuration != null) { - return configuration; - } - } - - // find Configured-annotated class if it exists - return extractConfigurationFromConfigured(spec.getDependentResourceClass(), - parentConfiguration); - } - - public static > Object extractConfigurationFromConfigured( - Class dependentResourceClass, C parentConfiguration) { + public static > void configureSpecFromConfigured( + DependentResourceSpec spec, + C parentConfiguration, + Class dependentResourceClass) { var converterAnnotationPair = converters.get(dependentResourceClass); Annotation configAnnotation; if (converterAnnotationPair == null) { var configuredClassPair = getConfigured(dependentResourceClass); if (configuredClassPair == null) { - return null; + return; } // check if we already have a converter registered for the found Configured annotated class @@ -76,7 +54,8 @@ public static > Object // always called even if the annotation is null so that implementations can provide default // values - return converter.configFrom(configAnnotation, parentConfiguration, dependentResourceClass); + final var config = converter.configFrom(configAnnotation, spec, parentConfiguration); + spec.setNullableConfiguration(config); } private static ConfiguredClassPair getConfigured( diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceSpec.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceSpec.java index 1fcd0709fb..accccb3f6e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceSpec.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceSpec.java @@ -8,23 +8,17 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; -public class DependentResourceSpec { +public class DependentResourceSpec { private final Class> dependentResourceClass; - private final String name; - private final Set dependsOn; - private final Condition readyCondition; - private final Condition reconcileCondition; - private final Condition deletePostCondition; - private final Condition activationCondition; - private final String useEventSourceWithName; + private C nullableConfiguration; public DependentResourceSpec(Class> dependentResourceClass, String name, Set dependsOn, Condition readyCondition, @@ -62,7 +56,7 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - DependentResourceSpec that = (DependentResourceSpec) o; + DependentResourceSpec that = (DependentResourceSpec) o; return name.equals(that.name); } @@ -98,4 +92,13 @@ public Condition getActivationCondition() { public Optional getUseEventSourceWithName() { return Optional.ofNullable(useEventSourceWithName); } + + public Optional getConfiguration() { + return Optional.ofNullable(nullableConfiguration); + } + + protected void setNullableConfiguration(C configuration) { + this.nullableConfiguration = configuration; + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java index 5371975ec5..6fb37953df 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java @@ -7,10 +7,10 @@ import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.informers.cache.ItemStore; +import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.DefaultResourceConfiguration; import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; import io.javaoperatorsdk.operator.api.config.Utils; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.processing.GroupVersionKind; import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; @@ -20,21 +20,26 @@ import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES_SET; +import static io.javaoperatorsdk.operator.api.reconciler.Constants.*; public interface InformerConfiguration extends ResourceConfiguration { + boolean DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE = true; + class DefaultInformerConfiguration extends DefaultResourceConfiguration implements InformerConfiguration { + private final String name; private final PrimaryToSecondaryMapper primaryToSecondaryMapper; private final SecondaryToPrimaryMapper secondaryToPrimaryMapper; private final boolean followControllerNamespaceChanges; private final OnDeleteFilter onDeleteFilter; private final GroupVersionKind groupVersionKind; - protected DefaultInformerConfiguration(String labelSelector, + protected DefaultInformerConfiguration( + String name, + String labelSelector, Class resourceClass, GroupVersionKind groupVersionKind, PrimaryToSecondaryMapper primaryToSecondaryMapper, @@ -47,6 +52,7 @@ protected DefaultInformerConfiguration(String labelSelector, ItemStore itemStore, Long informerListLimit) { super(resourceClass, namespaces, labelSelector, onAddFilter, onUpdateFilter, genericFilter, itemStore, informerListLimit); + this.name = name; this.followControllerNamespaceChanges = followControllerNamespaceChanges; this.groupVersionKind = groupVersionKind; this.primaryToSecondaryMapper = primaryToSecondaryMapper; @@ -75,9 +81,28 @@ public

PrimaryToSecondaryMapper

getPrimaryToSecondary return (PrimaryToSecondaryMapper

) primaryToSecondaryMapper; } + @Override public Optional getGroupVersionKind() { return Optional.ofNullable(groupVersionKind); } + + @Override + public String name() { + return name; + } + + public boolean inheritsNamespacesFromController() { + return InformerConfiguration.inheritsNamespacesFromController(getNamespaces()); + } + + @Override + public Set getEffectiveNamespaces(ControllerConfiguration controllerConfiguration) { + if (inheritsNamespacesFromController()) { + return controllerConfiguration.getEffectiveNamespaces(); + } else { + return super.getEffectiveNamespaces(controllerConfiguration); + } + } } /** @@ -117,23 +142,31 @@ public Optional getGroupVersionKind() { Optional getGroupVersionKind(); - @SuppressWarnings("unused") + String name(); + + static boolean inheritsNamespacesFromController(Set namespaces) { + return SAME_AS_CONTROLLER_NAMESPACES_SET.equals(namespaces); + } + + @SuppressWarnings({"unused", "UnusedReturnValue"}) class InformerConfigurationBuilder { private final Class resourceClass; private final GroupVersionKind groupVersionKind; + private final Class primaryResourceClass; + private String name; private PrimaryToSecondaryMapper primaryToSecondaryMapper; private SecondaryToPrimaryMapper secondaryToPrimaryMapper; - private Set namespaces; + private Set namespaces = SAME_AS_CONTROLLER_NAMESPACES_SET; private String labelSelector; private OnAddFilter onAddFilter; private OnUpdateFilter onUpdateFilter; private OnDeleteFilter onDeleteFilter; private GenericFilter genericFilter; - private boolean inheritControllerNamespacesOnChange = false; private ItemStore itemStore; private Long informerListLimit; - private final Class primaryResourceClass; + private boolean followControllerNamespacesOnChange = + DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; private InformerConfigurationBuilder(Class resourceClass, Class primaryResourceClass) { @@ -153,6 +186,11 @@ private InformerConfigurationBuilder(Class resourceClass, this.primaryResourceClass = primaryResourceClass; } + public InformerConfigurationBuilder withName(String name) { + this.name = name; + return this; + } + public

InformerConfigurationBuilder withPrimaryToSecondaryMapper( PrimaryToSecondaryMapper

primaryToSecondaryMapper) { this.primaryToSecondaryMapper = primaryToSecondaryMapper; @@ -187,25 +225,22 @@ public InformerConfigurationBuilder withNamespaces(Set namespaces) { public InformerConfigurationBuilder withNamespaces(Set namespaces, boolean followChanges) { this.namespaces = namespaces != null ? namespaces : DEFAULT_NAMESPACES_SET; - this.inheritControllerNamespacesOnChange = true; + this.followControllerNamespacesOnChange = followChanges; return this; } - /** - * Configures the informer to watch and track the same namespaces as the parent - * {@link io.javaoperatorsdk.operator.processing.Controller}, meaning that the informer will be - * restarted to watch the new namespaces if the parent controller's namespace configuration - * changes. - * - * @param context {@link EventSourceContext} from which the parent - * {@link io.javaoperatorsdk.operator.processing.Controller}'s configuration is retrieved - * @param

the primary resource type associated with the parent controller - * @return the builder instance so that calls can be chained fluently - */ - public

InformerConfigurationBuilder withNamespacesInheritedFromController( - EventSourceContext

context) { - namespaces = context.getControllerConfiguration().getEffectiveNamespaces(); - this.inheritControllerNamespacesOnChange = true; + public

InformerConfigurationBuilder withNamespacesInheritedFromController() { + this.namespaces = SAME_AS_CONTROLLER_NAMESPACES_SET; + return this; + } + + public

InformerConfigurationBuilder withWatchAllNamespaces() { + this.namespaces = WATCH_ALL_NAMESPACE_SET; + return this; + } + + public

InformerConfigurationBuilder withWatchCurrentNamespace() { + this.namespaces = WATCH_CURRENT_NAMESPACE_SET; return this; } @@ -217,8 +252,9 @@ public

InformerConfigurationBuilder withNamespacesInh * controller's namespaces are reconfigured, {@code false} otherwise * @return the builder instance so that calls can be chained fluently */ - public InformerConfigurationBuilder followNamespaceChanges(boolean followChanges) { - this.inheritControllerNamespacesOnChange = followChanges; + public InformerConfigurationBuilder followControllerNamespacesOnChange( + boolean followChanges) { + this.followControllerNamespacesOnChange = followChanges; return this; } @@ -267,13 +303,28 @@ public InformerConfigurationBuilder withInformerListLimit(Long informerListLi return this; } + public String getName() { + return name; + } + + public SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { + return secondaryToPrimaryMapper; + } + public InformerConfiguration build() { - return new DefaultInformerConfiguration<>(labelSelector, resourceClass, groupVersionKind, + if (groupVersionKind != null + && !GenericKubernetesResource.class.isAssignableFrom(resourceClass)) { + throw new IllegalStateException( + "If GroupVersionKind is set the resource type must be GenericKubernetesDependentResource"); + } + + return new DefaultInformerConfiguration<>(name, labelSelector, resourceClass, + groupVersionKind, primaryToSecondaryMapper, Objects.requireNonNullElse(secondaryToPrimaryMapper, Mappers.fromOwnerReferences(HasMetadata.getApiVersion(primaryResourceClass), HasMetadata.getKind(primaryResourceClass), false)), - namespaces, inheritControllerNamespacesOnChange, onAddFilter, onUpdateFilter, + namespaces, followControllerNamespacesOnChange, onAddFilter, onUpdateFilter, onDeleteFilter, genericFilter, itemStore, informerListLimit); } } @@ -283,31 +334,6 @@ static InformerConfigurationBuilder from( return new InformerConfigurationBuilder<>(resourceClass, primaryResourceClass); } - /** - * Creates a configuration builder that inherits namespaces from the controller and follows - * namespaces changes. - * - * @param resourceClass secondary resource class - * @param eventSourceContext of the initializer - * @return builder - * @param secondary resource type - */ - static InformerConfigurationBuilder from( - Class resourceClass, EventSourceContext eventSourceContext) { - return new InformerConfigurationBuilder<>(resourceClass, - eventSourceContext.getPrimaryResourceClass()) - .withNamespacesInheritedFromController(eventSourceContext); - } - - /** - * For the case when want to use {@link GenericKubernetesResource} - */ - static InformerConfigurationBuilder from( - GroupVersionKind groupVersionKind, EventSourceContext eventSourceContext) { - return new InformerConfigurationBuilder(groupVersionKind, - eventSourceContext.getPrimaryResourceClass()) - .withNamespacesInheritedFromController(eventSourceContext); - } static InformerConfigurationBuilder from( GroupVersionKind groupVersionKind, Class primaryResourceClass) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Constants.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Constants.java index 9876fda558..594fcddd09 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Constants.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Constants.java @@ -5,21 +5,23 @@ public final class Constants { - public static final Set DEFAULT_NAMESPACES_SET = + public static final String WATCH_CURRENT_NAMESPACE = "JOSDK_WATCH_CURRENT"; + public static final String WATCH_ALL_NAMESPACES = "JOSDK_ALL_NAMESPACES"; + public static final String SAME_AS_CONTROLLER = "JOSDK_SAME_AS_CONTROLLER"; + + public static final Set WATCH_ALL_NAMESPACE_SET = Collections.singleton(Constants.WATCH_ALL_NAMESPACES); public static final Set WATCH_CURRENT_NAMESPACE_SET = Collections.singleton(Constants.WATCH_CURRENT_NAMESPACE); - public static final Set SAME_AS_CONTROLLER_NAMESPACES_SET = Collections.singleton(Constants.SAME_AS_CONTROLLER); + public static final Set DEFAULT_NAMESPACES_SET = WATCH_ALL_NAMESPACE_SET; + public static final String NO_VALUE_SET = ""; public static final long NO_LONG_VALUE_SET = -1L; - public static final String WATCH_CURRENT_NAMESPACE = "JOSDK_WATCH_CURRENT"; - public static final String WATCH_ALL_NAMESPACES = "JOSDK_ALL_NAMESPACES"; public static final long NO_MAX_RECONCILIATION_INTERVAL = -1L; - public static final String SAME_AS_CONTROLLER = "JOSDK_SAME_AS_CONTROLLER"; public static final String RESOURCE_GVK_KEY = "josdk.resource.gvk"; public static final String CONTROLLER_NAME = "controller.name"; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceFactory.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceFactory.java index e9e47f6d97..105d2b6c75 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceFactory.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceFactory.java @@ -3,19 +3,28 @@ import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; - -import static io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver.configure; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; @SuppressWarnings({"rawtypes", "unchecked"}) public interface DependentResourceFactory> { DependentResourceFactory DEFAULT = new DependentResourceFactory() {}; - default DependentResource createFrom(DependentResourceSpec spec, C configuration) { + default DependentResource createFrom(DependentResourceSpec spec, C controllerConfiguration) { final var dependentResourceClass = spec.getDependentResourceClass(); return Utils.instantiateAndConfigureIfNeeded(dependentResourceClass, DependentResource.class, - Utils.contextFor(configuration, dependentResourceClass, Dependent.class), - (instance) -> configure(instance, spec, configuration)); + Utils.contextFor(controllerConfiguration, dependentResourceClass, Dependent.class), + (instance) -> configure(instance, spec, controllerConfiguration)); + } + + default void configure(DependentResource instance, DependentResourceSpec spec, + C controllerConfiguration) { + if (instance instanceof ConfiguredDependentResource configurable) { + final var config = controllerConfiguration.getConfigurationFor(spec); + if (config != null) { + configurable.configureWith(config); + } + } } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DependentResourceConfigurator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ConfiguredDependentResource.java similarity index 76% rename from operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DependentResourceConfigurator.java rename to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ConfiguredDependentResource.java index 2b361626aa..326482aab0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DependentResourceConfigurator.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ConfiguredDependentResource.java @@ -2,7 +2,8 @@ import java.util.Optional; -public interface DependentResourceConfigurator { + +public interface ConfiguredDependentResource { void configureWith(C config); Optional configuration(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java index 1f51a2d282..fa91e8cfeb 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java @@ -43,6 +43,27 @@ public GroupVersionKind(String group, String version, String kind) { this.apiVersion = (group == null || group.isBlank()) ? version : group + "/" + version; } + /** + * Parse GVK from a String representation. Expected format is: [group]/[version]/[kind] + *

+ * Sample: "apps/v1/Deployment" + *

+ * or: [version]/[kind] + *

+ * Sample: v1/ConfigMap + **/ + public static GroupVersionKind fromString(String gvk) { + String[] parts = gvk.split("/"); + if (parts.length == 3) { + return new GroupVersionKind(parts[0], parts[1], parts[2]); + } else if (parts.length == 2) { + return new GroupVersionKind(null, parts[0], parts[1]); + } else { + throw new IllegalArgumentException( + "Cannot parse gvk: " + gvk + ". Needs to be in form [group]/[version]/[kind]"); + } + } + public String getGroup() { return group; } @@ -81,4 +102,5 @@ public String toString() { ", kind='" + kind + '\'' + '}'; } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java index 6de936a5f8..6745a45a72 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java @@ -12,10 +12,6 @@ import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; @Ignore public abstract class AbstractEventSourceHolderDependentResource> @@ -24,10 +20,6 @@ public abstract class AbstractEventSourceHolderDependentResource resourceType; private boolean isCacheFillerEventSource; - protected OnAddFilter onAddFilter; - protected OnUpdateFilter onUpdateFilter; - protected OnDeleteFilter onDeleteFilter; - protected GenericFilter genericFilter; protected String eventSourceNameToUse; protected AbstractEventSourceHolderDependentResource(Class resourceType) { @@ -57,7 +49,6 @@ public synchronized Optional eventSource(EventSourceContext

context) { if (eventSource == null && eventSourceNameToUse == null) { setEventSource(createEventSource(context)); - applyFilters(); } return Optional.ofNullable(eventSource); } @@ -97,18 +88,11 @@ public Class resourceType() { protected abstract T createEventSource(EventSourceContext

context); - protected void setEventSource(T eventSource) { + public void setEventSource(T eventSource) { isCacheFillerEventSource = eventSource instanceof RecentOperationCacheFiller; this.eventSource = eventSource; } - protected void applyFilters() { - this.eventSource.setOnAddFilter(onAddFilter); - this.eventSource.setOnUpdateFilter(onUpdateFilter); - this.eventSource.setOnDeleteFilter(onDeleteFilter); - this.eventSource.setGenericFilter(genericFilter); - } - public Optional eventSource() { return Optional.ofNullable(eventSource); } @@ -132,15 +116,4 @@ private RecentOperationCacheFiller recentOperationCacheFiller() { return (RecentOperationCacheFiller) eventSource; } - public void setOnAddFilter(OnAddFilter onAddFilter) { - this.onAddFilter = onAddFilter; - } - - public void setOnUpdateFilter(OnUpdateFilter onUpdateFilter) { - this.onUpdateFilter = onUpdateFilter; - } - - public void setOnDeleteFilter(OnDeleteFilter onDeleteFilter) { - this.onDeleteFilter = onDeleteFilter; - } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PerResourcePollingDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PerResourcePollingDependentResource.java index 581698ffd6..f315619cde 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PerResourcePollingDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PerResourcePollingDependentResource.java @@ -27,10 +27,11 @@ public PerResourcePollingDependentResource(Class resourceType, Duration polli protected ExternalResourceCachingEventSource createEventSource( EventSourceContext

context) { - return new PerResourcePollingEventSource<>(name(), resourceType(), context, + return new PerResourcePollingEventSource<>(resourceType(), context, new PerResourcePollingConfigurationBuilder<>( this, getPollingPeriod()) .withCacheKeyMapper(this) + .withName(name()) .build()); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PollingDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PollingDependentResource.java index 519771d82d..01860cb4c5 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PollingDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/PollingDependentResource.java @@ -31,8 +31,8 @@ public PollingDependentResource(Class resourceType, Duration pollingPeriod, @Override protected ExternalResourceCachingEventSource createEventSource( EventSourceContext

context) { - return new PollingEventSource<>(name(), resourceType(), - new PollingConfiguration<>(this, getPollingPeriod(), cacheKeyMapper)); + return new PollingEventSource<>(resourceType(), + new PollingConfiguration<>(name(), this, getPollingPeriod(), cacheKeyMapper)); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/CRUDKubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/CRUDKubernetesDependentResource.java index 5b0a1c3235..f4ccf647ed 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/CRUDKubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/CRUDKubernetesDependentResource.java @@ -22,4 +22,8 @@ public abstract class CRUDKubernetesDependentResource resourceType) { super(resourceType); } + + public CRUDKubernetesDependentResource(Class resourceType, String name) { + super(resourceType, name); + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java index 0714aaa83c..f608b1c229 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java @@ -2,8 +2,8 @@ import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.processing.GroupVersionKind; public class GenericKubernetesDependentResource

@@ -20,14 +20,9 @@ public GenericKubernetesDependentResource(GroupVersionKindPlural groupVersionKin this.groupVersionKind = groupVersionKind; } - protected InformerConfiguration.InformerConfigurationBuilder informerConfigurationBuilder() { - return InformerConfiguration.from(groupVersionKind, getPrimaryResourceType()); - } - - @SuppressWarnings("unchecked") - @Override - protected Class

getPrimaryResourceType() { - return (Class

) Utils.getFirstTypeArgumentFromExtendedClass(getClass()); + protected InformerConfiguration.InformerConfigurationBuilder informerConfigurationBuilder( + EventSourceContext

context) { + return InformerConfiguration.from(groupVersionKind, context.getPrimaryResourceClass()); } @SuppressWarnings("unused") diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java new file mode 100644 index 0000000000..04dc5bc56b --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java @@ -0,0 +1,86 @@ +package io.javaoperatorsdk.operator.processing.dependent.kubernetes; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; + +import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; +import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +public @interface InformerConfig { + + String name() default NO_VALUE_SET; + + /** + * Specified which namespaces this Controller monitors for custom resources events. If no + * namespace is specified then the controller will monitor the namespaces configured for the + * controller. + * + * You can set a list of namespaces or also constants: + *

+ * + * @return the array of namespaces this controller monitors + */ + String[] namespaces() default {Constants.SAME_AS_CONTROLLER}; + + /** + * Optional label selector used to identify the set of custom resources the controller will act + * upon. The label selector can be made of multiple comma separated requirements that acts as a + * logical AND operator. + * + * @return the label selector + */ + String labelSelector() default NO_VALUE_SET; + + /** + * Optional {@link OnAddFilter} to filter events sent to this KubernetesDependent + * + * @return the {@link OnAddFilter} filter implementation to use, defaulting to the interface + * itself if no value is set + */ + Class onAddFilter() default OnAddFilter.class; + + /** + * Optional {@link OnUpdateFilter} to filter events sent to this KubernetesDependent + * + * @return the {@link OnUpdateFilter} filter implementation to use, defaulting to the interface + * itself if no value is set + */ + Class onUpdateFilter() default OnUpdateFilter.class; + + /** + * Optional {@link OnDeleteFilter} to filter events sent to this KubernetesDependent + * + * @return the {@link OnDeleteFilter} filter implementation to use, defaulting to the interface + * itself if no value is set + */ + Class onDeleteFilter() default OnDeleteFilter.class; + + /** + * Optional {@link GenericFilter} to filter events sent to this KubernetesDependent + * + * @return the {@link GenericFilter} filter implementation to use, defaulting to the interface + * itself if no value is set + */ + Class genericFilter() default GenericFilter.class; + + /** + * Set that in case of a runtime controller namespace changes, the informer should also follow the + * new namespace set. + */ + boolean followControllerNamespacesOnChange() default DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; + +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java index 572741dcbd..0c35751563 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java @@ -5,70 +5,12 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) public @interface KubernetesDependent { - String[] DEFAULT_NAMESPACES = {Constants.SAME_AS_CONTROLLER}; - - /** - * Specified which namespaces this Controller monitors for custom resources events. If no - * namespace is specified then the controller will monitor the namespaces configured for the - * controller. - * - * @return the array of namespaces this controller monitors - */ - String[] namespaces() default {Constants.SAME_AS_CONTROLLER}; - - /** - * Optional label selector used to identify the set of custom resources the controller will act - * upon. The label selector can be made of multiple comma separated requirements that acts as a - * logical AND operator. - * - * @return the label selector - */ - String labelSelector() default NO_VALUE_SET; - - /** - * Optional {@link OnAddFilter} to filter events sent to this KubernetesDependent - * - * @return the {@link OnAddFilter} filter implementation to use, defaulting to the interface - * itself if no value is set - */ - Class onAddFilter() default OnAddFilter.class; - - /** - * Optional {@link OnUpdateFilter} to filter events sent to this KubernetesDependent - * - * @return the {@link OnUpdateFilter} filter implementation to use, defaulting to the interface - * itself if no value is set - */ - Class onUpdateFilter() default OnUpdateFilter.class; - - /** - * Optional {@link OnDeleteFilter} to filter events sent to this KubernetesDependent - * - * @return the {@link OnDeleteFilter} filter implementation to use, defaulting to the interface - * itself if no value is set - */ - Class onDeleteFilter() default OnDeleteFilter.class; - - /** - * Optional {@link GenericFilter} to filter events sent to this KubernetesDependent - * - * @return the {@link GenericFilter} filter implementation to use, defaulting to the interface - * itself if no value is set - */ - Class genericFilter() default GenericFilter.class; - /** * Creates the resource only if did not exist before, this applies only if SSA is used. */ @@ -85,4 +27,7 @@ * global configuration */ BooleanWithUndefined useSSA() default BooleanWithUndefined.UNDEFINED; + + InformerConfig informerConfig() default @InformerConfig; + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java index 493f0b0146..04c8e1167d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java @@ -1,12 +1,12 @@ package io.javaoperatorsdk.operator.processing.dependent.kubernetes; -import java.util.Arrays; import java.util.Set; import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.config.dependent.ConfigurationConverter; +import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.api.reconciler.Constants; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; @@ -16,49 +16,85 @@ import static io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig.DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA; public class KubernetesDependentConverter implements - ConfigurationConverter, KubernetesDependentResource> { + ConfigurationConverter> { @Override - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings("unchecked") public KubernetesDependentResourceConfig configFrom(KubernetesDependent configAnnotation, - ControllerConfiguration parentConfiguration, - Class> originatingClass) { - var namespaces = parentConfiguration.getNamespaces(); - var configuredNS = false; - String labelSelector = null; + DependentResourceSpec> spec, + ControllerConfiguration controllerConfig) { var createResourceOnlyIfNotExistingWithSSA = DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA; - OnAddFilter onAddFilter = null; - OnUpdateFilter onUpdateFilter = null; - OnDeleteFilter onDeleteFilter = null; - GenericFilter genericFilter = null; + Boolean useSSA = null; if (configAnnotation != null) { - if (!Arrays.equals(KubernetesDependent.DEFAULT_NAMESPACES, configAnnotation.namespaces())) { - namespaces = Set.of(configAnnotation.namespaces()); - configuredNS = true; - } - - final var fromAnnotation = configAnnotation.labelSelector(); - labelSelector = Constants.NO_VALUE_SET.equals(fromAnnotation) ? null : fromAnnotation; - - final var context = Utils.contextFor(parentConfiguration, originatingClass, - configAnnotation.annotationType()); - onAddFilter = Utils.instantiate(configAnnotation.onAddFilter(), OnAddFilter.class, context); - onUpdateFilter = - Utils.instantiate(configAnnotation.onUpdateFilter(), OnUpdateFilter.class, context); - onDeleteFilter = - Utils.instantiate(configAnnotation.onDeleteFilter(), OnDeleteFilter.class, context); - genericFilter = - Utils.instantiate(configAnnotation.genericFilter(), GenericFilter.class, context); - createResourceOnlyIfNotExistingWithSSA = configAnnotation.createResourceOnlyIfNotExistingWithSSA(); useSSA = configAnnotation.useSSA().asBoolean(); } - return new KubernetesDependentResourceConfig(namespaces, labelSelector, configuredNS, - createResourceOnlyIfNotExistingWithSSA, - useSSA, onAddFilter, onUpdateFilter, onDeleteFilter, genericFilter); + var informerConfiguration = createInformerConfig(configAnnotation, + (DependentResourceSpec>) spec, + controllerConfig); + + return new KubernetesDependentResourceConfig<>(useSSA, createResourceOnlyIfNotExistingWithSSA, + informerConfiguration); } + + @SuppressWarnings({"unchecked"}) + private KubernetesDependentInformerConfig createInformerConfig( + KubernetesDependent configAnnotation, + DependentResourceSpec> spec, + ControllerConfiguration controllerConfig) { + Class> dependentResourceClass = + (Class>) spec.getDependentResourceClass(); + + final var config = new KubernetesDependentInformerConfigBuilder(); + if (configAnnotation != null) { + final var informerConfig = configAnnotation.informerConfig(); + if (informerConfig != null) { + + // override default name if more specific one is provided + if (!Constants.NO_VALUE_SET.equals(informerConfig.name())) { + config.withName(informerConfig.name()); + } + + var namespaces = Set.of(informerConfig.namespaces()); + config.withNamespaces(namespaces); + + final var fromAnnotation = informerConfig.labelSelector(); + var labelSelector = Constants.NO_VALUE_SET.equals(fromAnnotation) ? null : fromAnnotation; + config.withLabelSelector(labelSelector); + + final var context = Utils.contextFor(controllerConfig, dependentResourceClass, + configAnnotation.annotationType()); + + var onAddFilter = Utils.instantiate(informerConfig.onAddFilter(), + OnAddFilter.class, context); + config.withOnAddFilter(onAddFilter); + + var onUpdateFilter = + Utils.instantiate(informerConfig.onUpdateFilter(), + OnUpdateFilter.class, context); + config.withOnUpdateFilter(onUpdateFilter); + + var onDeleteFilter = + Utils.instantiate(informerConfig.onDeleteFilter(), + OnDeleteFilter.class, context); + config.withOnDeleteFilter(onDeleteFilter); + + var genericFilter = + Utils.instantiate(informerConfig.genericFilter(), + GenericFilter.class, + context); + + config.withGenericFilter(genericFilter); + + config.withFollowControllerNamespacesOnChange( + informerConfig.followControllerNamespacesOnChange()); + } + } + return config.build(); + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfig.java new file mode 100644 index 0000000000..f4f1d29a68 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfig.java @@ -0,0 +1,101 @@ +package io.javaoperatorsdk.operator.processing.dependent.kubernetes; + +import java.util.Set; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.client.informers.cache.ItemStore; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; + + +@SuppressWarnings("unused") +public class KubernetesDependentInformerConfig { + + private final String name; + private final Set namespaces; + private final boolean followControllerNamespacesOnChange; + private final String labelSelector; + private final OnAddFilter onAddFilter; + private final OnUpdateFilter onUpdateFilter; + private final OnDeleteFilter onDeleteFilter; + private final GenericFilter genericFilter; + private final ItemStore itemStore; + private final Long informerListLimit; + + public KubernetesDependentInformerConfig(String name, Set namespaces, + boolean followControllerNamespacesOnChange, + String labelSelector, OnAddFilter onAddFilter, + OnUpdateFilter onUpdateFilter, OnDeleteFilter onDeleteFilter, + GenericFilter genericFilter, ItemStore itemStore, Long informerListLimit) { + this.name = name; + this.namespaces = namespaces; + this.followControllerNamespacesOnChange = followControllerNamespacesOnChange; + this.labelSelector = labelSelector; + this.onAddFilter = onAddFilter; + this.onUpdateFilter = onUpdateFilter; + this.onDeleteFilter = onDeleteFilter; + this.genericFilter = genericFilter; + this.itemStore = itemStore; + this.informerListLimit = informerListLimit; + } + + public String getName() { + return name; + } + + public Set getNamespaces() { + return namespaces; + } + + public boolean isFollowControllerNamespacesOnChange() { + return followControllerNamespacesOnChange; + } + + public String getLabelSelector() { + return labelSelector; + } + + public OnAddFilter getOnAddFilter() { + return onAddFilter; + } + + public OnUpdateFilter getOnUpdateFilter() { + return onUpdateFilter; + } + + public OnDeleteFilter getOnDeleteFilter() { + return onDeleteFilter; + } + + public GenericFilter getGenericFilter() { + return genericFilter; + } + + public ItemStore getItemStore() { + return itemStore; + } + + public Long getInformerListLimit() { + return informerListLimit; + } + + void updateInformerConfigBuilder( + InformerConfiguration.InformerConfigurationBuilder builder) { + if (name != null) { + builder.withName(name); + } + builder.withNamespaces(namespaces); + builder.followControllerNamespacesOnChange(followControllerNamespacesOnChange); + builder.withLabelSelector(labelSelector); + builder.withItemStore(itemStore); + builder.withOnAddFilter(onAddFilter); + builder.withOnUpdateFilter(onUpdateFilter); + builder.withOnDeleteFilter(onDeleteFilter); + builder.withGenericFilter(genericFilter); + builder.withInformerListLimit(informerListLimit); + } + +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfigBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfigBuilder.java new file mode 100644 index 0000000000..a8a60b9638 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfigBuilder.java @@ -0,0 +1,93 @@ +package io.javaoperatorsdk.operator.processing.dependent.kubernetes; + +import java.util.Set; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.client.informers.cache.ItemStore; +import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; + +import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; +import static io.javaoperatorsdk.operator.api.reconciler.Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; + +@SuppressWarnings({"UnusedReturnValue", "unused"}) +public final class KubernetesDependentInformerConfigBuilder { + + private String name; + private Set namespaces = SAME_AS_CONTROLLER_NAMESPACES_SET; + private boolean followControllerNamespacesOnChange = + DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; + private String labelSelector; + private OnAddFilter onAddFilter; + private OnUpdateFilter onUpdateFilter; + private OnDeleteFilter onDeleteFilter; + private GenericFilter genericFilter; + private ItemStore itemStore; + private Long informerListLimit; + + public KubernetesDependentInformerConfigBuilder() {} + + public KubernetesDependentInformerConfigBuilder withName(String name) { + this.name = name; + return this; + } + + public KubernetesDependentInformerConfigBuilder withNamespaces(Set namespaces) { + this.namespaces = namespaces; + return this; + } + + public KubernetesDependentInformerConfigBuilder withFollowControllerNamespacesOnChange( + boolean followControllerNamespacesOnChange) { + this.followControllerNamespacesOnChange = followControllerNamespacesOnChange; + return this; + } + + public KubernetesDependentInformerConfigBuilder withLabelSelector(String labelSelector) { + this.labelSelector = labelSelector; + return this; + } + + public KubernetesDependentInformerConfigBuilder withOnAddFilter( + OnAddFilter onAddFilter) { + this.onAddFilter = onAddFilter; + return this; + } + + public KubernetesDependentInformerConfigBuilder withOnUpdateFilter( + OnUpdateFilter onUpdateFilter) { + this.onUpdateFilter = onUpdateFilter; + return this; + } + + public KubernetesDependentInformerConfigBuilder withOnDeleteFilter( + OnDeleteFilter onDeleteFilter) { + this.onDeleteFilter = onDeleteFilter; + return this; + } + + public KubernetesDependentInformerConfigBuilder withGenericFilter( + GenericFilter genericFilter) { + this.genericFilter = genericFilter; + return this; + } + + public KubernetesDependentInformerConfigBuilder withItemStore(ItemStore itemStore) { + this.itemStore = itemStore; + return this; + } + + public KubernetesDependentInformerConfigBuilder withInformerListLimit(Long informerListLimit) { + this.informerListLimit = informerListLimit; + return this; + } + + public KubernetesDependentInformerConfig build() { + return new KubernetesDependentInformerConfig<>(name, namespaces, + followControllerNamespacesOnChange, + labelSelector, onAddFilter, onUpdateFilter, onDeleteFilter, genericFilter, itemStore, + informerListLimit); + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index cc2c2f82a8..243731d07e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -11,17 +11,14 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.dsl.Resource; -import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.config.dependent.Configured; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Constants; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.Ignore; import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DependentResourceConfigurator; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; import io.javaoperatorsdk.operator.processing.dependent.AbstractEventSourceHolderDependentResource; import io.javaoperatorsdk.operator.processing.dependent.Matcher.Result; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.updatermatcher.GenericResourceUpdaterMatcher; @@ -35,13 +32,12 @@ converter = KubernetesDependentConverter.class) public abstract class KubernetesDependentResource extends AbstractEventSourceHolderDependentResource> - implements DependentResourceConfigurator> { + implements ConfiguredDependentResource> { private static final Logger log = LoggerFactory.getLogger(KubernetesDependentResource.class); private final boolean garbageCollected = this instanceof GarbageCollected; @SuppressWarnings("unchecked") private final ResourceUpdaterMatcher updaterMatcher = this instanceof ResourceUpdaterMatcher ? (ResourceUpdaterMatcher) this : GenericResourceUpdaterMatcher.updaterMatcherFor(resourceType()); - private final boolean clustered; private KubernetesDependentResourceConfig kubernetesDependentResourceConfig; private volatile Boolean useSSA; @@ -51,19 +47,6 @@ public KubernetesDependentResource(Class resourceType) { public KubernetesDependentResource(Class resourceType, String name) { super(resourceType, name); - final var primaryResourceType = getPrimaryResourceType(); - clustered = !Namespaced.class.isAssignableFrom(primaryResourceType); - } - - protected KubernetesDependentResource(Class resourceType, String name, - boolean primaryIsClustered) { - super(resourceType, name); - clustered = primaryIsClustered; - } - - @SuppressWarnings("unchecked") - protected Class

getPrimaryResourceType() { - return (Class

) Utils.getTypeArgumentFromExtendedClassByIndex(getClass(), 1); } @Override @@ -71,49 +54,6 @@ public void configureWith(KubernetesDependentResourceConfig config) { this.kubernetesDependentResourceConfig = config; } - private void configureWith(String labelSelector, Set namespaces, - boolean inheritNamespacesOnChange, EventSourceContext

context) { - - if (namespaces.equals(Constants.SAME_AS_CONTROLLER_NAMESPACES_SET)) { - namespaces = context.getControllerConfiguration().getNamespaces(); - } - - var ic = informerConfigurationBuilder() - .withLabelSelector(labelSelector) - .withSecondaryToPrimaryMapper(getSecondaryToPrimaryMapper()) - .withNamespaces(namespaces, inheritNamespacesOnChange) - .build(); - - configureWith(new InformerEventSource<>(name(), ic, context)); - } - - // just to seamlessly handle GenericKubernetesDependentResource - protected InformerConfiguration.InformerConfigurationBuilder informerConfigurationBuilder() { - return InformerConfiguration.from(resourceType(), getPrimaryResourceType()); - } - - @SuppressWarnings("unchecked") - private SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { - if (this instanceof SecondaryToPrimaryMapper) { - return (SecondaryToPrimaryMapper) this; - } else if (garbageCollected) { - return Mappers.fromOwnerReferences(getPrimaryResourceType(), clustered); - } else if (useNonOwnerRefBasedSecondaryToPrimaryMapping()) { - return Mappers.fromDefaultAnnotations(); - } else { - throw new OperatorException("Provide a SecondaryToPrimaryMapper to associate " + - "this resource with the primary resource. DependentResource: " + getClass().getName()); - } - } - - /** - * Use to share informers between event more resources. - * - * @param informerEventSource informer to use - */ - public void configureWith(InformerEventSource informerEventSource) { - setEventSource(informerEventSource); - } @SuppressWarnings("unused") public R create(R desired, P primary, Context

context) { @@ -162,11 +102,10 @@ public Result match(R actualResource, P primary, Context

context) { return match(actualResource, desired, primary, updaterMatcher, context); } - @SuppressWarnings({"unused", "unchecked"}) + @SuppressWarnings({"unused"}) public Result match(R actualResource, R desired, P primary, Context

context) { return match(actualResource, desired, primary, - (ResourceUpdaterMatcher) GenericResourceUpdaterMatcher - .updaterMatcherFor(actualResource.getClass()), + GenericResourceUpdaterMatcher.updaterMatcherFor(), context); } @@ -248,27 +187,31 @@ protected void addReferenceHandlingMetadata(R desired, P primary) { } @Override - @SuppressWarnings("unchecked") protected InformerEventSource createEventSource(EventSourceContext

context) { - if (kubernetesDependentResourceConfig != null) { - // sets the filters for the dependent resource, which are applied by parent class - onAddFilter = kubernetesDependentResourceConfig.onAddFilter(); - onUpdateFilter = kubernetesDependentResourceConfig.onUpdateFilter(); - onDeleteFilter = kubernetesDependentResourceConfig.onDeleteFilter(); - genericFilter = kubernetesDependentResourceConfig.genericFilter(); - configureWith(kubernetesDependentResourceConfig.labelSelector(), - kubernetesDependentResourceConfig.namespaces(), - !kubernetesDependentResourceConfig.wereNamespacesConfigured(), context); - } else { - configureWith(null, context.getControllerConfiguration().getNamespaces(), - true, context); - log.warn( - "Using default configuration for {} KubernetesDependentResource, call configureWith to provide configuration", - resourceType().getSimpleName()); + final InformerConfiguration.InformerConfigurationBuilder configBuilder = + informerConfigurationBuilder(context) + .withSecondaryToPrimaryMapper(getSecondaryToPrimaryMapper(context).orElseThrow()) + .withName(name()); + + // update configuration from annotation if specified + if (kubernetesDependentResourceConfig != null + && kubernetesDependentResourceConfig.informerConfig() != null) { + kubernetesDependentResourceConfig.informerConfig().updateInformerConfigBuilder(configBuilder); } + + var es = new InformerEventSource<>(configBuilder.build(), context); + setEventSource(es); return eventSource().orElseThrow(); } + /** + * To handle {@link io.fabric8.kubernetes.api.model.GenericKubernetesResource} based dependents. + */ + protected InformerConfiguration.InformerConfigurationBuilder informerConfigurationBuilder( + EventSourceContext

context) { + return InformerConfiguration.from(resourceType(), context.getPrimaryResourceClass()); + } + private boolean useNonOwnerRefBasedSecondaryToPrimaryMapping() { return !garbageCollected && isCreatable(); } @@ -330,4 +273,20 @@ public boolean isDeletable() { return super.isDeletable() && !garbageCollected; } + @SuppressWarnings("unchecked") + protected Optional> getSecondaryToPrimaryMapper( + EventSourceContext

context) { + if (this instanceof SecondaryToPrimaryMapper) { + return Optional.of((SecondaryToPrimaryMapper) this); + } else { + var clustered = !Namespaced.class.isAssignableFrom(context.getPrimaryResourceClass()); + if (garbageCollected) { + return Optional + .of(Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), clustered)); + } else if (isCreatable()) { + return Optional.of(Mappers.fromDefaultAnnotations()); + } + } + return Optional.empty(); + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java index e302ad437a..e5d5c23c40 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java @@ -1,98 +1,35 @@ package io.javaoperatorsdk.operator.processing.dependent.kubernetes; -import java.util.Optional; -import java.util.Set; -import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; +import io.fabric8.kubernetes.api.model.HasMetadata; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET; -public class KubernetesDependentResourceConfig { +public class KubernetesDependentResourceConfig { public static final boolean DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA = true; - private Set namespaces; - private String labelSelector; - private final boolean namespacesWereConfigured; - private final boolean createResourceOnlyIfNotExistingWithSSA; private final Boolean useSSA; + private final boolean createResourceOnlyIfNotExistingWithSSA; + private final KubernetesDependentInformerConfig informerConfig; - private final OnAddFilter onAddFilter; - private final OnUpdateFilter onUpdateFilter; - private final OnDeleteFilter onDeleteFilter; - private final GenericFilter genericFilter; - - public KubernetesDependentResourceConfig() { - this(Constants.SAME_AS_CONTROLLER_NAMESPACES_SET, NO_VALUE_SET, true, - DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA, - null, null, - null, null, null); - } - - public KubernetesDependentResourceConfig(Set namespaces, - String labelSelector, - boolean configuredNS, - boolean createResourceOnlyIfNotExistingWithSSA, + public KubernetesDependentResourceConfig( Boolean useSSA, - OnAddFilter onAddFilter, - OnUpdateFilter onUpdateFilter, - OnDeleteFilter onDeleteFilter, GenericFilter genericFilter) { - this.namespaces = namespaces; - this.labelSelector = labelSelector; - this.namespacesWereConfigured = configuredNS; - this.createResourceOnlyIfNotExistingWithSSA = createResourceOnlyIfNotExistingWithSSA; - this.onAddFilter = onAddFilter; - this.onUpdateFilter = onUpdateFilter; - this.onDeleteFilter = onDeleteFilter; - this.genericFilter = genericFilter; + boolean createResourceOnlyIfNotExistingWithSSA, + KubernetesDependentInformerConfig informerConfig) { this.useSSA = useSSA; - } - - public Set namespaces() { - return namespaces; - } - - public String labelSelector() { - return labelSelector; - } - - public boolean wereNamespacesConfigured() { - return namespacesWereConfigured; - } - - @SuppressWarnings("rawtypes") - public OnAddFilter onAddFilter() { - return onAddFilter; + this.createResourceOnlyIfNotExistingWithSSA = createResourceOnlyIfNotExistingWithSSA; + this.informerConfig = informerConfig; } public boolean createResourceOnlyIfNotExistingWithSSA() { return createResourceOnlyIfNotExistingWithSSA; } - public OnUpdateFilter onUpdateFilter() { - return onUpdateFilter; - } - - public OnDeleteFilter onDeleteFilter() { - return onDeleteFilter; - } - - public GenericFilter genericFilter() { - return genericFilter; - } - - @SuppressWarnings("unused") - protected void setNamespaces(Set namespaces) { - if (!wereNamespacesConfigured() && namespaces != null && !namespaces.isEmpty()) { - this.namespaces = namespaces; - } + public Boolean useSSA() { + return useSSA; } - public Optional useSSA() { - return Optional.ofNullable(useSSA); + public KubernetesDependentInformerConfig informerConfig() { + return informerConfig; } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java index 854ec7a56f..42bc379b06 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java @@ -1,78 +1,37 @@ package io.javaoperatorsdk.operator.processing.dependent.kubernetes; -import java.util.Set; -import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; +import io.fabric8.kubernetes.api.model.HasMetadata; -public final class KubernetesDependentResourceConfigBuilder { +public final class KubernetesDependentResourceConfigBuilder { - private Set namespaces = Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; - private String labelSelector; private boolean createResourceOnlyIfNotExistingWithSSA; - private Boolean useSSA; - private OnAddFilter onAddFilter; - private OnUpdateFilter onUpdateFilter; - private OnDeleteFilter onDeleteFilter; - private GenericFilter genericFilter; + private Boolean useSSA = null; + private KubernetesDependentInformerConfig kubernetesDependentInformerConfig; public KubernetesDependentResourceConfigBuilder() {} - public static KubernetesDependentResourceConfigBuilder aKubernetesDependentResourceConfig() { - return new KubernetesDependentResourceConfigBuilder<>(); - } - - public KubernetesDependentResourceConfigBuilder withNamespaces(Set namespaces) { - this.namespaces = namespaces; - return this; - } - - public KubernetesDependentResourceConfigBuilder withLabelSelector(String labelSelector) { - this.labelSelector = labelSelector; - return this; - } - + @SuppressWarnings("unused") public KubernetesDependentResourceConfigBuilder withCreateResourceOnlyIfNotExistingWithSSA( boolean createResourceOnlyIfNotExistingWithSSA) { this.createResourceOnlyIfNotExistingWithSSA = createResourceOnlyIfNotExistingWithSSA; return this; } - public KubernetesDependentResourceConfigBuilder withUseSSA(Boolean useSSA) { + public KubernetesDependentResourceConfigBuilder withUseSSA(boolean useSSA) { this.useSSA = useSSA; return this; } - public KubernetesDependentResourceConfigBuilder withOnAddFilter(OnAddFilter onAddFilter) { - this.onAddFilter = onAddFilter; - return this; - } - - public KubernetesDependentResourceConfigBuilder withOnUpdateFilter( - OnUpdateFilter onUpdateFilter) { - this.onUpdateFilter = onUpdateFilter; - return this; - } - - public KubernetesDependentResourceConfigBuilder withOnDeleteFilter( - OnDeleteFilter onDeleteFilter) { - this.onDeleteFilter = onDeleteFilter; - return this; - } - - public KubernetesDependentResourceConfigBuilder withGenericFilter( - GenericFilter genericFilter) { - this.genericFilter = genericFilter; + public KubernetesDependentResourceConfigBuilder withKubernetesDependentInformerConfig( + KubernetesDependentInformerConfig kubernetesDependentInformerConfig) { + this.kubernetesDependentInformerConfig = kubernetesDependentInformerConfig; return this; } public KubernetesDependentResourceConfig build() { - return new KubernetesDependentResourceConfig<>(namespaces, labelSelector, - namespaces != Constants.SAME_AS_CONTROLLER_NAMESPACES_SET, - createResourceOnlyIfNotExistingWithSSA, useSSA, onAddFilter, - onUpdateFilter, onDeleteFilter, genericFilter); + return new KubernetesDependentResourceConfig<>( + useSSA, createResourceOnlyIfNotExistingWithSSA, + kubernetesDependentInformerConfig); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java index 16b72d6dce..418a5dc964 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java @@ -17,8 +17,7 @@ public class GenericResourceUpdaterMatcher implements protected GenericResourceUpdaterMatcher() {} @SuppressWarnings("unchecked") - public static ResourceUpdaterMatcher updaterMatcherFor( - Class resourceType) { + public static ResourceUpdaterMatcher updaterMatcherFor() { return (ResourceUpdaterMatcher) INSTANCE; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java index c22bf9d666..319b1a9e56 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java @@ -135,13 +135,13 @@ protected void registerOrDeregisterEventSourceBasedOnActivation( if (dependentResourceNode.getActivationCondition().isPresent()) { final var dr = dependentResourceNode.getDependentResource(); final var eventSourceRetriever = context.eventSourceRetriever(); + var eventSource = + dr.eventSource(eventSourceRetriever.eventSourceContextForDynamicRegistration()); if (activationConditionMet) { - var eventSource = - dr.eventSource(eventSourceRetriever.eventSourceContextForDynamicRegistration()); var es = eventSource.orElseThrow(); eventSourceRetriever.dynamicallyRegisterEventSource(es); } else { - eventSourceRetriever.dynamicallyDeRegisterEventSource(dr.name()); + eventSourceRetriever.dynamicallyDeRegisterEventSource(eventSource.orElseThrow().name()); } } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java index 43bb807e30..64f936c70d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java @@ -31,7 +31,7 @@ protected DefaultManagedWorkflow(List orderedSpecs, boole .map(DependentResourceSpec::getName) .collect(Collectors.toSet()); this.orderedSpecs = orderedSpecs; - for (DependentResourceSpec spec : orderedSpecs) { + for (DependentResourceSpec spec : orderedSpecs) { // add cycle detection? if (spec.getDependsOn().isEmpty()) { topLevelResources.add(spec.getName()); @@ -99,7 +99,7 @@ public Workflow

resolve(KubernetesClient client, } @SuppressWarnings({"rawtypes", "unchecked"}) - private DependentResource resolve(DependentResourceSpec spec, + private DependentResource resolve(DependentResourceSpec spec, KubernetesClient client, ControllerConfiguration

configuration) { final DependentResource dependentResource = diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java index c65d897734..2bb8c7a39a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java @@ -138,8 +138,8 @@ public final synchronized void registerEventSource(EventSource eventSo Objects.requireNonNull(eventSource, "EventSource must not be null"); try { if (eventSource instanceof ManagedInformerEventSource managedInformerEventSource) { - managedInformerEventSource.setConfigurationService( - controller.getConfiguration().getConfigurationService()); + managedInformerEventSource.setControllerConfiguration( + controller.getConfiguration()); } eventSources.add(eventSource); eventSource.setEventHandler(controller.getEventProcessor()); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java index 3d66051e16..db457a4e41 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java @@ -48,8 +48,7 @@ public ControllerEventSource(Controller controller) { .ifPresentOrElse(filter -> setOnUpdateFilter(filter.and(internalOnUpdateFilter)), () -> setOnUpdateFilter(internalOnUpdateFilter)); config.genericFilter().ifPresent(this::setGenericFilter); - - setConfigurationService(config.getConfigurationService()); + setControllerConfiguration(config); } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java index 571e02dbc2..67e5500b24 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java @@ -76,28 +76,21 @@ public class InformerEventSource private final PrimaryToSecondaryMapper

primaryToSecondaryMapper; private final String id = UUID.randomUUID().toString(); - public InformerEventSource(String name, - InformerConfiguration configuration, EventSourceContext

context) { - this(name, configuration, context.getClient(), - context.getControllerConfiguration().getConfigurationService() - .parseResourceVersionsForEventFilteringAndCaching()); - } - public InformerEventSource( InformerConfiguration configuration, EventSourceContext

context) { - this(null, configuration, context.getClient(), + this(configuration, context.getClient(), context.getControllerConfiguration().getConfigurationService() .parseResourceVersionsForEventFilteringAndCaching()); } public InformerEventSource(InformerConfiguration configuration, KubernetesClient client) { - this(null, configuration, client, false); + this(configuration, client, false); } - public InformerEventSource(String name, InformerConfiguration configuration, + public InformerEventSource(InformerConfiguration configuration, KubernetesClient client, boolean parseResourceVersions) { - super(name, + super(configuration.name(), configuration.getGroupVersionKind() .map(gvk -> client.genericKubernetesResources(gvk.apiVersion(), gvk.getKind())) .orElseGet(() -> (MixedOperation) client.resources(configuration.getResourceClass())), diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java index a97897b1fa..d8f29e300d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java @@ -18,7 +18,7 @@ import io.fabric8.kubernetes.client.informers.ResourceEventHandler; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.api.config.ConfigurationService; +import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; import io.javaoperatorsdk.operator.health.InformerHealthIndicator; import io.javaoperatorsdk.operator.processing.LifecycleAware; @@ -28,49 +28,50 @@ import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_ALL_NAMESPACES; -public class InformerManager> - implements LifecycleAware, IndexerResourceCache { +public class InformerManager> + implements LifecycleAware, IndexerResourceCache { private static final Logger log = LoggerFactory.getLogger(InformerManager.class); - private final Map> sources = new ConcurrentHashMap<>(); + private final Map> sources = new ConcurrentHashMap<>(); private final C configuration; - private final MixedOperation, Resource> client; - private final ResourceEventHandler eventHandler; - private final Map>> indexers = new HashMap<>(); - private ConfigurationService configurationService; + private final MixedOperation, Resource> client; + private final ResourceEventHandler eventHandler; + private final Map>> indexers = new HashMap<>(); + private ControllerConfiguration controllerConfiguration; - InformerManager(MixedOperation, Resource> client, + InformerManager(MixedOperation, Resource> client, C configuration, - ResourceEventHandler eventHandler) { + ResourceEventHandler eventHandler) { this.client = client; this.configuration = configuration; this.eventHandler = eventHandler; } - void setConfigurationService(ConfigurationService configurationService) { - this.configurationService = configurationService; + void setControllerConfiguration(ControllerConfiguration controllerConfiguration) { + this.controllerConfiguration = controllerConfiguration; } @Override public void start() throws OperatorException { initSources(); // make sure informers are all started before proceeding further - configurationService.getExecutorServiceManager().boundedExecuteAndWaitForAllToComplete( - sources.values().stream(), - iw -> { - iw.start(); - return null; - }, - iw -> "InformerStarter-" + iw.getTargetNamespace() + "-" - + configuration.getResourceClass().getSimpleName()); + controllerConfiguration.getConfigurationService().getExecutorServiceManager() + .boundedExecuteAndWaitForAllToComplete( + sources.values().stream(), + iw -> { + iw.start(); + return null; + }, + iw -> "InformerStarter-" + iw.getTargetNamespace() + "-" + + configuration.getResourceClass().getSimpleName()); } private void initSources() { if (!sources.isEmpty()) { throw new IllegalStateException("Some sources already initialized."); } - final var targetNamespaces = configuration.getEffectiveNamespaces(configurationService); + final var targetNamespaces = configuration.getEffectiveNamespaces(controllerConfiguration); if (ResourceConfiguration.allNamespacesWatched(targetNamespaces)) { var source = createEventSourceForNamespace(WATCH_ALL_NAMESPACES); log.debug("Registered {} -> {} for any namespace", this, source); @@ -96,7 +97,7 @@ public void changeNamespaces(Set namespaces) { namespaces.forEach(ns -> { if (!sources.containsKey(ns)) { - final InformerWrapper source = createEventSourceForNamespace(ns); + final InformerWrapper source = createEventSourceForNamespace(ns); source.start(); log.debug("Registered new {} -> {} for namespace: {}", this, source, ns); @@ -105,8 +106,8 @@ public void changeNamespaces(Set namespaces) { } - private InformerWrapper createEventSourceForNamespace(String namespace) { - final InformerWrapper source; + private InformerWrapper createEventSourceForNamespace(String namespace) { + final InformerWrapper source; if (namespace.equals(WATCH_ALL_NAMESPACES)) { final var filteredBySelectorClient = client.inAnyNamespace().withLabelSelector(configuration.getLabelSelector()); @@ -120,13 +121,14 @@ private InformerWrapper createEventSourceForNamespace(String namespace) { return source; } - private InformerWrapper createEventSource( - FilterWatchListDeletable, Resource> filteredBySelectorClient, - ResourceEventHandler eventHandler, String namespaceIdentifier) { + private InformerWrapper createEventSource( + FilterWatchListDeletable, Resource> filteredBySelectorClient, + ResourceEventHandler eventHandler, String namespaceIdentifier) { var informer = configuration.getInformerListLimit().map(filteredBySelectorClient::withLimit) .orElse(filteredBySelectorClient).runnableInformer(0); configuration.getItemStore().ifPresent(informer::itemStore); - var source = new InformerWrapper<>(informer, configurationService, namespaceIdentifier); + var source = new InformerWrapper<>(informer, controllerConfiguration.getConfigurationService(), + namespaceIdentifier); source.addEventHandler(eventHandler); sources.put(namespaceIdentifier, source); return source; @@ -146,7 +148,7 @@ public void stop() { } @Override - public Stream list(Predicate predicate) { + public Stream list(Predicate predicate) { if (predicate == null) { return sources.values().stream().flatMap(IndexerResourceCache::list); } @@ -154,7 +156,7 @@ public Stream list(Predicate predicate) { } @Override - public Stream list(String namespace, Predicate predicate) { + public Stream list(String namespace, Predicate predicate) { if (isWatchingAllNamespaces()) { return getSource(WATCH_ALL_NAMESPACES) .map(source -> source.list(namespace, predicate)) @@ -167,12 +169,13 @@ public Stream list(String namespace, Predicate predicate) { } @Override - public Optional get(ResourceID resourceID) { + public Optional get(ResourceID resourceID) { return getSource(resourceID.getNamespace().orElse(WATCH_ALL_NAMESPACES)) .flatMap(source -> source.get(resourceID)) - .map(r -> configurationService.cloneSecondaryResourcesWhenGettingFromCache() - ? configurationService.getResourceCloner().clone(r) - : r); + .map(r -> controllerConfiguration.getConfigurationService() + .cloneSecondaryResourcesWhenGettingFromCache() + ? controllerConfiguration.getConfigurationService().getResourceCloner().clone(r) + : r); } @Override @@ -184,18 +187,18 @@ private boolean isWatchingAllNamespaces() { return sources.containsKey(WATCH_ALL_NAMESPACES); } - private Optional> getSource(String namespace) { + private Optional> getSource(String namespace) { namespace = isWatchingAllNamespaces() || namespace == null ? WATCH_ALL_NAMESPACES : namespace; return Optional.ofNullable(sources.get(namespace)); } @Override - public void addIndexers(Map>> indexers) { + public void addIndexers(Map>> indexers) { this.indexers.putAll(indexers); } @Override - public List byIndex(String indexName, String indexKey) { + public List byIndex(String indexName, String indexKey) { return sources.values().stream().map(s -> s.byIndex(indexName, indexKey)) .flatMap(List::stream).collect(Collectors.toList()); } @@ -206,7 +209,7 @@ public String toString() { return "InformerManager [" + ReconcilerUtils.getResourceTypeNameWithVersion(configuration.getResourceClass()) + "] watching: " - + configuration.getEffectiveNamespaces(configurationService) + + configuration.getEffectiveNamespaces(controllerConfiguration) + (selector != null ? " selector: " + selector : ""); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java index dcf0ab3d7e..0e5f8bd896 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java @@ -16,7 +16,7 @@ import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.informers.ResourceEventHandler; import io.javaoperatorsdk.operator.OperatorException; -import io.javaoperatorsdk.operator.api.config.ConfigurationService; +import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.NamespaceChangeable; import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.dependent.RecentOperationCacheFiller; @@ -36,7 +36,7 @@ public abstract class ManagedInformerEventSource cache; private final boolean parseResourceVersions; - private ConfigurationService configurationService; + private ControllerConfiguration controllerConfiguration; private final C configuration; private final Map>> indexers = new HashMap<>(); protected TemporaryResourceCache temporaryResourceCache; @@ -85,7 +85,7 @@ public synchronized void start() { } temporaryResourceCache = new TemporaryResourceCache<>(this, parseResourceVersions); this.cache = new InformerManager<>(client, configuration, this); - cache.setConfigurationService(configurationService); + cache.setControllerConfiguration(controllerConfiguration); cache.addIndexers(indexers); manager().start(); super.start(); @@ -191,8 +191,8 @@ public String toString() { "}"; } - public void setConfigurationService(ConfigurationService configurationService) { - this.configurationService = configurationService; + public void setControllerConfiguration(ControllerConfiguration controllerConfiguration) { + this.controllerConfiguration = controllerConfiguration; } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java index 24c4d18837..97ab1ef402 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java @@ -136,4 +136,13 @@ public static SecondaryToPrim .collect(Collectors.toSet()); }; } + + public static class SecondaryToPrimaryFromDefaultAnnotation + implements SecondaryToPrimaryMapper { + @Override + public Set toPrimaryResourceIDs(HasMetadata resource) { + return Mappers.fromDefaultAnnotations().toPrimaryResourceIDs(resource); + } + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfiguration.java index 23fa9e023a..52e1fbcd68 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfiguration.java @@ -9,17 +9,20 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; -public record PerResourcePollingConfiguration(ScheduledExecutorService executorService, CacheKeyMapper cacheKeyMapper, +public record PerResourcePollingConfiguration(String name,ScheduledExecutorService executorService, CacheKeyMapper cacheKeyMapper, PerResourcePollingEventSource.ResourceFetcher resourceFetcher, Predicate

registerPredicate, Duration defaultPollingPeriod) { public static final int DEFAULT_EXECUTOR_THREAD_NUMBER = 1; - public PerResourcePollingConfiguration(ScheduledExecutorService executorService, + public PerResourcePollingConfiguration( + String name, + ScheduledExecutorService executorService, CacheKeyMapper cacheKeyMapper, PerResourcePollingEventSource.ResourceFetcher resourceFetcher, Predicate

registerPredicate, Duration defaultPollingPeriod) { + this.name = name; this.executorService = executorService == null ? new ScheduledThreadPoolExecutor(DEFAULT_EXECUTOR_THREAD_NUMBER) : executorService; this.cacheKeyMapper = cacheKeyMapper == null ? CacheKeyMapper.singleResourceCacheKeyMapper() : cacheKeyMapper; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfigurationBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfigurationBuilder.java index ece10d347e..85b1fcf2b0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfigurationBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfigurationBuilder.java @@ -12,6 +12,7 @@ public final class PerResourcePollingConfigurationBuilder resourceFetcher; + private String name; private Predicate

registerPredicate; private ScheduledExecutorService executorService; private CacheKeyMapper cacheKeyMapper; @@ -42,8 +43,13 @@ public PerResourcePollingConfigurationBuilder withCacheKeyMapper( return this; } + public PerResourcePollingConfigurationBuilder withName(String name) { + this.name = name; + return this; + } + public PerResourcePollingConfiguration build() { - return new PerResourcePollingConfiguration<>(executorService, cacheKeyMapper, + return new PerResourcePollingConfiguration<>(name, executorService, cacheKeyMapper, resourceFetcher, registerPredicate, defaultPollingPeriod); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java index 2288e7eb75..983679a27a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java @@ -50,15 +50,12 @@ public class PerResourcePollingEventSource private final Predicate

registerPredicate; private final Duration period; - public PerResourcePollingEventSource(Class resourceClass, EventSourceContext

context, - PerResourcePollingConfiguration config) { - this(null, resourceClass, context, config); - } - public PerResourcePollingEventSource(String name, Class resourceClass, + + public PerResourcePollingEventSource(Class resourceClass, EventSourceContext

context, PerResourcePollingConfiguration config) { - super(name, resourceClass, config.cacheKeyMapper()); + super(config.name(), resourceClass, config.cacheKeyMapper()); this.primaryResourceCache = context.getPrimaryCache(); this.resourceFetcher = config.resourceFetcher(); this.registerPredicate = config.registerPredicate(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfiguration.java index 516d0546f7..c66ef38c8f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfiguration.java @@ -5,11 +5,12 @@ import io.javaoperatorsdk.operator.processing.event.source.CacheKeyMapper; -public record PollingConfiguration(PollingEventSource.GenericResourceFetcher genericResourceFetcher, +public record PollingConfiguration(String name,PollingEventSource.GenericResourceFetcher genericResourceFetcher, Duration period, CacheKeyMapper cacheKeyMapper) { - public PollingConfiguration(PollingEventSource.GenericResourceFetcher genericResourceFetcher, Duration period, + public PollingConfiguration(String name,PollingEventSource.GenericResourceFetcher genericResourceFetcher, Duration period, CacheKeyMapper cacheKeyMapper) { + this.name = name; this.genericResourceFetcher = Objects.requireNonNull(genericResourceFetcher); this.period = period; this.cacheKeyMapper = diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfigurationBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfigurationBuilder.java index 576f8fdb56..c6bccefa82 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfigurationBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingConfigurationBuilder.java @@ -8,6 +8,7 @@ public final class PollingConfigurationBuilder { private final Duration period; private final PollingEventSource.GenericResourceFetcher genericResourceFetcher; private CacheKeyMapper cacheKeyMapper; + private String name; public PollingConfigurationBuilder(PollingEventSource.GenericResourceFetcher fetcher, Duration period) { @@ -20,7 +21,12 @@ public PollingConfigurationBuilder withCacheKeyMapper(CacheKeyMapper cache return this; } + public PollingConfigurationBuilder withName(String name) { + this.name = name; + return this; + } + public PollingConfiguration build() { - return new PollingConfiguration<>(genericResourceFetcher, period, cacheKeyMapper); + return new PollingConfiguration<>(name, genericResourceFetcher, period, cacheKeyMapper); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java index 060128576c..6549030c4b 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java @@ -52,12 +52,10 @@ public class PollingEventSource private final Duration period; private final AtomicBoolean healthy = new AtomicBoolean(true); - public PollingEventSource(Class resourceClass, PollingConfiguration config) { - this(null, resourceClass, config); - } - public PollingEventSource(String name, Class resourceClass, PollingConfiguration config) { - super(name, resourceClass, config.cacheKeyMapper()); + + public PollingEventSource(Class resourceClass, PollingConfiguration config) { + super(config.name(), resourceClass, config.cacheKeyMapper()); this.genericResourceFetcher = config.genericResourceFetcher(); this.period = config.period(); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java index e280009da2..1993c37ad1 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java @@ -19,14 +19,13 @@ import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DependentResourceConfigurator; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.*; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; +import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.inheritsNamespacesFromController; import static org.junit.jupiter.api.Assertions.*; class ControllerConfigurationOverriderTest { @@ -66,18 +65,20 @@ void overridingNSShouldPreserveUntouchedDependents() { assertEquals(stringConfig, resourceConfig); } - @SuppressWarnings("rawtypes") + @SuppressWarnings({"unchecked", "rawtypes"}) private KubernetesDependentResourceConfig extractFirstDependentKubernetesResourceConfig( io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration) { - return (KubernetesDependentResourceConfig) extractDependentKubernetesResourceConfig( + var conf = (KubernetesDependentResourceConfig) extractDependentKubernetesResourceConfig( configuration, 0); + return conf; } - private Object extractDependentKubernetesResourceConfig( + @SuppressWarnings("unchecked") + private static Object extractDependentKubernetesResourceConfig( io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration, int index) { final var spec = configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().get(index); - return DependentResourceConfigurationResolver.configurationFor(spec, configuration); + return configuration.getConfigurationFor(spec); } private io.javaoperatorsdk.operator.api.config.ControllerConfiguration createConfiguration( @@ -171,8 +172,8 @@ void configuredDependentShouldNotChangeOnParentOverrideEvenWhenInitialConfigIsSa assertEquals(Set.of(OverriddenNSDependent.DEP_NS), configuration.getNamespaces()); // check that the DependentResource inherits has its own configured NS - assertEquals(1, config.namespaces().size()); - assertEquals(Set.of(OverriddenNSDependent.DEP_NS), config.namespaces()); + var informerConfig = config.informerConfig(); + assertEquals(Set.of(OverriddenNSDependent.DEP_NS), informerConfig.getNamespaces()); // override the parent's NS final var newNS = "bar"; @@ -181,8 +182,8 @@ void configuredDependentShouldNotChangeOnParentOverrideEvenWhenInitialConfigIsSa // check that dependent config is still using its own NS config = extractFirstDependentKubernetesResourceConfig(configuration); - assertEquals(1, config.namespaces().size()); - assertEquals(Set.of(OverriddenNSDependent.DEP_NS), config.namespaces()); + informerConfig = config.informerConfig(); + assertEquals(Set.of(OverriddenNSDependent.DEP_NS), informerConfig.getNamespaces()); } @SuppressWarnings("unchecked") @@ -193,17 +194,10 @@ void dependentShouldWatchAllNamespacesIfParentDoesAsWell() { var config = extractFirstDependentKubernetesResourceConfig(configuration); // check that the DependentResource inherits the controller's configuration if applicable - assertTrue(ResourceConfiguration.allNamespacesWatched(config.namespaces())); - - // override the NS - final var newNS = "bar"; - configuration = - ControllerConfigurationOverrider.override(configuration).settingNamespace(newNS).build(); + var informerConfig = config.informerConfig(); + assertTrue( + inheritsNamespacesFromController(informerConfig.getNamespaces())); - // check that dependent config is using the overridden namespace - config = extractFirstDependentKubernetesResourceConfig(configuration); - assertEquals(1, config.namespaces().size()); - assertEquals(Set.of(newNS), config.namespaces()); } @SuppressWarnings("unchecked") @@ -214,7 +208,9 @@ void shouldBePossibleToForceDependentToWatchAllNamespaces() { var config = extractFirstDependentKubernetesResourceConfig(configuration); // check that the DependentResource inherits the controller's configuration if applicable - assertTrue(ResourceConfiguration.allNamespacesWatched(config.namespaces())); + assertTrue( + ResourceConfiguration + .allNamespacesWatched(config.informerConfig().getNamespaces())); // override the NS final var newNS = "bar"; @@ -223,28 +219,20 @@ void shouldBePossibleToForceDependentToWatchAllNamespaces() { // check that dependent config is still configured to watch all NS config = extractFirstDependentKubernetesResourceConfig(configuration); - assertTrue(ResourceConfiguration.allNamespacesWatched(config.namespaces())); + assertTrue( + ResourceConfiguration + .allNamespacesWatched(config.informerConfig().getNamespaces())); } @Test + @SuppressWarnings("unchecked") void overridingNamespacesShouldBePropagatedToDependentsWithDefaultConfig() { var configuration = createConfiguration(new OneDepReconciler()); // retrieve the config for the first (and unique) dependent var config = extractFirstDependentKubernetesResourceConfig(configuration); // check that the DependentResource inherits the controller's configuration if applicable - assertEquals(1, config.namespaces().size()); - assertEquals(Set.of(OneDepReconciler.CONFIGURED_NS), config.namespaces()); - - // override the NS - final var newNS = "bar"; - configuration = - ControllerConfigurationOverrider.override(configuration).settingNamespace(newNS).build(); - - // check that dependent config is using the overridden namespace - config = extractFirstDependentKubernetesResourceConfig(configuration); - assertEquals(1, config.namespaces().size()); - assertEquals(Set.of(newNS), config.namespaces()); + assertEquals(1, config.informerConfig().getNamespaces().size()); } @Test @@ -254,8 +242,8 @@ void alreadyOverriddenDependentNamespacesShouldNotBePropagated() { var config = extractFirstDependentKubernetesResourceConfig(configuration); // DependentResource has its own NS - assertEquals(1, config.namespaces().size()); - assertEquals(Set.of(OverriddenNSDependent.DEP_NS), config.namespaces()); + assertEquals(Set.of(OverriddenNSDependent.DEP_NS), + config.informerConfig().getNamespaces()); // override the NS final var newNS = "bar"; @@ -264,12 +252,12 @@ void alreadyOverriddenDependentNamespacesShouldNotBePropagated() { // check that dependent config is still using its own NS config = extractFirstDependentKubernetesResourceConfig(configuration); - assertEquals(1, config.namespaces().size()); - assertEquals(Set.of(OverriddenNSDependent.DEP_NS), config.namespaces()); + assertEquals(Set.of(OverriddenNSDependent.DEP_NS), + config.informerConfig().getNamespaces()); } - @SuppressWarnings("rawtypes") @Test + @SuppressWarnings({"rawtypes", "unchecked"}) void replaceNamedDependentResourceConfigShouldWork() { var configuration = createConfiguration(new OneDepReconciler()); var dependents = configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); @@ -283,36 +271,40 @@ void replaceNamedDependentResourceConfigShouldWork() { .filter(dr -> dr.getName().equals(dependentResourceName)) .findFirst().orElseThrow(); assertEquals(ReadOnlyDependent.class, dependentSpec.getDependentResourceClass()); - var maybeConfig = - DependentResourceConfigurationResolver.configurationFor(dependentSpec, configuration); + var maybeConfig = extractFirstDependentKubernetesResourceConfig(configuration); assertNotNull(maybeConfig); assertInstanceOf(KubernetesDependentResourceConfig.class, maybeConfig); var config = (KubernetesDependentResourceConfig) maybeConfig; // check that the DependentResource inherits the controller's configuration if applicable - assertEquals(1, config.namespaces().size()); - assertNull(config.labelSelector()); - assertEquals(Set.of(OneDepReconciler.CONFIGURED_NS), config.namespaces()); + var informerConfig = config.informerConfig(); + assertEquals(1, informerConfig.getNamespaces().size()); + assertNull(informerConfig.getLabelSelector()); // override the namespaces for the dependent resource final var overriddenNS = "newNS"; final var labelSelector = "foo=bar"; + KubernetesDependentInformerConfigBuilder anInformerConfig = + new KubernetesDependentInformerConfigBuilder<>(); + anInformerConfig.withNamespaces(Set.of(overriddenNS)); + anInformerConfig.withLabelSelector(labelSelector); final var overridden = ControllerConfigurationOverrider.override(configuration) .replacingNamedDependentResourceConfig( - DependentResource.defaultNameFor(ReadOnlyDependent.class), - new KubernetesDependentResourceConfigBuilder<>() - .withNamespaces(Set.of(overriddenNS)) - .withLabelSelector(labelSelector) + dependentResourceName, + new KubernetesDependentResourceConfigBuilder() + .withKubernetesDependentInformerConfig(anInformerConfig.build()) + .build()) .build(); dependents = overridden.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); - dependentSpec = dependents.stream().filter(dr -> dr.getName().equals(dependentResourceName)) - .findFirst().orElseThrow(); - config = (KubernetesDependentResourceConfig) DependentResourceConfigurationResolver - .configurationFor(dependentSpec, overridden); - assertEquals(1, config.namespaces().size()); - assertEquals(labelSelector, config.labelSelector()); - assertEquals(Set.of(overriddenNS), config.namespaces()); + dependentSpec = dependents.stream() + .filter(dr -> dr.getName().equals(dependentResourceName)) + .findFirst() + .orElseThrow(); + config = (KubernetesDependentResourceConfig) overridden.getConfigurationFor(dependentSpec); + informerConfig = config.informerConfig(); + assertEquals(labelSelector, informerConfig.getLabelSelector()); + assertEquals(Set.of(overriddenNS), informerConfig.getNamespaces()); // check that we still have the proper workflow configuration assertInstanceOf(TestCondition.class, dependentSpec.getReadyCondition()); } @@ -360,16 +352,19 @@ public UpdateControl reconcile(ConfigMap resource, Context } } - private static class ReadOnlyDependent extends KubernetesDependentResource { + public static class ReadOnlyDependent extends KubernetesDependentResource + implements GarbageCollected { public ReadOnlyDependent() { super(ConfigMap.class); } } - @KubernetesDependent(namespaces = Constants.WATCH_ALL_NAMESPACES) - private static class WatchAllNSDependent - extends KubernetesDependentResource { + @KubernetesDependent( + informerConfig = @InformerConfig(namespaces = Constants.WATCH_ALL_NAMESPACES)) + public static class WatchAllNSDependent + extends KubernetesDependentResource + implements GarbageCollected { public WatchAllNSDependent() { super(ConfigMap.class); @@ -378,7 +373,7 @@ public WatchAllNSDependent() { @Workflow(dependents = @Dependent(type = OverriddenNSDependent.class)) @ControllerConfiguration(namespaces = OverriddenNSOnDepReconciler.CONFIGURED_NS) - private static class OverriddenNSOnDepReconciler implements Reconciler { + public static class OverriddenNSOnDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "parentNS"; @@ -388,9 +383,10 @@ public UpdateControl reconcile(ConfigMap resource, Context } } - @KubernetesDependent(namespaces = OverriddenNSDependent.DEP_NS) - private static class OverriddenNSDependent - extends KubernetesDependentResource { + @KubernetesDependent(informerConfig = @InformerConfig(namespaces = OverriddenNSDependent.DEP_NS)) + public static class OverriddenNSDependent + extends KubernetesDependentResource + implements GarbageCollected { private static final String DEP_NS = "dependentNS"; @@ -404,7 +400,7 @@ public OverriddenNSDependent() { @Dependent(type = NamedDependentReconciler.ExternalDependentResource.class) }) @ControllerConfiguration - private static class NamedDependentReconciler implements Reconciler { + public static class NamedDependentReconciler implements Reconciler { @Override public UpdateControl reconcile(ConfigMap resource, Context context) { @@ -412,7 +408,8 @@ public UpdateControl reconcile(ConfigMap resource, Context } private static class NamedDependentResource - extends KubernetesDependentResource { + extends KubernetesDependentResource + implements GarbageCollected { public NamedDependentResource() { super(ConfigMap.class); @@ -420,7 +417,7 @@ public NamedDependentResource() { } private static class ExternalDependentResource implements DependentResource, - DependentResourceConfigurator { + ConfiguredDependentResource, GarbageCollected { private String config = "UNSET"; @@ -443,6 +440,9 @@ public void configureWith(String config) { public Optional configuration() { return Optional.of(config); } + + @Override + public void delete(ConfigMap primary, Context context) {} } } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java index 702a12d124..5cc5472798 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java @@ -19,8 +19,9 @@ import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DependentResourceConfigurator; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentConverter; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; @@ -47,11 +48,23 @@ private

io.javaoperatorsdk.operator.api.config.Controlle return configurationService.configFor(reconciler); } + @SuppressWarnings({"rawtypes", "unchecked"}) + private static Object extractDependentKubernetesResourceConfig( + io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration, + Class target) { + final var spec = + configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().stream() + .filter(s -> target.isAssignableFrom(s.getDependentResourceClass())) + .findFirst().orElseThrow(); + return configuration.getConfigurationFor(spec); + } + @Test void controllerConfigurationProvidedShouldBeReturnedIfAvailable() { final var cfg = configFor(new CustomAnnotationReconciler()); - final var customConfig = DependentResourceConfigurationResolver - .extractConfigurationFromConfigured(CustomAnnotatedDep.class, cfg); + + final var customConfig = + extractDependentKubernetesResourceConfig(cfg, CustomAnnotatedDep.class); assertInstanceOf(CustomConfig.class, customConfig); assertEquals(CustomAnnotatedDep.PROVIDED_VALUE, ((CustomConfig) customConfig).getValue()); final var newConfig = new CustomConfig(72); @@ -62,28 +75,17 @@ void controllerConfigurationProvidedShouldBeReturnedIfAvailable() { .filter(s -> DR_NAME.equals(s.getName())) .findFirst() .orElseThrow(); - assertEquals(newConfig, - DependentResourceConfigurationResolver.configurationFor(spec, overridden)); + assertEquals(newConfig, overridden.getConfigurationFor(spec)); } @Test void getConverterShouldWork() { - final var cfg = configFor(new CustomAnnotationReconciler()); - var converter = DependentResourceConfigurationResolver.getConverter(CustomAnnotatedDep.class); - assertNull(converter); - assertNull(DependentResourceConfigurationResolver.getConverter(ChildCustomAnnotatedDep.class)); - // extracting configuration should trigger converter creation - DependentResourceConfigurationResolver.extractConfigurationFromConfigured( - CustomAnnotatedDep.class, cfg); - converter = DependentResourceConfigurationResolver.getConverter(CustomAnnotatedDep.class); + configFor(new CustomAnnotationReconciler()); + var converter = DependentResourceConfigurationResolver.getConverter(CustomAnnotatedDep.class); assertNotNull(converter); assertEquals(CustomConfigConverter.class, converter.getClass()); - converter = DependentResourceConfigurationResolver.getConverter(ChildCustomAnnotatedDep.class); - assertNull(converter); - DependentResourceConfigurationResolver.extractConfigurationFromConfigured( - ChildCustomAnnotatedDep.class, cfg); converter = DependentResourceConfigurationResolver.getConverter(ChildCustomAnnotatedDep.class); assertNotNull(converter); assertEquals(CustomConfigConverter.class, converter.getClass()); @@ -94,31 +96,23 @@ void getConverterShouldWork() { @SuppressWarnings("rawtypes") @Test void registerConverterShouldWork() { - final var cfg = configFor(new CustomAnnotationReconciler()); - var converter = DependentResourceConfigurationResolver.getConverter(ConfigMapDep.class); - assertNull(converter); - DependentResourceConfigurationResolver.extractConfigurationFromConfigured(ConfigMapDep.class, - cfg); - converter = DependentResourceConfigurationResolver.getConverter(ConfigMapDep.class); - assertInstanceOf(KubernetesDependentConverter.class, converter); final var overriddenConverter = new ConfigurationConverter() { + @Override - public Object configFrom(Annotation configAnnotation, - io.javaoperatorsdk.operator.api.config.ControllerConfiguration parentConfiguration, - Class originatingClass) { + public Object configFrom(Annotation configAnnotation, DependentResourceSpec spec, + io.javaoperatorsdk.operator.api.config.ControllerConfiguration parentConfiguration) { return null; } }; - DependentResourceConfigurationResolver.registerConverter(KubernetesDependentResource.class, + DependentResourceConfigurationResolver.registerConverter(ServiceDep.class, overriddenConverter); + configFor(new CustomAnnotationReconciler()); - // already resolved converters are kept unchanged - converter = DependentResourceConfigurationResolver.getConverter(ConfigMapDep.class); + // non overridden dependents should use the default converter + var converter = DependentResourceConfigurationResolver.getConverter(ConfigMapDep.class); assertInstanceOf(KubernetesDependentConverter.class, converter); - // but new converters should use the overridden version - DependentResourceConfigurationResolver.extractConfigurationFromConfigured(ServiceDep.class, - cfg); + // dependent with registered converter should use that one converter = DependentResourceConfigurationResolver.getConverter(ServiceDep.class); assertEquals(overriddenConverter, converter); } @@ -141,14 +135,16 @@ public UpdateControl reconcile(ConfigMap resource, Context } } - private static class ConfigMapDep extends KubernetesDependentResource { + public static class ConfigMapDep extends KubernetesDependentResource + implements GarbageCollected { public ConfigMapDep() { super(ConfigMap.class); } } - private static class ServiceDep extends KubernetesDependentResource { + public static class ServiceDep extends KubernetesDependentResource + implements GarbageCollected { public ServiceDep() { super(Service.class); @@ -159,7 +155,7 @@ public ServiceDep() { @Configured(by = CustomAnnotation.class, with = CustomConfig.class, converter = CustomConfigConverter.class) private static class CustomAnnotatedDep implements DependentResource, - DependentResourceConfigurator { + ConfiguredDependentResource, GarbageCollected { public static final int PROVIDED_VALUE = 42; private CustomConfig config; @@ -183,6 +179,11 @@ public void configureWith(CustomConfig config) { public Optional configuration() { return Optional.ofNullable(config); } + + @Override + public void delete(ConfigMap primary, Context context) { + + } } private static class ChildCustomAnnotatedDep extends CustomAnnotatedDep { @@ -209,14 +210,14 @@ public int getValue() { } private static class CustomConfigConverter - implements ConfigurationConverter { + implements ConfigurationConverter { static final int CONVERTER_PROVIDED_DEFAULT = 7; @Override public CustomConfig configFrom(CustomAnnotation configAnnotation, - io.javaoperatorsdk.operator.api.config.ControllerConfiguration parentConfiguration, - Class originatingClass) { + DependentResourceSpec spec, + io.javaoperatorsdk.operator.api.config.ControllerConfiguration parentConfiguration) { if (configAnnotation == null) { return new CustomConfig(CONVERTER_PROVIDED_DEFAULT); } else { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/GroupVersionKindTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/GroupVersionKindTest.java index a20233a6f0..aefbaf6d49 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/GroupVersionKindTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/GroupVersionKindTest.java @@ -7,6 +7,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.GroupVersionKindPlural; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; class GroupVersionKindTest { @@ -21,6 +22,24 @@ void testInitFromApiVersion() { assertThat(gvk.getVersion()).isEqualTo("v1"); } + @Test + void parseGVK() { + var gvk = GroupVersionKind.fromString("apps/v1/Deployment"); + assertThat(gvk.getGroup()).isEqualTo("apps"); + assertThat(gvk.getVersion()).isEqualTo("v1"); + assertThat(gvk.getKind()).isEqualTo("Deployment"); + + + gvk = GroupVersionKind.fromString("v1/ConfigMap"); + assertThat(gvk.getGroup()).isNull(); + assertThat(gvk.getVersion()).isEqualTo("v1"); + assertThat(gvk.getKind()).isEqualTo("ConfigMap"); + + assertThrows(IllegalArgumentException.class, () -> GroupVersionKind.fromString("v1#ConfigMap")); + assertThrows(IllegalArgumentException.class, + () -> GroupVersionKind.fromString("api/beta/v1/ConfigMap")); + } + @Test void pluralShouldOnlyBeProvidedIfExplicitlySet() { final var kind = "ConfigMap"; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java index 370d3d62c1..997f7688e8 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java @@ -146,7 +146,7 @@ void checkServiceAccount() { .addNewImagePullSecret("imagePullSecret3") .build(); - final var matcher = GenericResourceUpdaterMatcher.updaterMatcherFor(ServiceAccount.class); + final var matcher = GenericResourceUpdaterMatcher.updaterMatcherFor(); assertThat(matcher.matches(actual, desired, context)).isTrue(); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterMatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterMatcherTest.java index 44f3fb51ea..bbdb4811fe 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterMatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterMatcherTest.java @@ -40,7 +40,7 @@ static void setUp() { @Test void preservesValues() { - var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(Deployment.class); + var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(); var desired = createDeployment(); var actual = createDeployment(); actual.getMetadata().setLabels(new HashMap<>()); @@ -57,7 +57,7 @@ void preservesValues() { @Test void checkNamespaces() { - var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(Namespace.class); + var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(); var desired = new NamespaceBuilder().withNewMetadata().withName("foo").endMetadata().build(); var actual = new NamespaceBuilder().withNewMetadata().withName("foo").endMetadata().build(); actual.getMetadata().setLabels(new HashMap<>()); @@ -85,7 +85,7 @@ void checkNamespaces() { @Test void checkSecret() { - var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(Secret.class); + var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(); var desired = new SecretBuilder() .withMetadata(new ObjectMeta()) @@ -102,7 +102,7 @@ void checkSecret() { @Test void checkSeviceAccount() { - var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(ServiceAccount.class); + var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(); var desired = new ServiceAccountBuilder() .withMetadata(new ObjectMetaBuilder().addToLabels("new", "label").build()) .build(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java index adebd635f7..970e40eff6 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutorTest.java @@ -3,18 +3,24 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.processing.dependent.Creator; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class AbstractWorkflowExecutorTest { public static final String VALUE = "value"; @@ -39,11 +45,6 @@ public TestDependent(String name) { super(ConfigMap.class, name); } - @Override - protected Class getPrimaryResourceType() { - return TestCustomResource.class; - } - @Override public ReconcileResult reconcile(TestCustomResource primary, Context context) { @@ -52,6 +53,14 @@ public ReconcileResult reconcile(TestCustomResource primary, .resourceCreated(new ConfigMapBuilder().addToBinaryData("key", VALUE).build()); } + @Override + public synchronized Optional> eventSource( + EventSourceContext context) { + var mockIES = mock(InformerEventSource.class); + when(mockIES.name()).thenReturn(name); + return Optional.of(mockIES); + } + @Override public String toString() { return name(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTestUtils.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTestUtils.java index b314b5b112..ae0731b8f5 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTestUtils.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTestUtils.java @@ -11,9 +11,7 @@ import io.javaoperatorsdk.operator.processing.dependent.EmptyTestDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.withSettings; +import static org.mockito.Mockito.*; @SuppressWarnings("rawtypes") public class ManagedWorkflowTestUtils { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSourceTestBase.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSourceTestBase.java index de5df68319..41b8b76623 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSourceTestBase.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/AbstractEventSourceTestBase.java @@ -2,8 +2,7 @@ import org.junit.jupiter.api.AfterEach; -import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; -import io.javaoperatorsdk.operator.api.config.ConfigurationService; +import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.processing.event.EventHandler; import io.javaoperatorsdk.operator.processing.event.source.informer.ManagedInformerEventSource; @@ -23,7 +22,7 @@ public void setUpSource(S source) { } - public void setUpSource(S source, boolean start, ConfigurationService configurationService) { + public void setUpSource(S source, boolean start, ControllerConfiguration configurationService) { setUpSource(source, (T) mock(EventHandler.class), start, configurationService); } @@ -37,16 +36,16 @@ public void setUpSource(S source, T eventHandler) { } public void setUpSource(S source, T eventHandler, boolean start) { - setUpSource(source, eventHandler, start, new BaseConfigurationService()); + setUpSource(source, eventHandler, start, mock(ControllerConfiguration.class)); } public void setUpSource(S source, T eventHandler, boolean start, - ConfigurationService configurationService) { + ControllerConfiguration controllerConfiguration) { this.eventHandler = eventHandler; this.source = source; if (source instanceof ManagedInformerEventSource) { - ((ManagedInformerEventSource) source).setConfigurationService(configurationService); + ((ManagedInformerEventSource) source).setControllerConfiguration(controllerConfiguration); } source.setEventHandler(eventHandler); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java index ca6c030a88..71670a37b1 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java @@ -10,6 +10,7 @@ import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.TestUtils; import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; +import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.ResolvedControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; @@ -23,11 +24,7 @@ import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; class ControllerEventSourceTest extends AbstractEventSourceTestBase, EventHandler> { @@ -36,11 +33,14 @@ class ControllerEventSourceTest extends ReconcilerUtils.getDefaultFinalizerName(TestCustomResource.class); private final TestController testController = new TestController(true); + private final ControllerConfiguration controllerConfig = mock(ControllerConfiguration.class); @BeforeEach public void setup() { - setUpSource(new ControllerEventSource<>(testController), true, - new BaseConfigurationService()); + + when(controllerConfig.getConfigurationService()).thenReturn(new BaseConfigurationService()); + + setUpSource(new ControllerEventSource<>(testController), true, controllerConfig); } @Test @@ -128,7 +128,7 @@ void filtersOutEventsOnAddAndUpdate() { source = new ControllerEventSource<>( new TestController(onAddFilter, onUpdatePredicate, null)); - setUpSource(source); + setUpSource(source, true, controllerConfig); source.eventReceived(ResourceAction.ADDED, cr, null); source.eventReceived(ResourceAction.UPDATED, cr, cr); @@ -142,7 +142,7 @@ void genericFilterFiltersOutAddUpdateAndDeleteEvents() { source = new ControllerEventSource<>(new TestController(null, null, res -> false)); - setUpSource(source); + setUpSource(source, true, controllerConfig); source.eventReceived(ResourceAction.ADDED, cr, null); source.eventReceived(ResourceAction.UPDATED, cr, cr); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java index 5b8aac89e6..a6a5f33570 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java @@ -14,6 +14,7 @@ import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.ConfigurationService; +import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.InformerStoppedHandler; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.processing.event.EventHandler; @@ -56,8 +57,11 @@ void setup() { informerEventSource = new InformerEventSource<>(informerConfiguration, clientMock); + var mockControllerConfig = mock(ControllerConfiguration.class); + when(mockControllerConfig.getConfigurationService()).thenReturn(new BaseConfigurationService()); + informerEventSource.setEventHandler(eventHandlerMock); - informerEventSource.setConfigurationService(new BaseConfigurationService()); + informerEventSource.setControllerConfiguration(mockControllerConfig); SecondaryToPrimaryMapper secondaryToPrimaryMapper = mock(SecondaryToPrimaryMapper.class); when(informerConfiguration.getSecondaryToPrimaryMapper()) .thenReturn(secondaryToPrimaryMapper); @@ -177,11 +181,14 @@ void informerStoppedHandlerShouldBeCalledWhenInformerStops() { ConfigurationService.newOverriddenConfigurationService(new BaseConfigurationService(), o -> o.withInformerStoppedHandler(informerStoppedHandler)); + var mockControllerConfig = mock(ControllerConfiguration.class); + when(mockControllerConfig.getConfigurationService()).thenReturn(configuration); + informerEventSource = new InformerEventSource<>(informerConfiguration, MockKubernetesClient.client(Deployment.class, unused -> { throw exception; })); - informerEventSource.setConfigurationService(configuration); + informerEventSource.setControllerConfiguration(mockControllerConfig); // by default informer fails to start if there is an exception in the client on start. // Throws the exception further. diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java index 5dffa65ae7..ced96e9b7d 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java @@ -32,7 +32,7 @@ class PollingEventSourceTest mock(PollingEventSource.GenericResourceFetcher.class); private final PollingEventSource pollingEventSource = new PollingEventSource<>(SampleExternalResource.class, - new PollingConfiguration<>(resourceFetcher, POLL_PERIOD, + new PollingConfiguration<>(null, resourceFetcher, POLL_PERIOD, (SampleExternalResource er) -> er.getName() + "#" + er.getValue())); @BeforeEach diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java index dba08faba0..0ba8fa6229 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java @@ -1,5 +1,7 @@ package io.javaoperatorsdk.operator; +import java.time.Duration; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -48,7 +50,7 @@ void workflowInvokedExplicitly() { // The ConfigMap is not garbage collected, this tests that even if the cleaner is not // implemented the workflow cleanup still called even if there is explicit invocation - await().untilAsserted(() -> { + await().timeout(Duration.ofSeconds(30)).untilAsserted(() -> { assertThat(extension.get(ConfigMap.class, RESOURCE_NAME)).isNull(); }); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java index c39a2b68ea..103d7b0e12 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java @@ -7,7 +7,6 @@ import java.time.Duration; import java.util.List; import java.util.Optional; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Assertions; @@ -21,7 +20,6 @@ import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.dependent.ConfigurationConverter; import io.javaoperatorsdk.operator.api.config.dependent.Configured; -import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; @@ -32,10 +30,10 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DependentResourceConfigurator; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.BooleanWithUndefined; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig; import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimited; @@ -69,29 +67,19 @@ private

io.javaoperatorsdk.operator.api.config.Controlle return configurationService.configFor(reconciler); } - @Test - void defaultValuesShouldBeConsistent() { - final var configuration = configFor(new SelectorReconciler()); - final var annotated = extractDependentKubernetesResourceConfig(configuration, 1); - final var unannotated = extractDependentKubernetesResourceConfig(configuration, 0); - - assertNull(annotated.labelSelector()); - assertNull(unannotated.labelSelector()); - } - - @SuppressWarnings("rawtypes") - private KubernetesDependentResourceConfig extractDependentKubernetesResourceConfig( + @SuppressWarnings({"rawtypes", "unchecked"}) + private static KubernetesDependentResourceConfig extractDependentKubernetesResourceConfig( io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration, int index) { final var spec = configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().get(index); - return (KubernetesDependentResourceConfig) DependentResourceConfigurationResolver - .configurationFor(spec, configuration); + return (KubernetesDependentResourceConfig) configuration.getConfigurationFor(spec); } @Test - @SuppressWarnings("rawtypes") + @SuppressWarnings({"rawtypes", "unchecked"}) void getDependentResources() { var configuration = configFor(new NoDepReconciler()); + var workflowSpec = configuration.getWorkflowSpec(); assertTrue(workflowSpec.isEmpty()); @@ -103,14 +91,10 @@ void getDependentResources() { assertTrue(dependents.stream().anyMatch(d -> d.getName().equals(dependentResourceName))); var dependentSpec = findByName(dependents, dependentResourceName); assertEquals(ReadOnlyDependent.class, dependentSpec.getDependentResourceClass()); - var maybeConfig = - DependentResourceConfigurationResolver.configurationFor(dependentSpec, configuration); + var maybeConfig = extractDependentKubernetesResourceConfig(configuration, 0); assertNotNull(maybeConfig); assertInstanceOf(KubernetesDependentResourceConfig.class, maybeConfig); final var config = (KubernetesDependentResourceConfig) maybeConfig; - // check that the DependentResource inherits the controller's configuration if applicable - assertEquals(1, config.namespaces().size()); - assertEquals(Set.of(OneDepReconciler.CONFIGURED_NS), config.namespaces()); configuration = configFor(new NamedDepReconciler()); dependents = configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); @@ -118,8 +102,7 @@ void getDependentResources() { assertEquals(1, dependents.size()); dependentSpec = findByName(dependents, NamedDepReconciler.NAME); assertEquals(ReadOnlyDependent.class, dependentSpec.getDependentResourceClass()); - maybeConfig = DependentResourceConfigurationResolver.configurationFor(dependentSpec, - configuration); + maybeConfig = extractDependentKubernetesResourceConfig(configuration, 0); assertNotNull(maybeConfig); assertInstanceOf(KubernetesDependentResourceConfig.class, maybeConfig); } @@ -295,13 +278,12 @@ void shouldUseSSAShouldAlsoWorkWithManualConfiguration() { configurationService.shouldUseSSA(reconciler.getSsaConfigMapDependent())); } + @SuppressWarnings("unchecked") private static int getValue( io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration, int index) { - return ((CustomConfig) DependentResourceConfigurationResolver - .configurationFor( - configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().get(index), - configuration)) - .getValue(); + final var spec = + configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().get(index); + return ((CustomConfig) configuration.getConfigurationFor(spec)).value(); } @ControllerConfiguration( @@ -386,7 +368,7 @@ public UpdateControl reconcile(ConfigMapReader resource, @Dependent(type = ReadOnlyDependent.class) }) @ControllerConfiguration - private static class SelectorReconciler implements Reconciler { + public static class SelectorReconciler implements Reconciler { @Override public UpdateControl reconcile(ConfigMapReader resource, @@ -395,8 +377,8 @@ public UpdateControl reconcile(ConfigMapReader resource, } @KubernetesDependent(useSSA = BooleanWithUndefined.TRUE) - private static class WithAnnotation - extends KubernetesDependentResource { + public static class WithAnnotation + extends CRUDKubernetesDependentResource { public WithAnnotation() { super(ConfigMap.class); @@ -404,7 +386,7 @@ public WithAnnotation() { } } - private static class MissingAnnotationReconciler implements Reconciler { + public static class MissingAnnotationReconciler implements Reconciler { @Override public UpdateControl reconcile(ConfigMap resource, Context context) { @@ -548,7 +530,7 @@ public UpdateControl reconcile(ConfigMap resource, Context @Configured(by = CustomAnnotation.class, with = CustomConfig.class, converter = CustomConfigConverter.class) private static class CustomAnnotatedDep implements DependentResource, - DependentResourceConfigurator { + ConfiguredDependentResource { public static final int PROVIDED_VALUE = 42; private CustomConfig config; @@ -584,28 +566,17 @@ private static class ChildCustomAnnotatedDep extends CustomAnnotatedDep { int value(); } - private static class CustomConfig { - - private final int value; - - private CustomConfig(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - } + private record CustomConfig(int value) {} private static class CustomConfigConverter - implements ConfigurationConverter { + implements ConfigurationConverter { static final int CONVERTER_PROVIDED_DEFAULT = 7; @Override public CustomConfig configFrom(CustomAnnotation configAnnotation, - io.javaoperatorsdk.operator.api.config.ControllerConfiguration parentConfiguration, - Class originatingClass) { + DependentResourceSpec spec, + io.javaoperatorsdk.operator.api.config.ControllerConfiguration parentConfiguration) { if (configAnnotation == null) { return new CustomConfig(CONVERTER_PROVIDED_DEFAULT); } else { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java index 1ee4e3ef24..f9a92f9061 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java @@ -28,11 +28,6 @@ public ConfigMapDeleterBulkDependentResource() { super(ConfigMap.class); } - @Override - protected Class getPrimaryResourceType() { - return BulkDependentTestCustomResource.class; - } - @Override public Map desiredResources(BulkDependentTestCustomResource primary, Context context) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java index 0f4fb80b8a..661cfb931b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java @@ -8,6 +8,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; @@ -15,6 +16,7 @@ import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; +@KubernetesDependent public class ReadOnlyBulkDependentResource extends KubernetesDependentResource @@ -27,11 +29,6 @@ public ReadOnlyBulkDependentResource() { super(ConfigMap.class); } - @Override - protected Class getPrimaryResourceType() { - return BulkDependentTestCustomResource.class; - } - @Override public Map getSecondaryResources(BulkDependentTestCustomResource primary, Context context) { @@ -51,4 +48,5 @@ public Set toPrimaryResourceIDs(ConfigMap resource) { return Mappers.fromOwnerReferences(BulkDependentTestCustomResource.class, false) .toPrimaryResourceIDs(resource); } + } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java index 00750b30b0..e54e3e3cb7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java @@ -24,8 +24,10 @@ public List prepareEventSources( EventSourceContext context) { InformerEventSource configMapES = - new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) - .build(), context); + new InformerEventSource<>( + InformerConfiguration.from(ConfigMap.class, ChangeNamespaceTestCustomResource.class) + .build(), + context); return List.of(configMapES); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java index ec872bd6b2..f1f66bc3ae 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java @@ -55,11 +55,13 @@ private ConfigMap desired(ClusterScopedCustomResource resource) { @Override public List prepareEventSources( EventSourceContext context) { - var ies = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) - .withSecondaryToPrimaryMapper( - Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), true)) - .withLabelSelector(TEST_LABEL_KEY + "=" + TEST_LABEL_VALUE) - .build(), context); + var ies = new InformerEventSource<>( + InformerConfiguration.from(ConfigMap.class, ClusterScopedCustomResource.class) + .withSecondaryToPrimaryMapper( + Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), true)) + .withLabelSelector(TEST_LABEL_KEY + "=" + TEST_LABEL_VALUE) + .build(), + context); return List.of(ies); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java index d2259faeaf..1937a4783e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java @@ -54,12 +54,16 @@ public UpdateControl reconcile( public List prepareEventSources( EventSourceContext context) { InformerEventSource serviceEventSource = - new InformerEventSource<>(SERVICE_EVENT_SOURCE_NAME, - InformerConfiguration.from(Service.class, context).build(), + new InformerEventSource<>( + InformerConfiguration.from(Service.class, ComplexDependentCustomResource.class) + .withName(SERVICE_EVENT_SOURCE_NAME) + .build(), context); InformerEventSource statefulSetEventSource = - new InformerEventSource<>(STATEFUL_SET_EVENT_SOURCE_NAME, - InformerConfiguration.from(StatefulSet.class, context).build(), + new InformerEventSource<>( + InformerConfiguration.from(StatefulSet.class, ComplexDependentCustomResource.class) + .withName(STATEFUL_SET_EVENT_SOURCE_NAME) + .build(), context); return List.of(serviceEventSource, statefulSetEventSource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java index eee439cbfe..08e7e5fe2e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java @@ -16,11 +16,6 @@ public BaseDependentResource(Class resourceType, String component) { this.component = component; } - @Override - protected Class getPrimaryResourceType() { - return ComplexDependentCustomResource.class; - } - protected String name(ComplexDependentCustomResource primary) { return String.format("%s-%s", component, primary.getSpec().getProjectId()); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index 8567f49916..13c204d39d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -93,7 +93,7 @@ private ConfigMap createConfigMap(CreateUpdateEventFilterTestCustomResource reso public List prepareEventSources( EventSourceContext context) { InformerConfiguration informerConfiguration = - InformerConfiguration.from(ConfigMap.class, context) + InformerConfiguration.from(ConfigMap.class, CreateUpdateEventFilterTestCustomResource.class) .withLabelSelector("integrationtest = " + this.getClass().getSimpleName()) .build(); final var informerEventSource = diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java index e17fdb8099..d8b71c9cf9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java @@ -8,10 +8,12 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; +@KubernetesDependent public class CustomMappingConfigMapDependentResource extends CRUDNoGCKubernetesDependentResource implements SecondaryToPrimaryMapper { @@ -20,7 +22,7 @@ public class CustomMappingConfigMapDependentResource public static final String CUSTOM_NAMESPACE_KEY = "customNamespaceKey"; public static final String KEY = "key"; - private final SecondaryToPrimaryMapper mapper = + private static final SecondaryToPrimaryMapper mapper = Mappers.fromAnnotation(CUSTOM_NAME_KEY, CUSTOM_NAMESPACE_KEY); public CustomMappingConfigMapDependentResource() { @@ -39,14 +41,17 @@ protected ConfigMap desired(DependentCustomMappingCustomResource primary, .build(); } - @Override - public Set toPrimaryResourceIDs(ConfigMap resource) { - return mapper.toPrimaryResourceIDs(resource); - } - @Override protected void addSecondaryToPrimaryMapperAnnotations(ConfigMap desired, DependentCustomMappingCustomResource primary) { addSecondaryToPrimaryMapperAnnotations(desired, primary, CUSTOM_NAME_KEY, CUSTOM_NAMESPACE_KEY); } + + + @Override + public Set toPrimaryResourceIDs(ConfigMap resource) { + return mapper.toPrimaryResourceIDs(resource); + } + + } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/FilteredDependentConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/FilteredDependentConfigMap.java index ee4bd4cde7..18b9aaa510 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/FilteredDependentConfigMap.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/FilteredDependentConfigMap.java @@ -6,11 +6,12 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import static io.javaoperatorsdk.operator.sample.dependentfilter.DependentFilterTestReconciler.CM_VALUE_KEY; -@KubernetesDependent(onUpdateFilter = UpdateFilter.class) +@KubernetesDependent(informerConfig = @InformerConfig(onUpdateFilter = UpdateFilter.class)) public class FilteredDependentConfigMap extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java index 94744e30de..74d4890ec8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java @@ -70,9 +70,11 @@ private InformerEventSource clazz, Context context) { - return new InformerEventSource<>(clazz.getSimpleName(), - InformerConfiguration.from(GroupVersionKind.gvkFor(clazz), - context.eventSourceRetriever().eventSourceContextForDynamicRegistration()).build(), + return new InformerEventSource<>( + InformerConfiguration + .from(GroupVersionKind.gvkFor(clazz), DynamicGenericEventSourceRegistrationCustomResource.class) + .withName(clazz.getSimpleName()) + .build(), context.eventSourceRetriever().eventSourceContextForDynamicRegistration()); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java index b9c264ba63..8fe2a1f707 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java @@ -37,7 +37,8 @@ public int getNumberOfExecutions() { public List prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, context).build(), context); + InformerConfiguration.from(ConfigMap.class, ExternalStateCustomResource.class).build(), + context); return List.of(configMapEventSource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java index 4f7bb0ce5c..fd5e5aa37f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java @@ -111,7 +111,8 @@ public List prepareEventSources( EventSourceContext context) { configMapEventSource = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, context).build(), context); + InformerConfiguration.from(ConfigMap.class, ExternalStateCustomResource.class).build(), + context); configMapEventSource.setEventSourcePriority(EventSourceStartPriority.RESOURCE_STATE_LOADER); final PerResourcePollingEventSource.ResourceFetcher fetcher = diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java index 0da96c2e32..a0ea6c0089 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java @@ -36,7 +36,9 @@ public int getNumberOfExecutions() { public List prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, context).build(), context); + InformerConfiguration.from(ConfigMap.class, ExternalStateBulkDependentCustomResource.class) + .build(), + context); return List.of(configMapEventSource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java index e611968766..74fbfbbe2d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java @@ -54,7 +54,7 @@ public List prepareEventSources( InformerEventSource configMapES = new InformerEventSource<>(InformerConfiguration - .from(ConfigMap.class, context) + .from(ConfigMap.class, FilterTestCustomResource.class) .withOnUpdateFilter((newCM, oldCM) -> !newCM.getData().get(CM_VALUE_KEY) .equals(CONFIG_MAP_FILTER_VALUE)) .build(), context); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java index d5ab470cfb..00c202436f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java @@ -11,7 +11,9 @@ import io.javaoperatorsdk.operator.processing.dependent.Creator; import io.javaoperatorsdk.operator.processing.dependent.Updater; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.GenericKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; +@KubernetesDependent public class ConfigMapGenericKubernetesDependent extends GenericKubernetesDependentResource implements diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java index f5c66e8d30..4d93438735 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java @@ -69,7 +69,8 @@ public List prepareEventSources( EventSourceContext context) { var informerEventSource = new InformerEventSource<>(InformerConfiguration.from( - new GroupVersionKind("", VERSION, KIND), context).build(), + new GroupVersionKind("", VERSION, KIND), + GenericKubernetesResourceHandlingCustomResource.class).build(), context); return List.of(informerEventSource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java index 232426403d..868dc4f3ed 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java @@ -36,7 +36,7 @@ public List prepareEventSources( EventSourceContext context) { InformerConfiguration config = - InformerConfiguration.from(ConfigMap.class, context) + InformerConfiguration.from(ConfigMap.class, InformerEventSourceTestCustomResource.class) .withSecondaryToPrimaryMapper(Mappers.fromAnnotation(RELATED_RESOURCE_NAME)) .build(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/ConfigMapDependentResource.java index c9747cbd00..bda0b94845 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/ConfigMapDependentResource.java @@ -7,9 +7,10 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(labelSelector = "app=rbac-test") +@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = "app=rbac-test")) public class ConfigMapDependentResource extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java index c61d751079..e129b2e3d5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java @@ -36,10 +36,11 @@ public UpdateControl reconcile( public List prepareEventSources( EventSourceContext context) { InformerEventSource eventSource = - new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) + new InformerEventSource<>(InformerConfiguration + .from(ConfigMap.class, MultipleDependentResourceCustomResource.class) .build(), context); - firstDependentResourceConfigMap.configureWith(eventSource); - secondDependentResourceConfigMap.configureWith(eventSource); + firstDependentResourceConfigMap.setEventSource(eventSource); + secondDependentResourceConfigMap.setEventSource(eventSource); return List.of(eventSource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java index 9e04af6d24..fd90838ddd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java @@ -46,10 +46,11 @@ public int getNumberOfExecutions() { public List prepareEventSources( EventSourceContext context) { InformerEventSource eventSource = - new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) + new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, + MultipleDependentResourceCustomResourceWithDiscriminator.class) .build(), context); - firstDependentResourceConfigMap.configureWith(eventSource); - secondDependentResourceConfigMap.configureWith(eventSource); + firstDependentResourceConfigMap.setEventSource(eventSource); + secondDependentResourceConfigMap.setEventSource(eventSource); return List.of(eventSource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java index 6377385b6e..feec6dc727 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java @@ -49,8 +49,10 @@ public int getNumberOfExecutions() { public List prepareEventSources( EventSourceContext context) { InformerEventSource ies = - new InformerEventSource<>(CONFIG_MAP_EVENT_SOURCE, - InformerConfiguration.from(ConfigMap.class, context) + new InformerEventSource<>( + InformerConfiguration.from(ConfigMap.class, + MultipleManagedDependentNoDiscriminatorCustomResource.class) + .withName(CONFIG_MAP_EVENT_SOURCE) .build(), context); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java index 63c22436d8..53917dd593 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java @@ -49,8 +49,10 @@ public int getNumberOfExecutions() { public List prepareEventSources( EventSourceContext context) { InformerEventSource ies = - new InformerEventSource<>(CONFIG_MAP_EVENT_SOURCE, - InformerConfiguration.from(ConfigMap.class, context) + new InformerEventSource<>( + InformerConfiguration + .from(ConfigMap.class, MultipleManagedDependentResourceCustomResource.class) + .withName(CONFIG_MAP_EVENT_SOURCE) .build(), context); return List.of(ies); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java index 614f3a0b59..786e1c82d6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java @@ -71,8 +71,9 @@ public List prepareEventSources( }; PollingEventSource pollingEventSource = - new PollingEventSource<>(EVENT_SOURCE_NAME, ExternalResource.class, + new PollingEventSource<>(ExternalResource.class, new PollingConfigurationBuilder<>(fetcher, Duration.ofMillis(1000L)) + .withName(EVENT_SOURCE_NAME) .withCacheKeyMapper(ExternalResource::getId) .build()); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java index 88f97a8235..fb216e9edd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java @@ -64,7 +64,8 @@ public int getNumberOfExecutions() { public List prepareEventSources( EventSourceContext context) { - var config = InformerConfiguration.from(ConfigMap.class, context) + var config = InformerConfiguration + .from(ConfigMap.class, MultipleSecondaryEventSourceCustomResource.class) .withNamespaces(context.getControllerConfiguration().getNamespaces()) .withLabelSelector("multisecondary") .withSecondaryToPrimaryMapper(s -> { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java index 14530cf17e..8c5a844cfb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java @@ -8,9 +8,10 @@ import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(labelSelector = "dependent = cm1") +@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = "dependent = cm1")) public class ConfigMapDependentResource1 extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java index 35ae69586e..72a427aad6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java @@ -8,9 +8,10 @@ import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(labelSelector = "dependent = cm2") +@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = "dependent = cm2")) public class ConfigMapDependentResource2 extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java index 513cc2cb5d..6c277b0fa6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java @@ -1,12 +1,12 @@ package io.javaoperatorsdk.operator.sample.primaryindexer; -import java.util.Optional; -import java.util.Set; +import java.util.List; import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; @@ -15,21 +15,44 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.processing.event.source.IndexerResourceCache; -import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; -@Workflow(dependents = @Dependent( +import static io.javaoperatorsdk.operator.sample.primaryindexer.DependentPrimaryIndexerTestReconciler.CONFIG_MAP_EVENT_SOURCE; + +@Workflow(dependents = @Dependent(useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE, type = DependentPrimaryIndexerTestReconciler.ReadOnlyConfigMapDependent.class)) @ControllerConfiguration public class DependentPrimaryIndexerTestReconciler extends AbstractPrimaryIndexerTestReconciler implements Reconciler { + public static final String CONFIG_MAP_EVENT_SOURCE = "configMapEventSource"; + + @Override + public List prepareEventSources( + EventSourceContext context) { + + var cache = context.getPrimaryCache(); + cache.addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer); + + InformerEventSource es = + new InformerEventSource<>( + InformerConfiguration.from(ConfigMap.class, PrimaryIndexerTestCustomResource.class) + .withName(CONFIG_MAP_EVENT_SOURCE) + .withSecondaryToPrimaryMapper(resource -> cache + .byIndex(CONFIG_MAP_RELATION_INDEXER, resource.getMetadata().getName()) + .stream() + .map(ResourceID::fromResource) + .collect(Collectors.toSet())) + .build(), + context); + + return List.of(es); + } + public static class ReadOnlyConfigMapDependent - extends KubernetesDependentResource implements - SecondaryToPrimaryMapper { - private IndexerResourceCache cache; + extends KubernetesDependentResource { public ReadOnlyConfigMapDependent() { super(ConfigMap.class); @@ -45,21 +68,5 @@ protected ConfigMap desired(PrimaryIndexerTestCustomResource primary, .build()) .build(); } - - @Override - public Set toPrimaryResourceIDs(ConfigMap resource) { - return cache.byIndex(CONFIG_MAP_RELATION_INDEXER, resource.getMetadata().getName()) - .stream() - .map(ResourceID::fromResource) - .collect(Collectors.toSet()); - } - - @Override - public Optional> eventSource( - EventSourceContext context) { - cache = context.getPrimaryCache(); - cache.addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer); - return super.eventSource(context); - } } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java index 547c224e55..e20cf037c2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java @@ -22,7 +22,7 @@ public List prepareEventSources( context.getPrimaryCache().addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer); var informerConfiguration = - InformerConfiguration.from(ConfigMap.class, context) + InformerConfiguration.from(ConfigMap.class, PrimaryIndexerTestCustomResource.class) .withSecondaryToPrimaryMapper( (ConfigMap secondaryResource) -> context .getPrimaryCache() diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java index 8cd64b95db..afe5845c45 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java @@ -65,12 +65,12 @@ public List prepareEventSources(EventSourceContext context) { .of(indexKey(job.getSpec().getClusterName(), job.getMetadata().getNamespace())))); InformerConfiguration.InformerConfigurationBuilder informerConfiguration = - InformerConfiguration.from(Cluster.class, context) + InformerConfiguration.from(Cluster.class, Job.class) .withSecondaryToPrimaryMapper(cluster -> context.getPrimaryCache() .byIndex(JOB_CLUSTER_INDEX, indexKey(cluster.getMetadata().getName(), cluster.getMetadata().getNamespace())) .stream().map(ResourceID::fromResource).collect(Collectors.toSet())) - .withNamespacesInheritedFromController(context); + .withNamespacesInheritedFromController(); if (addPrimaryToSecondaryMapper) { informerConfiguration = informerConfiguration.withPrimaryToSecondaryMapper( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java index a6cf2cef12..2b48ee0d2a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java @@ -66,8 +66,9 @@ public List prepareEventSources( context.getPrimaryCache().addIndexer(CONFIG_MAP_INDEX, (primary -> List .of(indexKey(primary.getSpec().getConfigMapName(), primary.getMetadata().getNamespace())))); - var es = new InformerEventSource<>(CONFIG_MAP_EVENT_SOURCE, InformerConfiguration - .from(ConfigMap.class, context) + var es = new InformerEventSource<>(InformerConfiguration + .from(ConfigMap.class, PrimaryToSecondaryDependentCustomResource.class) + .withName(CONFIG_MAP_EVENT_SOURCE) // if there is a many-to-many relationship (thus no direct owner reference) // PrimaryToSecondaryMapper needs to be added .withPrimaryToSecondaryMapper( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ReadOnlyDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ReadOnlyDependent.java index 15fb02a0b6..b586e38636 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ReadOnlyDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ReadOnlyDependent.java @@ -1,8 +1,10 @@ package io.javaoperatorsdk.operator.sample.readonly; import io.fabric8.kubernetes.api.model.ConfigMap; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; +@KubernetesDependent public class ReadOnlyDependent extends KubernetesDependentResource { public ReadOnlyDependent() { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/ConfigMapDependentResource.java index edb4e2baff..261ebb63b3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/ConfigMapDependentResource.java @@ -7,9 +7,10 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(labelSelector = "app=restart-test") +@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = "app=restart-test")) public class ConfigMapDependentResource extends CRUDKubernetesDependentResource { diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java index 2098b531b3..60875e6ae3 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java @@ -16,9 +16,10 @@ import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.dependent.ConfigurationConverter; import io.javaoperatorsdk.operator.api.config.dependent.Configured; +import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DependentResourceConfigurator; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; import io.javaoperatorsdk.operator.processing.dependent.Creator; import io.javaoperatorsdk.operator.processing.dependent.external.PerResourcePollingDependentResource; import io.javaoperatorsdk.operator.sample.MySQLDbConfig; @@ -38,7 +39,7 @@ converter = ResourcePollerConfigConverter.class) public class SchemaDependentResource extends PerResourcePollingDependentResource - implements DependentResourceConfigurator, + implements ConfiguredDependentResource, Creator, Deleter { public static final String NAME = "schema"; @@ -121,12 +122,12 @@ public Set fetchResources(MySQLSchema primaryResource) { } static class ResourcePollerConfigConverter implements - ConfigurationConverter { + ConfigurationConverter { @Override public ResourcePollerConfig configFrom(SchemaConfig configAnnotation, - ControllerConfiguration parentConfiguration, - Class originatingClass) { + DependentResourceSpec spec, + ControllerConfiguration parentConfiguration) { if (configAnnotation != null) { return new ResourcePollerConfig(Duration.ofMillis(configAnnotation.pollPeriod()), new MySQLDbConfig(configAnnotation.host(), String.valueOf(configAnnotation.port()), diff --git a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SecretDependentResource.java b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SecretDependentResource.java index edaa5707ee..e6cf2a45e7 100644 --- a/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SecretDependentResource.java +++ b/sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SecretDependentResource.java @@ -10,13 +10,16 @@ import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.Creator; import io.javaoperatorsdk.operator.processing.dependent.Matcher.Result; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; import io.javaoperatorsdk.operator.sample.MySQLSchema; +@KubernetesDependent public class SecretDependentResource extends KubernetesDependentResource implements Creator, SecondaryToPrimaryMapper { + public static final String NAME = "secret"; public static final String SECRET_SUFFIX = "-secret"; public static final String SECRET_FORMAT = "%s" + SECRET_SUFFIX; @@ -60,10 +63,12 @@ public Result match(Secret actual, MySQLSchema primary, Context toPrimaryResourceIDs(Secret resource) { String name = resource.getMetadata().getName(); return Set.of(new ResourceID(name.substring(0, name.length() - SECRET_SUFFIX.length()), resource.getMetadata().getNamespace())); } + } diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentDependentResource.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentDependentResource.java index 25e46fad16..e0425235fb 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentDependentResource.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentDependentResource.java @@ -6,9 +6,11 @@ import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(labelSelector = "app.kubernetes.io/managed-by=tomcat-operator") +@KubernetesDependent(informerConfig = @InformerConfig( + labelSelector = "app.kubernetes.io/managed-by=tomcat-operator")) public class DeploymentDependentResource extends CRUDKubernetesDependentResource { diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/ServiceDependentResource.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/ServiceDependentResource.java index 3b526d02bc..56f3330a45 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/ServiceDependentResource.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/ServiceDependentResource.java @@ -6,9 +6,11 @@ import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(labelSelector = "app.kubernetes.io/managed-by=tomcat-operator") +@KubernetesDependent(informerConfig = @InformerConfig( + labelSelector = "app.kubernetes.io/managed-by=tomcat-operator")) public class ServiceDependentResource extends CRUDKubernetesDependentResource { public ServiceDependentResource() { diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java index 79194c7990..4a44070f51 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java @@ -59,7 +59,7 @@ public List prepareEventSources(EventSourceContext context) .collect(Collectors.toSet()); InformerConfiguration configuration = - InformerConfiguration.from(Tomcat.class, context) + InformerConfiguration.from(Tomcat.class, Webapp.class) .withSecondaryToPrimaryMapper(webappsMatchingTomcatName) .withPrimaryToSecondaryMapper( (Webapp primary) -> Set.of(new ResourceID(primary.getSpec().getTomcat(), diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index d8b64db9fd..ebbbd6f7c8 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -9,6 +9,7 @@ import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentInformerConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow; @@ -82,7 +83,10 @@ private void initDependentResources(KubernetesClient client) { Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR).forEach(dr -> { dr.configureWith(new KubernetesDependentResourceConfigBuilder() - .withLabelSelector(DEPENDENT_RESOURCE_LABEL_SELECTOR).build()); + .withKubernetesDependentInformerConfig(new KubernetesDependentInformerConfigBuilder<>() + .withLabelSelector(DEPENDENT_RESOURCE_LABEL_SELECTOR) + .build()) + .build()); }); } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index 68f55108db..84bfdcdc23 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -41,19 +41,19 @@ public WebPageReconciler() { @Override public List prepareEventSources(EventSourceContext context) { var configMapEventSource = - new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, context) + new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, WebPage.class) .withLabelSelector(SELECTOR) .build(), context); var deploymentEventSource = - new InformerEventSource<>(InformerConfiguration.from(Deployment.class, context) + new InformerEventSource<>(InformerConfiguration.from(Deployment.class, WebPage.class) .withLabelSelector(SELECTOR) .build(), context); var serviceEventSource = - new InformerEventSource<>(InformerConfiguration.from(Service.class, context) + new InformerEventSource<>(InformerConfiguration.from(Service.class, WebPage.class) .withLabelSelector(SELECTOR) .build(), context); var ingressEventSource = - new InformerEventSource<>(InformerConfiguration.from(Ingress.class, context) + new InformerEventSource<>(InformerConfiguration.from(Ingress.class, WebPage.class) .withLabelSelector(SELECTOR) .build(), context); return List.of(configMapEventSource, deploymentEventSource, diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java index 4b71f104f6..49a641da01 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java @@ -11,6 +11,7 @@ import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentInformerConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow; import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowBuilder; @@ -95,7 +96,9 @@ private Workflow createDependentResourcesAndWorkflow() { // configure them with our label selector Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR) .forEach(dr -> dr.configureWith(new KubernetesDependentResourceConfigBuilder() - .withLabelSelector(SELECTOR + "=true").build())); + .withKubernetesDependentInformerConfig(new KubernetesDependentInformerConfigBuilder<>() + .withLabelSelector(SELECTOR + "=true").build()) + .build())); // connect the dependent resources into a workflow, configuring them as we go // Note the method call order is significant and configuration applies to the dependent being diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ConfigMapDependentResource.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ConfigMapDependentResource.java index 8641aa343b..aa03aaabca 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ConfigMapDependentResource.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ConfigMapDependentResource.java @@ -8,6 +8,7 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.sample.customresource.WebPage; @@ -15,7 +16,7 @@ import static io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler.SELECTOR; // this annotation only activates when using managed dependents and is not otherwise needed -@KubernetesDependent(labelSelector = SELECTOR) +@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = SELECTOR)) public class ConfigMapDependentResource extends CRUDKubernetesDependentResource { diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/DeploymentDependentResource.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/DeploymentDependentResource.java index 4b2e373260..3aa90bf54c 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/DeploymentDependentResource.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/DeploymentDependentResource.java @@ -7,6 +7,7 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.sample.Utils; import io.javaoperatorsdk.operator.sample.customresource.WebPage; @@ -17,7 +18,7 @@ import static io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler.SELECTOR; // this annotation only activates when using managed dependents and is not otherwise needed -@KubernetesDependent(labelSelector = SELECTOR) +@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = SELECTOR)) public class DeploymentDependentResource extends CRUDKubernetesDependentResource { diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/IngressDependentResource.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/IngressDependentResource.java index f3a3aa65ba..abfe9a13f5 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/IngressDependentResource.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/IngressDependentResource.java @@ -3,6 +3,7 @@ import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler; import io.javaoperatorsdk.operator.sample.customresource.WebPage; @@ -10,7 +11,8 @@ import static io.javaoperatorsdk.operator.sample.Utils.makeDesiredIngress; // this annotation only activates when using managed dependents and is not otherwise needed -@KubernetesDependent(labelSelector = WebPageManagedDependentsReconciler.SELECTOR) +@KubernetesDependent( + informerConfig = @InformerConfig(labelSelector = WebPageManagedDependentsReconciler.SELECTOR)) public class IngressDependentResource extends CRUDKubernetesDependentResource { public IngressDependentResource() { diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ServiceDependentResource.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ServiceDependentResource.java index 80d5073a6e..2669fe5f97 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ServiceDependentResource.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ServiceDependentResource.java @@ -5,6 +5,7 @@ import io.fabric8.kubernetes.api.model.Service; import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.sample.Utils; import io.javaoperatorsdk.operator.sample.customresource.WebPage; @@ -15,7 +16,7 @@ import static io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler.SELECTOR; // this annotation only activates when using managed dependents and is not otherwise needed -@KubernetesDependent(labelSelector = SELECTOR) +@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = SELECTOR)) public class ServiceDependentResource extends io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource { From 16d729382b5634b6264fe8c84837c19bdad2a414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 19 Jun 2024 22:05:34 +0200 Subject: [PATCH 53/96] feat: general crd checking activation condition (#2433) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun --- docsy/content/en/docs/workflows/_index.md | 6 + .../CRDPresentActivationCondition.java | 128 ++++++++++++++++++ .../CRDPresentActivationConditionTest.java | 91 +++++++++++++ .../CRDPresentActivationConditionIT.java | 70 ++++++++++ .../CRDPresentActivationCustomResource.java | 17 +++ .../CRDPresentActivationDependent.java | 26 ++++ ...sentActivationDependentCustomResource.java | 16 +++ .../CRDPresentActivationReconciler.java | 30 ++++ 8 files changed, 384 insertions(+) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java create mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationConditionTest.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependent.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependentCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationReconciler.java diff --git a/docsy/content/en/docs/workflows/_index.md b/docsy/content/en/docs/workflows/_index.md index 32d93a6157..83272ec3a9 100644 --- a/docsy/content/en/docs/workflows/_index.md +++ b/docsy/content/en/docs/workflows/_index.md @@ -42,6 +42,12 @@ reconciliation process. platform (e.g. OpenShift vs plain Kubernetes) and/or change its behavior based on the availability of optional resources / features (e.g. CertManager, a specific Ingress controller, etc.). + A generic activation condition is provided out of the box, called + [CRDPresentActivationCondition](https://github.com/operator-framework/java-operator-sdk/blob/ba5e33527bf9e3ea0bd33025ccb35e677f9d44b4/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java) + that will prevent the associated dependent resource from being activated if the Custom Resource Definition associated + with the dependent's resource type is not present on the cluster. + See related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/ba5e33527bf9e3ea0bd33025ccb35e677f9d44b4/operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java). + Activation condition is semi-experimental at the moment, and it has its limitations. For example event sources cannot be shared between multiple managed dependent resources which use activation condition. The intention is to further improve and explore the possibilities with this approach. diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java new file mode 100644 index 0000000000..b3792bb9c7 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java @@ -0,0 +1,128 @@ +package io.javaoperatorsdk.operator.processing.dependent.workflow; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; + +/** + * A generic CRD checking activation condition. Makes sure that the CRD is not checked unnecessarily + * even used in multiple condition. By default, it checks CRD at most 10 times with a delay at least + * 10 seconds. To fully customize CRD check trigger behavior you can extend this class and override + * the {@link CRDPresentActivationCondition#shouldCheckStateNow(CRDCheckState)} method. + **/ +public class CRDPresentActivationCondition + implements Condition { + + public static final int DEFAULT_CRD_CHECK_LIMIT = 10; + public static final Duration DEFAULT_CRD_CHECK_INTERVAL = Duration.ofSeconds(10); + + private static final Map crdPresenceCache = new ConcurrentHashMap<>(); + + private final CRDPresentChecker crdPresentChecker; + private final int checkLimit; + private final Duration crdCheckInterval; + + public CRDPresentActivationCondition() { + this(DEFAULT_CRD_CHECK_LIMIT, DEFAULT_CRD_CHECK_INTERVAL); + } + + public CRDPresentActivationCondition(int checkLimit, Duration crdCheckInterval) { + this(new CRDPresentChecker(), checkLimit, crdCheckInterval); + } + + // for testing purposes only + CRDPresentActivationCondition(CRDPresentChecker crdPresentChecker, int checkLimit, + Duration crdCheckInterval) { + this.crdPresentChecker = crdPresentChecker; + this.checkLimit = checkLimit; + this.crdCheckInterval = crdCheckInterval; + } + + @Override + public boolean isMet(DependentResource dependentResource, + P primary, Context

context) { + + var resourceClass = dependentResource.resourceType(); + final var crdName = HasMetadata.getFullResourceName(resourceClass); + + var crdCheckState = crdPresenceCache.computeIfAbsent(crdName, + g -> new CRDCheckState()); + + synchronized (crdCheckState) { + if (shouldCheckStateNow(crdCheckState)) { + boolean isPresent = crdPresentChecker + .checkIfCRDPresent(crdName, context.getClient()); + crdCheckState.checkedNow(isPresent); + } + } + + if (crdCheckState.isCrdPresent() == null) { + throw new IllegalStateException("State should be already checked at this point."); + } + return crdCheckState.isCrdPresent(); + } + + /** + * Override this method to fine tune when the crd state should be refreshed; + */ + protected boolean shouldCheckStateNow(CRDCheckState crdCheckState) { + if (crdCheckState.isCrdPresent() == null) { + return true; + } + // assumption is that if CRD is present, it is not deleted anymore + if (crdCheckState.isCrdPresent()) { + return false; + } + if (crdCheckState.getCheckCount() >= checkLimit) { + return false; + } + if (crdCheckState.getLastChecked() == null) { + return true; + } + return LocalDateTime.now().isAfter(crdCheckState.getLastChecked().plus(crdCheckInterval)); + } + + public static class CRDCheckState { + private Boolean crdPresent; + private LocalDateTime lastChecked; + private int checkCount = 0; + + public void checkedNow(boolean crdPresent) { + this.crdPresent = crdPresent; + lastChecked = LocalDateTime.now(); + checkCount++; + } + + public Boolean isCrdPresent() { + return crdPresent; + } + + public LocalDateTime getLastChecked() { + return lastChecked; + } + + public int getCheckCount() { + return checkCount; + } + } + + public static class CRDPresentChecker { + boolean checkIfCRDPresent(String crdName, KubernetesClient client) { + return client.resources(CustomResourceDefinition.class) + .withName(crdName).get() != null; + } + } + + /** For testing purposes only */ + public static void clearState() { + crdPresenceCache.clear(); + } + +} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationConditionTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationConditionTest.java new file mode 100644 index 0000000000..58990214a3 --- /dev/null +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationConditionTest.java @@ -0,0 +1,91 @@ +package io.javaoperatorsdk.operator.processing.dependent.workflow; + +import java.time.Duration; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +@SuppressWarnings({"unchecked", "rawtypes"}) +class CRDPresentActivationConditionTest { + + public static final int TEST_CHECK_INTERVAL = 50; + public static final int TEST_CHECK_INTERVAL_WITH_SLACK = TEST_CHECK_INTERVAL + 10; + private final CRDPresentActivationCondition.CRDPresentChecker checkerMock = + mock(CRDPresentActivationCondition.CRDPresentChecker.class); + private final CRDPresentActivationCondition condition = + new CRDPresentActivationCondition(checkerMock, 2, + Duration.ofMillis(TEST_CHECK_INTERVAL)); + private final DependentResource dr = + mock(DependentResource.class); + private final Context context = mock(Context.class); + + + @BeforeEach + void setup() { + CRDPresentActivationCondition.clearState(); + when(checkerMock.checkIfCRDPresent(any(), any())).thenReturn(false); + when(dr.resourceType()).thenReturn(TestCustomResource.class); + } + + + @Test + void checkCRDIfNotCheckedBefore() { + when(checkerMock.checkIfCRDPresent(any(),any())).thenReturn(true); + + assertThat(condition.isMet(dr,null,context)).isTrue(); + verify(checkerMock, times(1)).checkIfCRDPresent(any(),any()); + } + + @Test + void instantMetCallSkipsApiCall() { + condition.isMet(dr, null, context); + verify(checkerMock, times(1)).checkIfCRDPresent(any(), any()); + + condition.isMet(dr, null, context); + verify(checkerMock, times(1)).checkIfCRDPresent(any(), any()); + } + + @Test + void intervalExpiredAPICheckedAgain() throws InterruptedException { + condition.isMet(dr, null, context); + verify(checkerMock, times(1)).checkIfCRDPresent(any(), any()); + + Thread.sleep(TEST_CHECK_INTERVAL_WITH_SLACK); + + condition.isMet(dr, null, context); + verify(checkerMock, times(2)).checkIfCRDPresent(any(), any()); + } + + @Test + void crdIsNotCheckedAnymoreIfIfOnceFound() throws InterruptedException { + when(checkerMock.checkIfCRDPresent(any(),any())).thenReturn(true); + + condition.isMet(dr,null,context); + verify(checkerMock, times(1)).checkIfCRDPresent(any(),any()); + + Thread.sleep(TEST_CHECK_INTERVAL_WITH_SLACK); + + condition.isMet(dr,null,context); + verify(checkerMock, times(1)).checkIfCRDPresent(any(),any()); + } + + @Test + void crdNotCheckedAnymoreIfCountExpires() throws InterruptedException { + condition.isMet(dr, null, context); + Thread.sleep(TEST_CHECK_INTERVAL_WITH_SLACK); + condition.isMet(dr, null, context); + Thread.sleep(TEST_CHECK_INTERVAL_WITH_SLACK); + condition.isMet(dr, null, context); + + verify(checkerMock, times(2)).checkIfCRDPresent(any(), any()); + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java new file mode 100644 index 0000000000..67b2920836 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java @@ -0,0 +1,70 @@ +package io.javaoperatorsdk.operator; + +import java.time.Duration; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.crdpresentactivation.CRDPresentActivationCustomResource; +import io.javaoperatorsdk.operator.sample.crdpresentactivation.CRDPresentActivationDependentCustomResource; +import io.javaoperatorsdk.operator.sample.crdpresentactivation.CRDPresentActivationReconciler; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class CRDPresentActivationConditionIT { + + public static final String TEST_1 = "test1"; + public static final String CRD_NAME = + "crdpresentactivationdependentcustomresources.sample.javaoperatorsdk"; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(new CRDPresentActivationReconciler()) + .build(); + + + @Test + void resourceCreatedOnlyIfCRDPresent() { + // deleted so test can be repeated + extension.getKubernetesClient().resources(CustomResourceDefinition.class) + .withName(CRD_NAME).delete(); + + var resource = extension.create(testResource()); + + await().pollDelay(Duration.ofMillis(300)).untilAsserted(() -> { + var crd = extension.getKubernetesClient().resources(CustomResourceDefinition.class) + .withName(CRD_NAME).get(); + assertThat(crd).isNull(); + + var dr = extension.get(CRDPresentActivationDependentCustomResource.class, TEST_1); + assertThat(dr).isNull(); + }); + + LocallyRunOperatorExtension.applyCrd(CRDPresentActivationDependentCustomResource.class, + extension.getKubernetesClient()); + + resource.getMetadata().setAnnotations(Map.of("sample", "value")); + extension.replace(resource); + + await().pollDelay(Duration.ofMillis(300)).untilAsserted(() -> { + var cm = extension.get(CRDPresentActivationDependentCustomResource.class, TEST_1); + assertThat(cm).isNull(); + }); + + } + + CRDPresentActivationCustomResource testResource() { + var res = new CRDPresentActivationCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(TEST_1) + .build()); + return res; + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationCustomResource.java new file mode 100644 index 0000000000..af2aea00ab --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationCustomResource.java @@ -0,0 +1,17 @@ +package io.javaoperatorsdk.operator.sample.crdpresentactivation; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("crdp") +public class CRDPresentActivationCustomResource + extends CustomResource + implements Namespaced { + + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependent.java new file mode 100644 index 0000000000..6e86e2a475 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependent.java @@ -0,0 +1,26 @@ +package io.javaoperatorsdk.operator.sample.crdpresentactivation; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; + +public class CRDPresentActivationDependent + extends + CRUDNoGCKubernetesDependentResource { + + public CRDPresentActivationDependent() { + super(CRDPresentActivationDependentCustomResource.class); + } + + @Override + protected CRDPresentActivationDependentCustomResource desired( + CRDPresentActivationCustomResource primary, + Context context) { + var res = new CRDPresentActivationDependentCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(primary.getMetadata().getName()) + .withNamespace(primary.getMetadata().getNamespace()) + .build()); + return res; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependentCustomResource.java new file mode 100644 index 0000000000..899cea0e69 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependentCustomResource.java @@ -0,0 +1,16 @@ +package io.javaoperatorsdk.operator.sample.crdpresentactivation; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("addp") +public class CRDPresentActivationDependentCustomResource extends CustomResource + implements Namespaced { + + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationReconciler.java new file mode 100644 index 0000000000..ef96f3b7eb --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationReconciler.java @@ -0,0 +1,30 @@ +package io.javaoperatorsdk.operator.sample.crdpresentactivation; + +import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.processing.dependent.workflow.CRDPresentActivationCondition; + +@Workflow(dependents = { + @Dependent(type = CRDPresentActivationDependent.class, + activationCondition = CRDPresentActivationCondition.class), +}) +// to trigger reconciliation with metadata change +@ControllerConfiguration(generationAwareEventProcessing = false) +public class CRDPresentActivationReconciler + implements Reconciler, + Cleaner { + + @Override + public UpdateControl reconcile( + CRDPresentActivationCustomResource resource, + Context context) { + + return UpdateControl.noUpdate(); + } + + @Override + public DeleteControl cleanup(CRDPresentActivationCustomResource resource, + Context context) { + return DeleteControl.defaultDelete(); + } +} From 4d26dd4f6b7aedd3f04890399dc4e4beabed3bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 19 Jun 2024 22:06:07 +0200 Subject: [PATCH 54/96] improve: generics for prepare event source (#2407) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../source/cache/sample/AbstractTestReconciler.java | 2 +- .../operator/api/reconciler/EventSourceUtils.java | 10 +++++----- .../operator/api/reconciler/Reconciler.java | 2 +- .../StandaloneBulkDependentReconciler.java | 2 +- .../changenamespace/ChangeNamespaceTestReconciler.java | 2 +- .../ClusterScopedCustomResourceReconciler.java | 2 +- .../complexdependent/ComplexDependentReconciler.java | 2 +- .../CreateUpdateEventFilterTestReconciler.java | 2 +- .../DependentReInitializationReconciler.java | 2 +- .../sample/dependentssa/DependentSSAReconciler.java | 2 +- .../ExternalStateDependentReconciler.java | 2 +- .../sample/externalstate/ExternalStateReconciler.java | 2 +- .../ExternalStateBulkDependentReconciler.java | 2 +- .../operator/sample/filter/FilterTestReconciler.java | 2 +- ...GenericKubernetesDependentStandaloneReconciler.java | 2 +- .../GenericKubernetesResourceHandlingReconciler.java | 2 +- .../InformerEventSourceTestCustomReconciler.java | 2 +- .../DependentGarbageCollectionTestReconciler.java | 2 +- .../MultipleDependentResourceReconciler.java | 2 +- ...leDependentResourceWithDiscriminatorReconciler.java | 2 +- ...agedDependentSameTypeNoDiscriminatorReconciler.java | 2 +- .../MultipleManagedDependentResourceReconciler.java | 2 +- ...ipleManagedExternalDependentResourceReconciler.java | 2 +- .../MultipleSecondaryEventSourceReconciler.java | 2 +- .../PerResourcePollingEventSourceTestReconciler.java | 2 +- .../DependentPrimaryIndexerTestReconciler.java | 2 +- .../primaryindexer/PrimaryIndexerTestReconciler.java | 2 +- .../sample/primarytosecondary/JobReconciler.java | 2 +- .../PrimaryToSecondaryDependentReconciler.java | 2 +- .../StandaloneDependentTestReconciler.java | 2 +- .../operator/sample/WebappReconciler.java | 2 +- .../sample/WebPageDependentsWorkflowReconciler.java | 2 +- .../operator/sample/WebPageReconciler.java | 2 +- .../sample/WebPageStandaloneDependentsReconciler.java | 2 +- 34 files changed, 38 insertions(+), 38 deletions(-) diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java index 98101d1243..d43094cdf8 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java @@ -70,7 +70,7 @@ protected void createConfigMap(P resource, Context

context) { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext

context) { var boundedItemStore = diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java index 4294fee405..9531599072 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceUtils.java @@ -10,16 +10,16 @@ public class EventSourceUtils { @SuppressWarnings("unchecked") - public static List dependentEventSources( - EventSourceContext eventSourceContext, DependentResource... dependentResources) { + public static

List> dependentEventSources( + EventSourceContext

eventSourceContext, DependentResource... dependentResources) { return Arrays.stream(dependentResources) .flatMap(dr -> dr.eventSource(eventSourceContext).stream()).toList(); } @SuppressWarnings("unchecked") - public static List eventSourcesFromWorkflow( - EventSourceContext context, - Workflow workflow) { + public static

List> eventSourcesFromWorkflow( + EventSourceContext

context, + Workflow

workflow) { return workflow.getDependentResourcesWithoutActivationCondition().stream() .flatMap(dr -> dr.eventSource(context).stream()).toList(); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java index f271652686..1545a87fe9 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java @@ -27,7 +27,7 @@ public interface Reconciler

{ * sources * @return a list of event sources */ - default List prepareEventSources(EventSourceContext

context) { + default List> prepareEventSources(EventSourceContext

context) { return Collections.emptyList(); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java index b8feb5c87e..4622fd657c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java @@ -35,7 +35,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { return List.of(dependent.initEventSource(context)); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java index e54e3e3cb7..be208d3ba2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java @@ -20,7 +20,7 @@ public class ChangeNamespaceTestReconciler new ConcurrentHashMap<>(); @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { InformerEventSource configMapES = diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java index f1f66bc3ae..3f8923c2b3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java @@ -53,7 +53,7 @@ private ConfigMap desired(ClusterScopedCustomResource resource) { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { var ies = new InformerEventSource<>( InformerConfiguration.from(ConfigMap.class, ClusterScopedCustomResource.class) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java index 1937a4783e..c96a6ee248 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java @@ -51,7 +51,7 @@ public UpdateControl reconcile( } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { InformerEventSource serviceEventSource = new InformerEventSource<>( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index 13c204d39d..e97cf78b1d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -90,7 +90,7 @@ private ConfigMap createConfigMap(CreateUpdateEventFilterTestCustomResource reso } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { InformerConfiguration informerConfiguration = InformerConfiguration.from(ConfigMap.class, CreateUpdateEventFilterTestCustomResource.class) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java index 75d0a31f41..43b727b8cd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java @@ -24,7 +24,7 @@ public UpdateControl reconcile( } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { return EventSourceUtils.dependentEventSources(context, configMapDependentResource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java index 26720891cb..846dc9ccd6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java @@ -57,7 +57,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { return EventSourceUtils.dependentEventSources(context, ssaConfigMapDependent); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java index 8fe2a1f707..706e1d041f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java @@ -34,7 +34,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( InformerConfiguration.from(ConfigMap.class, ExternalStateCustomResource.class).build(), diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java index fd5e5aa37f..9412df210b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java @@ -107,7 +107,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { configMapEventSource = new InformerEventSource<>( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java index a0ea6c0089..92ae85275b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java @@ -33,7 +33,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( InformerConfiguration.from(ConfigMap.class, ExternalStateBulkDependentCustomResource.class) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java index 74fbfbbe2d..ee37918af9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java @@ -49,7 +49,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { InformerEventSource configMapES = diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java index 0d1f5b157a..0f2543ce49 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java @@ -30,7 +30,7 @@ public UpdateControl reconci } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { return List.of(dependent.eventSource(context).orElseThrow()); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java index 4d93438735..939878873d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java @@ -65,7 +65,7 @@ GenericKubernetesResource desiredConfigMap( @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { var informerEventSource = new InformerEventSource<>(InformerConfiguration.from( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java index 868dc4f3ed..631f8c29fe 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java @@ -32,7 +32,7 @@ public class InformerEventSourceTestCustomReconciler private final AtomicInteger numberOfExecutions = new AtomicInteger(0); @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { InformerConfiguration config = diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java index a4162c09d2..79c050a448 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java @@ -28,7 +28,7 @@ public DependentGarbageCollectionTestReconciler() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { return EventSourceUtils.dependentEventSources(context, configMapDependent); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java index e129b2e3d5..8a6986b151 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java @@ -33,7 +33,7 @@ public UpdateControl reconcile( } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { InformerEventSource eventSource = new InformerEventSource<>(InformerConfiguration diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java index fd90838ddd..dbc7742f42 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java @@ -43,7 +43,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { InformerEventSource eventSource = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java index feec6dc727..14726d591e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java @@ -46,7 +46,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { InformerEventSource ies = new InformerEventSource<>( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java index 53917dd593..10f1497ce4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java @@ -46,7 +46,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { InformerEventSource ies = new InformerEventSource<>( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java index 786e1c82d6..6752a82e0b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java @@ -56,7 +56,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { final PollingEventSource.GenericResourceFetcher fetcher = () -> { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java index fb216e9edd..b3cb06bc37 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java @@ -61,7 +61,7 @@ public int getNumberOfExecutions() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { var config = InformerConfiguration diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java index d8dde593ac..89b144da0d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java @@ -34,7 +34,7 @@ public UpdateControl reconcile( } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { PerResourcePollingEventSource eventSource = new PerResourcePollingEventSource<>(String.class, context, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java index 6c277b0fa6..ea606ecd6b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java @@ -30,7 +30,7 @@ public class DependentPrimaryIndexerTestReconciler extends AbstractPrimaryIndexe public static final String CONFIG_MAP_EVENT_SOURCE = "configMapEventSource"; @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { var cache = context.getPrimaryCache(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java index e20cf037c2..15f76b6ae2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java @@ -16,7 +16,7 @@ public class PrimaryIndexerTestReconciler extends AbstractPrimaryIndexerTestReconciler { @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { context.getPrimaryCache().addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java index afe5845c45..22472f0e05 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java @@ -60,7 +60,7 @@ public UpdateControl reconcile( } @Override - public List prepareEventSources(EventSourceContext context) { + public List> prepareEventSources(EventSourceContext context) { context.getPrimaryCache().addIndexer(JOB_CLUSTER_INDEX, (job -> List .of(indexKey(job.getSpec().getClusterName(), job.getMetadata().getNamespace())))); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java index 2b48ee0d2a..b98e0e6839 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java @@ -58,7 +58,7 @@ public int getNumberOfExecutions() { * demand for it. **/ @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { // there is no owner reference in the config map, but we still want to trigger reconciliation if // the config map changes. So first we add an index which custom resource references the config diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java index a2197c48a1..6de0b01464 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java @@ -29,7 +29,7 @@ public StandaloneDependentTestReconciler() { } @Override - public List prepareEventSources( + public List> prepareEventSources( EventSourceContext context) { return EventSourceUtils.dependentEventSources(context, deploymentDependent); diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java index 4a44070f51..00bd5614fa 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java @@ -45,7 +45,7 @@ public WebappReconciler(KubernetesClient kubernetesClient) { } @Override - public List prepareEventSources(EventSourceContext context) { + public List> prepareEventSources(EventSourceContext context) { /* * To create an event to a related WebApp resource and trigger the reconciliation we need to * find which WebApp this Tomcat custom resource is related to. To find the related diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index ebbbd6f7c8..f85cd1459e 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -49,7 +49,7 @@ public WebPageDependentsWorkflowReconciler(KubernetesClient kubernetesClient) { } @Override - public List prepareEventSources(EventSourceContext context) { + public List> prepareEventSources(EventSourceContext context) { return EventSourceUtils.dependentEventSources(context, configMapDR, deploymentDR, serviceDR, ingressDR); diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index 84bfdcdc23..27495a7ba8 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -39,7 +39,7 @@ public WebPageReconciler() { } @Override - public List prepareEventSources(EventSourceContext context) { + public List> prepareEventSources(EventSourceContext context) { var configMapEventSource = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, WebPage.class) .withLabelSelector(SELECTOR) diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java index 49a641da01..62a7eb3cdc 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java @@ -41,7 +41,7 @@ public WebPageStandaloneDependentsReconciler() { } @Override - public List prepareEventSources(EventSourceContext context) { + public List> prepareEventSources(EventSourceContext context) { // initializes the dependents' event sources from the given context return EventSourceUtils.eventSourcesFromWorkflow(context, workflow); } From e55f1e7f92d24ab3d5ab75af20707566abbb3987 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 20 Jun 2024 10:40:02 +0200 Subject: [PATCH 55/96] fix: improper javadoc preventing release (#2450) Signed-off-by: Chris Laprun --- .../operator/processing/GroupVersionKind.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java index fa91e8cfeb..4b0a607182 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java @@ -45,12 +45,16 @@ public GroupVersionKind(String group, String version, String kind) { /** * Parse GVK from a String representation. Expected format is: [group]/[version]/[kind] - *

- * Sample: "apps/v1/Deployment" - *

+ * + *

+   *   Sample: "apps/v1/Deployment"
+   * 
+ * * or: [version]/[kind] - *

- * Sample: v1/ConfigMap + * + *

+   *     Sample: v1/ConfigMap
+   * 
**/ public static GroupVersionKind fromString(String gvk) { String[] parts = gvk.split("/"); From 088e5be4efd5736bf0b1913ec3f557f37255f44d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 20 Jun 2024 14:16:00 +0200 Subject: [PATCH 56/96] docs: use docs dir instead of docsy (#2443) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .github/workflows/hugo.yaml | 6 +++--- README.md | 2 +- {docsy => docs}/.gitignore | 0 {docsy => docs}/.nvmrc | 0 {docsy => docs}/CONTRIBUTING.md | 0 {docsy => docs}/Dockerfile | 0 {docsy => docs}/LICENSE | 0 {docsy => docs}/README.md | 0 {docsy => docs}/assets/icons/logo.svg | 0 {docsy => docs}/assets/scss/_variables_project.scss | 0 {docsy => docs}/config.yaml | 0 {docsy => docs}/content/en/_index.md | 0 {docsy => docs}/content/en/blog/_index.md | 0 {docsy => docs}/content/en/blog/news/_index.md | 0 {docsy => docs}/content/en/blog/releases/_index.md | 0 {docsy => docs}/content/en/community/_index.md | 0 {docsy => docs}/content/en/docs/_index.md | 0 .../content/en/docs/architecture/_index.md | 0 .../content/en/docs/configuration/_index.md | 0 .../content/en/docs/contributing/_index.md | 0 .../content/en/docs/dependent-resources/_index.md | 0 {docsy => docs}/content/en/docs/faq/_index.md | 0 {docsy => docs}/content/en/docs/features/_index.md | 0 .../content/en/docs/getting-started/_index.md | 0 {docsy => docs}/content/en/docs/glossary/_index.md | 0 .../content/en/docs/intro-to-operators/_index.md | 0 {docsy => docs}/content/en/docs/migration/_index.md | 0 .../content/en/docs/migration/v2-migration.md | 0 .../content/en/docs/migration/v3-1-migration.md | 0 .../content/en/docs/migration/v3-migration.md | 0 .../content/en/docs/migration/v4-3-migration.md | 0 .../content/en/docs/migration/v4-4-migration.md | 0 .../content/en/docs/migration/v4-5-migration.md | 0 .../content/en/docs/migration/v5-0-migration.md | 0 .../en/docs/patterns-and-best-practices/_index.md | 0 .../content/en/docs/using-samples/_index.md | 0 {docsy => docs}/content/en/docs/workflows/_index.md | 0 {docsy => docs}/content/en/featured-background.jpg | Bin {docsy => docs}/content/en/search.md | 0 {docsy => docs}/content/fileList.txt | 0 {docsy => docs}/docker-compose.yaml | 0 {docsy => docs}/docsy.work | 0 {docsy => docs}/docsy.work.sum | 0 {docsy => docs}/go.mod | 0 {docsy => docs}/go.sum | 0 {docsy => docs}/hugo.toml | 2 +- {docsy => docs}/layouts/404.html | 0 .../layouts/_default/_markup/render-heading.html | 0 {docsy => docs}/netlify.toml | 0 {docsy => docs}/package.json | 0 {docsy => docs}/static/favicons/favicon.ico | Bin {docsy => docs}/static/images/architecture.svg | 0 {docsy => docs}/static/images/cncf_logo.png | Bin {docsy => docs}/static/images/cs-logo.svg | 0 {docsy => docs}/static/images/full-logo-white.svg | 0 {docsy => docs}/static/images/full_logo.png | Bin {docsy => docs}/static/images/red-hat.webp | Bin 57 files changed, 5 insertions(+), 5 deletions(-) rename {docsy => docs}/.gitignore (100%) rename {docsy => docs}/.nvmrc (100%) rename {docsy => docs}/CONTRIBUTING.md (100%) rename {docsy => docs}/Dockerfile (100%) rename {docsy => docs}/LICENSE (100%) rename {docsy => docs}/README.md (100%) rename {docsy => docs}/assets/icons/logo.svg (100%) rename {docsy => docs}/assets/scss/_variables_project.scss (100%) rename {docsy => docs}/config.yaml (100%) rename {docsy => docs}/content/en/_index.md (100%) rename {docsy => docs}/content/en/blog/_index.md (100%) rename {docsy => docs}/content/en/blog/news/_index.md (100%) rename {docsy => docs}/content/en/blog/releases/_index.md (100%) rename {docsy => docs}/content/en/community/_index.md (100%) rename {docsy => docs}/content/en/docs/_index.md (100%) rename {docsy => docs}/content/en/docs/architecture/_index.md (100%) rename {docsy => docs}/content/en/docs/configuration/_index.md (100%) rename {docsy => docs}/content/en/docs/contributing/_index.md (100%) rename {docsy => docs}/content/en/docs/dependent-resources/_index.md (100%) rename {docsy => docs}/content/en/docs/faq/_index.md (100%) rename {docsy => docs}/content/en/docs/features/_index.md (100%) rename {docsy => docs}/content/en/docs/getting-started/_index.md (100%) rename {docsy => docs}/content/en/docs/glossary/_index.md (100%) rename {docsy => docs}/content/en/docs/intro-to-operators/_index.md (100%) rename {docsy => docs}/content/en/docs/migration/_index.md (100%) rename {docsy => docs}/content/en/docs/migration/v2-migration.md (100%) rename {docsy => docs}/content/en/docs/migration/v3-1-migration.md (100%) rename {docsy => docs}/content/en/docs/migration/v3-migration.md (100%) rename {docsy => docs}/content/en/docs/migration/v4-3-migration.md (100%) rename {docsy => docs}/content/en/docs/migration/v4-4-migration.md (100%) rename {docsy => docs}/content/en/docs/migration/v4-5-migration.md (100%) rename {docsy => docs}/content/en/docs/migration/v5-0-migration.md (100%) rename {docsy => docs}/content/en/docs/patterns-and-best-practices/_index.md (100%) rename {docsy => docs}/content/en/docs/using-samples/_index.md (100%) rename {docsy => docs}/content/en/docs/workflows/_index.md (100%) rename {docsy => docs}/content/en/featured-background.jpg (100%) rename {docsy => docs}/content/en/search.md (100%) rename {docsy => docs}/content/fileList.txt (100%) rename {docsy => docs}/docker-compose.yaml (100%) rename {docsy => docs}/docsy.work (100%) rename {docsy => docs}/docsy.work.sum (100%) rename {docsy => docs}/go.mod (100%) rename {docsy => docs}/go.sum (100%) rename {docsy => docs}/hugo.toml (99%) rename {docsy => docs}/layouts/404.html (100%) rename {docsy => docs}/layouts/_default/_markup/render-heading.html (100%) rename {docsy => docs}/netlify.toml (100%) rename {docsy => docs}/package.json (100%) rename {docsy => docs}/static/favicons/favicon.ico (100%) rename {docsy => docs}/static/images/architecture.svg (100%) rename {docsy => docs}/static/images/cncf_logo.png (100%) rename {docsy => docs}/static/images/cs-logo.svg (100%) rename {docsy => docs}/static/images/full-logo-white.svg (100%) rename {docsy => docs}/static/images/full_logo.png (100%) rename {docsy => docs}/static/images/red-hat.webp (100%) diff --git a/.github/workflows/hugo.yaml b/.github/workflows/hugo.yaml index 2a5ee0d64e..1d91c85ef3 100644 --- a/.github/workflows/hugo.yaml +++ b/.github/workflows/hugo.yaml @@ -49,7 +49,7 @@ jobs: id: pages uses: actions/configure-pages@v5 - name: Install Node.js dependencies - working-directory: ./docsy + working-directory: ./docs run: | [[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true npm install -D autoprefixer @@ -61,7 +61,7 @@ jobs: HUGO_ENVIRONMENT: production HUGO_ENV: production TZ: America/Los_Angeles - working-directory: ./docsy + working-directory: ./docs run: | hugo \ --gc \ @@ -70,7 +70,7 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: ./docsy/public + path: ./docs/public # Deployment job deploy: diff --git a/README.md b/README.md index 435ead4967..933dacb54b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ![java-operator-sdk](docsy/static/images/full_logo.png) +# ![java-operator-sdk](docs/static/images/full_logo.png) ![Java CI with Maven](https://github.com/operator-framework/java-operator-sdk/actions/workflows/snapshot-releases.yml/badge.svg) [![Slack](https://img.shields.io/badge/Slack-4A154B?style=flat-square&logo=slack&logoColor=white)](https://kubernetes.slack.com/archives/CAW0GV7A5 "get invite here: https://communityinviter.com/apps/kubernetes/community" ) diff --git a/docsy/.gitignore b/docs/.gitignore similarity index 100% rename from docsy/.gitignore rename to docs/.gitignore diff --git a/docsy/.nvmrc b/docs/.nvmrc similarity index 100% rename from docsy/.nvmrc rename to docs/.nvmrc diff --git a/docsy/CONTRIBUTING.md b/docs/CONTRIBUTING.md similarity index 100% rename from docsy/CONTRIBUTING.md rename to docs/CONTRIBUTING.md diff --git a/docsy/Dockerfile b/docs/Dockerfile similarity index 100% rename from docsy/Dockerfile rename to docs/Dockerfile diff --git a/docsy/LICENSE b/docs/LICENSE similarity index 100% rename from docsy/LICENSE rename to docs/LICENSE diff --git a/docsy/README.md b/docs/README.md similarity index 100% rename from docsy/README.md rename to docs/README.md diff --git a/docsy/assets/icons/logo.svg b/docs/assets/icons/logo.svg similarity index 100% rename from docsy/assets/icons/logo.svg rename to docs/assets/icons/logo.svg diff --git a/docsy/assets/scss/_variables_project.scss b/docs/assets/scss/_variables_project.scss similarity index 100% rename from docsy/assets/scss/_variables_project.scss rename to docs/assets/scss/_variables_project.scss diff --git a/docsy/config.yaml b/docs/config.yaml similarity index 100% rename from docsy/config.yaml rename to docs/config.yaml diff --git a/docsy/content/en/_index.md b/docs/content/en/_index.md similarity index 100% rename from docsy/content/en/_index.md rename to docs/content/en/_index.md diff --git a/docsy/content/en/blog/_index.md b/docs/content/en/blog/_index.md similarity index 100% rename from docsy/content/en/blog/_index.md rename to docs/content/en/blog/_index.md diff --git a/docsy/content/en/blog/news/_index.md b/docs/content/en/blog/news/_index.md similarity index 100% rename from docsy/content/en/blog/news/_index.md rename to docs/content/en/blog/news/_index.md diff --git a/docsy/content/en/blog/releases/_index.md b/docs/content/en/blog/releases/_index.md similarity index 100% rename from docsy/content/en/blog/releases/_index.md rename to docs/content/en/blog/releases/_index.md diff --git a/docsy/content/en/community/_index.md b/docs/content/en/community/_index.md similarity index 100% rename from docsy/content/en/community/_index.md rename to docs/content/en/community/_index.md diff --git a/docsy/content/en/docs/_index.md b/docs/content/en/docs/_index.md similarity index 100% rename from docsy/content/en/docs/_index.md rename to docs/content/en/docs/_index.md diff --git a/docsy/content/en/docs/architecture/_index.md b/docs/content/en/docs/architecture/_index.md similarity index 100% rename from docsy/content/en/docs/architecture/_index.md rename to docs/content/en/docs/architecture/_index.md diff --git a/docsy/content/en/docs/configuration/_index.md b/docs/content/en/docs/configuration/_index.md similarity index 100% rename from docsy/content/en/docs/configuration/_index.md rename to docs/content/en/docs/configuration/_index.md diff --git a/docsy/content/en/docs/contributing/_index.md b/docs/content/en/docs/contributing/_index.md similarity index 100% rename from docsy/content/en/docs/contributing/_index.md rename to docs/content/en/docs/contributing/_index.md diff --git a/docsy/content/en/docs/dependent-resources/_index.md b/docs/content/en/docs/dependent-resources/_index.md similarity index 100% rename from docsy/content/en/docs/dependent-resources/_index.md rename to docs/content/en/docs/dependent-resources/_index.md diff --git a/docsy/content/en/docs/faq/_index.md b/docs/content/en/docs/faq/_index.md similarity index 100% rename from docsy/content/en/docs/faq/_index.md rename to docs/content/en/docs/faq/_index.md diff --git a/docsy/content/en/docs/features/_index.md b/docs/content/en/docs/features/_index.md similarity index 100% rename from docsy/content/en/docs/features/_index.md rename to docs/content/en/docs/features/_index.md diff --git a/docsy/content/en/docs/getting-started/_index.md b/docs/content/en/docs/getting-started/_index.md similarity index 100% rename from docsy/content/en/docs/getting-started/_index.md rename to docs/content/en/docs/getting-started/_index.md diff --git a/docsy/content/en/docs/glossary/_index.md b/docs/content/en/docs/glossary/_index.md similarity index 100% rename from docsy/content/en/docs/glossary/_index.md rename to docs/content/en/docs/glossary/_index.md diff --git a/docsy/content/en/docs/intro-to-operators/_index.md b/docs/content/en/docs/intro-to-operators/_index.md similarity index 100% rename from docsy/content/en/docs/intro-to-operators/_index.md rename to docs/content/en/docs/intro-to-operators/_index.md diff --git a/docsy/content/en/docs/migration/_index.md b/docs/content/en/docs/migration/_index.md similarity index 100% rename from docsy/content/en/docs/migration/_index.md rename to docs/content/en/docs/migration/_index.md diff --git a/docsy/content/en/docs/migration/v2-migration.md b/docs/content/en/docs/migration/v2-migration.md similarity index 100% rename from docsy/content/en/docs/migration/v2-migration.md rename to docs/content/en/docs/migration/v2-migration.md diff --git a/docsy/content/en/docs/migration/v3-1-migration.md b/docs/content/en/docs/migration/v3-1-migration.md similarity index 100% rename from docsy/content/en/docs/migration/v3-1-migration.md rename to docs/content/en/docs/migration/v3-1-migration.md diff --git a/docsy/content/en/docs/migration/v3-migration.md b/docs/content/en/docs/migration/v3-migration.md similarity index 100% rename from docsy/content/en/docs/migration/v3-migration.md rename to docs/content/en/docs/migration/v3-migration.md diff --git a/docsy/content/en/docs/migration/v4-3-migration.md b/docs/content/en/docs/migration/v4-3-migration.md similarity index 100% rename from docsy/content/en/docs/migration/v4-3-migration.md rename to docs/content/en/docs/migration/v4-3-migration.md diff --git a/docsy/content/en/docs/migration/v4-4-migration.md b/docs/content/en/docs/migration/v4-4-migration.md similarity index 100% rename from docsy/content/en/docs/migration/v4-4-migration.md rename to docs/content/en/docs/migration/v4-4-migration.md diff --git a/docsy/content/en/docs/migration/v4-5-migration.md b/docs/content/en/docs/migration/v4-5-migration.md similarity index 100% rename from docsy/content/en/docs/migration/v4-5-migration.md rename to docs/content/en/docs/migration/v4-5-migration.md diff --git a/docsy/content/en/docs/migration/v5-0-migration.md b/docs/content/en/docs/migration/v5-0-migration.md similarity index 100% rename from docsy/content/en/docs/migration/v5-0-migration.md rename to docs/content/en/docs/migration/v5-0-migration.md diff --git a/docsy/content/en/docs/patterns-and-best-practices/_index.md b/docs/content/en/docs/patterns-and-best-practices/_index.md similarity index 100% rename from docsy/content/en/docs/patterns-and-best-practices/_index.md rename to docs/content/en/docs/patterns-and-best-practices/_index.md diff --git a/docsy/content/en/docs/using-samples/_index.md b/docs/content/en/docs/using-samples/_index.md similarity index 100% rename from docsy/content/en/docs/using-samples/_index.md rename to docs/content/en/docs/using-samples/_index.md diff --git a/docsy/content/en/docs/workflows/_index.md b/docs/content/en/docs/workflows/_index.md similarity index 100% rename from docsy/content/en/docs/workflows/_index.md rename to docs/content/en/docs/workflows/_index.md diff --git a/docsy/content/en/featured-background.jpg b/docs/content/en/featured-background.jpg similarity index 100% rename from docsy/content/en/featured-background.jpg rename to docs/content/en/featured-background.jpg diff --git a/docsy/content/en/search.md b/docs/content/en/search.md similarity index 100% rename from docsy/content/en/search.md rename to docs/content/en/search.md diff --git a/docsy/content/fileList.txt b/docs/content/fileList.txt similarity index 100% rename from docsy/content/fileList.txt rename to docs/content/fileList.txt diff --git a/docsy/docker-compose.yaml b/docs/docker-compose.yaml similarity index 100% rename from docsy/docker-compose.yaml rename to docs/docker-compose.yaml diff --git a/docsy/docsy.work b/docs/docsy.work similarity index 100% rename from docsy/docsy.work rename to docs/docsy.work diff --git a/docsy/docsy.work.sum b/docs/docsy.work.sum similarity index 100% rename from docsy/docsy.work.sum rename to docs/docsy.work.sum diff --git a/docsy/go.mod b/docs/go.mod similarity index 100% rename from docsy/go.mod rename to docs/go.mod diff --git a/docsy/go.sum b/docs/go.sum similarity index 100% rename from docsy/go.sum rename to docs/go.sum diff --git a/docsy/hugo.toml b/docs/hugo.toml similarity index 99% rename from docsy/hugo.toml rename to docs/hugo.toml index 520a1cb358..b4535c08af 100644 --- a/docsy/hugo.toml +++ b/docs/hugo.toml @@ -110,7 +110,7 @@ github_repo = "https://github.com/operator-framework/java-operator-sdk/" # github_project_repo = "https://github.com/operator-framework/java-operator-sdk" # Specify a value here if your content directory is not in your repo's root directory -github_subdir = "docsy" +github_subdir = "docs" # Uncomment this if your GitHub repo does not have "main" as the default branch, # or specify a new value if you want to reference another branch in your GitHub links diff --git a/docsy/layouts/404.html b/docs/layouts/404.html similarity index 100% rename from docsy/layouts/404.html rename to docs/layouts/404.html diff --git a/docsy/layouts/_default/_markup/render-heading.html b/docs/layouts/_default/_markup/render-heading.html similarity index 100% rename from docsy/layouts/_default/_markup/render-heading.html rename to docs/layouts/_default/_markup/render-heading.html diff --git a/docsy/netlify.toml b/docs/netlify.toml similarity index 100% rename from docsy/netlify.toml rename to docs/netlify.toml diff --git a/docsy/package.json b/docs/package.json similarity index 100% rename from docsy/package.json rename to docs/package.json diff --git a/docsy/static/favicons/favicon.ico b/docs/static/favicons/favicon.ico similarity index 100% rename from docsy/static/favicons/favicon.ico rename to docs/static/favicons/favicon.ico diff --git a/docsy/static/images/architecture.svg b/docs/static/images/architecture.svg similarity index 100% rename from docsy/static/images/architecture.svg rename to docs/static/images/architecture.svg diff --git a/docsy/static/images/cncf_logo.png b/docs/static/images/cncf_logo.png similarity index 100% rename from docsy/static/images/cncf_logo.png rename to docs/static/images/cncf_logo.png diff --git a/docsy/static/images/cs-logo.svg b/docs/static/images/cs-logo.svg similarity index 100% rename from docsy/static/images/cs-logo.svg rename to docs/static/images/cs-logo.svg diff --git a/docsy/static/images/full-logo-white.svg b/docs/static/images/full-logo-white.svg similarity index 100% rename from docsy/static/images/full-logo-white.svg rename to docs/static/images/full-logo-white.svg diff --git a/docsy/static/images/full_logo.png b/docs/static/images/full_logo.png similarity index 100% rename from docsy/static/images/full_logo.png rename to docs/static/images/full_logo.png diff --git a/docsy/static/images/red-hat.webp b/docs/static/images/red-hat.webp similarity index 100% rename from docsy/static/images/red-hat.webp rename to docs/static/images/red-hat.webp From 36c71c39440cef0ddb468d12af2cfdedc1de5eba Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 20 Jun 2024 15:31:51 +0200 Subject: [PATCH 57/96] refactor: move getResourceClassResolver to BaseConfigurationService (#2451) The class resolving mechanism is only needed in that class right now Signed-off-by: Chris Laprun --- .../api/config/BaseConfigurationService.java | 178 +++++++++--------- .../api/config/ConfigurationService.java | 4 - .../config/ConfigurationServiceOverrider.java | 15 +- .../config/DefaultResourceClassResolver.java | 2 +- .../api/config/ResourceClassResolver.java | 3 +- 5 files changed, 98 insertions(+), 104 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index 70c86a2a94..243359a1d0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -39,6 +39,7 @@ public class BaseConfigurationService extends AbstractConfigurationService { private static final String LOGGER_NAME = "Default ConfigurationService implementation"; private static final Logger logger = LoggerFactory.getLogger(LOGGER_NAME); + private static final ResourceClassResolver DEFAULT_RESOLVER = new DefaultResourceClassResolver(); public BaseConfigurationService(Version version) { this(version, null); @@ -56,6 +57,89 @@ public BaseConfigurationService() { this(Utils.VERSION); } + @SuppressWarnings({"unchecked", "rawtypes"}) + private static List dependentResources( + Workflow annotation, + ControllerConfiguration controllerConfiguration) { + final var dependents = annotation.dependents(); + + + if (dependents == null || dependents.length == 0) { + return Collections.emptyList(); + } + + final var specsMap = new LinkedHashMap(dependents.length); + for (Dependent dependent : dependents) { + final Class dependentType = dependent.type(); + + final var dependentName = getName(dependent.name(), dependentType); + var spec = specsMap.get(dependentName); + if (spec != null) { + throw new IllegalArgumentException( + "A DependentResource named '" + dependentName + "' already exists: " + spec); + } + + final var name = controllerConfiguration.getName(); + + var eventSourceName = dependent.useEventSourceWithName(); + eventSourceName = Constants.NO_VALUE_SET.equals(eventSourceName) ? null : eventSourceName; + final var context = Utils.contextFor(name, dependentType, null); + spec = new DependentResourceSpec(dependentType, dependentName, + Set.of(dependent.dependsOn()), + Utils.instantiate(dependent.readyPostcondition(), Condition.class, context), + Utils.instantiate(dependent.reconcilePrecondition(), Condition.class, context), + Utils.instantiate(dependent.deletePostcondition(), Condition.class, context), + Utils.instantiate(dependent.activationCondition(), Condition.class, context), + eventSourceName); + + // extract potential configuration + DependentResourceConfigurationResolver.configureSpecFromConfigured(spec, + controllerConfiguration, + dependentType); + + specsMap.put(dependentName, spec); + } + return specsMap.values().stream().toList(); + } + + private static T valueOrDefault( + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration controllerConfiguration, + Function mapper, + T defaultValue) { + if (controllerConfiguration == null) { + return defaultValue; + } else { + return mapper.apply(controllerConfiguration); + } + } + + @SuppressWarnings("rawtypes") + private static String getName(String name, Class dependentType) { + if (name.isBlank()) { + name = DependentResource.defaultNameFor(dependentType); + } + return name; + } + + @SuppressWarnings("unused") + private static Configurator configuratorFor(Class instanceType, + Reconciler reconciler) { + return instance -> configureFromAnnotatedReconciler(instance, reconciler); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + private static void configureFromAnnotatedReconciler(Object instance, Reconciler reconciler) { + if (instance instanceof AnnotationConfigurable configurable) { + final Class configurationClass = + (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface( + instance.getClass(), AnnotationConfigurable.class); + final var configAnnotation = reconciler.getClass().getAnnotation(configurationClass); + if (configAnnotation != null) { + configurable.initFrom(configAnnotation); + } + } + } + @Override protected void logMissingReconcilerWarning(String reconcilerKey, String reconcilersNameMessage) { logger.warn("Configuration for reconciler '{}' was not found. {}", reconcilerKey, @@ -95,6 +179,15 @@ public ControllerConfiguration getConfigurationFor( return config; } + /** + * Override if a different class resolution is needed + * + * @return the custom {@link ResourceClassResolver} implementation to use + */ + protected ResourceClassResolver getResourceClassResolver() { + return DEFAULT_RESOLVER; + } + @SuppressWarnings({"unchecked", "rawtypes"}) protected

ControllerConfiguration

configFor(Reconciler

reconciler) { final var annotation = reconciler.getClass().getAnnotation( @@ -109,7 +202,7 @@ protected

ControllerConfiguration

configFor(Reconcile " annotation for reconciler: " + reconciler); } Class> reconcilerClass = (Class>) reconciler.getClass(); - final var resourceClass = getResourceClassResolver().getResourceClass(reconcilerClass); + final var resourceClass = getResourceClassResolver().getPrimaryResourceClass(reconcilerClass); final var name = ReconcilerUtils.getNameFor(reconciler); final var generationAware = valueOrDefault( @@ -192,51 +285,6 @@ public boolean handleExceptionsInReconciler() { return config; } - @SuppressWarnings({"unchecked", "rawtypes"}) - private static List dependentResources( - Workflow annotation, - ControllerConfiguration controllerConfiguration) { - final var dependents = annotation.dependents(); - - - if (dependents == null || dependents.length == 0) { - return Collections.emptyList(); - } - - final var specsMap = new LinkedHashMap(dependents.length); - for (Dependent dependent : dependents) { - final Class dependentType = dependent.type(); - - final var dependentName = getName(dependent.name(), dependentType); - var spec = specsMap.get(dependentName); - if (spec != null) { - throw new IllegalArgumentException( - "A DependentResource named '" + dependentName + "' already exists: " + spec); - } - - final var name = controllerConfiguration.getName(); - - var eventSourceName = dependent.useEventSourceWithName(); - eventSourceName = Constants.NO_VALUE_SET.equals(eventSourceName) ? null : eventSourceName; - final var context = Utils.contextFor(name, dependentType, null); - spec = new DependentResourceSpec(dependentType, dependentName, - Set.of(dependent.dependsOn()), - Utils.instantiate(dependent.readyPostcondition(), Condition.class, context), - Utils.instantiate(dependent.reconcilePrecondition(), Condition.class, context), - Utils.instantiate(dependent.deletePostcondition(), Condition.class, context), - Utils.instantiate(dependent.activationCondition(), Condition.class, context), - eventSourceName); - - // extract potential configuration - DependentResourceConfigurationResolver.configureSpecFromConfigured(spec, - controllerConfiguration, - dependentType); - - specsMap.put(dependentName, spec); - } - return specsMap.values().stream().toList(); - } - protected boolean createIfNeeded() { return true; } @@ -245,42 +293,4 @@ protected boolean createIfNeeded() { public boolean checkCRDAndValidateLocalModel() { return Utils.shouldCheckCRDAndValidateLocalModel(); } - - private static T valueOrDefault( - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration controllerConfiguration, - Function mapper, - T defaultValue) { - if (controllerConfiguration == null) { - return defaultValue; - } else { - return mapper.apply(controllerConfiguration); - } - } - - @SuppressWarnings("rawtypes") - private static String getName(String name, Class dependentType) { - if (name.isBlank()) { - name = DependentResource.defaultNameFor(dependentType); - } - return name; - } - - @SuppressWarnings("unused") - private static Configurator configuratorFor(Class instanceType, - Reconciler reconciler) { - return instance -> configureFromAnnotatedReconciler(instance, reconciler); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private static void configureFromAnnotatedReconciler(Object instance, Reconciler reconciler) { - if (instance instanceof AnnotationConfigurable configurable) { - final Class configurationClass = - (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface( - instance.getClass(), AnnotationConfigurable.class); - final var configAnnotation = reconciler.getClass().getAnnotation(configurationClass); - if (configAnnotation != null) { - configurable.initFrom(configAnnotation); - } - } - } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index 3cee8d3cec..1a31376054 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -236,10 +236,6 @@ default ManagedWorkflowFactory getWorkflowFactory() { return ManagedWorkflowFactory.DEFAULT; } - default ResourceClassResolver getResourceClassResolver() { - return new DefaultResourceClassResolver(); - } - /** * Creates a new {@link ConfigurationService} instance used to configure an * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java index edfb7734d8..24f9f36e5b 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java @@ -15,7 +15,7 @@ import io.javaoperatorsdk.operator.api.monitoring.Metrics; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceFactory; -@SuppressWarnings("unused") +@SuppressWarnings({"unused", "UnusedReturnValue"}) public class ConfigurationServiceOverrider { private static final Logger log = LoggerFactory.getLogger(ConfigurationServiceOverrider.class); @@ -33,7 +33,6 @@ public class ConfigurationServiceOverrider { private InformerStoppedHandler informerStoppedHandler; private Boolean stopOnInformerErrorDuringStartup; private Duration cacheSyncTimeout; - private ResourceClassResolver resourceClassResolver; private Boolean ssaBasedCreateUpdateMatchForDependentResources; private Set> defaultNonSSAResource; private Boolean previousAnnotationForDependentResources; @@ -133,12 +132,6 @@ public ConfigurationServiceOverrider withCacheSyncTimeout(Duration cacheSyncTime return this; } - public ConfigurationServiceOverrider withResourceClassResolver( - ResourceClassResolver resourceClassResolver) { - this.resourceClassResolver = resourceClassResolver; - return this; - } - public ConfigurationServiceOverrider withSSABasedCreateUpdateMatchForDependentResources( boolean value) { this.ssaBasedCreateUpdateMatchForDependentResources = value; @@ -280,12 +273,6 @@ public Duration cacheSyncTimeout() { return overriddenValueOrDefault(cacheSyncTimeout, ConfigurationService::cacheSyncTimeout); } - @Override - public ResourceClassResolver getResourceClassResolver() { - return overriddenValueOrDefault(resourceClassResolver, - ConfigurationService::getResourceClassResolver); - } - @Override public boolean ssaBasedCreateUpdateMatchForDependentResources() { return overriddenValueOrDefault(ssaBasedCreateUpdateMatchForDependentResources, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceClassResolver.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceClassResolver.java index c038e7d966..cdd4c5540e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceClassResolver.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceClassResolver.java @@ -7,7 +7,7 @@ public class DefaultResourceClassResolver implements ResourceClassResolver { @SuppressWarnings("unchecked") @Override - public Class getResourceClass( + public Class getPrimaryResourceClass( Class> reconcilerClass) { return (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface(reconcilerClass, Reconciler.class); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceClassResolver.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceClassResolver.java index e15d53016a..001eb3e0de 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceClassResolver.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceClassResolver.java @@ -5,6 +5,7 @@ public interface ResourceClassResolver { - Class getResourceClass(Class> reconcilerClass); +

Class

getPrimaryResourceClass( + Class> reconcilerClass); } From 24f2dc0eb844d23e2775ad90e477095beefe2161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 21 Jun 2024 16:48:52 +0200 Subject: [PATCH 58/96] feat: @ControllerConfiguration annotation is optional (#2412) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Co-authored-by: Chris Laprun --- .../api/config/BaseConfigurationService.java | 179 +++++++++++------- .../config/BaseConfigurationServiceTest.java | 31 ++- .../WebPageManagedDependentsReconciler.java | 1 - 3 files changed, 128 insertions(+), 83 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index 243359a1d0..3383bde416 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -14,7 +14,6 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.informers.cache.ItemStore; -import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.Utils.Configurator; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver; @@ -33,7 +32,6 @@ import io.javaoperatorsdk.operator.processing.retry.Retry; import static io.javaoperatorsdk.operator.api.config.ControllerConfiguration.CONTROLLER_NAME_AS_FIELD_MANAGER; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES_SET; public class BaseConfigurationService extends AbstractConfigurationService { @@ -91,6 +89,7 @@ private static List dependentResources( Utils.instantiate(dependent.deletePostcondition(), Condition.class, context), Utils.instantiate(dependent.activationCondition(), Condition.class, context), eventSourceName); + specsMap.put(dependentName, spec); // extract potential configuration DependentResourceConfigurationResolver.configureSpecFromConfigured(spec, @@ -99,17 +98,24 @@ private static List dependentResources( specsMap.put(dependentName, spec); } + return specsMap.values().stream().toList(); } - private static T valueOrDefault( + @SuppressWarnings("unchecked") + private static T valueOrDefaultFromAnnotation( io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration controllerConfiguration, Function mapper, - T defaultValue) { - if (controllerConfiguration == null) { - return defaultValue; - } else { - return mapper.apply(controllerConfiguration); + String defaultMethodName) { + try { + if (controllerConfiguration == null) { + return (T) io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.class + .getDeclaredMethod(defaultMethodName).getDefaultValue(); + } else { + return mapper.apply(controllerConfiguration); + } + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); } } @@ -123,17 +129,18 @@ private static String getName(String name, Class de @SuppressWarnings("unused") private static Configurator configuratorFor(Class instanceType, - Reconciler reconciler) { - return instance -> configureFromAnnotatedReconciler(instance, reconciler); + Class> reconcilerClass) { + return instance -> configureFromAnnotatedReconciler(instance, reconcilerClass); } @SuppressWarnings({"unchecked", "rawtypes"}) - private static void configureFromAnnotatedReconciler(Object instance, Reconciler reconciler) { + private static void configureFromAnnotatedReconciler(Object instance, + Class> reconcilerClass) { if (instance instanceof AnnotationConfigurable configurable) { final Class configurationClass = (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface( instance.getClass(), AnnotationConfigurable.class); - final var configAnnotation = reconciler.getClass().getAnnotation(configurationClass); + final var configAnnotation = reconcilerClass.getAnnotation(configurationClass); if (configAnnotation != null) { configurable.initFrom(configAnnotation); } @@ -190,38 +197,73 @@ protected ResourceClassResolver getResourceClassResolver() { @SuppressWarnings({"unchecked", "rawtypes"}) protected

ControllerConfiguration

configFor(Reconciler

reconciler) { - final var annotation = reconciler.getClass().getAnnotation( + final Class> reconcilerClass = + (Class>) reconciler.getClass(); + final var controllerAnnotation = reconcilerClass.getAnnotation( io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.class); - if (annotation == null) { - throw new OperatorException( - "Missing mandatory @" - + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.class - .getSimpleName() - + - " annotation for reconciler: " + reconciler); + ResolvedControllerConfiguration

config = + controllerConfiguration(reconcilerClass, controllerAnnotation); + + final var workflowAnnotation = reconcilerClass.getAnnotation( + io.javaoperatorsdk.operator.api.reconciler.Workflow.class); + if (workflowAnnotation != null) { + final var specs = dependentResources(workflowAnnotation, config); + WorkflowSpec workflowSpec = new WorkflowSpec() { + @Override + public List getDependentResourceSpecs() { + return specs; + } + + @Override + public boolean isExplicitInvocation() { + return workflowAnnotation.explicitInvocation(); + } + + @Override + public boolean handleExceptionsInReconciler() { + return workflowAnnotation.handleExceptionsInReconciler(); + } + + }; + config.setWorkflowSpec(workflowSpec); } - Class> reconcilerClass = (Class>) reconciler.getClass(); + + return config; + } + + @SuppressWarnings({"unchecked"}) + private

ResolvedControllerConfiguration

controllerConfiguration( + Class> reconcilerClass, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration annotation) { final var resourceClass = getResourceClassResolver().getPrimaryResourceClass(reconcilerClass); - final var name = ReconcilerUtils.getNameFor(reconciler); - final var generationAware = valueOrDefault( + final var name = ReconcilerUtils.getNameFor(reconcilerClass); + final var generationAware = valueOrDefaultFromAnnotation( annotation, io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::generationAwareEventProcessing, - true); + "generationAwareEventProcessing"); final var associatedReconcilerClass = - ResolvedControllerConfiguration.getAssociatedReconcilerClassName(reconciler.getClass()); + ResolvedControllerConfiguration.getAssociatedReconcilerClassName(reconcilerClass); final var context = Utils.contextFor(name); - final Class retryClass = annotation.retry(); + final Class retryClass = + valueOrDefaultFromAnnotation(annotation, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::retry, + "retry"); final var retry = Utils.instantiateAndConfigureIfNeeded(retryClass, Retry.class, - context, configuratorFor(Retry.class, reconciler)); + context, configuratorFor(Retry.class, reconcilerClass)); - final Class rateLimiterClass = annotation.rateLimiter(); + @SuppressWarnings("rawtypes") + final Class rateLimiterClass = valueOrDefaultFromAnnotation(annotation, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::rateLimiter, + "rateLimiter"); final var rateLimiter = Utils.instantiateAndConfigureIfNeeded(rateLimiterClass, - RateLimiter.class, context, configuratorFor(RateLimiter.class, reconciler)); + RateLimiter.class, context, configuratorFor(RateLimiter.class, reconcilerClass)); - final var reconciliationInterval = annotation.maxReconciliationInterval(); + final var reconciliationInterval = valueOrDefaultFromAnnotation(annotation, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::maxReconciliationInterval, + "maxReconciliationInterval"); long interval = -1; TimeUnit timeUnit = null; if (reconciliationInterval != null && reconciliationInterval.interval() > 0) { @@ -229,62 +271,53 @@ protected

ControllerConfiguration

configFor(Reconcile timeUnit = reconciliationInterval.timeUnit(); } + var fieldManager = valueOrDefaultFromAnnotation(annotation, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::fieldManager, + "fieldManager"); final var dependentFieldManager = - annotation.fieldManager().equals(CONTROLLER_NAME_AS_FIELD_MANAGER) ? name - : annotation.fieldManager(); + fieldManager.equals(CONTROLLER_NAME_AS_FIELD_MANAGER) ? name + : fieldManager; + var informerListLimitValue = valueOrDefaultFromAnnotation(annotation, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::informerListLimit, + "informerListLimit"); final var informerListLimit = - annotation.informerListLimit() == Constants.NO_LONG_VALUE_SET ? null - : annotation.informerListLimit(); + informerListLimitValue == Constants.NO_LONG_VALUE_SET ? null + : informerListLimitValue; - final var config = new ResolvedControllerConfiguration

( + return new ResolvedControllerConfiguration

( resourceClass, name, generationAware, associatedReconcilerClass, retry, rateLimiter, ResolvedControllerConfiguration.getMaxReconciliationInterval(interval, timeUnit), - Utils.instantiate(annotation.onAddFilter(), OnAddFilter.class, context), - Utils.instantiate(annotation.onUpdateFilter(), OnUpdateFilter.class, context), - Utils.instantiate(annotation.genericFilter(), GenericFilter.class, context), - Set.of(valueOrDefault(annotation, + Utils.instantiate(valueOrDefaultFromAnnotation(annotation, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::onAddFilter, + "onAddFilter"), OnAddFilter.class, context), + Utils.instantiate(valueOrDefaultFromAnnotation(annotation, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::onUpdateFilter, + "onUpdateFilter"), OnUpdateFilter.class, context), + Utils.instantiate(valueOrDefaultFromAnnotation(annotation, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::genericFilter, + "genericFilter"), GenericFilter.class, context), + Set.of(valueOrDefaultFromAnnotation(annotation, io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::namespaces, - DEFAULT_NAMESPACES_SET.toArray(String[]::new))), - valueOrDefault(annotation, + "namespaces")), + valueOrDefaultFromAnnotation(annotation, io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::finalizerName, - Constants.NO_VALUE_SET), - valueOrDefault(annotation, + "finalizerName"), + valueOrDefaultFromAnnotation(annotation, io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::labelSelector, - Constants.NO_VALUE_SET), + "labelSelector"), null, - Utils.instantiate(annotation.itemStore(), ItemStore.class, context), dependentFieldManager, + Utils.instantiate( + valueOrDefaultFromAnnotation(annotation, + io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::itemStore, + "itemStore"), + ItemStore.class, context), + dependentFieldManager, this, informerListLimit); - - - final var workflowAnnotation = reconciler.getClass().getAnnotation( - io.javaoperatorsdk.operator.api.reconciler.Workflow.class); - if (workflowAnnotation != null) { - final var specs = dependentResources(workflowAnnotation, config); - WorkflowSpec workflowSpec = new WorkflowSpec() { - @Override - public List getDependentResourceSpecs() { - return specs; - } - - @Override - public boolean isExplicitInvocation() { - return workflowAnnotation.explicitInvocation(); - } - - @Override - public boolean handleExceptionsInReconciler() { - return workflowAnnotation.handleExceptionsInReconciler(); - } - - }; - config.setWorkflowSpec(workflowSpec); - } - - return config; } + protected boolean createIfNeeded() { return true; } @@ -293,4 +326,6 @@ protected boolean createIfNeeded() { public boolean checkCRDAndValidateLocalModel() { return Utils.shouldCheckCRDAndValidateLocalModel(); } + + } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java index 103d7b0e12..5aaacf3236 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java @@ -9,24 +9,18 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.Service; -import io.javaoperatorsdk.operator.OperatorException; +import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.AnnotationConfigurable; import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.dependent.ConfigurationConverter; import io.javaoperatorsdk.operator.api.config.dependent.Configured; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; -import io.javaoperatorsdk.operator.api.reconciler.Workflow; +import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; @@ -45,6 +39,8 @@ import io.javaoperatorsdk.operator.sample.readonly.ConfigMapReader; import io.javaoperatorsdk.operator.sample.readonly.ReadOnlyDependent; +import static io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval.DEFAULT_INTERVAL; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; class BaseConfigurationServiceTest { @@ -108,9 +104,24 @@ void getDependentResources() { } @Test - void missingAnnotationThrowsException() { + void missingAnnotationCreatesDefaultConfig() { final var reconciler = new MissingAnnotationReconciler(); - Assertions.assertThrows(OperatorException.class, () -> configFor(reconciler)); + var config = configFor(reconciler); + + assertThat(config.getName()).isEqualTo(ReconcilerUtils.getNameFor(reconciler)); + assertThat(config.getLabelSelector()).isEmpty(); + assertThat(config.getRetry()).isInstanceOf(GenericRetry.class); + assertThat(config.getRateLimiter()).isInstanceOf(LinearRateLimiter.class); + assertThat(config.maxReconciliationInterval()).hasValue(Duration.ofHours(DEFAULT_INTERVAL)); + assertThat(config.fieldManager()).isEqualTo(config.getName()); + assertThat(config.getInformerListLimit()).isEmpty(); + assertThat(config.onAddFilter()).isEmpty(); + assertThat(config.onUpdateFilter()).isEmpty(); + assertThat(config.genericFilter()).isEmpty(); + assertThat(config.getNamespaces()).isEqualTo(Constants.DEFAULT_NAMESPACES_SET); + assertThat(config.getFinalizerName()) + .isEqualTo(ReconcilerUtils.getDefaultFinalizerName(config.getResourceClass())); + assertThat(config.getItemStore()).isEmpty(); } @SuppressWarnings("rawtypes") diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java index df3cae354f..e59f7fe0fc 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageManagedDependentsReconciler.java @@ -18,7 +18,6 @@ @Dependent(type = IngressDependentResource.class, reconcilePrecondition = ExposedIngressCondition.class) }) -@ControllerConfiguration public class WebPageManagedDependentsReconciler implements Reconciler, Cleaner { From aa3dc1037f6e114a5b83e970534248c1273a9a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sat, 29 Jun 2024 10:23:49 +0200 Subject: [PATCH 59/96] bump: chore use slf4j v2 (#2406) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- bootstrapper-maven-plugin/pom.xml | 2 +- .../src/main/resources/templates/pom.xml | 2 +- caffeine-bounded-cache-support/pom.xml | 2 +- operator-framework-core/pom.xml | 2 +- operator-framework/pom.xml | 2 +- pom.xml | 4 ++-- sample-operators/leader-election/pom.xml | 2 +- sample-operators/mysql-schema/pom.xml | 2 +- sample-operators/tomcat-operator/pom.xml | 2 +- sample-operators/webpage/pom.xml | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bootstrapper-maven-plugin/pom.xml b/bootstrapper-maven-plugin/pom.xml index 491e811dad..ce93472d79 100644 --- a/bootstrapper-maven-plugin/pom.xml +++ b/bootstrapper-maven-plugin/pom.xml @@ -39,7 +39,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl test diff --git a/bootstrapper-maven-plugin/src/main/resources/templates/pom.xml b/bootstrapper-maven-plugin/src/main/resources/templates/pom.xml index 6ada7516c7..6a835598a3 100644 --- a/bootstrapper-maven-plugin/src/main/resources/templates/pom.xml +++ b/bootstrapper-maven-plugin/src/main/resources/templates/pom.xml @@ -58,7 +58,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl ${log4j.version} diff --git a/caffeine-bounded-cache-support/pom.xml b/caffeine-bounded-cache-support/pom.xml index 32bfa6ad13..d0840f420a 100644 --- a/caffeine-bounded-cache-support/pom.xml +++ b/caffeine-bounded-cache-support/pom.xml @@ -37,7 +37,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl test diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index 1ff0d34e8c..7f015c87f6 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -30,7 +30,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl test diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index bac97460b0..0026c48dd6 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -70,7 +70,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl test diff --git a/pom.xml b/pom.xml index aa53a9d859..4a47bded31 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ 5.10.1 6.13.4 - 1.7.36 + 2.0.12 2.23.1 5.13.0 3.16.0 @@ -170,7 +170,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl ${log4j.version} diff --git a/sample-operators/leader-election/pom.xml b/sample-operators/leader-election/pom.xml index bcbc4fbcff..894b96d988 100644 --- a/sample-operators/leader-election/pom.xml +++ b/sample-operators/leader-election/pom.xml @@ -32,7 +32,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl compile diff --git a/sample-operators/mysql-schema/pom.xml b/sample-operators/mysql-schema/pom.xml index dedb681116..bc8207a92e 100644 --- a/sample-operators/mysql-schema/pom.xml +++ b/sample-operators/mysql-schema/pom.xml @@ -51,7 +51,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl org.apache.logging.log4j diff --git a/sample-operators/tomcat-operator/pom.xml b/sample-operators/tomcat-operator/pom.xml index 158133160d..7af9893609 100644 --- a/sample-operators/tomcat-operator/pom.xml +++ b/sample-operators/tomcat-operator/pom.xml @@ -47,7 +47,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl org.apache.logging.log4j diff --git a/sample-operators/webpage/pom.xml b/sample-operators/webpage/pom.xml index 5470ece6d3..9982da49c4 100644 --- a/sample-operators/webpage/pom.xml +++ b/sample-operators/webpage/pom.xml @@ -32,7 +32,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl org.apache.logging.log4j From a11f4e261ff278b22b686abcdee40506db0711aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 1 Jul 2024 09:12:34 +0200 Subject: [PATCH 60/96] feat: integration test to show multiple dependents with activation condition (#2454) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- docs/content/en/docs/workflows/_index.md | 8 +- .../MultipleDependentWithActivationIT.java | 76 +++++++++++++++++++ .../ActivationCondition.java | 20 +++++ .../ConfigMapDependentResource1.java | 35 +++++++++ .../ConfigMapDependentResource2.java | 35 +++++++++ ...ipleDependentActivationCustomResource.java | 17 +++++ ...MultipleDependentActivationReconciler.java | 34 +++++++++ .../MultipleDependentActivationSpec.java | 14 ++++ .../SecretDependentResource.java | 31 ++++++++ 9 files changed, 267 insertions(+), 3 deletions(-) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentWithActivationIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ActivationCondition.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource1.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource2.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationReconciler.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationSpec.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/SecretDependentResource.java diff --git a/docs/content/en/docs/workflows/_index.md b/docs/content/en/docs/workflows/_index.md index 83272ec3a9..cbb39840b0 100644 --- a/docs/content/en/docs/workflows/_index.md +++ b/docs/content/en/docs/workflows/_index.md @@ -48,9 +48,11 @@ reconciliation process. with the dependent's resource type is not present on the cluster. See related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/ba5e33527bf9e3ea0bd33025ccb35e677f9d44b4/operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java). - Activation condition is semi-experimental at the moment, and it has its limitations. - For example event sources cannot be shared between multiple managed dependent resources which use activation condition. - The intention is to further improve and explore the possibilities with this approach. + To have multiple resources of same type with an activation condition is a bit tricky, since you + don't want to have multiple `InformerEvetnSource` for the same type, you have to explicitly + name the informer for the Dependent Resource (`@KubernetesDependent(informerConfig = @InformerConfig(name = "configMapInformer"))`) + for all resource of same type with activation condition. This will make sure that only one is registered. + See details at [low level api](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java#L20-L52). ## Defining Workflows diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentWithActivationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentWithActivationIT.java new file mode 100644 index 0000000000..e5d1542b19 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentWithActivationIT.java @@ -0,0 +1,76 @@ +package io.javaoperatorsdk.operator; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.api.model.Secret; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.multipledependentwithactivation.*; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class MultipleDependentWithActivationIT { + + public static final String INITIAL_VALUE = "initial_value"; + public static final String CHANGED_VALUE = "changed_value"; + public static final String TEST_RESOURCE_NAME = "test1"; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(new MultipleDependentActivationReconciler()) + .build(); + + @Test + void bothDependentsWithActivationAreHandled() { + var resource = extension.create(testResource()); + + await().untilAsserted(() -> { + var cm1 = + extension.get(ConfigMap.class, TEST_RESOURCE_NAME + ConfigMapDependentResource1.SUFFIX); + var cm2 = + extension.get(ConfigMap.class, TEST_RESOURCE_NAME + ConfigMapDependentResource2.SUFFIX); + var secret = extension.get(Secret.class, TEST_RESOURCE_NAME); + assertThat(secret).isNotNull(); + assertThat(cm1).isNull(); + assertThat(cm2).isNull(); + }); + + ActivationCondition.MET = true; + resource.getSpec().setValue(CHANGED_VALUE); + extension.replace(resource); + + await().untilAsserted(() -> { + var cm1 = + extension.get(ConfigMap.class, TEST_RESOURCE_NAME + ConfigMapDependentResource1.SUFFIX); + var cm2 = + extension.get(ConfigMap.class, TEST_RESOURCE_NAME + ConfigMapDependentResource2.SUFFIX); + var secret = extension.get(Secret.class, TEST_RESOURCE_NAME); + + assertThat(secret).isNotNull(); + assertThat(cm1).isNotNull(); + assertThat(cm2).isNotNull(); + assertThat(cm1.getData()).containsEntry(ConfigMapDependentResource1.DATA_KEY, + CHANGED_VALUE + ConfigMapDependentResource1.SUFFIX); + assertThat(cm2.getData()).containsEntry(ConfigMapDependentResource2.DATA_KEY, + CHANGED_VALUE + ConfigMapDependentResource2.SUFFIX); + }); + + } + + MultipleDependentActivationCustomResource testResource() { + var res = new MultipleDependentActivationCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(TEST_RESOURCE_NAME) + .build()); + res.setSpec(new MultipleDependentActivationSpec()); + res.getSpec().setValue(INITIAL_VALUE); + + return res; + } + + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ActivationCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ActivationCondition.java new file mode 100644 index 0000000000..5e357351f5 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ActivationCondition.java @@ -0,0 +1,20 @@ +package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; + +import io.fabric8.openshift.api.model.Route; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; + +public class ActivationCondition + implements Condition { + + public static volatile boolean MET = false; + + @Override + public boolean isMet( + DependentResource dependentResource, + MultipleDependentActivationCustomResource primary, + Context context) { + return MET; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource1.java new file mode 100644 index 0000000000..e9b53898b8 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource1.java @@ -0,0 +1,35 @@ +package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; + +import java.util.Map; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; + +@KubernetesDependent(informerConfig = @InformerConfig(name = "configMapInformer")) +public class ConfigMapDependentResource1 + extends + CRUDNoGCKubernetesDependentResource { + + public static final String DATA_KEY = "data"; + public static final String SUFFIX = "1"; + + public ConfigMapDependentResource1() { + super(ConfigMap.class); + } + + @Override + protected ConfigMap desired(MultipleDependentActivationCustomResource primary, + Context context) { + ConfigMap configMap = new ConfigMap(); + configMap.setMetadata(new ObjectMetaBuilder() + .withName(primary.getMetadata().getName() + SUFFIX) + .withNamespace(primary.getMetadata().getNamespace()) + .build()); + configMap.setData(Map.of(DATA_KEY, primary.getSpec().getValue() + SUFFIX)); + return configMap; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource2.java new file mode 100644 index 0000000000..c88929a61f --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource2.java @@ -0,0 +1,35 @@ +package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; + +import java.util.Map; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; + +@KubernetesDependent(informerConfig = @InformerConfig(name = "configMapInformer")) +public class ConfigMapDependentResource2 + extends + CRUDNoGCKubernetesDependentResource { + + public static final String DATA_KEY = "data"; + public static final String SUFFIX = "2"; + + public ConfigMapDependentResource2() { + super(ConfigMap.class); + } + + @Override + protected ConfigMap desired(MultipleDependentActivationCustomResource primary, + Context context) { + ConfigMap configMap = new ConfigMap(); + configMap.setMetadata(new ObjectMetaBuilder() + .withName(primary.getMetadata().getName() + SUFFIX) + .withNamespace(primary.getMetadata().getNamespace()) + .build()); + configMap.setData(Map.of(DATA_KEY, primary.getSpec().getValue() + SUFFIX)); + return configMap; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationCustomResource.java new file mode 100644 index 0000000000..e373a7bc01 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationCustomResource.java @@ -0,0 +1,17 @@ +package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("mdar") +public class MultipleDependentActivationCustomResource + extends CustomResource + implements Namespaced { + + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationReconciler.java new file mode 100644 index 0000000000..5a4961c6c6 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationReconciler.java @@ -0,0 +1,34 @@ +package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; + +import java.util.concurrent.atomic.AtomicInteger; + +import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; + +@Workflow(dependents = { + @Dependent(type = ConfigMapDependentResource1.class, + activationCondition = ActivationCondition.class), + @Dependent(type = ConfigMapDependentResource2.class, + activationCondition = ActivationCondition.class), + @Dependent(type = SecretDependentResource.class) +}) +@ControllerConfiguration +public class MultipleDependentActivationReconciler + implements Reconciler { + + private final AtomicInteger numberOfReconciliationExecution = new AtomicInteger(0); + + @Override + public UpdateControl reconcile( + MultipleDependentActivationCustomResource resource, + Context context) { + + numberOfReconciliationExecution.incrementAndGet(); + + return UpdateControl.noUpdate(); + } + + public int getNumberOfReconciliationExecution() { + return numberOfReconciliationExecution.get(); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationSpec.java new file mode 100644 index 0000000000..93bf4b18f3 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationSpec.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; + +public class MultipleDependentActivationSpec { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/SecretDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/SecretDependentResource.java new file mode 100644 index 0000000000..821f5482dc --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/SecretDependentResource.java @@ -0,0 +1,31 @@ +package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; + +import java.util.Base64; +import java.util.Map; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.api.model.Secret; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; + +public class SecretDependentResource + extends CRUDKubernetesDependentResource { + + public SecretDependentResource() { + super(Secret.class); + } + + @Override + protected Secret desired(MultipleDependentActivationCustomResource primary, + Context context) { + // basically does not matter since this should not be called + Secret secret = new Secret(); + secret.setMetadata(new ObjectMetaBuilder() + .withName(primary.getMetadata().getName()) + .withNamespace(primary.getMetadata().getNamespace()) + .build()); + secret.setData(Map.of("data", + Base64.getEncoder().encodeToString(primary.getSpec().getValue().getBytes()))); + return secret; + } +} From 3601eeca11029f3e79e57ab723a8b8dda5e50ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 2 Jul 2024 19:41:37 +0200 Subject: [PATCH 61/96] refactor: `updateMatcher` removal (#2431) --- .../GenericKubernetesResourceMatcher.java | 56 +++++-------------- ...tcher.java => GenericResourceUpdater.java} | 24 +------- .../KubernetesDependentResource.java | 20 ++----- .../GenericKubernetesResourceMatcherTest.java | 28 +++++----- ...t.java => GenericResourceUpdaterTest.java} | 23 +++----- 5 files changed, 45 insertions(+), 106 deletions(-) rename operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/{updatermatcher/GenericResourceUpdaterMatcher.java => GenericResourceUpdater.java} (62%) rename operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/{GenericResourceUpdaterMatcherTest.java => GenericResourceUpdaterTest.java} (81%) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcher.java index 05ee05b036..00f68f36a7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcher.java @@ -4,17 +4,14 @@ import java.util.Collections; import java.util.List; -import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.zjsonpatch.JsonDiff; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.Matcher; import com.fasterxml.jackson.databind.JsonNode; -public class GenericKubernetesResourceMatcher - implements Matcher { +public class GenericKubernetesResourceMatcher { private static final String SPEC = "/spec"; private static final String METADATA = "/metadata"; @@ -26,40 +23,7 @@ public class GenericKubernetesResourceMatcher dependentResource; - private GenericKubernetesResourceMatcher(KubernetesDependentResource dependentResource) { - this.dependentResource = dependentResource; - } - - @SuppressWarnings({"unchecked", "rawtypes", "unused"}) - static Matcher matcherFor( - KubernetesDependentResource dependentResource) { - return new GenericKubernetesResourceMatcher(dependentResource); - } - - /** - * {@inheritDoc} - *

- * This implementation attempts to cover most common cases out of the box by considering - * non-additive changes to the resource's spec (if the resource in question has a {@code spec} - * field), making special provisions for {@link ConfigMap} and {@link Secret} resources. Additive - * changes (i.e. a field is added that previously didn't exist) are not considered as triggering a - * mismatch by default to account for validating webhooks that might add default values - * automatically when not present or some other controller adding labels and/or annotations. - *

- *

- * It should be noted that this implementation is potentially intensive because it generically - * attempts to cover common use cases by performing diffs on the JSON representation of objects. - * If performance is a concern, it might be easier / simpler to provide a {@link Matcher} - * implementation optimized for your use case. - *

- */ - @Override - public Result match(R actualResource, P primary, Context

context) { - var desired = dependentResource.desired(primary, context); - return match(desired, actualResource, false, false, context); - } /** * Determines whether the specified actual resource matches the specified desired resource, @@ -84,7 +48,7 @@ public Result match(R actualResource, P primary, Context

context) { * @param resource * @return results of matching */ - public static Result match(R desired, + public static Matcher.Result match(R desired, R actualResource, boolean labelsAndAnnotationsEquality, boolean valuesEquality, Context

context) { @@ -92,6 +56,12 @@ public static Result match(R d labelsAndAnnotationsEquality, valuesEquality, context, EMPTY_ARRAY); } + public static Matcher.Result match(R desired, + R actualResource, Context

context) { + return match(desired, actualResource, + false, false, context, EMPTY_ARRAY); + } + /** * Determines whether the specified actual resource matches the specified desired resource, * possibly considering metadata and deeper equality checks. @@ -108,7 +78,7 @@ public static Result match(R d * @param resource * @return results of matching */ - public static Result match(R desired, + public static Matcher.Result match(R desired, R actualResource, boolean labelsAndAnnotationsEquality, Context

context, String... ignorePaths) { @@ -139,7 +109,7 @@ public static Result match(R d * match fails. * @return a {@link io.javaoperatorsdk.operator.processing.dependent.Matcher.Result} object */ - public static Result match( + public static Matcher.Result match( KubernetesDependentResource dependentResource, R actualResource, P primary, Context

context, boolean labelsAndAnnotationsEquality, @@ -150,7 +120,7 @@ public static Result match( ignorePaths); } - public static Result match( + public static Matcher.Result match( KubernetesDependentResource dependentResource, R actualResource, P primary, Context

context, boolean specEquality, @@ -161,7 +131,7 @@ public static Result match( labelsAndAnnotationsEquality, specEquality, context, ignorePaths); } - public static Result match(R desired, + public static Matcher.Result match(R desired, R actualResource, boolean labelsAndAnnotationsEquality, boolean valuesEquality, Context

context, String... ignoredPaths) { @@ -194,7 +164,7 @@ public static Result match(R d } } - return Result.computed(matched, desired); + return Matcher.Result.computed(matched, desired); } private static boolean match(boolean equality, JsonNode diff, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdater.java similarity index 62% rename from operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java rename to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdater.java index 418a5dc964..4a8fef01e9 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/updatermatcher/GenericResourceUpdaterMatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdater.java @@ -1,29 +1,17 @@ -package io.javaoperatorsdk.operator.processing.dependent.kubernetes.updatermatcher; +package io.javaoperatorsdk.operator.processing.dependent.kubernetes; import java.util.Map; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.utils.KubernetesSerialization; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.GenericKubernetesResourceMatcher; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.ResourceUpdaterMatcher; -public class GenericResourceUpdaterMatcher implements - ResourceUpdaterMatcher { +public class GenericResourceUpdater { private static final String METADATA = "metadata"; - private static final ResourceUpdaterMatcher INSTANCE = new GenericResourceUpdaterMatcher<>(); - - protected GenericResourceUpdaterMatcher() {} - - @SuppressWarnings("unchecked") - public static ResourceUpdaterMatcher updaterMatcherFor() { - return (ResourceUpdaterMatcher) INSTANCE; - } @SuppressWarnings("unchecked") - @Override - public R updateResource(R actual, R desired, Context context) { + public static R updateResource(R actual, R desired, Context context) { KubernetesSerialization kubernetesSerialization = context.getClient().getKubernetesSerialization(); Map actualMap = kubernetesSerialization.convertValue(actual, Map.class); @@ -40,12 +28,6 @@ public R updateResource(R actual, R desired, Context context) { return clonedActual; } - @Override - public boolean matches(R actual, R desired, Context context) { - return GenericKubernetesResourceMatcher.match(desired, actual, - false, false, context).matched(); - } - public static void updateLabelsAndAnnotation(K actual, K desired) { actual.getMetadata().getLabels().putAll(desired.getMetadata().getLabels()); actual.getMetadata().getAnnotations().putAll(desired.getMetadata().getAnnotations()); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 243731d07e..37069bd1c4 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -21,7 +21,6 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; import io.javaoperatorsdk.operator.processing.dependent.AbstractEventSourceHolderDependentResource; import io.javaoperatorsdk.operator.processing.dependent.Matcher.Result; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.updatermatcher.GenericResourceUpdaterMatcher; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; @@ -36,8 +35,6 @@ public abstract class KubernetesDependentResource updaterMatcher = this instanceof ResourceUpdaterMatcher ? (ResourceUpdaterMatcher) this : GenericResourceUpdaterMatcher.updaterMatcherFor(resourceType()); private KubernetesDependentResourceConfig kubernetesDependentResourceConfig; private volatile Boolean useSSA; @@ -54,7 +51,6 @@ public void configureWith(KubernetesDependentResourceConfig config) { this.kubernetesDependentResourceConfig = config; } - @SuppressWarnings("unused") public R create(R desired, P primary, Context

context) { if (useSSA(context)) { @@ -88,7 +84,7 @@ public R update(R actual, R desired, P primary, Context

context) { .fieldManager(context.getControllerConfiguration().fieldManager()) .forceConflicts().serverSideApply(); } else { - var updatedActual = updaterMatcher.updateResource(actual, desired, context); + var updatedActual = GenericResourceUpdater.updateResource(actual, desired, context); updatedResource = prepare(context, updatedActual, primary, "Updating").update(); } log.debug("Resource version after update: {}", @@ -99,17 +95,10 @@ public R update(R actual, R desired, P primary, Context

context) { @Override public Result match(R actualResource, P primary, Context

context) { final var desired = desired(primary, context); - return match(actualResource, desired, primary, updaterMatcher, context); - } - - @SuppressWarnings({"unused"}) - public Result match(R actualResource, R desired, P primary, Context

context) { - return match(actualResource, desired, primary, - GenericResourceUpdaterMatcher.updaterMatcherFor(), - context); + return match(actualResource, desired, primary, context); } - public Result match(R actualResource, R desired, P primary, ResourceUpdaterMatcher matcher, + public Result match(R actualResource, R desired, P primary, Context

context) { final boolean matches; addMetadata(true, actualResource, desired, primary, context); @@ -117,7 +106,8 @@ public Result match(R actualResource, R desired, P primary, ResourceUpdaterMa matches = SSABasedGenericKubernetesResourceMatcher.getInstance() .matches(actualResource, desired, context); } else { - matches = matcher.matches(actualResource, desired, context); + matches = GenericKubernetesResourceMatcher.match(desired, actualResource, + false, false, context).matched(); } return Result.computed(matches, desired); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java index 997f7688e8..2663657157 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesResourceMatcherTest.java @@ -13,15 +13,13 @@ import io.javaoperatorsdk.operator.MockKubernetesClient; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.processing.dependent.Matcher; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.updatermatcher.GenericResourceUpdaterMatcher; import static io.javaoperatorsdk.operator.processing.dependent.kubernetes.GenericKubernetesResourceMatcher.match; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@SuppressWarnings({"unchecked", "rawtypes"}) +@SuppressWarnings({"unchecked"}) class GenericKubernetesResourceMatcherTest { private static final Context context = mock(Context.class); @@ -29,7 +27,7 @@ class GenericKubernetesResourceMatcherTest { Deployment actual = createDeployment(); Deployment desired = createDeployment(); TestDependentResource dependentResource = new TestDependentResource(desired); - Matcher matcher = GenericKubernetesResourceMatcher.matcherFor(dependentResource); + @BeforeAll static void setUp() { @@ -39,15 +37,17 @@ static void setUp() { @Test void matchesTrivialCases() { - assertThat(matcher.match(actual, null, context).matched()).isTrue(); - assertThat(matcher.match(actual, null, context).computedDesired()).isPresent(); - assertThat(matcher.match(actual, null, context).computedDesired()).contains(desired); + assertThat(GenericKubernetesResourceMatcher.match(desired, actual, context).matched()).isTrue(); + assertThat(GenericKubernetesResourceMatcher.match(desired, actual, context).computedDesired()) + .isPresent(); + assertThat(GenericKubernetesResourceMatcher.match(desired, actual, context).computedDesired()) + .contains(desired); } @Test void matchesAdditiveOnlyChanges() { actual.getSpec().getTemplate().getMetadata().getLabels().put("new-key", "val"); - assertThat(matcher.match(actual, null, context).matched()) + assertThat(GenericKubernetesResourceMatcher.match(desired, actual, context).matched()) .withFailMessage("Additive changes should not cause a mismatch by default") .isTrue(); } @@ -64,7 +64,9 @@ void matchesWithStrongSpecEquality() { @Test void doesNotMatchRemovedValues() { actual = createDeployment(); - assertThat(matcher.match(actual, createPrimary("removed"), context).matched()) + assertThat(GenericKubernetesResourceMatcher + .match(dependentResource.desired(createPrimary("removed"), null), actual, context) + .matched()) .withFailMessage("Removing values in metadata should lead to a mismatch") .isFalse(); } @@ -73,7 +75,7 @@ void doesNotMatchRemovedValues() { void doesNotMatchChangedValues() { actual = createDeployment(); actual.getSpec().setReplicas(2); - assertThat(matcher.match(actual, null, context).matched()) + assertThat(GenericKubernetesResourceMatcher.match(desired, actual, context).matched()) .withFailMessage("Should not have matched because values have changed") .isFalse(); } @@ -82,7 +84,7 @@ void doesNotMatchChangedValues() { void ignoreStatus() { actual = createDeployment(); actual.setStatus(new DeploymentStatusBuilder().withReadyReplicas(1).build()); - assertThat(matcher.match(actual, null, context).matched()) + assertThat(GenericKubernetesResourceMatcher.match(desired, actual, context).matched()) .withFailMessage("Should ignore status in actual") .isTrue(); } @@ -146,8 +148,8 @@ void checkServiceAccount() { .addNewImagePullSecret("imagePullSecret3") .build(); - final var matcher = GenericResourceUpdaterMatcher.updaterMatcherFor(); - assertThat(matcher.matches(actual, desired, context)).isTrue(); + assertThat(GenericKubernetesResourceMatcher.match(desired, actual, false, false, context) + .matched()).isTrue(); } @Test diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterMatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterTest.java similarity index 81% rename from operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterMatcherTest.java rename to operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterTest.java index bbdb4811fe..313520b89e 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterMatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericResourceUpdaterTest.java @@ -14,14 +14,13 @@ import io.javaoperatorsdk.operator.api.config.ConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.updatermatcher.GenericResourceUpdaterMatcher; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @SuppressWarnings("rawtypes") -class GenericResourceUpdaterMatcherTest { +class GenericResourceUpdaterTest { private static final Context context = mock(Context.class); @@ -40,7 +39,6 @@ static void setUp() { @Test void preservesValues() { - var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(); var desired = createDeployment(); var actual = createDeployment(); actual.getMetadata().setLabels(new HashMap<>()); @@ -48,7 +46,7 @@ void preservesValues() { actual.getMetadata().setResourceVersion("1234"); actual.getSpec().setRevisionHistoryLimit(5); - var result = processor.updateResource(actual, desired, context); + var result = GenericResourceUpdater.updateResource(actual, desired, context); assertThat(result.getMetadata().getLabels().get("additionalActualKey")).isEqualTo("value"); assertThat(result.getMetadata().getResourceVersion()).isEqualTo("1234"); @@ -57,27 +55,26 @@ void preservesValues() { @Test void checkNamespaces() { - var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(); var desired = new NamespaceBuilder().withNewMetadata().withName("foo").endMetadata().build(); var actual = new NamespaceBuilder().withNewMetadata().withName("foo").endMetadata().build(); actual.getMetadata().setLabels(new HashMap<>()); actual.getMetadata().getLabels().put("additionalActualKey", "value"); actual.getMetadata().setResourceVersion("1234"); - var result = processor.updateResource(actual, desired, context); + var result = GenericResourceUpdater.updateResource(actual, desired, context); assertThat(result.getMetadata().getLabels().get("additionalActualKey")).isEqualTo("value"); assertThat(result.getMetadata().getResourceVersion()).isEqualTo("1234"); desired.setSpec(new NamespaceSpec(List.of("halkyon.io/finalizer"))); - result = processor.updateResource(actual, desired, context); + result = GenericResourceUpdater.updateResource(actual, desired, context); assertThat(result.getMetadata().getLabels().get("additionalActualKey")).isEqualTo("value"); assertThat(result.getMetadata().getResourceVersion()).isEqualTo("1234"); assertThat(result.getSpec().getFinalizers()).containsExactly("halkyon.io/finalizer"); desired = new NamespaceBuilder().withNewMetadata().withName("foo").endMetadata().build(); - result = processor.updateResource(actual, desired, context); + result = GenericResourceUpdater.updateResource(actual, desired, context); assertThat(result.getMetadata().getLabels().get("additionalActualKey")).isEqualTo("value"); assertThat(result.getMetadata().getResourceVersion()).isEqualTo("1234"); assertThat(result.getSpec()).isNull(); @@ -85,7 +82,6 @@ void checkNamespaces() { @Test void checkSecret() { - var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(); var desired = new SecretBuilder() .withMetadata(new ObjectMeta()) @@ -94,15 +90,14 @@ void checkSecret() { .withMetadata(new ObjectMeta()) .build(); - final var secret = processor.updateResource(actual, desired, context); + final var secret = GenericResourceUpdater.updateResource(actual, desired, context); assertThat(secret.getImmutable()).isTrue(); assertThat(secret.getType()).isEqualTo("Opaque"); assertThat(secret.getData()).containsOnlyKeys("foo"); } @Test - void checkSeviceAccount() { - var processor = GenericResourceUpdaterMatcher.updaterMatcherFor(); + void checkServiceAccount() { var desired = new ServiceAccountBuilder() .withMetadata(new ObjectMetaBuilder().addToLabels("new", "label").build()) .build(); @@ -111,7 +106,7 @@ void checkSeviceAccount() { .withImagePullSecrets(new LocalObjectReferenceBuilder().withName("secret").build()) .build(); - final var serviceAccount = processor.updateResource(actual, desired, context); + final var serviceAccount = GenericResourceUpdater.updateResource(actual, desired, context); assertThat(serviceAccount.getMetadata().getLabels()) .isEqualTo(Map.of("a", "label", "new", "label")); assertThat(serviceAccount.getImagePullSecrets()).isNullOrEmpty(); @@ -119,7 +114,7 @@ void checkSeviceAccount() { Deployment createDeployment() { return ReconcilerUtils.loadYaml( - Deployment.class, GenericResourceUpdaterMatcherTest.class, "nginx-deployment.yaml"); + Deployment.class, GenericResourceUpdaterTest.class, "nginx-deployment.yaml"); } } From a4b0efbdfa558dd94ad1a65ab907539b220e575b Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Wed, 3 Jul 2024 13:40:41 +0200 Subject: [PATCH 62/96] chore(docs): add some javadoc (#2452) Signed-off-by: Chris Laprun --- .../config/AbstractConfigurationService.java | 7 +- .../api/config/ConfigurationService.java | 166 ++++++++++++------ .../dependent/DependentResource.java | 32 +++- .../health/EventSourceHealthIndicator.java | 7 + .../operator/health/Status.java | 3 + .../dependent/AbstractDependentResource.java | 17 +- .../dependent/BulkDependentResource.java | 3 + .../DependentResourceWithExplicitState.java | 4 + .../CRDPresentActivationCondition.java | 6 +- .../processing/event/source/EventSource.java | 39 +++- .../source/EventSourceStartPriority.java | 26 ++- 11 files changed, 224 insertions(+), 86 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractConfigurationService.java index 1a54dbafc7..f7ed42c577 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractConfigurationService.java @@ -10,6 +10,9 @@ import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +/** + * An abstract implementation of {@link ConfigurationService} meant to ease custom implementations + */ @SuppressWarnings("rawtypes") public class AbstractConfigurationService implements ConfigurationService { private final Map configurations = new ConcurrentHashMap<>(); @@ -18,11 +21,11 @@ public class AbstractConfigurationService implements ConfigurationService { private Cloner cloner; private ExecutorServiceManager executorServiceManager; - public AbstractConfigurationService(Version version) { + protected AbstractConfigurationService(Version version) { this(version, null); } - public AbstractConfigurationService(Version version, Cloner cloner) { + protected AbstractConfigurationService(Version version, Cloner cloner) { this(version, cloner, null, null); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index 1a31376054..d29e545bb6 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -36,6 +36,68 @@ public interface ConfigurationService { Logger log = LoggerFactory.getLogger(ConfigurationService.class); int DEFAULT_MAX_CONCURRENT_REQUEST = 512; + /** + * The default numbers of concurrent reconciliations + */ + int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50; + /** + * The default number of threads used to process dependent workflows + */ + int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER; + + /** + * Creates a new {@link ConfigurationService} instance used to configure an + * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base + * configuration and overriding specific aspects according to the provided + * {@link ConfigurationServiceOverrider} instance. + * + *

+ * NOTE: This overriding mechanism should only be used before creating + * your Operator instance as the configuration service is set at creation time and cannot be + * subsequently changed. As a result, overriding values this way after the Operator has been + * configured will not take effect. + *

+ * + * @param baseConfiguration the {@link ConfigurationService} to start from + * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided + * by the base configuration + * @return a new {@link ConfigurationService} starting from the configuration provided as base but + * with overridden values. + */ + static ConfigurationService newOverriddenConfigurationService( + ConfigurationService baseConfiguration, + Consumer overrider) { + if (overrider != null) { + final var toOverride = new ConfigurationServiceOverrider(baseConfiguration); + overrider.accept(toOverride); + return toOverride.build(); + } + return baseConfiguration; + } + + /** + * Creates a new {@link ConfigurationService} instance used to configure an + * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the default configuration + * and overriding specific aspects according to the provided {@link ConfigurationServiceOverrider} + * instance. + * + *

+ * NOTE: This overriding mechanism should only be used before creating + * your Operator instance as the configuration service is set at creation time and cannot be + * subsequently changed. As a result, overriding values this way after the Operator has been + * configured will not take effect. + *

+ * + * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided + * by the default configuration + * @return a new {@link ConfigurationService} overriding the default values with the ones provided + * by the specified {@link ConfigurationServiceOverrider} + * @since 4.4.0 + */ + static ConfigurationService newOverriddenConfigurationService( + Consumer overrider) { + return newOverriddenConfigurationService(new BaseConfigurationService(), overrider); + } /** * Retrieves the configuration associated with the specified reconciler @@ -47,7 +109,6 @@ public interface ConfigurationService { */ ControllerConfiguration getConfigurationFor(Reconciler reconciler); - /** * Used to clone custom resources. * @@ -131,8 +192,6 @@ default boolean checkCRDAndValidateLocalModel() { return false; } - int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50; - /** * The number of threads the operator can spin out to dispatch reconciliation requests to * reconcilers with the default executors @@ -143,8 +202,6 @@ default int concurrentReconciliationThreads() { return DEFAULT_RECONCILIATION_THREADS_NUMBER; } - int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER; - /** * Number of threads the operator can spin out to be used in the workflows with the default * executor. @@ -155,27 +212,64 @@ default int concurrentWorkflowExecutorThreads() { return DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER; } + /** + * Override to provide a custom {@link Metrics} implementation + * + * @return the {@link Metrics} implementation + */ default Metrics getMetrics() { return Metrics.NOOP; } + /** + * Override to provide a custom {@link ExecutorService} implementation to change how threads + * handle concurrent reconciliations + * + * @return the {@link ExecutorService} implementation to use for concurrent reconciliation + * processing + */ default ExecutorService getExecutorService() { return Executors.newFixedThreadPool(concurrentReconciliationThreads()); } + /** + * Override to provide a custom {@link ExecutorService} implementation to change how dependent + * workflows are processed in parallel + * + * @return the {@link ExecutorService} implementation to use for dependent workflow processing + */ default ExecutorService getWorkflowExecutorService() { return Executors.newFixedThreadPool(concurrentWorkflowExecutorThreads()); } + /** + * Determines whether the associated Kubernetes client should be closed when the associated + * {@link io.javaoperatorsdk.operator.Operator} is stopped. + * + * @return {@code true} if the Kubernetes should be closed on stop, {@code false} otherwise + */ default boolean closeClientOnStop() { return true; } + /** + * Override to provide a custom {@link DependentResourceFactory} implementation to change how + * {@link io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource} are instantiated + * + * @return the custom {@link DependentResourceFactory} implementation + */ @SuppressWarnings("rawtypes") default DependentResourceFactory dependentResourceFactory() { return DependentResourceFactory.DEFAULT; } + /** + * Retrieves the optional {@link LeaderElectionConfiguration} to specify how the associated + * {@link io.javaoperatorsdk.operator.Operator} handles leader election to ensure only one + * instance of the operator runs on the cluster at any given time + * + * @return the {@link LeaderElectionConfiguration} + */ default Optional getLeaderElectionConfiguration() { return Optional.empty(); } @@ -231,65 +325,23 @@ default Optional getInformerStoppedHandler() { }); } + /** + * Override to provide a custom {@link ManagedWorkflowFactory} implementation to change how + * {@link io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflow} are + * instantiated + * + * @return the custom {@link ManagedWorkflowFactory} implementation + */ @SuppressWarnings("rawtypes") default ManagedWorkflowFactory getWorkflowFactory() { return ManagedWorkflowFactory.DEFAULT; } /** - * Creates a new {@link ConfigurationService} instance used to configure an - * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base - * configuration and overriding specific aspects according to the provided - * {@link ConfigurationServiceOverrider} instance. - * - *

- * NOTE: This overriding mechanism should only be used before creating - * your Operator instance as the configuration service is set at creation time and cannot be - * subsequently changed. As a result, overriding values this way after the Operator has been - * configured will not take effect. - *

- * - * @param baseConfiguration the {@link ConfigurationService} to start from - * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided - * by the base configuration - * @return a new {@link ConfigurationService} starting from the configuration provided as base but - * with overridden values. - */ - static ConfigurationService newOverriddenConfigurationService( - ConfigurationService baseConfiguration, - Consumer overrider) { - if (overrider != null) { - final var toOverride = new ConfigurationServiceOverrider(baseConfiguration); - overrider.accept(toOverride); - return toOverride.build(); - } - return baseConfiguration; - } - - /** - * Creates a new {@link ConfigurationService} instance used to configure an - * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the default configuration - * and overriding specific aspects according to the provided {@link ConfigurationServiceOverrider} - * instance. - * - *

- * NOTE: This overriding mechanism should only be used before creating - * your Operator instance as the configuration service is set at creation time and cannot be - * subsequently changed. As a result, overriding values this way after the Operator has been - * configured will not take effect. - *

- * - * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided - * by the default configuration - * @return a new {@link ConfigurationService} overriding the default values with the ones provided - * by the specified {@link ConfigurationServiceOverrider} - * @since 4.4.0 + * Override to provide a custom {@link ExecutorServiceManager} implementation + * + * @return the custom {@link ExecutorServiceManager} implementation */ - static ConfigurationService newOverriddenConfigurationService( - Consumer overrider) { - return newOverriddenConfigurationService(new BaseConfigurationService(), overrider); - } - default ExecutorServiceManager getExecutorServiceManager() { return new ExecutorServiceManager(this); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java index 2b75b0d969..375afd4397 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java @@ -15,6 +15,18 @@ */ public interface DependentResource { + /** + * Computes a default name for the specified DependentResource class + * + * @param dependentResourceClass the DependentResource class for which we want to compute a + * default name + * @return the default name for the specified DependentResource class + */ + @SuppressWarnings("rawtypes") + static String defaultNameFor(Class dependentResourceClass) { + return dependentResourceClass.getName(); + } + /** * Reconciles the dependent resource given the desired primary state * @@ -65,21 +77,23 @@ default Optional getSecondaryResource(P primary, Context

context) { } /** - * Computes a default name for the specified DependentResource class + * Determines whether resources associated with this dependent need explicit handling when + * deleted, usually meaning that the dependent implements {@link Deleter} * - * @param dependentResourceClass the DependentResource class for which we want to compute a - * default name - * @return the default name for the specified DependentResource class + * @return {@code true} if explicit handling of resource deletion is needed, {@link false} + * otherwise */ - @SuppressWarnings("rawtypes") - static String defaultNameFor(Class dependentResourceClass) { - return dependentResourceClass.getName(); - } - default boolean isDeletable() { return this instanceof Deleter; } + + /** + * Retrieves the name identifying this DependentResource implementation, useful to refer to this + * in {@link io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow} instances + * + * @return the name identifying this DependentResource implementation + */ default String name() { return defaultNameFor(getClass()); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/EventSourceHealthIndicator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/EventSourceHealthIndicator.java index e44fcb5b72..2732c16707 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/EventSourceHealthIndicator.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/EventSourceHealthIndicator.java @@ -2,5 +2,12 @@ public interface EventSourceHealthIndicator { + /** + * Retrieves the health status of an + * {@link io.javaoperatorsdk.operator.processing.event.source.EventSource} + * + * @return the health status + * @see Status + */ Status getStatus(); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/Status.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/Status.java index d3a300b7d8..272c360a87 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/Status.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/Status.java @@ -1,5 +1,8 @@ package io.javaoperatorsdk.operator.health; +/** + * The health status of an {@link io.javaoperatorsdk.operator.processing.event.source.EventSource} + */ public enum Status { HEALTHY, UNHEALTHY, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java index 24ea12ed0b..63223a01ff 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java @@ -16,6 +16,14 @@ import io.javaoperatorsdk.operator.processing.dependent.Matcher.Result; import io.javaoperatorsdk.operator.processing.event.ResourceID; +/** + * An abstract implementation of {@link DependentResource} to be used as base for custom + * implementations, providing, in particular, the core {@link #reconcile(HasMetadata, Context)} + * logic for dependents + * + * @param the dependent resource type + * @param

the associated primary resource type + */ @Ignore public abstract class AbstractDependentResource implements DependentResource, NameSetter { @@ -24,18 +32,16 @@ public abstract class AbstractDependentResource private final boolean creatable = this instanceof Creator; private final boolean updatable = this instanceof Updater; private final boolean deletable = this instanceof Deleter; - + private final DependentResourceReconciler dependentResourceReconciler; protected Creator creator; protected Updater updater; - private final DependentResourceReconciler dependentResourceReconciler; - protected String name; - @SuppressWarnings({"unchecked"}) protected AbstractDependentResource() { this(null); } + @SuppressWarnings("unchecked") protected AbstractDependentResource(String name) { creator = creatable ? (Creator) this : null; updater = updatable ? (Updater) this : null; @@ -120,7 +126,8 @@ public Optional getSecondaryResource(P primary, Context

context) { * secondary candidates for equality with the specified desired state, which might end up costly. * * @param secondaryResources to select the target resource from - * + * @param primary the primary resource + * @param context the context in which this method is called * @return the matching secondary resource or {@link Optional#empty()} if none matches * @throws IllegalStateException if more than one candidate is found, in which case some other * mechanism might be necessary to distinguish between candidate secondary resources diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java index 313d7115c9..a54027e4c3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java @@ -12,6 +12,9 @@ * dependent resource is to manage the number of secondary resources dynamically it implement * {@link Creator} and {@link Deleter} interfaces out of the box. A concrete dependent resource can * implement additionally also {@link Updater}. + * + * @param the dependent resource type + * @param

the primary resource type */ public interface BulkDependentResource { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/DependentResourceWithExplicitState.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/DependentResourceWithExplicitState.java index 05206731db..4609b4a9c7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/DependentResourceWithExplicitState.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/DependentResourceWithExplicitState.java @@ -11,6 +11,10 @@ * are non Kubernetes resources which when created their ID is generated, so cannot be determined * based only on primary resources. In order to manage such dependent resource use this interface * for a resource that extends {@link AbstractExternalDependentResource}. + * + * @param the dependent resource type + * @param

the primary resource type + * @param the state type */ public interface DependentResourceWithExplicitState extends Creator, Deleter

{ diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java index b3792bb9c7..5a60b63d41 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java @@ -16,7 +16,11 @@ * even used in multiple condition. By default, it checks CRD at most 10 times with a delay at least * 10 seconds. To fully customize CRD check trigger behavior you can extend this class and override * the {@link CRDPresentActivationCondition#shouldCheckStateNow(CRDCheckState)} method. - **/ + * + * @param the resource type associated with the CRD to check for presence + * @param

the primary resource type associated with the reconciler processing dependents + * associated with this condition + */ public class CRDPresentActivationCondition implements Condition { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java index 11b884bb73..850a9deb35 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java @@ -17,10 +17,18 @@ * Creates an event source to trigger your reconciler whenever something happens to a secondary or * external resource that should cause a reconciliation of the primary resource. EventSource * generalizes the concept of Informers and extends it to external (i.e. non Kubernetes) resources. + * + * @param the resource type that this EventSource is associated with + * @param

the primary resource type which reconciler needs to be triggered when events occur on + * resources of type R */ public interface EventSource extends LifecycleAware, EventSourceHealthIndicator { + static String generateName(EventSource eventSource) { + return eventSource.getClass().getName() + "@" + Integer.toHexString(eventSource.hashCode()); + } + /** * Sets the {@link EventHandler} that is linked to your reconciler when this EventSource is * registered. @@ -29,10 +37,21 @@ public interface EventSource */ void setEventHandler(EventHandler handler); + /** + * Retrieves the EventSource's name so that it can be referred to + * + * @return the EventSource's name + */ default String name() { return generateName(this); } + /** + * Retrieves the EventSource's starting priority + * + * @return the EventSource's starting priority + * @see EventSourceStartPriority + */ default EventSourceStartPriority priority() { return EventSourceStartPriority.DEFAULT; } @@ -44,6 +63,15 @@ default EventSourceStartPriority priority() { */ Class resourceType(); + /** + * Retrieves the optional unique secondary resource associated with the specified primary + * resource. Note that this operation will fail if multiple resources are associated with the + * specified primary resource. + * + * @param primary the primary resource for which the secondary resource is requested + * @return the secondary resource associated with the specified primary resource + * @throws IllegalStateException if multiple resources are associated with the primary one + */ default Optional getSecondaryResource(P primary) { var resources = getSecondaryResources(primary); if (resources.isEmpty()) { @@ -55,6 +83,13 @@ default Optional getSecondaryResource(P primary) { } } + /** + * Retrieves a potential empty set of resources tracked by this EventSource associated with the + * specified primary resource + * + * @param primary the primary resource for which the secondary resource is requested + * @return the set of secondary resources associated with the specified primary + */ Set getSecondaryResources(P primary); void setOnAddFilter(OnAddFilter onAddFilter); @@ -69,8 +104,4 @@ default Optional getSecondaryResource(P primary) { default Status getStatus() { return Status.UNKNOWN; } - - static String generateName(EventSource eventSource) { - return eventSource.getClass().getName() + "@" + Integer.toHexString(eventSource.hashCode()); - } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSourceStartPriority.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSourceStartPriority.java index d1d758bdb4..8284d611f2 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSourceStartPriority.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSourceStartPriority.java @@ -1,17 +1,27 @@ package io.javaoperatorsdk.operator.processing.event.source; +/** + * Defines priority levels for {@link EventSource} implementation to ensure that some sources are + * started before others + */ public enum EventSourceStartPriority { /** * Event Sources with this priority are started and synced before the event source with DEFAULT - * priority. The use case to use this, if the event source holds an information regarding the - * state of a resource. For example a ConfigMap would store an ID of an external resource, in this - * case an event source that tracks the external resource might need this ID (event before the - * reconciliation) to check the state of the external resource. The only way to ensure that the ID - * is already cached is to start/sync related event source before the event source of the external - * resource. + * priority. This is needed if the event source holds information about another resource's state. + * In this situation, it is needed to initialize this event source before the one associated with + * resources which state is being tracked since that state information might be required to + * properly retrieve the other resources. + * + *

+ * For example a {@code ConfigMap} could store the identifier of a fictional external resource + * {@code A}. In this case, the event source tracking {@code A} resources might need the + * identifier from the {@code ConfigMap} to identify and check the state of {@code A} resources. + * This is usually needed before any reconciliation occurs and the only way to ensure the proper + * behavior in this case is to make sure that the event source tracking the {@code ConfigMaps} (in + * this example) is started/cache-synced before the event source for {@code A} resources gets + * started. + *

*/ RESOURCE_STATE_LOADER, DEFAULT - - } From d20e5e9cbf6b78a5408e70096e258ea8f9cd8814 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Wed, 3 Jul 2024 17:39:05 +0200 Subject: [PATCH 63/96] fix: improper use of @link (#2464) Signed-off-by: Chris Laprun --- .../operator/api/reconciler/dependent/DependentResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java index 375afd4397..7c4e530ce2 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java @@ -80,7 +80,7 @@ default Optional getSecondaryResource(P primary, Context

context) { * Determines whether resources associated with this dependent need explicit handling when * deleted, usually meaning that the dependent implements {@link Deleter} * - * @return {@code true} if explicit handling of resource deletion is needed, {@link false} + * @return {@code true} if explicit handling of resource deletion is needed, {@code false} * otherwise */ default boolean isDeletable() { From 935ec6123901d60c4c09087a746f0428a49f30b1 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 8 Jul 2024 15:56:34 +0200 Subject: [PATCH 64/96] feat: move controller informer-related configuration to InformerConfig (#2455) * feat: move controller informer-related configuration to InformerConfig Signed-off-by: Chris Laprun * refactor: start isolating ResourceConfiguration Signed-off-by: Chris Laprun * fix: initFromAnnotation now properly inits the current instance Signed-off-by: Chris Laprun * fix: default onDeleteFilter implementation Signed-off-by: Chris Laprun * fix: properly set default namespaces in controller case Signed-off-by: Chris Laprun * refactor: remove KubernetesDependentInformerConfigBuilder Signed-off-by: Chris Laprun * refactor: use InformerConfigHolder in more places, unifying handling Signed-off-by: Chris Laprun * fix: properly propagate name to informer config Signed-off-by: Chris Laprun * feat: add factory method to init builder from an extising configuation Signed-off-by: Chris Laprun * fix: remove potentially problematic default implementation Signed-off-by: Chris Laprun --------- Signed-off-by: Chris Laprun --- .../cache/sample/AbstractTestReconciler.java | 2 +- .../api/config/BaseConfigurationService.java | 38 +-- .../ControllerConfigurationOverrider.java | 84 ++--- .../config/DefaultResourceConfiguration.java | 63 +--- .../ResolvedControllerConfiguration.java | 87 ++--- .../api/config/ResourceConfiguration.java | 20 +- .../informer/InformerConfiguration.java | 278 +++++----------- .../reconciler/ControllerConfiguration.java | 73 +---- ...merWrappingEventSourceHealthIndicator.java | 3 - .../dependent/kubernetes/InformerConfig.java | 61 +++- .../kubernetes/InformerConfigHolder.java | 296 ++++++++++++++++++ .../KubernetesDependentConverter.java | 58 +--- .../KubernetesDependentInformerConfig.java | 101 ------ ...ernetesDependentInformerConfigBuilder.java | 93 ------ .../KubernetesDependentResourceConfig.java | 6 +- ...ernetesDependentResourceConfigBuilder.java | 8 +- .../source/informer/InformerEventSource.java | 5 +- .../source/informer/InformerManager.java | 2 +- .../informer/ManagedInformerEventSource.java | 5 - .../ControllerConfigurationOverriderTest.java | 74 +++-- .../api/config/ResourceConfigurationTest.java | 12 +- .../controller/ControllerEventSourceTest.java | 12 +- .../config/BaseConfigurationServiceTest.java | 7 +- .../ObservedGenerationTestReconciler.java | 8 +- ...ClusterScopedCustomResourceReconciler.java | 9 +- ...CreateUpdateEventFilterTestReconciler.java | 53 ++-- .../DependentFilterTestReconciler.java | 3 +- ...entFilterCustomResourceTestReconciler.java | 4 +- .../deployment/DeploymentReconciler.java | 4 +- .../sample/filter/FilterTestReconciler.java | 21 +- .../LabelSelectorTestReconciler.java | 4 +- ...MultipleReconcilerSameTypeReconciler1.java | 3 +- ...MultipleReconcilerSameTypeReconciler2.java | 3 +- ...ultipleSecondaryEventSourceReconciler.java | 27 +- .../MultiVersionCRDTestReconciler1.java | 3 +- .../MultiVersionCRDTestReconciler2.java | 3 +- ...OrderedManagedDependentTestReconciler.java | 3 +- .../primarytosecondary/JobReconciler.java | 4 +- .../SpecialResourceTestReconciler.java | 4 +- .../WebPageDependentsWorkflowReconciler.java | 19 +- .../operator/sample/WebPageReconciler.java | 8 +- ...WebPageStandaloneDependentsReconciler.java | 7 +- 42 files changed, 710 insertions(+), 868 deletions(-) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfigHolder.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfig.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfigBuilder.java diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java index d43094cdf8..cc59738e1c 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java @@ -78,7 +78,7 @@ public List> prepareEventSources( ConfigMap.class, Duration.ofMinutes(1), 1); // setting max size for testing purposes var es = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, primaryClass()) - .withItemStore(boundedItemStore) + .withInformerConfiguration(c -> c.withItemStore(boundedItemStore)) .withSecondaryToPrimaryMapper( Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), this instanceof BoundedCacheClusterScopeTestReconciler)) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index 3383bde416..cb685cffb9 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -13,7 +13,6 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.KubernetesClient; -import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.Utils.Configurator; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver; @@ -24,11 +23,9 @@ import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; import io.javaoperatorsdk.operator.processing.retry.Retry; import static io.javaoperatorsdk.operator.api.config.ControllerConfiguration.CONTROLLER_NAME_AS_FIELD_MANAGER; @@ -278,43 +275,20 @@ private

ResolvedControllerConfiguration

controllerCon fieldManager.equals(CONTROLLER_NAME_AS_FIELD_MANAGER) ? name : fieldManager; - var informerListLimitValue = valueOrDefaultFromAnnotation(annotation, - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::informerListLimit, - "informerListLimit"); - final var informerListLimit = - informerListLimitValue == Constants.NO_LONG_VALUE_SET ? null - : informerListLimitValue; + InformerConfigHolder

informerConfig = InformerConfigHolder.builder(resourceClass) + .initFromAnnotation(annotation != null ? annotation.informerConfig() : null, context) + .buildForController(); return new ResolvedControllerConfiguration

( resourceClass, name, generationAware, associatedReconcilerClass, retry, rateLimiter, ResolvedControllerConfiguration.getMaxReconciliationInterval(interval, timeUnit), - Utils.instantiate(valueOrDefaultFromAnnotation(annotation, - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::onAddFilter, - "onAddFilter"), OnAddFilter.class, context), - Utils.instantiate(valueOrDefaultFromAnnotation(annotation, - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::onUpdateFilter, - "onUpdateFilter"), OnUpdateFilter.class, context), - Utils.instantiate(valueOrDefaultFromAnnotation(annotation, - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::genericFilter, - "genericFilter"), GenericFilter.class, context), - Set.of(valueOrDefaultFromAnnotation(annotation, - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::namespaces, - "namespaces")), valueOrDefaultFromAnnotation(annotation, io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::finalizerName, "finalizerName"), - valueOrDefaultFromAnnotation(annotation, - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::labelSelector, - "labelSelector"), null, - Utils.instantiate( - valueOrDefaultFromAnnotation(annotation, - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration::itemStore, - "itemStore"), - ItemStore.class, context), dependentFieldManager, - this, informerListLimit); + this, informerConfig); } @@ -326,6 +300,4 @@ protected boolean createIfNeeded() { public boolean checkCRDAndValidateLocalModel() { return Utils.shouldCheckCRDAndValidateLocalModel(); } - - } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java index 315ed29c7b..c4d28b7829 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java @@ -10,51 +10,46 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; import io.javaoperatorsdk.operator.processing.retry.Retry; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES_SET; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE_SET; @SuppressWarnings({"rawtypes", "unused", "UnusedReturnValue"}) public class ControllerConfigurationOverrider { + private final ControllerConfiguration original; + private String name; private String finalizer; private boolean generationAware; - private Set namespaces; private Retry retry; - private String labelSelector; - private final ControllerConfiguration original; - private Duration reconciliationMaxInterval; - private OnAddFilter onAddFilter; - private OnUpdateFilter onUpdateFilter; - private GenericFilter genericFilter; private RateLimiter rateLimiter; - private Map configurations; - private ItemStore itemStore; - private String name; private String fieldManager; - private Long informerListLimit; + private Duration reconciliationMaxInterval; + private Map configurations; + private final InformerConfigHolder.Builder config; private ControllerConfigurationOverrider(ControllerConfiguration original) { this.finalizer = original.getFinalizerName(); this.generationAware = original.isGenerationAware(); - this.namespaces = new HashSet<>(original.getNamespaces()); + this.config = InformerConfigHolder.builder(original.getResourceClass()) + .withName(name) + .withNamespaces(original.getNamespaces()) + .withLabelSelector(original.getLabelSelector()) + .withOnAddFilter(original.onAddFilter().orElse(null)) + .withOnUpdateFilter(original.onUpdateFilter().orElse(null)) + .withGenericFilter(original.genericFilter().orElse(null)) + .withInformerListLimit(original.getInformerListLimit().orElse(null)) + .withItemStore(original.getItemStore().orElse(null)); this.retry = original.getRetry(); - this.labelSelector = original.getLabelSelector(); this.reconciliationMaxInterval = original.maxReconciliationInterval().orElse(null); - this.onAddFilter = original.onAddFilter().orElse(null); - this.onUpdateFilter = original.onUpdateFilter().orElse(null); - this.genericFilter = original.genericFilter().orElse(null); this.original = original; this.rateLimiter = original.getRateLimiter(); this.name = original.getName(); this.fieldManager = original.fieldManager(); - this.informerListLimit = original.getInformerListLimit().orElse(null); - this.itemStore = original.getItemStore().orElse(null); } public ControllerConfigurationOverrider withFinalizer(String finalizer) { @@ -68,26 +63,36 @@ public ControllerConfigurationOverrider withGenerationAware(boolean generatio } public ControllerConfigurationOverrider watchingOnlyCurrentNamespace() { - this.namespaces = WATCH_CURRENT_NAMESPACE_SET; + config.withWatchCurrentNamespace(); return this; } public ControllerConfigurationOverrider addingNamespaces(String... namespaces) { - this.namespaces.addAll(List.of(namespaces)); + if (namespaces != null && namespaces.length > 0) { + final var current = config.namespaces(); + final var aggregated = new HashSet(current.size() + namespaces.length); + aggregated.addAll(current); + aggregated.addAll(Set.of(namespaces)); + config.withNamespaces(aggregated); + } return this; } public ControllerConfigurationOverrider removingNamespaces(String... namespaces) { - List.of(namespaces).forEach(this.namespaces::remove); - if (this.namespaces.isEmpty()) { - this.namespaces = DEFAULT_NAMESPACES_SET; + if (namespaces != null && namespaces.length > 0) { + final var current = new HashSet<>(config.namespaces()); + List.of(namespaces).forEach(current::remove); + if (current.isEmpty()) { + return watchingAllNamespaces(); + } else { + config.withNamespaces(current); + } } return this; } public ControllerConfigurationOverrider settingNamespaces(Set newNamespaces) { - this.namespaces.clear(); - this.namespaces.addAll(newNamespaces); + config.withNamespaces(newNamespaces); return this; } @@ -96,13 +101,12 @@ public ControllerConfigurationOverrider settingNamespaces(String... newNamesp } public ControllerConfigurationOverrider settingNamespace(String namespace) { - this.namespaces.clear(); - this.namespaces.add(namespace); + config.withNamespaces(Set.of(namespace)); return this; } public ControllerConfigurationOverrider watchingAllNamespaces() { - this.namespaces = DEFAULT_NAMESPACES_SET; + config.withWatchAllNamespaces(); return this; } @@ -117,7 +121,7 @@ public ControllerConfigurationOverrider withRateLimiter(RateLimiter rateLimit } public ControllerConfigurationOverrider withLabelSelector(String labelSelector) { - this.labelSelector = labelSelector; + config.withLabelSelector(labelSelector); return this; } @@ -128,27 +132,28 @@ public ControllerConfigurationOverrider withReconciliationMaxInterval( } public ControllerConfigurationOverrider withOnAddFilter(OnAddFilter onAddFilter) { - this.onAddFilter = onAddFilter; + config.withOnAddFilter(onAddFilter); return this; } public ControllerConfigurationOverrider withOnUpdateFilter(OnUpdateFilter onUpdateFilter) { - this.onUpdateFilter = onUpdateFilter; + config.withOnUpdateFilter(onUpdateFilter); return this; } public ControllerConfigurationOverrider withGenericFilter(GenericFilter genericFilter) { - this.genericFilter = genericFilter; + config.withGenericFilter(genericFilter); return this; } public ControllerConfigurationOverrider withItemStore(ItemStore itemStore) { - this.itemStore = itemStore; + config.withItemStore(itemStore); return this; } public ControllerConfigurationOverrider withName(String name) { this.name = name; + config.withName(name); return this; } @@ -168,7 +173,7 @@ public ControllerConfigurationOverrider withFieldManager( */ public ControllerConfigurationOverrider withInformerListLimit( Long informerListLimit) { - this.informerListLimit = informerListLimit; + config.withInformerListLimit(informerListLimit); return this; } @@ -192,9 +197,10 @@ public ControllerConfiguration build() { return new ResolvedControllerConfiguration<>(original.getResourceClass(), name, generationAware, original.getAssociatedReconcilerClassName(), retry, rateLimiter, - reconciliationMaxInterval, onAddFilter, onUpdateFilter, genericFilter, - namespaces, finalizer, labelSelector, configurations, itemStore, fieldManager, - original.getConfigurationService(), informerListLimit, + reconciliationMaxInterval, + finalizer, configurations, fieldManager, + original.getConfigurationService(), + config.buildForController(), original.getWorkflowSpec().orElse(null)); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java index 61ec044694..5bd3267e12 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java @@ -1,47 +1,27 @@ package io.javaoperatorsdk.operator.api.config; -import java.util.Optional; -import java.util.Set; import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; public class DefaultResourceConfiguration implements ResourceConfiguration { private final Class resourceClass; private final String resourceTypeName; - private final OnAddFilter onAddFilter; - private final OnUpdateFilter onUpdateFilter; - private final GenericFilter genericFilter; - private final String labelSelector; - private final Set namespaces; - private final ItemStore itemStore; - private final Long informerListLimit; + private final InformerConfigHolder informerConfig; protected DefaultResourceConfiguration(Class resourceClass, - Set namespaces, String labelSelector, OnAddFilter onAddFilter, - OnUpdateFilter onUpdateFilter, GenericFilter genericFilter, - ItemStore itemStore, Long informerListLimit) { + InformerConfigHolder informerConfig) { this.resourceClass = resourceClass; this.resourceTypeName = resourceClass.isAssignableFrom(GenericKubernetesResource.class) // in general this is irrelevant now for secondary resources it is used just by controller // where GenericKubernetesResource now does not apply ? GenericKubernetesResource.class.getSimpleName() : ReconcilerUtils.getResourceTypeName(resourceClass); - this.onAddFilter = onAddFilter; - this.onUpdateFilter = onUpdateFilter; - this.genericFilter = genericFilter; - - this.namespaces = ResourceConfiguration.ensureValidNamespaces(namespaces); - this.labelSelector = ResourceConfiguration.ensureValidLabelSelector(labelSelector); - this.itemStore = itemStore; - this.informerListLimit = informerListLimit; + this.informerConfig = informerConfig; } @Override @@ -49,44 +29,13 @@ public String getResourceTypeName() { return resourceTypeName; } - @Override - public String getLabelSelector() { - return labelSelector; - } - - @Override - public Set getNamespaces() { - return namespaces; - } - @Override public Class getResourceClass() { return resourceClass; } @Override - public Optional> onAddFilter() { - return Optional.ofNullable(onAddFilter); - } - - @Override - public Optional> onUpdateFilter() { - return Optional.ofNullable(onUpdateFilter); + public InformerConfigHolder getInformerConfig() { + return informerConfig; } - - @Override - public Optional> genericFilter() { - return Optional.ofNullable(genericFilter); - } - - @Override - public Optional> getItemStore() { - return Optional.ofNullable(itemStore); - } - - @Override - public Optional getInformerListLimit() { - return Optional.ofNullable(informerListLimit); - } - } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java index 9ecf24adc7..53d086d3b3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java @@ -4,18 +4,14 @@ import java.util.Collections; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.concurrent.TimeUnit; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; import io.javaoperatorsdk.operator.processing.retry.Retry; @SuppressWarnings("rawtypes") @@ -31,7 +27,6 @@ public class ResolvedControllerConfiguration

private final Duration maxReconciliationInterval; private final String finalizer; private final Map configurations; - private final ItemStore

itemStore; private final ConfigurationService configurationService; private final String fieldManager; private WorkflowSpec workflowSpec; @@ -40,60 +35,35 @@ public ResolvedControllerConfiguration(Class

resourceClass, ControllerConfigu this(resourceClass, other.getName(), other.isGenerationAware(), other.getAssociatedReconcilerClassName(), other.getRetry(), other.getRateLimiter(), other.maxReconciliationInterval().orElse(null), - other.onAddFilter().orElse(null), other.onUpdateFilter().orElse(null), - other.genericFilter().orElse(null), - other.getNamespaces(), - other.getFinalizerName(), other.getLabelSelector(), Collections.emptyMap(), - other.getItemStore().orElse(null), other.fieldManager(), + other.getFinalizerName(), Collections.emptyMap(), + other.fieldManager(), other.getConfigurationService(), - other.getInformerListLimit().orElse(null), other.getWorkflowSpec().orElse(null)); - } - - public static Duration getMaxReconciliationInterval(long interval, TimeUnit timeUnit) { - return interval > 0 ? Duration.of(interval, timeUnit.toChronoUnit()) : null; - } - - public static String getAssociatedReconcilerClassName( - Class reconcilerClass) { - return reconcilerClass.getCanonicalName(); - } - - protected Retry ensureRetry(Retry given) { - return given == null ? ControllerConfiguration.super.getRetry() : given; - } - - protected RateLimiter ensureRateLimiter(RateLimiter given) { - return given == null ? ControllerConfiguration.super.getRateLimiter() : given; + other.getInformerConfig(), + other.getWorkflowSpec().orElse(null)); } public ResolvedControllerConfiguration(Class

resourceClass, String name, boolean generationAware, String associatedReconcilerClassName, Retry retry, RateLimiter rateLimiter, Duration maxReconciliationInterval, - OnAddFilter onAddFilter, OnUpdateFilter onUpdateFilter, - GenericFilter genericFilter, - Set namespaces, String finalizer, String labelSelector, - Map configurations, ItemStore

itemStore, + String finalizer, + Map configurations, String fieldManager, - ConfigurationService configurationService, Long informerListLimit, + ConfigurationService configurationService, + InformerConfigHolder

informerConfig, WorkflowSpec workflowSpec) { this(resourceClass, name, generationAware, associatedReconcilerClassName, retry, rateLimiter, - maxReconciliationInterval, onAddFilter, onUpdateFilter, genericFilter, - namespaces, finalizer, labelSelector, configurations, itemStore, fieldManager, - configurationService, informerListLimit); + maxReconciliationInterval, finalizer, configurations, fieldManager, + configurationService, informerConfig); setWorkflowSpec(workflowSpec); } protected ResolvedControllerConfiguration(Class

resourceClass, String name, boolean generationAware, String associatedReconcilerClassName, Retry retry, - RateLimiter rateLimiter, Duration maxReconciliationInterval, - OnAddFilter onAddFilter, OnUpdateFilter onUpdateFilter, - GenericFilter genericFilter, - Set namespaces, String finalizer, String labelSelector, - Map configurations, ItemStore

itemStore, + RateLimiter rateLimiter, Duration maxReconciliationInterval, String finalizer, + Map configurations, String fieldManager, - ConfigurationService configurationService, Long informerListLimit) { - super(resourceClass, namespaces, labelSelector, onAddFilter, onUpdateFilter, genericFilter, - itemStore, informerListLimit); + ConfigurationService configurationService, InformerConfigHolder

informerConfig) { + super(resourceClass, informerConfig); this.configurationService = configurationService; this.name = ControllerConfiguration.ensureValidName(name, associatedReconcilerClassName); this.generationAware = generationAware; @@ -102,7 +72,6 @@ protected ResolvedControllerConfiguration(Class

resourceClass, String name, this.rateLimiter = ensureRateLimiter(rateLimiter); this.maxReconciliationInterval = maxReconciliationInterval; this.configurations = configurations != null ? configurations : Collections.emptyMap(); - this.itemStore = itemStore; this.finalizer = ControllerConfiguration.ensureValidFinalizerName(finalizer, getResourceTypeName()); this.fieldManager = fieldManager; @@ -111,8 +80,25 @@ protected ResolvedControllerConfiguration(Class

resourceClass, String name, protected ResolvedControllerConfiguration(Class

resourceClass, String name, Class reconcilerClas, ConfigurationService configurationService) { this(resourceClass, name, false, getAssociatedReconcilerClassName(reconcilerClas), null, null, - null, null, null, null, null, - null, null, null, null, null, configurationService, null); + null, null, null, null, configurationService, + InformerConfigHolder.builder(resourceClass).buildForController()); + } + + public static Duration getMaxReconciliationInterval(long interval, TimeUnit timeUnit) { + return interval > 0 ? Duration.of(interval, timeUnit.toChronoUnit()) : null; + } + + public static String getAssociatedReconcilerClassName( + Class reconcilerClass) { + return reconcilerClass.getCanonicalName(); + } + + protected Retry ensureRetry(Retry given) { + return given == null ? ControllerConfiguration.super.getRetry() : given; + } + + protected RateLimiter ensureRateLimiter(RateLimiter given) { + return given == null ? ControllerConfiguration.super.getRateLimiter() : given; } @Override @@ -177,11 +163,6 @@ public C getConfigurationFor(DependentResourceSpec spec) { return (C) config; } - @Override - public Optional> getItemStore() { - return Optional.ofNullable(itemStore); - } - @Override public String fieldManager() { return fieldManager; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java index b4677a8de6..1e6699f9d9 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java @@ -4,12 +4,14 @@ import java.util.Collections; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; @@ -24,16 +26,18 @@ default String getResourceTypeName() { return ReconcilerUtils.getResourceTypeName(getResourceClass()); } + InformerConfigHolder getInformerConfig(); + default Optional> onAddFilter() { - return Optional.empty(); + return Optional.ofNullable(getInformerConfig().getOnAddFilter()); } default Optional> onUpdateFilter() { - return Optional.empty(); + return Optional.ofNullable(getInformerConfig().getOnUpdateFilter()); } default Optional> genericFilter() { - return Optional.empty(); + return Optional.ofNullable(getInformerConfig().getGenericFilter()); } /** @@ -45,7 +49,7 @@ default Optional> genericFilter() { * @return the label selector filtering watched resources */ default String getLabelSelector() { - return null; + return getInformerConfig().getLabelSelector(); } static String ensureValidLabelSelector(String labelSelector) { @@ -60,7 +64,7 @@ default Class getResourceClass() { } default Set getNamespaces() { - return DEFAULT_NAMESPACES_SET; + return getInformerConfig().getNamespaces(); } default boolean watchAllNamespaces() { @@ -98,7 +102,7 @@ static void failIfNotValid(Set namespaces) { static Set ensureValidNamespaces(Collection namespaces) { if (namespaces != null && !namespaces.isEmpty()) { - return Set.copyOf(namespaces); + return namespaces.stream().map(String::trim).collect(Collectors.toSet()); } else { return Constants.DEFAULT_NAMESPACES_SET; } @@ -144,7 +148,7 @@ default Set getEffectiveNamespaces(ControllerConfiguration controller * the informers. */ default Optional> getItemStore() { - return Optional.empty(); + return Optional.ofNullable(getInformerConfig().getItemStore()); } /** @@ -152,6 +156,6 @@ default Optional> getItemStore() { * is a not null it will result in paginating for the initial load of the informer cache. */ default Optional getInformerListLimit() { - return Optional.empty(); + return Optional.ofNullable(getInformerConfig().getInformerListLimit()); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java index 6fb37953df..2376765ae4 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java @@ -3,21 +3,19 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.function.Consumer; import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.DefaultResourceConfiguration; import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.processing.GroupVersionKind; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; import static io.javaoperatorsdk.operator.api.reconciler.Constants.*; @@ -27,42 +25,79 @@ public interface InformerConfiguration boolean DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE = true; + static boolean inheritsNamespacesFromController(Set namespaces) { + return SAME_AS_CONTROLLER_NAMESPACES_SET.equals(namespaces); + } + + static InformerConfigurationBuilder from( + Class resourceClass, Class primaryResourceClass) { + return new InformerConfigurationBuilder<>(resourceClass, primaryResourceClass); + } + + static InformerConfigurationBuilder from( + GroupVersionKind groupVersionKind, Class primaryResourceClass) { + return new InformerConfigurationBuilder<>(groupVersionKind, primaryResourceClass); + } + + /** + * Used in case the watched namespaces are changed dynamically, thus when operator is running (See + * {@link io.javaoperatorsdk.operator.RegisteredController}). If true, changing the target + * namespaces of a controller would result to change target namespaces for the + * InformerEventSource. + * + * @return if namespace changes should be followed + */ + default boolean followControllerNamespaceChanges() { + return getInformerConfig().isFollowControllerNamespacesOnChange(); + } + + /** + * Returns the configured {@link SecondaryToPrimaryMapper} which will allow JOSDK to identify + * which secondary resources are associated with a given primary resource in cases where there is + * no explicit reference to the primary resource (e.g. using owner references) in the associated + * secondary resources. + * + * @return the configured {@link SecondaryToPrimaryMapper} + * @see SecondaryToPrimaryMapper for more explanations on when using such a mapper is useful / + * needed + */ + SecondaryToPrimaryMapper getSecondaryToPrimaryMapper(); + + default Optional> onDeleteFilter() { + return Optional.ofNullable(getInformerConfig().getOnDeleteFilter()); + } + +

PrimaryToSecondaryMapper

getPrimaryToSecondaryMapper(); + + Optional getGroupVersionKind(); + + default String name() { + return getInformerConfig().getName(); + } + + @SuppressWarnings("unchecked") + @Override + default Class getResourceClass() { + return (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface(getClass(), + InformerConfiguration.class); + } + class DefaultInformerConfiguration extends DefaultResourceConfiguration implements InformerConfiguration { - - private final String name; private final PrimaryToSecondaryMapper primaryToSecondaryMapper; private final SecondaryToPrimaryMapper secondaryToPrimaryMapper; - private final boolean followControllerNamespaceChanges; - private final OnDeleteFilter onDeleteFilter; private final GroupVersionKind groupVersionKind; protected DefaultInformerConfiguration( - String name, - String labelSelector, Class resourceClass, GroupVersionKind groupVersionKind, PrimaryToSecondaryMapper primaryToSecondaryMapper, SecondaryToPrimaryMapper secondaryToPrimaryMapper, - Set namespaces, boolean followControllerNamespaceChanges, - OnAddFilter onAddFilter, - OnUpdateFilter onUpdateFilter, - OnDeleteFilter onDeleteFilter, - GenericFilter genericFilter, - ItemStore itemStore, Long informerListLimit) { - super(resourceClass, namespaces, labelSelector, onAddFilter, onUpdateFilter, genericFilter, - itemStore, informerListLimit); - this.name = name; - this.followControllerNamespaceChanges = followControllerNamespaceChanges; + InformerConfigHolder informerConfig) { + super(resourceClass, informerConfig); this.groupVersionKind = groupVersionKind; this.primaryToSecondaryMapper = primaryToSecondaryMapper; this.secondaryToPrimaryMapper = secondaryToPrimaryMapper; - this.onDeleteFilter = onDeleteFilter; - } - - @Override - public boolean followControllerNamespaceChanges() { - return followControllerNamespaceChanges; } @Override @@ -72,7 +107,7 @@ public SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { @Override public Optional> onDeleteFilter() { - return Optional.ofNullable(onDeleteFilter); + return Optional.ofNullable(getInformerConfig().getOnDeleteFilter()); } @Override @@ -86,11 +121,6 @@ public Optional getGroupVersionKind() { return Optional.ofNullable(groupVersionKind); } - @Override - public String name() { - return name; - } - public boolean inheritsNamespacesFromController() { return InformerConfiguration.inheritsNamespacesFromController(getNamespaces()); } @@ -105,48 +135,6 @@ public Set getEffectiveNamespaces(ControllerConfiguration controllerC } } - /** - * Used in case the watched namespaces are changed dynamically, thus when operator is running (See - * {@link io.javaoperatorsdk.operator.RegisteredController}). If true, changing the target - * namespaces of a controller would result to change target namespaces for the - * InformerEventSource. - * - * @return if namespace changes should be followed - */ - boolean followControllerNamespaceChanges(); - - /** - * Returns the configured {@link SecondaryToPrimaryMapper} which will allow JOSDK to identify - * which secondary resources are associated with a given primary resource in cases where there is - * no explicit reference to the primary resource (e.g. using owner references) in the associated - * secondary resources. - * - * @return the configured {@link SecondaryToPrimaryMapper} - * @see SecondaryToPrimaryMapper for more explanations on when using such a mapper is useful / - * needed - */ - SecondaryToPrimaryMapper getSecondaryToPrimaryMapper(); - - @Override - Optional> onAddFilter(); - - @Override - Optional> onUpdateFilter(); - - Optional> onDeleteFilter(); - - @Override - Optional> genericFilter(); - -

PrimaryToSecondaryMapper

getPrimaryToSecondaryMapper(); - - Optional getGroupVersionKind(); - - String name(); - - static boolean inheritsNamespacesFromController(Set namespaces) { - return SAME_AS_CONTROLLER_NAMESPACES_SET.equals(namespaces); - } @SuppressWarnings({"unused", "UnusedReturnValue"}) class InformerConfigurationBuilder { @@ -157,16 +145,7 @@ class InformerConfigurationBuilder { private String name; private PrimaryToSecondaryMapper primaryToSecondaryMapper; private SecondaryToPrimaryMapper secondaryToPrimaryMapper; - private Set namespaces = SAME_AS_CONTROLLER_NAMESPACES_SET; - private String labelSelector; - private OnAddFilter onAddFilter; - private OnUpdateFilter onUpdateFilter; - private OnDeleteFilter onDeleteFilter; - private GenericFilter genericFilter; - private ItemStore itemStore; - private Long informerListLimit; - private boolean followControllerNamespacesOnChange = - DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; + private final InformerConfigHolder.Builder config; private InformerConfigurationBuilder(Class resourceClass, Class primaryResourceClass) { @@ -184,10 +163,18 @@ private InformerConfigurationBuilder(Class resourceClass, this.resourceClass = resourceClass; this.groupVersionKind = groupVersionKind; this.primaryResourceClass = primaryResourceClass; + this.config = InformerConfigHolder.builder(resourceClass); + } + + public InformerConfigurationBuilder withInformerConfiguration( + Consumer.Builder> configurator) { + configurator.accept(config); + return this; } public InformerConfigurationBuilder withName(String name) { this.name = name; + config.withName(name); return this; } @@ -203,106 +190,6 @@ public InformerConfigurationBuilder withSecondaryToPrimaryMapper( return this; } - public InformerConfigurationBuilder withNamespaces(String... namespaces) { - return withNamespaces( - namespaces != null ? Set.of(namespaces) : DEFAULT_NAMESPACES_SET); - } - - public InformerConfigurationBuilder withNamespaces(Set namespaces) { - return withNamespaces(namespaces, false); - } - - /** - * Sets the initial set of namespaces to watch (typically extracted from the parent - * {@link io.javaoperatorsdk.operator.processing.Controller}'s configuration), specifying - * whether changes made to the parent controller configured namespaces should be tracked or not. - * - * @param namespaces the initial set of namespaces to watch - * @param followChanges {@code true} to follow the changes made to the parent controller - * namespaces, {@code false} otherwise - * @return the builder instance so that calls can be chained fluently - */ - public InformerConfigurationBuilder withNamespaces(Set namespaces, - boolean followChanges) { - this.namespaces = namespaces != null ? namespaces : DEFAULT_NAMESPACES_SET; - this.followControllerNamespacesOnChange = followChanges; - return this; - } - - public

InformerConfigurationBuilder withNamespacesInheritedFromController() { - this.namespaces = SAME_AS_CONTROLLER_NAMESPACES_SET; - return this; - } - - public

InformerConfigurationBuilder withWatchAllNamespaces() { - this.namespaces = WATCH_ALL_NAMESPACE_SET; - return this; - } - - public

- * The main goal, is to be able to use limited caches or provide any custom implementation. - *

- * - *

- * See {@link BoundedItemStore} and CaffeinBoundedCache - *

- * - * @return the class of the {@link ItemStore} implementation to use - */ - Class itemStore() default ItemStore.class; - /** * Retrieves the name used to assign as field manager for * Server-Side @@ -135,11 +75,4 @@ MaxReconciliationInterval maxReconciliationInterval() default @MaxReconciliation * @return the name used as field manager for SSA operations */ String fieldManager() default CONTROLLER_NAME_AS_FIELD_MANAGER; - - /** - * The maximum amount of items to return for a single list call when starting the primary resource - * related informers. If this is a not null it will result in paginating for the initial load of - * the informer cache. - */ - long informerListLimit() default NO_LONG_VALUE_SET; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/InformerWrappingEventSourceHealthIndicator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/InformerWrappingEventSourceHealthIndicator.java index 5a603ad321..da9b2ace2c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/InformerWrappingEventSourceHealthIndicator.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/InformerWrappingEventSourceHealthIndicator.java @@ -3,7 +3,6 @@ import java.util.Map; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; public interface InformerWrappingEventSourceHealthIndicator extends EventSourceHealthIndicator { @@ -17,6 +16,4 @@ default Status getStatus() { return nonUp.isPresent() ? Status.UNHEALTHY : Status.HEALTHY; } - - ResourceConfiguration getInformerConfiguration(); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java index 04dc5bc56b..29db90c253 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java @@ -5,13 +5,16 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; +import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_LONG_VALUE_SET; import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET; @Retention(RetentionPolicy.RUNTIME) @@ -21,32 +24,36 @@ String name() default NO_VALUE_SET; /** - * Specified which namespaces this Controller monitors for custom resources events. If no - * namespace is specified then the controller will monitor the namespaces configured for the - * controller. + * Specified which namespaces the associated informer monitors for custom resources events. If no + * namespace is specified then which namespaces the informer will monitor will depend on the + * context in which the informer is configured: + *
    + *
  • all namespaces if configuring a controller informer
  • + *
  • the namespaces configured for the associated controller if configuring an event source
  • + *
* - * You can set a list of namespaces or also constants: + * You can set a list of namespaces or use the following constants: *
    - *
  • {@link Constants#WATCH_ALL_NAMESPACE_SET}
  • + *
  • {@link Constants#WATCH_ALL_NAMESPACES}
  • *
  • {@link Constants#WATCH_CURRENT_NAMESPACE}
  • *
  • {@link Constants#SAME_AS_CONTROLLER}
  • *
* - * @return the array of namespaces this controller monitors + * @return the array of namespaces the associated informer monitors */ String[] namespaces() default {Constants.SAME_AS_CONTROLLER}; /** - * Optional label selector used to identify the set of custom resources the controller will act - * upon. The label selector can be made of multiple comma separated requirements that acts as a - * logical AND operator. + * Optional label selector used to identify the set of custom resources the associated informer + * will act upon. The label selector can be made of multiple comma separated requirements that + * acts as a logical AND operator. * * @return the label selector */ String labelSelector() default NO_VALUE_SET; /** - * Optional {@link OnAddFilter} to filter events sent to this KubernetesDependent + * Optional {@link OnAddFilter} to filter add events sent to the associated informer * * @return the {@link OnAddFilter} filter implementation to use, defaulting to the interface * itself if no value is set @@ -54,7 +61,7 @@ Class onAddFilter() default OnAddFilter.class; /** - * Optional {@link OnUpdateFilter} to filter events sent to this KubernetesDependent + * Optional {@link OnUpdateFilter} to filter update events sent to the associated informer * * @return the {@link OnUpdateFilter} filter implementation to use, defaulting to the interface * itself if no value is set @@ -62,7 +69,7 @@ Class onUpdateFilter() default OnUpdateFilter.class; /** - * Optional {@link OnDeleteFilter} to filter events sent to this KubernetesDependent + * Optional {@link OnDeleteFilter} to filter delete events sent to the associated informer * * @return the {@link OnDeleteFilter} filter implementation to use, defaulting to the interface * itself if no value is set @@ -70,7 +77,7 @@ Class onDeleteFilter() default OnDeleteFilter.class; /** - * Optional {@link GenericFilter} to filter events sent to this KubernetesDependent + * Optional {@link GenericFilter} to filter events sent to the associated informer * * @return the {@link GenericFilter} filter implementation to use, defaulting to the interface * itself if no value is set @@ -83,4 +90,32 @@ */ boolean followControllerNamespacesOnChange() default DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; + /** + * Replaces the item store used by the informer for the associated primary resource controller. + * See underlying
+ * method in fabric8 client informer implementation. + * + *

+ * The main goal, is to be able to use limited caches or provide any custom implementation. + *

+ * + *

+ * See {@link BoundedItemStore} and CaffeinBoundedCache + *

+ * + * @return the class of the {@link ItemStore} implementation to use + */ + // todo: check javadoc + Class itemStore() default ItemStore.class; + + /** + * The maximum amount of items to return for a single list call when starting the primary resource + * related informers. If this is a not null it will result in paginating for the initial load of + * the informer cache. + */ + // todo: check javadoc + long informerListLimit() default NO_LONG_VALUE_SET; + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfigHolder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfigHolder.java new file mode 100644 index 0000000000..22517372f8 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfigHolder.java @@ -0,0 +1,296 @@ +package io.javaoperatorsdk.operator.processing.dependent.kubernetes; + +import java.util.Set; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.client.informers.cache.ItemStore; +import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; +import io.javaoperatorsdk.operator.api.config.Utils; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; + +import static io.javaoperatorsdk.operator.api.reconciler.Constants.*; + + +@SuppressWarnings("unused") +public class InformerConfigHolder { + private final Builder builder = new Builder(); + private String name; + private Set namespaces; + private Boolean followControllerNamespacesOnChange; + private String labelSelector; + private OnAddFilter onAddFilter; + private OnUpdateFilter onUpdateFilter; + private OnDeleteFilter onDeleteFilter; + private GenericFilter genericFilter; + private ItemStore itemStore; + private Long informerListLimit; + + public InformerConfigHolder(String name, Set namespaces, + boolean followControllerNamespacesOnChange, + String labelSelector, OnAddFilter onAddFilter, + OnUpdateFilter onUpdateFilter, OnDeleteFilter onDeleteFilter, + GenericFilter genericFilter, ItemStore itemStore, Long informerListLimit) { + this.name = name; + this.namespaces = namespaces; + this.followControllerNamespacesOnChange = followControllerNamespacesOnChange; + this.labelSelector = labelSelector; + this.onAddFilter = onAddFilter; + this.onUpdateFilter = onUpdateFilter; + this.onDeleteFilter = onDeleteFilter; + this.genericFilter = genericFilter; + this.itemStore = itemStore; + this.informerListLimit = informerListLimit; + } + + private InformerConfigHolder() {} + + @SuppressWarnings({"rawtypes", "unchecked"}) + public static InformerConfigHolder.Builder builder() { + return new InformerConfigHolder().builder; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public static InformerConfigHolder.Builder builder( + Class resourceClass) { + return new InformerConfigHolder().builder; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public static InformerConfigHolder.Builder builder( + InformerConfigHolder original) { + return new InformerConfigHolder(original.name, original.namespaces, + original.followControllerNamespacesOnChange, original.labelSelector, original.onAddFilter, + original.onUpdateFilter, original.onDeleteFilter, original.genericFilter, + original.itemStore, original.informerListLimit).builder; + } + + public String getName() { + return name; + } + + public Set getNamespaces() { + return namespaces; + } + + public boolean isFollowControllerNamespacesOnChange() { + return followControllerNamespacesOnChange; + } + + public String getLabelSelector() { + return labelSelector; + } + + public OnAddFilter getOnAddFilter() { + return onAddFilter; + } + + public OnUpdateFilter getOnUpdateFilter() { + return onUpdateFilter; + } + + public OnDeleteFilter getOnDeleteFilter() { + return onDeleteFilter; + } + + public GenericFilter getGenericFilter() { + return genericFilter; + } + + public ItemStore getItemStore() { + return itemStore; + } + + public Long getInformerListLimit() { + return informerListLimit; + } + + void updateInformerConfigBuilder( + InformerConfiguration.InformerConfigurationBuilder builder) { + if (name != null) { + builder.withName(name); + } + builder.withInformerConfiguration(c -> c.withNamespaces(namespaces) + .withFollowControllerNamespacesOnChange(followControllerNamespacesOnChange) + .withLabelSelector(labelSelector) + .withItemStore(itemStore) + .withOnAddFilter(onAddFilter) + .withOnUpdateFilter(onUpdateFilter) + .withOnDeleteFilter(onDeleteFilter) + .withGenericFilter(genericFilter) + .withInformerListLimit(informerListLimit)); + } + + @SuppressWarnings("UnusedReturnValue") + public class Builder { + + public InformerConfigHolder buildForController() { + // if the informer config uses the default "same as controller" value, reset the namespaces to + // the default set for controllers + if (namespaces == null || namespaces.isEmpty() + || InformerConfiguration.inheritsNamespacesFromController(namespaces)) { + namespaces = Constants.DEFAULT_NAMESPACES_SET; + } + return InformerConfigHolder.this; + } + + public InformerConfigHolder buildForInformerEventSource() { + if (namespaces == null || namespaces.isEmpty()) { + namespaces = Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; + } + if (followControllerNamespacesOnChange == null) { + followControllerNamespacesOnChange = + InformerConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; + } + return InformerConfigHolder.this; + } + + @SuppressWarnings({"unchecked"}) + public InformerConfigHolder.Builder initFromAnnotation(InformerConfig informerConfig, + String context) { + if (informerConfig != null) { + + // override default name if more specific one is provided + if (!Constants.NO_VALUE_SET.equals(informerConfig.name())) { + withName(informerConfig.name()); + } + + var namespaces = Set.of(informerConfig.namespaces()); + withNamespaces(namespaces); + + final var fromAnnotation = informerConfig.labelSelector(); + var labelSelector = Constants.NO_VALUE_SET.equals(fromAnnotation) ? null : fromAnnotation; + withLabelSelector(labelSelector); + + withOnAddFilter(Utils.instantiate(informerConfig.onAddFilter(), + OnAddFilter.class, context)); + + withOnUpdateFilter(Utils.instantiate(informerConfig.onUpdateFilter(), + OnUpdateFilter.class, context)); + + withOnDeleteFilter(Utils.instantiate(informerConfig.onDeleteFilter(), + OnDeleteFilter.class, context)); + + withGenericFilter(Utils.instantiate(informerConfig.genericFilter(), + GenericFilter.class, + context)); + + withFollowControllerNamespacesOnChange( + informerConfig.followControllerNamespacesOnChange()); + + withItemStore(Utils.instantiate(informerConfig.itemStore(), + ItemStore.class, context)); + + final var informerListLimitValue = informerConfig.informerListLimit(); + final var informerListLimit = + informerListLimitValue == Constants.NO_LONG_VALUE_SET ? null : informerListLimitValue; + withInformerListLimit(informerListLimit); + } + return this; + } + + public Builder withName(String name) { + InformerConfigHolder.this.name = name; + return this; + } + + public Builder withNamespaces(Set namespaces) { + InformerConfigHolder.this.namespaces = + ResourceConfiguration.ensureValidNamespaces(namespaces); + return this; + } + + public Set namespaces() { + return Set.copyOf(namespaces); + } + + /** + * Sets the initial set of namespaces to watch (typically extracted from the parent + * {@link io.javaoperatorsdk.operator.processing.Controller}'s configuration), specifying + * whether changes made to the parent controller configured namespaces should be tracked or not. + * + * @param namespaces the initial set of namespaces to watch + * @param followChanges {@code true} to follow the changes made to the parent controller + * namespaces, {@code false} otherwise + * @return the builder instance so that calls can be chained fluently + */ + public Builder withNamespaces(Set namespaces, boolean followChanges) { + withNamespaces(namespaces).withFollowControllerNamespacesOnChange(followChanges); + return this; + } + + public Builder withNamespacesInheritedFromController() { + withNamespaces(SAME_AS_CONTROLLER_NAMESPACES_SET); + return this; + } + + public Builder withWatchAllNamespaces() { + withNamespaces(WATCH_ALL_NAMESPACE_SET); + return this; + } + + public Builder withWatchCurrentNamespace() { + withNamespaces(WATCH_CURRENT_NAMESPACE_SET); + return this; + } + + + /** + * Whether the associated informer should track changes made to the parent + * {@link io.javaoperatorsdk.operator.processing.Controller}'s namespaces configuration. + * + * @param followChanges {@code true} to reconfigure the associated informer when the parent + * controller's namespaces are reconfigured, {@code false} otherwise + * @return the builder instance so that calls can be chained fluently + */ + public Builder withFollowControllerNamespacesOnChange(boolean followChanges) { + InformerConfigHolder.this.followControllerNamespacesOnChange = + followChanges; + return this; + } + + public Builder withLabelSelector(String labelSelector) { + InformerConfigHolder.this.labelSelector = + ResourceConfiguration.ensureValidLabelSelector(labelSelector); + return this; + } + + public Builder withOnAddFilter( + OnAddFilter onAddFilter) { + InformerConfigHolder.this.onAddFilter = onAddFilter; + return this; + } + + public Builder withOnUpdateFilter( + OnUpdateFilter onUpdateFilter) { + InformerConfigHolder.this.onUpdateFilter = onUpdateFilter; + return this; + } + + public Builder withOnDeleteFilter( + OnDeleteFilter onDeleteFilter) { + InformerConfigHolder.this.onDeleteFilter = onDeleteFilter; + return this; + } + + public Builder withGenericFilter( + GenericFilter genericFilter) { + InformerConfigHolder.this.genericFilter = genericFilter; + return this; + } + + public Builder withItemStore(ItemStore itemStore) { + InformerConfigHolder.this.itemStore = itemStore; + return this; + } + + public Builder withInformerListLimit(Long informerListLimit) { + InformerConfigHolder.this.informerListLimit = informerListLimit; + return this; + } + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java index 04c8e1167d..c8aa20840e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java @@ -1,17 +1,10 @@ package io.javaoperatorsdk.operator.processing.dependent.kubernetes; -import java.util.Set; - import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.config.dependent.ConfigurationConverter; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; -import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; import static io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig.DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA; @@ -42,59 +35,20 @@ public KubernetesDependentResourceConfig configFrom(KubernetesDependent confi } @SuppressWarnings({"unchecked"}) - private KubernetesDependentInformerConfig createInformerConfig( + private InformerConfigHolder createInformerConfig( KubernetesDependent configAnnotation, DependentResourceSpec> spec, ControllerConfiguration controllerConfig) { Class> dependentResourceClass = (Class>) spec.getDependentResourceClass(); - final var config = new KubernetesDependentInformerConfigBuilder(); + InformerConfigHolder.Builder config = InformerConfigHolder.builder(); if (configAnnotation != null) { final var informerConfig = configAnnotation.informerConfig(); - if (informerConfig != null) { - - // override default name if more specific one is provided - if (!Constants.NO_VALUE_SET.equals(informerConfig.name())) { - config.withName(informerConfig.name()); - } - - var namespaces = Set.of(informerConfig.namespaces()); - config.withNamespaces(namespaces); - - final var fromAnnotation = informerConfig.labelSelector(); - var labelSelector = Constants.NO_VALUE_SET.equals(fromAnnotation) ? null : fromAnnotation; - config.withLabelSelector(labelSelector); - - final var context = Utils.contextFor(controllerConfig, dependentResourceClass, - configAnnotation.annotationType()); - - var onAddFilter = Utils.instantiate(informerConfig.onAddFilter(), - OnAddFilter.class, context); - config.withOnAddFilter(onAddFilter); - - var onUpdateFilter = - Utils.instantiate(informerConfig.onUpdateFilter(), - OnUpdateFilter.class, context); - config.withOnUpdateFilter(onUpdateFilter); - - var onDeleteFilter = - Utils.instantiate(informerConfig.onDeleteFilter(), - OnDeleteFilter.class, context); - config.withOnDeleteFilter(onDeleteFilter); - - var genericFilter = - Utils.instantiate(informerConfig.genericFilter(), - GenericFilter.class, - context); - - config.withGenericFilter(genericFilter); - - config.withFollowControllerNamespacesOnChange( - informerConfig.followControllerNamespacesOnChange()); - } + final var context = Utils.contextFor(controllerConfig, dependentResourceClass, + configAnnotation.annotationType()); + config = config.initFromAnnotation(informerConfig, context); } - return config.build(); + return config.buildForInformerEventSource(); } - } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfig.java deleted file mode 100644 index f4f1d29a68..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfig.java +++ /dev/null @@ -1,101 +0,0 @@ -package io.javaoperatorsdk.operator.processing.dependent.kubernetes; - -import java.util.Set; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.informers.cache.ItemStore; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; - - -@SuppressWarnings("unused") -public class KubernetesDependentInformerConfig { - - private final String name; - private final Set namespaces; - private final boolean followControllerNamespacesOnChange; - private final String labelSelector; - private final OnAddFilter onAddFilter; - private final OnUpdateFilter onUpdateFilter; - private final OnDeleteFilter onDeleteFilter; - private final GenericFilter genericFilter; - private final ItemStore itemStore; - private final Long informerListLimit; - - public KubernetesDependentInformerConfig(String name, Set namespaces, - boolean followControllerNamespacesOnChange, - String labelSelector, OnAddFilter onAddFilter, - OnUpdateFilter onUpdateFilter, OnDeleteFilter onDeleteFilter, - GenericFilter genericFilter, ItemStore itemStore, Long informerListLimit) { - this.name = name; - this.namespaces = namespaces; - this.followControllerNamespacesOnChange = followControllerNamespacesOnChange; - this.labelSelector = labelSelector; - this.onAddFilter = onAddFilter; - this.onUpdateFilter = onUpdateFilter; - this.onDeleteFilter = onDeleteFilter; - this.genericFilter = genericFilter; - this.itemStore = itemStore; - this.informerListLimit = informerListLimit; - } - - public String getName() { - return name; - } - - public Set getNamespaces() { - return namespaces; - } - - public boolean isFollowControllerNamespacesOnChange() { - return followControllerNamespacesOnChange; - } - - public String getLabelSelector() { - return labelSelector; - } - - public OnAddFilter getOnAddFilter() { - return onAddFilter; - } - - public OnUpdateFilter getOnUpdateFilter() { - return onUpdateFilter; - } - - public OnDeleteFilter getOnDeleteFilter() { - return onDeleteFilter; - } - - public GenericFilter getGenericFilter() { - return genericFilter; - } - - public ItemStore getItemStore() { - return itemStore; - } - - public Long getInformerListLimit() { - return informerListLimit; - } - - void updateInformerConfigBuilder( - InformerConfiguration.InformerConfigurationBuilder builder) { - if (name != null) { - builder.withName(name); - } - builder.withNamespaces(namespaces); - builder.followControllerNamespacesOnChange(followControllerNamespacesOnChange); - builder.withLabelSelector(labelSelector); - builder.withItemStore(itemStore); - builder.withOnAddFilter(onAddFilter); - builder.withOnUpdateFilter(onUpdateFilter); - builder.withOnDeleteFilter(onDeleteFilter); - builder.withGenericFilter(genericFilter); - builder.withInformerListLimit(informerListLimit); - } - -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfigBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfigBuilder.java deleted file mode 100644 index a8a60b9638..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentInformerConfigBuilder.java +++ /dev/null @@ -1,93 +0,0 @@ -package io.javaoperatorsdk.operator.processing.dependent.kubernetes; - -import java.util.Set; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.informers.cache.ItemStore; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; - -import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; - -@SuppressWarnings({"UnusedReturnValue", "unused"}) -public final class KubernetesDependentInformerConfigBuilder { - - private String name; - private Set namespaces = SAME_AS_CONTROLLER_NAMESPACES_SET; - private boolean followControllerNamespacesOnChange = - DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; - private String labelSelector; - private OnAddFilter onAddFilter; - private OnUpdateFilter onUpdateFilter; - private OnDeleteFilter onDeleteFilter; - private GenericFilter genericFilter; - private ItemStore itemStore; - private Long informerListLimit; - - public KubernetesDependentInformerConfigBuilder() {} - - public KubernetesDependentInformerConfigBuilder withName(String name) { - this.name = name; - return this; - } - - public KubernetesDependentInformerConfigBuilder withNamespaces(Set namespaces) { - this.namespaces = namespaces; - return this; - } - - public KubernetesDependentInformerConfigBuilder withFollowControllerNamespacesOnChange( - boolean followControllerNamespacesOnChange) { - this.followControllerNamespacesOnChange = followControllerNamespacesOnChange; - return this; - } - - public KubernetesDependentInformerConfigBuilder withLabelSelector(String labelSelector) { - this.labelSelector = labelSelector; - return this; - } - - public KubernetesDependentInformerConfigBuilder withOnAddFilter( - OnAddFilter onAddFilter) { - this.onAddFilter = onAddFilter; - return this; - } - - public KubernetesDependentInformerConfigBuilder withOnUpdateFilter( - OnUpdateFilter onUpdateFilter) { - this.onUpdateFilter = onUpdateFilter; - return this; - } - - public KubernetesDependentInformerConfigBuilder withOnDeleteFilter( - OnDeleteFilter onDeleteFilter) { - this.onDeleteFilter = onDeleteFilter; - return this; - } - - public KubernetesDependentInformerConfigBuilder withGenericFilter( - GenericFilter genericFilter) { - this.genericFilter = genericFilter; - return this; - } - - public KubernetesDependentInformerConfigBuilder withItemStore(ItemStore itemStore) { - this.itemStore = itemStore; - return this; - } - - public KubernetesDependentInformerConfigBuilder withInformerListLimit(Long informerListLimit) { - this.informerListLimit = informerListLimit; - return this; - } - - public KubernetesDependentInformerConfig build() { - return new KubernetesDependentInformerConfig<>(name, namespaces, - followControllerNamespacesOnChange, - labelSelector, onAddFilter, onUpdateFilter, onDeleteFilter, genericFilter, itemStore, - informerListLimit); - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java index e5d5c23c40..bdb07d9230 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java @@ -10,12 +10,12 @@ public class KubernetesDependentResourceConfig { private final Boolean useSSA; private final boolean createResourceOnlyIfNotExistingWithSSA; - private final KubernetesDependentInformerConfig informerConfig; + private final InformerConfigHolder informerConfig; public KubernetesDependentResourceConfig( Boolean useSSA, boolean createResourceOnlyIfNotExistingWithSSA, - KubernetesDependentInformerConfig informerConfig) { + InformerConfigHolder informerConfig) { this.useSSA = useSSA; this.createResourceOnlyIfNotExistingWithSSA = createResourceOnlyIfNotExistingWithSSA; this.informerConfig = informerConfig; @@ -29,7 +29,7 @@ public Boolean useSSA() { return useSSA; } - public KubernetesDependentInformerConfig informerConfig() { + public InformerConfigHolder informerConfig() { return informerConfig; } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java index 42bc379b06..dcfbc94a07 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java @@ -7,7 +7,7 @@ public final class KubernetesDependentResourceConfigBuilder kubernetesDependentInformerConfig; + private InformerConfigHolder informerConfigHolder; public KubernetesDependentResourceConfigBuilder() {} @@ -24,14 +24,14 @@ public KubernetesDependentResourceConfigBuilder withUseSSA(boolean useSSA) { } public KubernetesDependentResourceConfigBuilder withKubernetesDependentInformerConfig( - KubernetesDependentInformerConfig kubernetesDependentInformerConfig) { - this.kubernetesDependentInformerConfig = kubernetesDependentInformerConfig; + InformerConfigHolder informerConfigHolder) { + this.informerConfigHolder = informerConfigHolder; return this; } public KubernetesDependentResourceConfig build() { return new KubernetesDependentResourceConfig<>( useSSA, createResourceOnlyIfNotExistingWithSSA, - kubernetesDependentInformerConfig); + informerConfigHolder); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java index 67e5500b24..f5b6f3a6d8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java @@ -83,11 +83,12 @@ public InformerEventSource( .parseResourceVersionsForEventFilteringAndCaching()); } - public InformerEventSource(InformerConfiguration configuration, KubernetesClient client) { + InformerEventSource(InformerConfiguration configuration, KubernetesClient client) { this(configuration, client, false); } - public InformerEventSource(InformerConfiguration configuration, + @SuppressWarnings({"unchecked", "rawtypes"}) + private InformerEventSource(InformerConfiguration configuration, KubernetesClient client, boolean parseResourceVersions) { super(configuration.name(), diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java index d8f29e300d..9fc4a7db19 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java @@ -28,7 +28,7 @@ import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_ALL_NAMESPACES; -public class InformerManager> +class InformerManager> implements LifecycleAware, IndexerResourceCache { private static final Logger log = LoggerFactory.getLogger(InformerManager.class); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java index 0e5f8bd896..54d60e2cdf 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java @@ -174,11 +174,6 @@ public Status getStatus() { return InformerWrappingEventSourceHealthIndicator.super.getStatus(); } - @Override - public ResourceConfiguration getInformerConfiguration() { - return configuration(); - } - @Override public C configuration() { return configuration; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java index 1993c37ad1..f362726b65 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java @@ -22,7 +22,12 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.*; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.inheritsNamespacesFromController; @@ -31,6 +36,13 @@ class ControllerConfigurationOverriderTest { private final BaseConfigurationService configurationService = new BaseConfigurationService(); + @SuppressWarnings("unchecked") + private static Object extractDependentKubernetesResourceConfig( + io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration, int index) { + final var spec = + configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().get(index); + return configuration.getConfigurationFor(spec); + } @BeforeEach void clearStaticState() { @@ -73,36 +85,11 @@ private KubernetesDependentResourceConfig extractFirstDependentKubernetesResourc return conf; } - @SuppressWarnings("unchecked") - private static Object extractDependentKubernetesResourceConfig( - io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration, int index) { - final var spec = - configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs().get(index); - return configuration.getConfigurationFor(spec); - } - private io.javaoperatorsdk.operator.api.config.ControllerConfiguration createConfiguration( Reconciler reconciler) { return configurationService.configFor(reconciler); } - private static class MyItemStore extends BasicItemStore { - - public MyItemStore() { - super(Cache::metaNamespaceKeyFunc); - } - - } - - @ControllerConfiguration(namespaces = "foo", itemStore = MyItemStore.class) - private static class WatchCurrentReconciler implements Reconciler { - - @Override - public UpdateControl reconcile(ConfigMap resource, Context context) { - return null; - } - } - @Test void overridingNamespacesShouldWork() { var configuration = createConfiguration(new WatchCurrentReconciler()); @@ -284,16 +271,15 @@ void replaceNamedDependentResourceConfigShouldWork() { // override the namespaces for the dependent resource final var overriddenNS = "newNS"; final var labelSelector = "foo=bar"; - KubernetesDependentInformerConfigBuilder anInformerConfig = - new KubernetesDependentInformerConfigBuilder<>(); - anInformerConfig.withNamespaces(Set.of(overriddenNS)); - anInformerConfig.withLabelSelector(labelSelector); + final var overridingInformerConfig = InformerConfigHolder.builder(ConfigMap.class) + .withNamespaces(Set.of(overriddenNS)) + .withLabelSelector(labelSelector) + .buildForInformerEventSource(); final var overridden = ControllerConfigurationOverrider.override(configuration) .replacingNamedDependentResourceConfig( dependentResourceName, new KubernetesDependentResourceConfigBuilder() - .withKubernetesDependentInformerConfig(anInformerConfig.build()) - + .withKubernetesDependentInformerConfig(overridingInformerConfig) .build()) .build(); dependents = overridden.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); @@ -309,6 +295,24 @@ void replaceNamedDependentResourceConfigShouldWork() { assertInstanceOf(TestCondition.class, dependentSpec.getReadyCondition()); } + private static class MyItemStore extends BasicItemStore { + + public MyItemStore() { + super(Cache::metaNamespaceKeyFunc); + } + + } + + @ControllerConfiguration( + informerConfig = @InformerConfig(namespaces = "foo", itemStore = MyItemStore.class)) + private static class WatchCurrentReconciler implements Reconciler { + + @Override + public UpdateControl reconcile(ConfigMap resource, Context context) { + return null; + } + } + @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class)) @ControllerConfiguration private static class WatchAllNamespacesReconciler implements Reconciler { @@ -341,7 +345,8 @@ public boolean isMet(DependentResource dependentResource, @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class, readyPostcondition = TestCondition.class)) - @ControllerConfiguration(namespaces = OneDepReconciler.CONFIGURED_NS) + @ControllerConfiguration( + informerConfig = @InformerConfig(namespaces = OneDepReconciler.CONFIGURED_NS)) private static class OneDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "foo"; @@ -372,7 +377,8 @@ public WatchAllNSDependent() { } @Workflow(dependents = @Dependent(type = OverriddenNSDependent.class)) - @ControllerConfiguration(namespaces = OverriddenNSOnDepReconciler.CONFIGURED_NS) + @ControllerConfiguration( + informerConfig = @InformerConfig(namespaces = OverriddenNSOnDepReconciler.CONFIGURED_NS)) public static class OverriddenNSOnDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "parentNS"; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java index 013eec9cc0..2a65a179ea 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java @@ -3,14 +3,20 @@ import java.util.Collections; import java.util.Set; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import static org.junit.jupiter.api.Assertions.*; class ResourceConfigurationTest { + public static final ResourceConfiguration DEFAULT = + () -> InformerConfigHolder.builder().buildForInformerEventSource(); + @Test void allNamespacesWatched() { assertThrows(IllegalArgumentException.class, @@ -45,12 +51,14 @@ void currentNamespaceWatched() { @Test void nullLabelSelectorByDefault() { - assertNull(new ResourceConfiguration<>() {}.getLabelSelector()); + assertNull(DEFAULT.getLabelSelector()); } + // todo: fix me + @Disabled @Test void shouldWatchAllNamespacesByDefault() { - assertTrue(new ResourceConfiguration<>() {}.watchAllNamespaces()); + assertTrue(DEFAULT.watchAllNamespaces()); } @Test diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java index 71670a37b1..053e6ebb22 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java @@ -15,6 +15,7 @@ import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.Controller; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.EventHandler; import io.javaoperatorsdk.operator.processing.event.EventSourceManager; import io.javaoperatorsdk.operator.processing.event.source.AbstractEventSourceTestBase; @@ -197,14 +198,13 @@ public TestConfiguration(boolean generationAware, OnAddFilter reconcile(ConfigMap resource, Context } @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class)) - @ControllerConfiguration(namespaces = OneDepReconciler.CONFIGURED_NS) + @ControllerConfiguration( + informerConfig = @InformerConfig(namespaces = OneDepReconciler.CONFIGURED_NS)) private static class OneDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "foo"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/builtinresourcecleaner/ObservedGenerationTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/builtinresourcecleaner/ObservedGenerationTestReconciler.java index cba16a5c1f..93337b1c84 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/builtinresourcecleaner/ObservedGenerationTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/builtinresourcecleaner/ObservedGenerationTestReconciler.java @@ -2,18 +2,14 @@ import java.util.concurrent.atomic.AtomicInteger; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.fabric8.kubernetes.api.model.Service; import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; -@ControllerConfiguration(labelSelector = "builtintest=true") +@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "builtintest=true")) public class ObservedGenerationTestReconciler implements Reconciler, Cleaner { - private static final Logger log = LoggerFactory.getLogger(ObservedGenerationTestReconciler.class); - private final AtomicInteger reconciled = new AtomicInteger(0); private final AtomicInteger cleaned = new AtomicInteger(0); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java index 3f8923c2b3..5ee675cf5e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java @@ -7,7 +7,11 @@ import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; @@ -59,7 +63,8 @@ public List> prepareEventSources( InformerConfiguration.from(ConfigMap.class, ClusterScopedCustomResource.class) .withSecondaryToPrimaryMapper( Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), true)) - .withLabelSelector(TEST_LABEL_KEY + "=" + TEST_LABEL_VALUE) + .withInformerConfiguration( + c -> c.withLabelSelector(TEST_LABEL_KEY + "=" + TEST_LABEL_VALUE)) .build(), context); return List.of(ies); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index e97cf78b1d..8714b8c31f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -21,29 +21,6 @@ public class CreateUpdateEventFilterTestReconciler implements Reconciler { - private static final class DirectConfigMapDependentResource - extends - CRUDKubernetesDependentResource { - - private ConfigMap desired; - - private DirectConfigMapDependentResource(Class resourceType) { - super(resourceType); - } - - @Override - protected ConfigMap desired(CreateUpdateEventFilterTestCustomResource primary, - Context context) { - return desired; - } - - @Override - public void setEventSource( - io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource eventSource) { - super.setEventSource(eventSource); - } - } - public static final String CONFIG_MAP_TEST_DATA_KEY = "key"; private final AtomicInteger numberOfExecutions = new AtomicInteger(0); private final DirectConfigMapDependentResource configMapDR = @@ -94,11 +71,10 @@ public List> prepareEv EventSourceContext context) { InformerConfiguration informerConfiguration = InformerConfiguration.from(ConfigMap.class, CreateUpdateEventFilterTestCustomResource.class) - .withLabelSelector("integrationtest = " + this.getClass().getSimpleName()) + .withInformerConfiguration(c -> c + .withLabelSelector("integrationtest = " + this.getClass().getSimpleName())) .build(); - final var informerEventSource = - new InformerEventSource( - informerConfiguration, context.getClient()); + final var informerEventSource = new InformerEventSource<>(informerConfiguration, context); this.configMapDR.setEventSource(informerEventSource); return List.of(informerEventSource); @@ -107,4 +83,27 @@ public List> prepareEv public int getNumberOfExecutions() { return numberOfExecutions.get(); } + + private static final class DirectConfigMapDependentResource + extends + CRUDKubernetesDependentResource { + + private ConfigMap desired; + + private DirectConfigMapDependentResource(Class resourceType) { + super(resourceType); + } + + @Override + protected ConfigMap desired(CreateUpdateEventFilterTestCustomResource primary, + Context context) { + return desired; + } + + @Override + public void setEventSource( + io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource eventSource) { + super.setEventSource(eventSource); + } + } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java index 97ff1b5484..74f447dd37 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java @@ -4,9 +4,10 @@ import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; @Workflow(dependents = {@Dependent(type = FilteredDependentConfigMap.class)}) -@ControllerConfiguration(onUpdateFilter = UpdateFilter.class) +@ControllerConfiguration(informerConfig = @InformerConfig(onUpdateFilter = UpdateFilter.class)) public class DependentFilterTestReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java index d8551c72e6..4b37ba342f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java @@ -4,12 +4,14 @@ import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @Workflow(dependents = { @Dependent(type = ConfigMapDependentResource.class) }) -@ControllerConfiguration(namespaces = Constants.WATCH_CURRENT_NAMESPACE) +@ControllerConfiguration( + informerConfig = @InformerConfig(namespaces = Constants.WATCH_CURRENT_NAMESPACE)) public class DependentOperationEventFilterCustomResourceTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/deployment/DeploymentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/deployment/DeploymentReconciler.java index fc721af52c..9544e75c2e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/deployment/DeploymentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/deployment/DeploymentReconciler.java @@ -13,9 +13,11 @@ import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration(labelSelector = "test=KubernetesResourceStatusUpdateIT") +@ControllerConfiguration( + informerConfig = @InformerConfig(labelSelector = "test=KubernetesResourceStatusUpdateIT")) public class DeploymentReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java index ee37918af9..7857516d34 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java @@ -7,11 +7,16 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; -@ControllerConfiguration(onUpdateFilter = UpdateFilter.class) +@ControllerConfiguration(informerConfig = @InformerConfig(onUpdateFilter = UpdateFilter.class)) public class FilterTestReconciler implements Reconciler { @@ -52,12 +57,14 @@ public int getNumberOfExecutions() { public List> prepareEventSources( EventSourceContext context) { + final var informerConfiguration = InformerConfiguration + .from(ConfigMap.class, FilterTestCustomResource.class) + .withInformerConfiguration(c -> c.withOnUpdateFilter((newCM, + oldCM) -> !newCM.getData().get(CM_VALUE_KEY) + .equals(CONFIG_MAP_FILTER_VALUE))) + .build(); InformerEventSource configMapES = - new InformerEventSource<>(InformerConfiguration - .from(ConfigMap.class, FilterTestCustomResource.class) - .withOnUpdateFilter((newCM, oldCM) -> !newCM.getData().get(CM_VALUE_KEY) - .equals(CONFIG_MAP_FILTER_VALUE)) - .build(), context); + new InformerEventSource<>(informerConfiguration, context); return List.of(configMapES); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestReconciler.java index 3fc0a78630..81ba706591 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestReconciler.java @@ -3,12 +3,14 @@ import java.util.concurrent.atomic.AtomicInteger; import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; import static io.javaoperatorsdk.operator.sample.labelselector.LabelSelectorTestReconciler.LABEL_KEY; import static io.javaoperatorsdk.operator.sample.labelselector.LabelSelectorTestReconciler.LABEL_VALUE; -@ControllerConfiguration(labelSelector = LABEL_KEY + "=" + LABEL_VALUE) +@ControllerConfiguration( + informerConfig = @InformerConfig(labelSelector = LABEL_KEY + "=" + LABEL_VALUE)) public class LabelSelectorTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java index e32a6ad7e2..a8f78d328e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java @@ -3,9 +3,10 @@ import java.util.concurrent.atomic.AtomicInteger; import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration(labelSelector = "reconciler = 1") +@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "reconciler = 1")) public class MultipleReconcilerSameTypeReconciler1 implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java index 73b082f3b0..a65535908e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java @@ -6,9 +6,10 @@ import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration(labelSelector = "reconciler != 1") +@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "reconciler != 1")) public class MultipleReconcilerSameTypeReconciler2 implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java index b3cb06bc37..6ba1cfa801 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java @@ -8,7 +8,11 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; @@ -20,6 +24,14 @@ public class MultipleSecondaryEventSourceReconciler private final AtomicInteger numberOfExecutions = new AtomicInteger(0); + public static String getName1(MultipleSecondaryEventSourceCustomResource resource) { + return resource.getMetadata().getName() + "1"; + } + + public static String getName2(MultipleSecondaryEventSourceCustomResource resource) { + return resource.getMetadata().getName() + "2"; + } + @Override public UpdateControl reconcile( MultipleSecondaryEventSourceCustomResource resource, @@ -48,14 +60,6 @@ public UpdateControl reconcile( return UpdateControl.noUpdate(); } - public static String getName1(MultipleSecondaryEventSourceCustomResource resource) { - return resource.getMetadata().getName() + "1"; - } - - public static String getName2(MultipleSecondaryEventSourceCustomResource resource) { - return resource.getMetadata().getName() + "2"; - } - public int getNumberOfExecutions() { return numberOfExecutions.get(); } @@ -66,8 +70,9 @@ public List> prepareE var config = InformerConfiguration .from(ConfigMap.class, MultipleSecondaryEventSourceCustomResource.class) - .withNamespaces(context.getControllerConfiguration().getNamespaces()) - .withLabelSelector("multisecondary") + .withInformerConfiguration(c -> c + .withNamespaces(context.getControllerConfiguration().getNamespaces()) + .withLabelSelector("multisecondary")) .withSecondaryToPrimaryMapper(s -> { var name = s.getMetadata().getName().subSequence(0, s.getMetadata().getName().length() - 1); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler1.java index bd564e3d07..0a433e4047 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler1.java @@ -7,8 +7,9 @@ import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; -@ControllerConfiguration(labelSelector = "!version") +@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "!version")) public class MultiVersionCRDTestReconciler1 implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler2.java index 28f556afc0..2e8bd30fdd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler2.java @@ -7,8 +7,9 @@ import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; -@ControllerConfiguration(labelSelector = "version in (v2)") +@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "version in (v2)")) public class MultiVersionCRDTestReconciler2 implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java index 5f8595a131..148ceb1499 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java @@ -7,6 +7,7 @@ import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @Workflow(dependents = { @@ -14,7 +15,7 @@ @Dependent(type = ConfigMapDependentResource2.class, dependsOn = "cm1") }) @ControllerConfiguration( - namespaces = Constants.WATCH_CURRENT_NAMESPACE) + informerConfig = @InformerConfig(namespaces = Constants.WATCH_CURRENT_NAMESPACE)) public class OrderedManagedDependentTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java index 22472f0e05..4f2bf2d488 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java @@ -7,6 +7,7 @@ import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper; @@ -70,7 +71,8 @@ public List> prepareEventSources(EventSourceContext con .byIndex(JOB_CLUSTER_INDEX, indexKey(cluster.getMetadata().getName(), cluster.getMetadata().getNamespace())) .stream().map(ResourceID::fromResource).collect(Collectors.toSet())) - .withNamespacesInheritedFromController(); + .withInformerConfiguration( + InformerConfigHolder.Builder::withNamespacesInheritedFromController); if (addPrimaryToSecondaryMapper) { informerConfiguration = informerConfiguration.withPrimaryToSecondaryMapper( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java index b36b6f31a2..5914b08e68 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java @@ -4,12 +4,14 @@ import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @Workflow(dependents = { @Dependent(type = ServiceAccountDependentResource.class), }) -@ControllerConfiguration(namespaces = Constants.WATCH_CURRENT_NAMESPACE) +@ControllerConfiguration( + informerConfig = @InformerConfig(namespaces = Constants.WATCH_CURRENT_NAMESPACE)) public class SpecialResourceTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index f85cd1459e..4eb1a1c0a3 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -9,7 +9,8 @@ import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.*; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentInformerConfigBuilder; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow; @@ -24,7 +25,8 @@ * Shows how to implement reconciler using standalone dependent resources. */ @ControllerConfiguration( - labelSelector = WebPageDependentsWorkflowReconciler.DEPENDENT_RESOURCE_LABEL_SELECTOR) + informerConfig = @InformerConfig( + labelSelector = WebPageDependentsWorkflowReconciler.DEPENDENT_RESOURCE_LABEL_SELECTOR)) @SuppressWarnings("unused") public class WebPageDependentsWorkflowReconciler implements Reconciler { @@ -81,13 +83,12 @@ private void initDependentResources(KubernetesClient client) { this.serviceDR = new ServiceDependentResource(); this.ingressDR = new IngressDependentResource(); - Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR).forEach(dr -> { - dr.configureWith(new KubernetesDependentResourceConfigBuilder() - .withKubernetesDependentInformerConfig(new KubernetesDependentInformerConfigBuilder<>() - .withLabelSelector(DEPENDENT_RESOURCE_LABEL_SELECTOR) - .build()) - .build()); - }); + Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR) + .forEach(dr -> dr.configureWith(new KubernetesDependentResourceConfigBuilder() + .withKubernetesDependentInformerConfig(InformerConfigHolder.builder() + .withLabelSelector(DEPENDENT_RESOURCE_LABEL_SELECTOR) + .buildForInformerEventSource()) + .build())); } } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index 27495a7ba8..6cb199b0fc 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -42,19 +42,19 @@ public WebPageReconciler() { public List> prepareEventSources(EventSourceContext context) { var configMapEventSource = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, WebPage.class) - .withLabelSelector(SELECTOR) + .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) .build(), context); var deploymentEventSource = new InformerEventSource<>(InformerConfiguration.from(Deployment.class, WebPage.class) - .withLabelSelector(SELECTOR) + .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) .build(), context); var serviceEventSource = new InformerEventSource<>(InformerConfiguration.from(Service.class, WebPage.class) - .withLabelSelector(SELECTOR) + .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) .build(), context); var ingressEventSource = new InformerEventSource<>(InformerConfiguration.from(Ingress.class, WebPage.class) - .withLabelSelector(SELECTOR) + .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) .build(), context); return List.of(configMapEventSource, deploymentEventSource, serviceEventSource, ingressEventSource); diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java index 62a7eb3cdc..0b8d44fe22 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java @@ -11,7 +11,7 @@ import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentInformerConfigBuilder; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow; import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowBuilder; @@ -96,8 +96,9 @@ private Workflow createDependentResourcesAndWorkflow() { // configure them with our label selector Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR) .forEach(dr -> dr.configureWith(new KubernetesDependentResourceConfigBuilder() - .withKubernetesDependentInformerConfig(new KubernetesDependentInformerConfigBuilder<>() - .withLabelSelector(SELECTOR + "=true").build()) + .withKubernetesDependentInformerConfig(InformerConfigHolder.builder() + .withLabelSelector(SELECTOR + "=true") + .buildForInformerEventSource()) .build())); // connect the dependent resources into a workflow, configuring them as we go From 132cbe302321563628f39f359acfe9d566bc1f9d Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 8 Jul 2024 17:50:05 +0200 Subject: [PATCH 65/96] feat: allow returning additional information from conditions (#2426) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2424. --------- Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Attila Mészáros Signed-off-by: Chris Laprun --- docs/content/en/docs/workflows/_index.md | 17 +- .../operator/api/reconciler/Workflow.java | 13 +- .../workflow/AbstractWorkflowExecutor.java | 70 ++++-- .../dependent/workflow/Condition.java | 4 + .../dependent/workflow/ConditionWithType.java | 31 +++ .../dependent/workflow/DefaultResult.java | 26 +++ .../dependent/workflow/DefaultWorkflow.java | 7 +- .../workflow/DependentResourceNode.java | 44 ++-- .../dependent/workflow/DetailedCondition.java | 94 ++++++++ .../dependent/workflow/NodeExecutor.java | 8 +- .../dependent/workflow/Workflow.java | 17 +- .../dependent/workflow/WorkflowBuilder.java | 4 + .../workflow/WorkflowCleanupExecutor.java | 91 ++++---- .../workflow/WorkflowCleanupResult.java | 20 +- .../workflow/WorkflowReconcileExecutor.java | 154 +++++++------ .../workflow/WorkflowReconcileResult.java | 28 +-- .../dependent/workflow/WorkflowResult.java | 211 +++++++++++++++++- .../processing/event/NamedEventSource.java | 0 .../dependent/workflow/ExecutionAssert.java | 25 ++- .../WorkflowReconcileExecutorTest.java | 99 +++++++- .../workflow/WorkflowResultTest.java | 11 +- .../dependent/workflow/WorkflowTest.java | 6 +- .../operator/WorkflowAllFeatureIT.java | 26 ++- .../config/BaseConfigurationServiceTest.java | 8 +- ...CreateUpdateEventFilterTestReconciler.java | 4 +- .../ConfigMapReconcileCondition.java | 17 +- .../WorkflowAllFeatureReconciler.java | 22 +- .../WorkflowAllFeatureStatus.java | 13 +- pom.xml | 37 +-- 29 files changed, 811 insertions(+), 296 deletions(-) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ConditionWithType.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultResult.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DetailedCondition.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java diff --git a/docs/content/en/docs/workflows/_index.md b/docs/content/en/docs/workflows/_index.md index cbb39840b0..4b61c6f1b0 100644 --- a/docs/content/en/docs/workflows/_index.md +++ b/docs/content/en/docs/workflows/_index.md @@ -49,11 +49,26 @@ reconciliation process. See related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/ba5e33527bf9e3ea0bd33025ccb35e677f9d44b4/operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java). To have multiple resources of same type with an activation condition is a bit tricky, since you - don't want to have multiple `InformerEvetnSource` for the same type, you have to explicitly + don't want to have multiple `InformerEventSource` for the same type, you have to explicitly name the informer for the Dependent Resource (`@KubernetesDependent(informerConfig = @InformerConfig(name = "configMapInformer"))`) for all resource of same type with activation condition. This will make sure that only one is registered. See details at [low level api](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceRetriever.java#L20-L52). +### Result conditions + +While simple conditions are usually enough, it might happen you want to convey extra information as a result of the +evaluation of the conditions (e.g., to report error messages or because the result of the condition evaluation might be +interesting for other purposes). In this situation, you should implement `DetailedCondition` instead of `Condition` and +provide an implementation of the `detailedIsMet` method, which allows you to return a more detailed `Result` object via +which you can provide extra information. The `DetailedCondition.Result` interface provides factory method for your +convenience but you can also provide your own implementation if required. + +You can access the results for conditions from the `WorkflowResult` instance that is returned whenever a workflow is +evaluated. You can access that result from the `ManagedWorkflowAndDependentResourceContext` accessible from the +reconciliation `Context`. You can then access individual condition results using the ` +getDependentConditionResult` methods. You can see an example of this +in [this integration test](https://github.com/operator-framework/java-operator-sdk/blob/fd0e92c0de55c47d5df50658cf4e147ee5e6102d/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java#L44-L49). + ## Defining Workflows Similarly to dependent resources, there are two ways to define workflows, in managed and standalone diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java index a9497a9749..3fb6c2c830 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Workflow.java @@ -8,6 +8,8 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowCleanupResult; +import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowReconcileResult; @Inherited @Retention(RetentionPolicy.RUNTIME) @@ -29,12 +31,11 @@ * execution as would normally be the case. Instead, it will proceed to its * {@link Reconciler#reconcile(HasMetadata, Context)} method as if no error occurred. It is then * up to the developer to decide how to proceed by retrieving the errored dependents (and their - * associated exception) via - * {@link io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowResult#erroredDependents}, - * the workflow result itself being accessed from - * {@link Context#managedWorkflowAndDependentResourceContext()}. If {@code false}, an exception - * will be automatically thrown at the end of the workflow execution, presenting an aggregated - * view of what happened. + * associated exception) via {@link WorkflowReconcileResult#getErroredDependents()} or + * {@link WorkflowCleanupResult#getErroredDependents()}, the workflow result itself being accessed + * from {@link Context#managedWorkflowAndDependentResourceContext()}. If {@code false}, an + * exception will be automatically thrown at the end of the workflow execution, presenting an + * aggregated view of what happened. */ boolean handleExceptionsInReconciler() default false; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java index 319b1a9e56..32c0bddbc0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java @@ -1,12 +1,11 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; import java.util.Map; -import java.util.Map.Entry; import java.util.Optional; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; +import java.util.function.Function; import java.util.stream.Collectors; import org.slf4j.Logger; @@ -20,25 +19,24 @@ @SuppressWarnings("rawtypes") abstract class AbstractWorkflowExecutor

{ - protected final Workflow

workflow; + protected final DefaultWorkflow

workflow; protected final P primary; protected final ResourceID primaryID; protected final Context

context; + protected final Map, WorkflowResult.DetailBuilder> results; /** * Covers both deleted and reconciled */ - private final Set alreadyVisited = ConcurrentHashMap.newKeySet(); private final Map> actualExecutions = new ConcurrentHashMap<>(); - private final Map exceptionsDuringExecution = - new ConcurrentHashMap<>(); private final ExecutorService executorService; - public AbstractWorkflowExecutor(Workflow

workflow, P primary, Context

context) { + protected AbstractWorkflowExecutor(DefaultWorkflow

workflow, P primary, Context

context) { this.workflow = workflow; this.primary = primary; this.context = context; this.primaryID = ResourceID.fromResource(primary); executorService = context.getWorkflowExecutorService(); + results = new ConcurrentHashMap<>(workflow.getDependentResourcesByName().size()); } protected abstract Logger logger(); @@ -75,11 +73,31 @@ protected boolean noMoreExecutionsScheduled() { } protected boolean alreadyVisited(DependentResourceNode dependentResourceNode) { - return alreadyVisited.contains(dependentResourceNode); + return getResultFlagFor(dependentResourceNode, WorkflowResult.DetailBuilder::isVisited); } - protected void markAsVisited(DependentResourceNode dependentResourceNode) { - alreadyVisited.add(dependentResourceNode); + protected boolean postDeleteConditionNotMet(DependentResourceNode drn) { + return getResultFlagFor(drn, WorkflowResult.DetailBuilder::hasPostDeleteConditionNotMet); + } + + protected boolean isMarkedForDelete(DependentResourceNode drn) { + return getResultFlagFor(drn, WorkflowResult.DetailBuilder::isMarkedForDelete); + } + + protected WorkflowResult.DetailBuilder createOrGetResultFor( + DependentResourceNode dependentResourceNode) { + return results.computeIfAbsent(dependentResourceNode, + unused -> new WorkflowResult.DetailBuilder()); + } + + protected Optional> getResultFor( + DependentResourceNode dependentResourceNode) { + return Optional.ofNullable(results.get(dependentResourceNode)); + } + + protected boolean getResultFlagFor(DependentResourceNode dependentResourceNode, + Function, Boolean> flag) { + return getResultFor(dependentResourceNode).map(flag).orElse(false); } protected boolean isExecutingNow(DependentResourceNode dependentResourceNode) { @@ -94,17 +112,15 @@ protected void markAsExecuting(DependentResourceNode dependentResourceNode protected synchronized void handleExceptionInExecutor( DependentResourceNode dependentResourceNode, RuntimeException e) { - exceptionsDuringExecution.put(dependentResourceNode, e); + createOrGetResultFor(dependentResourceNode).withError(e); } - protected boolean isInError(DependentResourceNode dependentResourceNode) { - return exceptionsDuringExecution.containsKey(dependentResourceNode); + protected boolean isNotReady(DependentResourceNode dependentResourceNode) { + return getResultFlagFor(dependentResourceNode, WorkflowResult.DetailBuilder::isNotReady); } - protected Map getErroredDependents() { - return exceptionsDuringExecution.entrySet().stream() - .collect( - Collectors.toMap(e -> e.getKey().getDependentResource(), Entry::getValue)); + protected boolean isInError(DependentResourceNode dependentResourceNode) { + return getResultFlagFor(dependentResourceNode, WorkflowResult.DetailBuilder::hasError); } protected synchronized void handleNodeExecutionFinish( @@ -116,9 +132,17 @@ protected synchronized void handleNodeExecutionFinish( } } - protected boolean isConditionMet(Optional> condition, - DependentResource dependentResource) { - return condition.map(c -> c.isMet(dependentResource, primary, context)).orElse(true); + @SuppressWarnings("unchecked") + protected boolean isConditionMet( + Optional> condition, + DependentResourceNode dependentResource) { + final var dr = dependentResource.getDependentResource(); + return condition.map(c -> { + final DetailedCondition.Result r = c.detailedIsMet(dr, primary, context); + results.computeIfAbsent(dependentResource, unused -> new WorkflowResult.DetailBuilder()) + .withResultForCondition(c, r); + return r; + }).orElse(DetailedCondition.Result.metWithoutResult).isSuccess(); } protected void submit(DependentResourceNode dependentResourceNode, @@ -145,4 +169,10 @@ protected void registerOrDeregisterEventSourceBasedOnActivation( } } } + + protected Map> asDetails() { + return results.entrySet().stream() + .collect( + Collectors.toMap(e -> e.getKey().getDependentResource(), e -> e.getValue().build())); + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Condition.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Condition.java index 87690ed69b..de96c99ca5 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Condition.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Condition.java @@ -6,6 +6,10 @@ public interface Condition { + enum Type { + ACTIVATION, DELETE, READY, RECONCILE + } + /** * Checks whether a condition holds true for a given * {@link io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource} based on the diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ConditionWithType.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ConditionWithType.java new file mode 100644 index 0000000000..de95830a92 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ConditionWithType.java @@ -0,0 +1,31 @@ +package io.javaoperatorsdk.operator.processing.dependent.workflow; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; + +class ConditionWithType implements DetailedCondition { + private final Condition condition; + private final Type type; + + ConditionWithType(Condition condition, Type type) { + this.condition = condition; + this.type = type; + } + + public Type type() { + return type; + } + + @SuppressWarnings("unchecked") + @Override + public Result detailedIsMet(DependentResource dependentResource, P primary, + Context

context) { + if (condition instanceof DetailedCondition detailedCondition) { + return detailedCondition.detailedIsMet(dependentResource, primary, context); + } else { + return Result + .withoutResult(condition.isMet(dependentResource, primary, context)); + } + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultResult.java new file mode 100644 index 0000000000..cc63f637cf --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultResult.java @@ -0,0 +1,26 @@ +package io.javaoperatorsdk.operator.processing.dependent.workflow; + +public class DefaultResult implements DetailedCondition.Result { + private final T result; + private final boolean success; + + public DefaultResult(boolean success, T result) { + this.result = result; + this.success = success; + } + + @Override + public T getDetail() { + return result; + } + + @Override + public boolean isSuccess() { + return success; + } + + @Override + public String toString() { + return asString(); + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java index bf186f01ca..782f8a61ec 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java @@ -113,12 +113,10 @@ public WorkflowCleanupResult cleanup(P primary, Context

context) { return result; } - @Override public Set getTopLevelDependentResources() { return topLevelResources; } - @Override public Set getBottomLevelResource() { return bottomLevelResource; } @@ -145,6 +143,11 @@ public boolean isEmpty() { return dependentResourceNodes.isEmpty(); } + @Override + public int size() { + return dependentResourceNodes.size(); + } + @Override public Map getDependentResourcesByName() { final var resources = new HashMap(dependentResourceNodes.size()); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java index 3e8a762c5e..aa8bb31c66 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java @@ -13,10 +13,10 @@ class DependentResourceNode { private final List dependsOn = new LinkedList<>(); private final List parents = new LinkedList<>(); - private Condition reconcilePrecondition; - private Condition deletePostcondition; - private Condition readyPostcondition; - private Condition activationCondition; + private ConditionWithType reconcilePrecondition; + private ConditionWithType deletePostcondition; + private ConditionWithType readyPostcondition; + private ConditionWithType activationCondition; private final DependentResource dependentResource; DependentResourceNode(DependentResource dependentResource) { @@ -26,10 +26,10 @@ class DependentResourceNode { public DependentResourceNode(Condition reconcilePrecondition, Condition deletePostcondition, Condition readyPostcondition, Condition activationCondition, DependentResource dependentResource) { - this.reconcilePrecondition = reconcilePrecondition; - this.deletePostcondition = deletePostcondition; - this.readyPostcondition = readyPostcondition; - this.activationCondition = activationCondition; + setReconcilePrecondition(reconcilePrecondition); + setDeletePostcondition(deletePostcondition); + setReadyPostcondition(readyPostcondition); + setActivationCondition(activationCondition); this.dependentResource = dependentResource; } @@ -50,36 +50,40 @@ public List getParents() { return parents; } - public Optional> getReconcilePrecondition() { + public Optional> getReconcilePrecondition() { return Optional.ofNullable(reconcilePrecondition); } - public Optional> getDeletePostcondition() { + public Optional> getDeletePostcondition() { return Optional.ofNullable(deletePostcondition); } - public Optional> getActivationCondition() { + public Optional> getActivationCondition() { return Optional.ofNullable(activationCondition); } - void setReconcilePrecondition(Condition reconcilePrecondition) { - this.reconcilePrecondition = reconcilePrecondition; + public Optional> getReadyPostcondition() { + return Optional.ofNullable(readyPostcondition); } - void setDeletePostcondition(Condition cleanupCondition) { - this.deletePostcondition = cleanupCondition; + void setReconcilePrecondition(Condition reconcilePrecondition) { + this.reconcilePrecondition = reconcilePrecondition == null ? null + : new ConditionWithType<>(reconcilePrecondition, Condition.Type.RECONCILE); } - void setActivationCondition(Condition activationCondition) { - this.activationCondition = activationCondition; + void setDeletePostcondition(Condition deletePostcondition) { + this.deletePostcondition = deletePostcondition == null ? null + : new ConditionWithType<>(deletePostcondition, Condition.Type.DELETE); } - public Optional> getReadyPostcondition() { - return Optional.ofNullable(readyPostcondition); + void setActivationCondition(Condition activationCondition) { + this.activationCondition = activationCondition == null ? null + : new ConditionWithType<>(activationCondition, Condition.Type.ACTIVATION); } void setReadyPostcondition(Condition readyPostcondition) { - this.readyPostcondition = readyPostcondition; + this.readyPostcondition = readyPostcondition == null ? null + : new ConditionWithType<>(readyPostcondition, Condition.Type.READY); } public DependentResource getDependentResource() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DetailedCondition.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DetailedCondition.java new file mode 100644 index 0000000000..200743cc0e --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DetailedCondition.java @@ -0,0 +1,94 @@ +package io.javaoperatorsdk.operator.processing.dependent.workflow; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; + +/** + * A condition that can return extra information in addition of whether it is met or not. + * + * @param the resource type this condition applies to + * @param

the primary resource type associated with the dependent workflow this condition is + * part of + * @param the type of the extra information returned by the condition + */ +public interface DetailedCondition extends Condition { + + /** + * Checks whether a condition holds true for the specified {@link DependentResource}, returning + * additional information as needed. + * + * @param dependentResource the {@link DependentResource} for which we want to check the condition + * @param primary the primary resource being considered + * @param context the current reconciliation {@link Context} + * @return a {@link Result} instance containing the result of the evaluation of the condition as + * well as additional detail + * @see Condition#isMet(DependentResource, HasMetadata, Context) + */ + Result detailedIsMet(DependentResource dependentResource, P primary, Context

context); + + @Override + default boolean isMet(DependentResource dependentResource, P primary, Context

context) { + return detailedIsMet(dependentResource, primary, context).isSuccess(); + } + + /** + * Holds a more detailed {@link Condition} result. + * + * @param the type of the extra information provided in condition evaluation + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + interface Result { + /** + * A result expressing a condition has been met without extra information + */ + Result metWithoutResult = new DefaultResult(true, null); + + /** + * A result expressing a condition has not been met without extra information + */ + Result unmetWithoutResult = new DefaultResult(false, null); + + /** + * Creates a {@link Result} without extra information + * + * @param success whether or not the condition has been met + * @return a {@link Result} without extra information + */ + static Result withoutResult(boolean success) { + return success ? metWithoutResult : unmetWithoutResult; + } + + /** + * Creates a {@link Result} with the specified condition evaluation result and extra information + * + * @param success whether or not the condition has been met + * @param detail the extra information that the condition provided during its evaluation + * @return a {@link Result} with the specified condition evaluation result and extra information + * @param the type of the extra information provided by the condition + */ + static Result withResult(boolean success, T detail) { + return new DefaultResult<>(success, detail); + } + + default String asString() { + return "Detail: " + getDetail() + " met: " + isSuccess(); + } + + /** + * The extra information provided by the associated {@link DetailedCondition} during its + * evaluation + * + * @return extra information provided by the associated {@link DetailedCondition} during its + * evaluation or {@code null} if none was provided + */ + T getDetail(); + + /** + * Whether the associated condition held true + * + * @return {@code true} if the associated condition was met, {@code false} otherwise + */ + boolean isSuccess(); + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/NodeExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/NodeExecutor.java index 0067c55321..2006486dc1 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/NodeExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/NodeExecutor.java @@ -1,7 +1,6 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; abstract class NodeExecutor implements Runnable { @@ -17,9 +16,7 @@ protected NodeExecutor(DependentResourceNode dependentResourceNode, @Override public void run() { try { - var dependentResource = dependentResourceNode.getDependentResource(); - - doRun(dependentResourceNode, dependentResource); + doRun(dependentResourceNode); } catch (RuntimeException e) { workflowExecutor.handleExceptionInExecutor(dependentResourceNode, e); @@ -28,6 +25,5 @@ public void run() { } } - protected abstract void doRun(DependentResourceNode dependentResourceNode, - DependentResource dependentResource); + protected abstract void doRun(DependentResourceNode dependentResourceNode); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java index 7f30ba6c9e..02f7d9c89f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java @@ -3,7 +3,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.Context; @@ -21,22 +20,16 @@ default WorkflowCleanupResult cleanup(P primary, Context

context) { throw new UnsupportedOperationException("Implement this"); } - @SuppressWarnings("rawtypes") - default Set getTopLevelDependentResources() { - return Collections.emptySet(); - } - - @SuppressWarnings("rawtypes") - default Set getBottomLevelResource() { - return Collections.emptySet(); - } - default boolean hasCleaner() { return false; } default boolean isEmpty() { - return true; + return size() == 0; + } + + default int size() { + return getDependentResourcesByName().size(); } @SuppressWarnings("rawtypes") diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java index 2f7a6b2afa..7bb5f75f6f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java @@ -81,6 +81,10 @@ public WorkflowBuilder

withThrowExceptionFurther(boolean throwExceptionFurthe } public Workflow

build() { + return buildAsDefaultWorkflow(); + } + + DefaultWorkflow

buildAsDefaultWorkflow() { return new DefaultWorkflow(new HashSet<>(dependentResourceNodes.values()), throwExceptionAutomatically, isCleaner); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutor.java index dda4db6729..da518be6ce 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutor.java @@ -1,9 +1,7 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; +import java.util.ArrayList; import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,19 +9,14 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; -import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; @SuppressWarnings("rawtypes") -public class WorkflowCleanupExecutor

extends AbstractWorkflowExecutor

{ +class WorkflowCleanupExecutor

extends AbstractWorkflowExecutor

{ private static final Logger log = LoggerFactory.getLogger(WorkflowCleanupExecutor.class); private static final String CLEANUP = "cleanup"; - private final Set postDeleteConditionNotMet = - ConcurrentHashMap.newKeySet(); - private final Set deleteCalled = ConcurrentHashMap.newKeySet(); - - public WorkflowCleanupExecutor(Workflow

workflow, P primary, Context

context) { + WorkflowCleanupExecutor(DefaultWorkflow

workflow, P primary, Context

context) { super(workflow, primary, context); } @@ -42,13 +35,30 @@ protected Logger logger() { @SuppressWarnings({"rawtypes", "unchecked"}) private synchronized void handleCleanup(DependentResourceNode dependentResourceNode) { - log.debug("Submitting for cleanup: {} primaryID: {}", dependentResourceNode, primaryID); - - if (alreadyVisited(dependentResourceNode) - || isExecutingNow(dependentResourceNode) - || !allDependentsCleaned(dependentResourceNode) - || hasErroredDependent(dependentResourceNode)) { - log.debug("Skipping submit of: {} primaryID: {}", dependentResourceNode, primaryID); + log.debug("Considering for cleanup: {} primaryID: {}", dependentResourceNode, primaryID); + + final var alreadyVisited = alreadyVisited(dependentResourceNode); + final var executingNow = isExecutingNow(dependentResourceNode); + final var waitingOnDependents = !allDependentsCleaned(dependentResourceNode); + final var hasErroredDependent = hasErroredDependent(dependentResourceNode); + if (waitingOnDependents || alreadyVisited || executingNow || hasErroredDependent) { + if (log.isDebugEnabled()) { + final var causes = new ArrayList(); + if (alreadyVisited) { + causes.add("already visited"); + } + if (executingNow) { + causes.add("executing now"); + } + if (waitingOnDependents) { + causes.add("waiting on dependents"); + } + if (hasErroredDependent) { + causes.add("errored dependent"); + } + log.debug("Skipping: {} primaryID: {} causes: {}", dependentResourceNode, + primaryID, String.join(", ", causes)); + } return; } @@ -64,33 +74,27 @@ private CleanupExecutor(DependentResourceNode drn) { @Override @SuppressWarnings("unchecked") - protected void doRun(DependentResourceNode dependentResourceNode, - DependentResource dependentResource) { - var deletePostCondition = dependentResourceNode.getDeletePostcondition(); - - var active = - isConditionMet(dependentResourceNode.getActivationCondition(), dependentResource); + protected void doRun(DependentResourceNode dependentResourceNode) { + final var active = + isConditionMet(dependentResourceNode.getActivationCondition(), dependentResourceNode); registerOrDeregisterEventSourceBasedOnActivation(active, dependentResourceNode); - if (dependentResource.isDeletable() && active) { - ((Deleter

) dependentResource).delete(primary, context); - deleteCalled.add(dependentResourceNode); - } - - boolean deletePostConditionMet; + boolean deletePostConditionMet = true; if (active) { - deletePostConditionMet = isConditionMet(deletePostCondition, dependentResource); - } else { - deletePostConditionMet = true; + final var dependentResource = dependentResourceNode.getDependentResource(); + if (dependentResource.isDeletable()) { + ((Deleter

) dependentResource).delete(primary, context); + createOrGetResultFor(dependentResourceNode).markAsDeleted(); + } + + deletePostConditionMet = + isConditionMet(dependentResourceNode.getDeletePostcondition(), dependentResourceNode); } + + createOrGetResultFor(dependentResourceNode).markAsVisited(); + if (deletePostConditionMet) { - markAsVisited(dependentResourceNode); handleDependentCleaned(dependentResourceNode); - } else { - // updating alreadyVisited needs to be the last operation otherwise could lead to a race - // condition in handleCleanup condition checks - postDeleteConditionNotMet.add(dependentResourceNode); - markAsVisited(dependentResourceNode); } } } @@ -112,7 +116,7 @@ private boolean allDependentsCleaned(DependentResourceNode dependentResourceNode List parents = dependentResourceNode.getParents(); return parents.isEmpty() || parents.stream() - .allMatch(d -> alreadyVisited(d) && !postDeleteConditionNotMet.contains(d)); + .allMatch(d -> alreadyVisited(d) && !postDeleteConditionNotMet(d)); } @SuppressWarnings("unchecked") @@ -122,13 +126,6 @@ private boolean hasErroredDependent(DependentResourceNode dependentResourceNode) } private WorkflowCleanupResult createCleanupResult() { - final var erroredDependents = getErroredDependents(); - final var postConditionNotMet = postDeleteConditionNotMet.stream() - .map(DependentResourceNode::getDependentResource) - .collect(Collectors.toList()); - final var deleteCalled = this.deleteCalled.stream() - .map(DependentResourceNode::getDependentResource) - .collect(Collectors.toList()); - return new WorkflowCleanupResult(erroredDependents, postConditionNotMet, deleteCalled); + return new WorkflowCleanupResult(asDetails()); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupResult.java index 860a553c39..b93741ef56 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupResult.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupResult.java @@ -7,26 +7,24 @@ @SuppressWarnings("rawtypes") public class WorkflowCleanupResult extends WorkflowResult { + private Boolean allPostConditionsMet; - private final List deleteCalledOnDependents; - private final List postConditionNotMetDependents; - - WorkflowCleanupResult(Map erroredDependents, - List postConditionNotMet, List deleteCalled) { - super(erroredDependents); - this.deleteCalledOnDependents = deleteCalled; - this.postConditionNotMetDependents = postConditionNotMet; + WorkflowCleanupResult(Map> results) { + super(results); } public List getDeleteCalledOnDependents() { - return deleteCalledOnDependents; + return listFilteredBy(Detail::deleted); } public List getPostConditionNotMetDependents() { - return postConditionNotMetDependents; + return listFilteredBy(detail -> !detail.isConditionWithTypeMet(Condition.Type.DELETE)); } public boolean allPostConditionsMet() { - return postConditionNotMetDependents.isEmpty(); + if (allPostConditionsMet == null) { + allPostConditionsMet = getPostConditionNotMetDependents().isEmpty(); + } + return allPostConditionsMet; } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java index 2da0bd7525..b130e8fd5f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java @@ -1,10 +1,8 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; +import java.util.ArrayList; import java.util.HashSet; -import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,28 +10,16 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; -import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; @SuppressWarnings({"rawtypes", "unchecked"}) -public class WorkflowReconcileExecutor

extends AbstractWorkflowExecutor

{ +class WorkflowReconcileExecutor

extends AbstractWorkflowExecutor

{ private static final Logger log = LoggerFactory.getLogger(WorkflowReconcileExecutor.class); private static final String RECONCILE = "reconcile"; private static final String DELETE = "delete"; - - private final Set notReady = ConcurrentHashMap.newKeySet(); - - private final Set markedForDelete = ConcurrentHashMap.newKeySet(); - private final Set deletePostConditionNotMet = - ConcurrentHashMap.newKeySet(); - // used to remember reconciled (not deleted or errored) dependents - private final Set reconciled = ConcurrentHashMap.newKeySet(); - private final Map reconcileResults = - new ConcurrentHashMap<>(); - - public WorkflowReconcileExecutor(Workflow

workflow, P primary, Context

context) { + public WorkflowReconcileExecutor(DefaultWorkflow

workflow, P primary, Context

context) { super(workflow, primary, context); } @@ -51,25 +37,46 @@ protected Logger logger() { } private synchronized void handleReconcile(DependentResourceNode dependentResourceNode) { - log.debug("Submitting for reconcile: {} primaryID: {}", dependentResourceNode, primaryID); - - if (alreadyVisited(dependentResourceNode) - || isExecutingNow(dependentResourceNode) - || !allParentsReconciledAndReady(dependentResourceNode) - || markedForDelete.contains(dependentResourceNode) - || hasErroredParent(dependentResourceNode)) { - log.debug("Skipping submit of: {}, primaryID: {}", dependentResourceNode, primaryID); + log.debug("Considering for reconcile: {} primaryID: {}", dependentResourceNode, primaryID); + + final var alreadyVisited = alreadyVisited(dependentResourceNode); + final var executingNow = isExecutingNow(dependentResourceNode); + final var isWaitingOnParents = !allParentsReconciledAndReady(dependentResourceNode); + final var isMarkedForDelete = isMarkedForDelete(dependentResourceNode); + final var hasErroredParent = hasErroredParent(dependentResourceNode); + if (isWaitingOnParents || alreadyVisited || executingNow || isMarkedForDelete + || hasErroredParent) { + if (log.isDebugEnabled()) { + final var causes = new ArrayList(); + if (alreadyVisited) { + causes.add("already visited"); + } + if (executingNow) { + causes.add("executing now"); + } + if (isMarkedForDelete) { + causes.add("marked for delete"); + } + if (isWaitingOnParents) { + causes.add("waiting on parents"); + } + if (hasErroredParent) { + causes.add("errored parent"); + } + log.debug("Skipping: {} primaryID: {} causes: {}", dependentResourceNode, + primaryID, String.join(", ", causes)); + } return; } boolean activationConditionMet = isConditionMet(dependentResourceNode.getActivationCondition(), - dependentResourceNode.getDependentResource()); + dependentResourceNode); registerOrDeregisterEventSourceBasedOnActivation(activationConditionMet, dependentResourceNode); boolean reconcileConditionMet = true; if (activationConditionMet) { reconcileConditionMet = isConditionMet(dependentResourceNode.getReconcilePrecondition(), - dependentResourceNode.getDependentResource()); + dependentResourceNode); } if (!reconcileConditionMet || !activationConditionMet) { handleReconcileOrActivationConditionNotMet(dependentResourceNode, activationConditionMet); @@ -81,12 +88,29 @@ private synchronized void handleReconcile(DependentResourceNode depend private synchronized void handleDelete(DependentResourceNode dependentResourceNode) { log.debug("Submitting for delete: {}", dependentResourceNode); - if (alreadyVisited(dependentResourceNode) - || isExecutingNow(dependentResourceNode) - || !markedForDelete.contains(dependentResourceNode) - || !allDependentsDeletedAlready(dependentResourceNode)) { - log.debug("Skipping submit for delete of: {} primaryID: {} ", dependentResourceNode, - primaryID); + final var alreadyVisited = alreadyVisited(dependentResourceNode); + final var executingNow = isExecutingNow(dependentResourceNode); + final var isNotMarkedForDelete = !isMarkedForDelete(dependentResourceNode); + final var isWaitingOnDependents = !allDependentsDeletedAlready(dependentResourceNode); + if (isNotMarkedForDelete || alreadyVisited || executingNow || isWaitingOnDependents) { + if (log.isDebugEnabled()) { + final var causes = new ArrayList(); + if (alreadyVisited) { + causes.add("already visited"); + } + if (executingNow) { + causes.add("executing now"); + } + if (isNotMarkedForDelete) { + causes.add("not marked for delete"); + } + if (isWaitingOnDependents) { + causes.add("waiting on dependents"); + } + log.debug("Skipping submit for delete of: {} primaryID: {} causes: {}", + dependentResourceNode, + primaryID, String.join(", ", causes)); + } return; } @@ -96,16 +120,8 @@ private synchronized void handleDelete(DependentResourceNode dependentResourceNo private boolean allDependentsDeletedAlready(DependentResourceNode dependentResourceNode) { var dependents = dependentResourceNode.getParents(); - return dependents.stream().allMatch(d -> alreadyVisited(d) && !notReady.contains(d) - && !isInError(d) && !deletePostConditionNotMet.contains(d)); - } - - // needs to be in one step - private synchronized void setAlreadyReconciledButNotReady( - DependentResourceNode dependentResourceNode) { - log.debug("Setting already reconciled but not ready for: {}", dependentResourceNode); - markAsVisited(dependentResourceNode); - notReady.add(dependentResourceNode); + return dependents.stream().allMatch(d -> alreadyVisited(d) && !isNotReady(d) + && !isInError(d) && !postDeleteConditionNotMet(d)); } private class NodeReconcileExecutor extends NodeExecutor { @@ -115,24 +131,20 @@ private NodeReconcileExecutor(DependentResourceNode dependentResourceNode) } @Override - protected void doRun(DependentResourceNode dependentResourceNode, - DependentResource dependentResource) { - + protected void doRun(DependentResourceNode dependentResourceNode) { + final var dependentResource = dependentResourceNode.getDependentResource(); log.debug( "Reconciling for primary: {} node: {} ", primaryID, dependentResourceNode); ReconcileResult reconcileResult = dependentResource.reconcile(primary, context); - reconcileResults.put(dependentResource, reconcileResult); - reconciled.add(dependentResourceNode); + final var detailBuilder = createOrGetResultFor(dependentResourceNode); + detailBuilder.withReconcileResult(reconcileResult).markAsVisited(); - boolean ready = isConditionMet(dependentResourceNode.getReadyPostcondition(), - dependentResource); - if (ready) { + if (isConditionMet(dependentResourceNode.getReadyPostcondition(), dependentResourceNode)) { log.debug("Setting already reconciled for: {} primaryID: {}", dependentResourceNode, primaryID); - markAsVisited(dependentResourceNode); handleDependentsReconcile(dependentResourceNode); } else { - setAlreadyReconciledButNotReady(dependentResourceNode); + log.debug("Setting already reconciled but not ready for: {}", dependentResourceNode); } } } @@ -145,29 +157,23 @@ private NodeDeleteExecutor(DependentResourceNode dependentResourceNode) { @Override @SuppressWarnings("unchecked") - protected void doRun(DependentResourceNode dependentResourceNode, - DependentResource dependentResource) { - var deletePostCondition = dependentResourceNode.getDeletePostcondition(); - + protected void doRun(DependentResourceNode dependentResourceNode) { boolean deletePostConditionMet = true; - if (isConditionMet(dependentResourceNode.getActivationCondition(), dependentResource)) { + if (isConditionMet(dependentResourceNode.getActivationCondition(), dependentResourceNode)) { // GarbageCollected status is irrelevant here, as this method is only called when a // precondition does not hold, // a deleter should be deleted even if it is otherwise garbage collected + final var dependentResource = dependentResourceNode.getDependentResource(); if (dependentResource instanceof Deleter) { ((Deleter

) dependentResource).delete(primary, context); } - deletePostConditionMet = isConditionMet(deletePostCondition, dependentResource); + deletePostConditionMet = + isConditionMet(dependentResourceNode.getDeletePostcondition(), dependentResourceNode); } + createOrGetResultFor(dependentResourceNode).markAsVisited(); if (deletePostConditionMet) { - markAsVisited(dependentResourceNode); handleDependentDeleted(dependentResourceNode); - } else { - // updating alreadyVisited needs to be the last operation otherwise could lead to a race - // condition in handleDelete condition checks - deletePostConditionNotMet.add(dependentResourceNode); - markAsVisited(dependentResourceNode); } } } @@ -191,7 +197,6 @@ private synchronized void handleDependentsReconcile( }); } - private void handleReconcileOrActivationConditionNotMet( DependentResourceNode dependentResourceNode, boolean activationConditionMet) { @@ -206,7 +211,7 @@ private void markDependentsForDelete(DependentResourceNode dependentResour // so if the activation condition was false, this node is not meant to be deleted. var dependents = dependentResourceNode.getParents(); if (activationConditionMet) { - markedForDelete.add(dependentResourceNode); + createOrGetResultFor(dependentResourceNode).markForDelete(); if (dependents.isEmpty()) { bottomNodes.add(dependentResourceNode); } else { @@ -214,7 +219,7 @@ private void markDependentsForDelete(DependentResourceNode dependentResour } } else { // this is for an edge case when there is only one resource but that is not active - markAsVisited(dependentResourceNode); + createOrGetResultFor(dependentResourceNode).markAsVisited(); if (dependents.isEmpty()) { handleNodeExecutionFinish(dependentResourceNode); } else { @@ -226,7 +231,7 @@ private void markDependentsForDelete(DependentResourceNode dependentResour private boolean allParentsReconciledAndReady(DependentResourceNode dependentResourceNode) { return dependentResourceNode.getDependsOn().isEmpty() || dependentResourceNode.getDependsOn().stream() - .allMatch(d -> alreadyVisited(d) && !notReady.contains(d)); + .allMatch(d -> alreadyVisited(d) && !isNotReady(d)); } private boolean hasErroredParent(DependentResourceNode dependentResourceNode) { @@ -236,15 +241,6 @@ private boolean hasErroredParent(DependentResourceNode dependentResourceNo } private WorkflowReconcileResult createReconcileResult() { - return new WorkflowReconcileResult( - reconciled.stream() - .map(DependentResourceNode::getDependentResource) - .collect(Collectors.toList()), - notReady.stream() - .map(DependentResourceNode::getDependentResource) - .collect(Collectors.toList()), - getErroredDependents(), - reconcileResults); + return new WorkflowReconcileResult(asDetails()); } - } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileResult.java index 6fbd06486c..055fca3bfe 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileResult.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileResult.java @@ -2,41 +2,31 @@ import java.util.List; import java.util.Map; +import java.util.Optional; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; -import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; @SuppressWarnings("rawtypes") public class WorkflowReconcileResult extends WorkflowResult { - private final List reconciledDependents; - private final List notReadyDependents; - private final Map reconcileResults; - - public WorkflowReconcileResult(List reconciledDependents, - List notReadyDependents, - Map erroredDependents, - Map reconcileResults) { - super(erroredDependents); - this.reconciledDependents = reconciledDependents; - this.notReadyDependents = notReadyDependents; - this.reconcileResults = reconcileResults; + WorkflowReconcileResult(Map> results) { + super(results); } public List getReconciledDependents() { - return reconciledDependents; + return listFilteredBy(detail -> detail.reconcileResult() != null); } public List getNotReadyDependents() { - return notReadyDependents; + return listFilteredBy(detail -> !detail.isConditionWithTypeMet(Condition.Type.READY)); } - @SuppressWarnings("unused") - public Map getReconcileResults() { - return reconcileResults; + public Optional getNotReadyDependentResult(DependentResource dependentResource, + Class expectedResultType) { + return getDependentConditionResult(dependentResource, Condition.Type.READY, expectedResultType); } public boolean allDependentResourcesReady() { - return notReadyDependents.isEmpty(); + return getNotReadyDependents().isEmpty(); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java index 7014ccd5d4..900022444d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java @@ -1,36 +1,227 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; -import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; +import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import io.javaoperatorsdk.operator.AggregatedOperatorException; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; @SuppressWarnings("rawtypes") class WorkflowResult { + private final Map> results; + private Boolean hasErroredDependents; - private final Map erroredDependents; - - WorkflowResult(Map erroredDependents) { - this.erroredDependents = erroredDependents != null ? erroredDependents : Collections.emptyMap(); + WorkflowResult(Map> results) { + this.results = results; } public Map getErroredDependents() { - return erroredDependents; + return getErroredDependentsStream() + .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().error)); + } + + private Stream>> getErroredDependentsStream() { + return results.entrySet().stream().filter(entry -> entry.getValue().error != null); + } + + protected Map> results() { + return results; + } + + /** + * Retrieves the {@link DependentResource} associated with the specified name if it exists, + * {@link Optional#empty()} otherwise. + * + * @param name the name of the {@link DependentResource} to retrieve + * @return the {@link DependentResource} associated with the specified name if it exists, + * {@link Optional#empty()} otherwise + */ + public Optional getDependentResourceByName(String name) { + if (name == null || name.isEmpty()) { + return Optional.empty(); + } + return results.keySet().stream().filter(dr -> dr.name().equals(name)).findFirst(); + } + + /** + * Retrieves the optional result of the condition with the specified type for the specified + * dependent resource. + * + * @param the expected result type of the condition + * @param dependentResourceName the dependent resource for which we want to retrieve a condition + * result + * @param conditionType the condition type which result we're interested in + * @param expectedResultType the expected result type of the condition + * @return the dependent condition result if it exists or {@link Optional#empty()} otherwise + * @throws IllegalArgumentException if a result exists but is not of the expected type + */ + public Optional getDependentConditionResult(String dependentResourceName, + Condition.Type conditionType, Class expectedResultType) { + return getDependentConditionResult( + getDependentResourceByName(dependentResourceName).orElse(null), conditionType, + expectedResultType); + } + + /** + * Retrieves the optional result of the condition with the specified type for the specified + * dependent resource. + * + * @param the expected result type of the condition + * @param dependentResource the dependent resource for which we want to retrieve a condition + * result + * @param conditionType the condition type which result we're interested in + * @param expectedResultType the expected result type of the condition + * @return the dependent condition result if it exists or {@link Optional#empty()} otherwise + * @throws IllegalArgumentException if a result exists but is not of the expected type + */ + public Optional getDependentConditionResult(DependentResource dependentResource, + Condition.Type conditionType, Class expectedResultType) { + if (dependentResource == null) { + return Optional.empty(); + } + + final var result = new Object[1]; + try { + return Optional.ofNullable(results().get(dependentResource)) + .flatMap(detail -> detail.getResultForConditionWithType(conditionType)) + .map(r -> result[0] = r.getDetail()) + .map(expectedResultType::cast); + } catch (Exception e) { + throw new IllegalArgumentException("Condition " + + "result " + result[0] + + " for Dependent " + dependentResource.name() + " doesn't match expected type " + + expectedResultType.getSimpleName(), e); + } + } + + protected List listFilteredBy( + Function filter) { + return results.entrySet().stream() + .filter(e -> filter.apply(e.getValue())) + .map(Map.Entry::getKey) + .toList(); } - @SuppressWarnings("unused") public boolean erroredDependentsExist() { - return !erroredDependents.isEmpty(); + if (hasErroredDependents == null) { + hasErroredDependents = !getErroredDependents().isEmpty(); + } + return hasErroredDependents; } public void throwAggregateExceptionIfErrorsPresent() { if (erroredDependentsExist()) { throw new AggregatedOperatorException("Exception(s) during workflow execution.", - erroredDependents.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey().name(), Entry::getValue))); + getErroredDependentsStream() + .collect(Collectors.toMap(e -> e.getKey().name(), e -> e.getValue().error))); + } + } + + @SuppressWarnings("UnusedReturnValue") + static class DetailBuilder { + private Exception error; + private ReconcileResult reconcileResult; + private DetailedCondition.Result activationConditionResult; + private DetailedCondition.Result deletePostconditionResult; + private DetailedCondition.Result readyPostconditionResult; + private DetailedCondition.Result reconcilePostconditionResult; + private boolean deleted; + private boolean visited; + private boolean markedForDelete; + + Detail build() { + return new Detail<>(error, reconcileResult, activationConditionResult, + deletePostconditionResult, readyPostconditionResult, reconcilePostconditionResult, + deleted, visited, markedForDelete); + } + + DetailBuilder withResultForCondition( + ConditionWithType conditionWithType, + DetailedCondition.Result conditionResult) { + switch (conditionWithType.type()) { + case ACTIVATION -> activationConditionResult = conditionResult; + case DELETE -> deletePostconditionResult = conditionResult; + case READY -> readyPostconditionResult = conditionResult; + case RECONCILE -> reconcilePostconditionResult = conditionResult; + default -> + throw new IllegalStateException("Unexpected condition type: " + conditionWithType); + } + return this; + } + + DetailBuilder withError(Exception error) { + this.error = error; + return this; + } + + DetailBuilder withReconcileResult(ReconcileResult reconcileResult) { + this.reconcileResult = reconcileResult; + return this; + } + + DetailBuilder markAsDeleted() { + this.deleted = true; + return this; + } + + public boolean hasError() { + return error != null; + } + + public boolean hasPostDeleteConditionNotMet() { + return deletePostconditionResult != null && !deletePostconditionResult.isSuccess(); + } + + public boolean isNotReady() { + return readyPostconditionResult != null && !readyPostconditionResult.isSuccess(); + } + + DetailBuilder markAsVisited() { + visited = true; + return this; + } + + public boolean isVisited() { + return visited; + } + + public boolean isMarkedForDelete() { + return markedForDelete; + } + + DetailBuilder markForDelete() { + markedForDelete = true; + return this; + } + } + + + record Detail(Exception error, ReconcileResult reconcileResult, + DetailedCondition.Result activationConditionResult, + DetailedCondition.Result deletePostconditionResult, + DetailedCondition.Result readyPostconditionResult, + DetailedCondition.Result reconcilePostconditionResult, + boolean deleted, boolean visited, boolean markedForDelete) { + + boolean isConditionWithTypeMet(Condition.Type conditionType) { + return getResultForConditionWithType(conditionType).map(DetailedCondition.Result::isSuccess) + .orElse(true); + } + + Optional> getResultForConditionWithType( + Condition.Type conditionType) { + return switch (conditionType) { + case ACTIVATION -> Optional.ofNullable(activationConditionResult); + case DELETE -> Optional.ofNullable(deletePostconditionResult); + case READY -> Optional.ofNullable(readyPostconditionResult); + case RECONCILE -> Optional.ofNullable(reconcilePostconditionResult); + }; } } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NamedEventSource.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ExecutionAssert.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ExecutionAssert.java index 095b090208..d857c0e9dd 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ExecutionAssert.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ExecutionAssert.java @@ -21,12 +21,13 @@ public static ExecutionAssert assertThat(List actual) { public ExecutionAssert reconciled(DependentResource... dependentResources) { for (int i = 0; i < dependentResources.length; i++) { - var rr = getReconcileRecordFor(dependentResources[i]); + final DependentResource dr = dependentResources[i]; + var rr = getReconcileRecordFor(dr); if (rr.isEmpty()) { - failWithMessage("Resource not reconciled: %s with index %d", dependentResources, i); + failWithMessage("Resource not reconciled: %s with index %d", dr, i); } else { if (rr.get().isDeleted()) { - failWithMessage("Resource deleted: %s with index %d", dependentResources, i); + failWithMessage("Resource deleted: %s with index %d", dr, i); } } } @@ -35,12 +36,13 @@ public ExecutionAssert reconciled(DependentResource... dependentResources) public ExecutionAssert deleted(DependentResource... dependentResources) { for (int i = 0; i < dependentResources.length; i++) { - var rr = getReconcileRecordFor(dependentResources[i]); + final DependentResource dr = dependentResources[i]; + var rr = getReconcileRecordFor(dr); if (rr.isEmpty()) { - failWithMessage("Resource not reconciled: %s with index %d", dependentResources, i); + failWithMessage("Resource not reconciled: %s with index %d", dr, i); } else { if (!rr.get().isDeleted()) { - failWithMessage("Resource not deleted: %s with index %d", dependentResources, i); + failWithMessage("Resource not deleted: %s with index %d", dr, i); } } } @@ -75,17 +77,18 @@ public ExecutionAssert reconciledInOrder(DependentResource... dependentRes public ExecutionAssert notReconciled(DependentResource... dependentResources) { for (int i = 0; i < dependentResources.length; i++) { - if (getActualDependentResources().contains(dependentResources[i])) { - failWithMessage("Resource was reconciled: %s with index %d", dependentResources, i); + final DependentResource dr = dependentResources[i]; + if (getActualDependentResources().contains(dr)) { + failWithMessage("Resource was reconciled: %s with index %d", dr, i); } } return this; } private void checkIfReconciled(int i, DependentResource[] dependentResources) { - if (!getActualDependentResources().contains(dependentResources[i])) { - failWithMessage("Dependent resource: %s, not reconciled on place %d", dependentResources[i], - i); + final DependentResource dr = dependentResources[i]; + if (!getActualDependentResources().contains(dr)) { + failWithMessage("Dependent resource: %s, not reconciled on place %d", dr, i); } } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java index 7bfc481450..996dd66e38 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java @@ -7,14 +7,16 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.AggregatedOperatorException; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedDependentResourceContext; +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; import static io.javaoperatorsdk.operator.processing.dependent.workflow.ExecutionAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; class WorkflowReconcileExecutorTest extends AbstractWorkflowExecutorTest { @@ -27,6 +29,7 @@ class WorkflowReconcileExecutorTest extends AbstractWorkflowExecutorTest { TestDependent dr4 = new TestDependent("DR_4"); @BeforeEach + @SuppressWarnings("unchecked") void setup() { when(mockContext.managedDependentResourceContext()).thenReturn(mock(ManagedDependentResourceContext.class)); when(mockContext.getWorkflowExecutorService()).thenReturn(executorService); @@ -183,8 +186,18 @@ void onlyOneDependsOnErroredResourceNotReconciled() { @Test void simpleReconcileCondition() { + final var result = "Some error message"; + final var unmetWithResult = new DetailedCondition() { + @Override + public Result detailedIsMet( + DependentResource dependentResource, + TestCustomResource primary, Context context) { + return Result.withResult(false, result); + } + }; + var workflow = new WorkflowBuilder() - .addDependentResource(dr1).withReconcilePrecondition(notMetCondition) + .addDependentResource(dr1).withReconcilePrecondition(unmetWithResult) .addDependentResource(dr2).withReconcilePrecondition(metCondition) .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition) .build(); @@ -195,6 +208,8 @@ void simpleReconcileCondition() { Assertions.assertThat(res.getErroredDependents()).isEmpty(); Assertions.assertThat(res.getReconciledDependents()).containsExactlyInAnyOrder(dr2); Assertions.assertThat(res.getNotReadyDependents()).isEmpty(); + res.getDependentConditionResult(dr1, Condition.Type.RECONCILE, String.class) + .ifPresentOrElse(s -> assertEquals(result, s), org.junit.jupiter.api.Assertions::fail); } @@ -522,6 +537,7 @@ void readyConditionNotCheckedOnNonActiveDependent() { } @Test + @SuppressWarnings("unchecked") void reconcilePreconditionNotCheckedOnNonActiveDependent() { var precondition = mock(Condition.class); @@ -558,6 +574,7 @@ void deletesDependentsOfNonActiveDependentButNotTheNonActive() { } @Test + @SuppressWarnings("unchecked") void activationConditionOnlyCalledOnceOnDeleteDependents() { TestDeleterDependent drDeleter2 = new TestDeleterDependent("DR_DELETER_2"); var condition = mock(Condition.class); @@ -574,4 +591,80 @@ void activationConditionOnlyCalledOnceOnDeleteDependents() { verify(condition, times(1)).isMet(any(), any(), any()); } + + @Test + void resultFromReadyConditionShouldBeAvailableIfExisting() { + final var result = Integer.valueOf(42); + final var resultCondition = new DetailedCondition<>() { + @Override + public Result detailedIsMet(DependentResource dependentResource, + HasMetadata primary, Context context) { + return new Result<>() { + @Override + public Object getDetail() { + return result; + } + + @Override + public boolean isSuccess() { + return false; // force not ready + } + }; + } + }; + var workflow = new WorkflowBuilder() + .addDependentResource(dr1) + .withReadyPostcondition(resultCondition) + .build(); + + final var reconcileResult = workflow.reconcile(new TestCustomResource(), mockContext); + assertEquals(result, + reconcileResult.getNotReadyDependentResult(dr1, Integer.class).orElseThrow()); + } + + @Test + void shouldThrowIllegalArgumentExceptionIfTypesDoNotMatch() { + final var result = "FOO"; + final var resultCondition = new DetailedCondition<>() { + @Override + public Result detailedIsMet(DependentResource dependentResource, + HasMetadata primary, Context context) { + return new Result<>() { + @Override + public Object getDetail() { + return result; + } + + @Override + public boolean isSuccess() { + return false; // force not ready + } + }; + } + }; + var workflow = new WorkflowBuilder() + .addDependentResource(dr1) + .withReadyPostcondition(resultCondition) + .build(); + + final var reconcileResult = workflow.reconcile(new TestCustomResource(), mockContext); + final var expectedResultType = Integer.class; + final var e = assertThrows(IllegalArgumentException.class, + () -> reconcileResult.getNotReadyDependentResult(dr1, expectedResultType)); + final var message = e.getMessage(); + assertTrue(message.contains(dr1.name())); + assertTrue(message.contains(expectedResultType.getSimpleName())); + assertTrue(message.contains(result)); + } + + @Test + void shouldReturnEmptyIfNoConditionResultExists() { + var workflow = new WorkflowBuilder() + .addDependentResource(dr1) + .withReadyPostcondition(notMetCondition) + .build(); + + final var reconcileResult = workflow.reconcile(new TestCustomResource(), mockContext); + assertTrue(reconcileResult.getNotReadyDependentResult(dr1, Integer.class).isEmpty()); + } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResultTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResultTest.java index c89ca53f07..ca0b883e99 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResultTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResultTest.java @@ -13,11 +13,14 @@ import static org.assertj.core.api.Assertions.assertThat; class WorkflowResultTest { + private final static WorkflowResult.Detail detail = + new WorkflowResult.Detail<>(new RuntimeException(), null, null, null, null, null, false, + false, false); @Test void throwsExceptionWithoutNumberingIfAllDifferentClass() { - var res = new WorkflowResult(Map.of(new DependentA(), new RuntimeException(), - new DependentB(), new RuntimeException())); + var res = new WorkflowResult(Map.of(new DependentA(), detail, + new DependentB(), detail)); try { res.throwAggregateExceptionIfErrorsPresent(); } catch (AggregatedOperatorException e) { @@ -28,8 +31,8 @@ void throwsExceptionWithoutNumberingIfAllDifferentClass() { @Test void numbersDependentClassNamesIfMoreOfSameType() { - var res = new WorkflowResult(Map.of(new DependentA("name1"), new RuntimeException(), - new DependentA("name2"), new RuntimeException())); + var res = new WorkflowResult(Map.of(new DependentA("name1"), detail, + new DependentA("name2"), detail)); try { res.throwAggregateExceptionIfErrorsPresent(); } catch (AggregatedOperatorException e) { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java index ef48fccd6e..d6e14a1645 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java @@ -50,7 +50,7 @@ void calculatesTopLevelResources() { .addDependentResource(independentDR) .addDependentResource(dr1) .addDependentResource(dr2).dependsOn(dr1) - .build(); + .buildAsDefaultWorkflow(); Set topResources = workflow.getTopLevelDependentResources().stream() @@ -66,11 +66,11 @@ void calculatesBottomLevelResources() { var dr2 = mockDependent("dr2"); var independentDR = mockDependent("independentDR"); - Workflow workflow = new WorkflowBuilder() + final var workflow = new WorkflowBuilder() .addDependentResource(independentDR) .addDependentResource(dr1) .addDependentResource(dr2).dependsOn(dr1) - .build(); + .buildAsDefaultWorkflow(); Set bottomResources = workflow.getBottomLevelResource().stream() diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java index f60f2b6fde..0473c50ddb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java @@ -10,9 +10,11 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.sample.workflowallfeature.ConfigMapReconcileCondition; import io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureCustomResource; import io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureReconciler; import io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureSpec; +import io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureStatus; import static io.javaoperatorsdk.operator.sample.workflowallfeature.ConfigMapDependentResource.READY_TO_DELETE_ANNOTATION; import static org.assertj.core.api.Assertions.assertThat; @@ -39,6 +41,8 @@ void configMapNotReconciledUntilDeploymentReady() { .isPositive(); assertThat(operator.get(Deployment.class, RESOURCE_NAME)).isNotNull(); assertThat(operator.get(ConfigMap.class, RESOURCE_NAME)).isNull(); + assertThat(getPrimaryStatus().getMsgFromCondition()) + .isEqualTo(ConfigMapReconcileCondition.NOT_RECONCILED_YET); }); await().atMost(ONE_MINUTE).untilAsserted(() -> { @@ -47,13 +51,20 @@ void configMapNotReconciledUntilDeploymentReady() { .getNumberOfReconciliationExecution()) .isGreaterThan(1); assertThat(operator.get(ConfigMap.class, RESOURCE_NAME)).isNotNull(); - assertThat(operator.get(WorkflowAllFeatureCustomResource.class, RESOURCE_NAME) - .getStatus().getReady()).isTrue(); + final var primaryStatus = getPrimaryStatus(); + assertThat(primaryStatus.getReady()).isTrue(); + assertThat(primaryStatus.getMsgFromCondition()) + .isEqualTo(ConfigMapReconcileCondition.CREATE_SET); }); markConfigMapForDelete(); } + private WorkflowAllFeatureStatus getPrimaryStatus() { + return operator.get(WorkflowAllFeatureCustomResource.class, RESOURCE_NAME) + .getStatus(); + } + @Test void configMapNotReconciledIfReconcileConditionNotMet() { @@ -61,8 +72,7 @@ void configMapNotReconciledIfReconcileConditionNotMet() { await().atMost(ONE_MINUTE).untilAsserted(() -> { assertThat(operator.get(ConfigMap.class, RESOURCE_NAME)).isNull(); - assertThat(operator.get(WorkflowAllFeatureCustomResource.class, RESOURCE_NAME) - .getStatus().getReady()).isTrue(); + assertThat(getPrimaryStatus().getReady()).isTrue(); }); resource.getSpec().setCreateConfigMap(true); @@ -70,8 +80,7 @@ void configMapNotReconciledIfReconcileConditionNotMet() { await().untilAsserted(() -> { assertThat(operator.get(ConfigMap.class, RESOURCE_NAME)).isNotNull(); - assertThat(operator.get(WorkflowAllFeatureCustomResource.class, RESOURCE_NAME) - .getStatus().getReady()).isTrue(); + assertThat(getPrimaryStatus().getReady()).isTrue(); }); } @@ -81,10 +90,9 @@ void configMapNotDeletedUntilNotMarked() { var resource = operator.create(customResource(true)); await().atMost(ONE_MINUTE).untilAsserted(() -> { - assertThat(operator.get(WorkflowAllFeatureCustomResource.class, RESOURCE_NAME).getStatus()) + assertThat(getPrimaryStatus()) .isNotNull(); - assertThat(operator.get(WorkflowAllFeatureCustomResource.class, RESOURCE_NAME) - .getStatus().getReady()).isTrue(); + assertThat(getPrimaryStatus().getReady()).isTrue(); assertThat(operator.get(ConfigMap.class, RESOURCE_NAME)).isNotNull(); }); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java index 8363b85f37..81e4ea5a10 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java @@ -20,7 +20,13 @@ import io.javaoperatorsdk.operator.api.config.dependent.ConfigurationConverter; import io.javaoperatorsdk.operator.api.config.dependent.Configured; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index 8714b8c31f..5f8b20ffa8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -74,7 +74,9 @@ public List> prepareEv .withInformerConfiguration(c -> c .withLabelSelector("integrationtest = " + this.getClass().getSimpleName())) .build(); - final var informerEventSource = new InformerEventSource<>(informerConfiguration, context); + final var informerEventSource = + new InformerEventSource( + informerConfiguration, context); this.configMapDR.setEventSource(informerEventSource); return List.of(informerEventSource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapReconcileCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapReconcileCondition.java index b3d9d7a541..dfdc0ad8a4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapReconcileCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapReconcileCondition.java @@ -3,17 +3,20 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; -import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; +import io.javaoperatorsdk.operator.processing.dependent.workflow.DetailedCondition; public class ConfigMapReconcileCondition - implements Condition { + implements DetailedCondition { + + public static final String CREATE_SET = "create set"; + public static final String CREATE_NOT_SET = "create not set"; + public static final String NOT_RECONCILED_YET = "Not reconciled yet"; @Override - public boolean isMet( + public Result detailedIsMet( DependentResource dependentResource, - WorkflowAllFeatureCustomResource primary, - Context context) { - - return primary.getSpec().isCreateConfigMap(); + WorkflowAllFeatureCustomResource primary, Context context) { + final var createConfigMap = primary.getSpec().isCreateConfigMap(); + return Result.withResult(createConfigMap, createConfigMap ? CREATE_SET : CREATE_NOT_SET); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java index f5c14d6f96..61b42e0c64 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java @@ -2,8 +2,16 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.api.reconciler.Cleaner; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; import static io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureReconciler.DEPLOYMENT_NAME; @@ -33,11 +41,15 @@ public UpdateControl reconcile( if (resource.getStatus() == null) { resource.setStatus(new WorkflowAllFeatureStatus()); } + final var reconcileResult = context.managedWorkflowAndDependentResourceContext() + .getWorkflowReconcileResult(); + final var msgFromCondition = reconcileResult.getDependentConditionResult( + DependentResource.defaultNameFor(ConfigMapDependentResource.class), + Condition.Type.RECONCILE, String.class) + .orElse(ConfigMapReconcileCondition.NOT_RECONCILED_YET); resource.getStatus() - .setReady( - context.managedWorkflowAndDependentResourceContext() - .getWorkflowReconcileResult() - .allDependentResourcesReady()); + .withReady(reconcileResult.allDependentResourcesReady()) + .withMsgFromCondition(msgFromCondition); return UpdateControl.patchStatus(resource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureStatus.java index 11d0798fca..c53931b206 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureStatus.java @@ -3,13 +3,24 @@ public class WorkflowAllFeatureStatus { private Boolean ready; + private String msgFromCondition; public Boolean getReady() { return ready; } - public WorkflowAllFeatureStatus setReady(Boolean ready) { + public String getMsgFromCondition() { + return msgFromCondition; + } + + public WorkflowAllFeatureStatus withReady(Boolean ready) { this.ready = ready; return this; } + + @SuppressWarnings("UnusedReturnValue") + public WorkflowAllFeatureStatus withMsgFromCondition(String msgFromCondition) { + this.msgFromCondition = msgFromCondition; + return this; + } } diff --git a/pom.xml b/pom.xml index 4a47bded31..ea64799795 100644 --- a/pom.xml +++ b/pom.xml @@ -66,29 +66,30 @@ 2.0.12 2.23.1 5.13.0 - 3.16.0 - 0.21.0 - 1.13.0 - 3.26.3 - 4.2.0 - 2.7.3 - 1.13.3 - 3.1.8 - 0.9.6 - 0.9.11 - 2.16.1 + 3.16.0 + 0.21.0 + 1.13.0 + 3.26.3 + 4.2.0 + 2.7.3 + 1.13.3 + 4.12.0 + 3.1.8 + 0.9.6 + 0.9.11 + 2.16.1 2.11 3.12.1 3.5.0 3.10.0 - 3.3.1 - 3.3.1 - 3.4.2 - 3.4.0 - 3.2.5 - 1.7.0 - 3.0.0 + 3.3.1 + 3.3.1 + 3.4.2 + 3.4.0 + 3.2.5 + 1.7.0 + 3.0.0 3.1.3 9.0.1 3.4.1 From 889d4543245d6f2f07a64a0ef1eecb601fca15b0 Mon Sep 17 00:00:00 2001 From: 10000-ki <76486121+10000-ki@users.noreply.github.com> Date: Wed, 7 Aug 2024 02:31:10 +0900 Subject: [PATCH 66/96] feat: support for graceful shutdown based on configuration (#2479) --------- Signed-off-by: 10000-ki <10000ki6472@gmail.com> --- .../patterns-and-best-practices/_index.md | 12 +++++ .../io/javaoperatorsdk/operator/Operator.java | 18 ++++--- .../api/config/ConfigurationService.java | 47 +++++++++++-------- .../config/ConfigurationServiceOverrider.java | 13 +++++ .../ConfigurationServiceOverriderTest.java | 4 ++ .../operator/GracefulStopIT.java | 17 +++---- .../operator/InformerRelatedBehaviorITS.java | 3 +- 7 files changed, 72 insertions(+), 42 deletions(-) diff --git a/docs/content/en/docs/patterns-and-best-practices/_index.md b/docs/content/en/docs/patterns-and-best-practices/_index.md index 422f3f7bfe..a2b3b716b6 100644 --- a/docs/content/en/docs/patterns-and-best-practices/_index.md +++ b/docs/content/en/docs/patterns-and-best-practices/_index.md @@ -120,3 +120,15 @@ might be a permission issue for some resources in another namespace. The `stopOnInformerErrorDuringStartup` has implication on [cache sync timeout](https://github.com/java-operator-sdk/java-operator-sdk/blob/114c4312c32b34688811df8dd7cea275878c9e73/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L177-L179) behavior. If true operator will stop on cache sync timeout. if `false`, after the timeout the controller will start reconcile resources even if one or more event source caches did not sync yet. + +## Graceful Shutdown + +You can provide sufficient time for the reconciler to process and complete the currently ongoing events before shutting down. +The configuration is simple. You just need to set an appropriate duration value for `reconciliationTerminationTimeout` using `ConfigurationServiceOverrider`. + +```java +final var overridden = new ConfigurationServiceOverrider(config) + .withReconciliationTerminationTimeout(Duration.ofSeconds(5)); + +final var operator = new Operator(overridden); +``` diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java index d85de6b1e5..1283896a42 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java @@ -100,7 +100,7 @@ private static ConfigurationService initConfigurationService(KubernetesClient cl @SuppressWarnings("unused") public void installShutdownHook(Duration gracefulShutdownTimeout) { if (!leaderElectionManager.isLeaderElectionEnabled()) { - Runtime.getRuntime().addShutdownHook(new Thread(() -> stop(gracefulShutdownTimeout))); + Runtime.getRuntime().addShutdownHook(new Thread(this::stop)); } else { log.warn("Leader election is on, shutdown hook will not be installed."); } @@ -145,15 +145,18 @@ public synchronized void start() { } } - public void stop(Duration gracefulShutdownTimeout) throws OperatorException { + @Override + public void stop() throws OperatorException { + Duration reconciliationTerminationTimeout = + configurationService.reconciliationTerminationTimeout(); if (!started) { return; } - log.info( - "Operator SDK {} is shutting down...", configurationService.getVersion().getSdkVersion()); + log.info("Operator SDK {} is shutting down...", + configurationService.getVersion().getSdkVersion()); controllerManager.stop(); - configurationService.getExecutorServiceManager().stop(gracefulShutdownTimeout); + configurationService.getExecutorServiceManager().stop(reconciliationTerminationTimeout); leaderElectionManager.stop(); if (configurationService.closeClientOnStop()) { getKubernetesClient().close(); @@ -162,11 +165,6 @@ public void stop(Duration gracefulShutdownTimeout) throws OperatorException { started = false; } - @Override - public void stop() throws OperatorException { - stop(Duration.ZERO); - } - /** * Add a registration requests for the specified reconciler with this operator. The effective * registration of the reconciler is delayed till the operator is started. diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index d29e545bb6..bdc23a1cb7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -104,8 +104,8 @@ static ConfigurationService newOverriddenConfigurationService( * * @param reconciler the reconciler we want the configuration of * @param the {@code CustomResource} type associated with the specified reconciler - * @return the {@link ControllerConfiguration} associated with the specified reconciler or {@code - * null} if no configuration exists for the reconciler + * @return the {@link ControllerConfiguration} associated with the specified reconciler or + * {@code null} if no configuration exists for the reconciler */ ControllerConfiguration getConfigurationFor(Reconciler reconciler); @@ -214,7 +214,7 @@ default int concurrentWorkflowExecutorThreads() { /** * Override to provide a custom {@link Metrics} implementation - * + * * @return the {@link Metrics} implementation */ default Metrics getMetrics() { @@ -224,7 +224,7 @@ default Metrics getMetrics() { /** * Override to provide a custom {@link ExecutorService} implementation to change how threads * handle concurrent reconciliations - * + * * @return the {@link ExecutorService} implementation to use for concurrent reconciliation * processing */ @@ -235,7 +235,7 @@ default ExecutorService getExecutorService() { /** * Override to provide a custom {@link ExecutorService} implementation to change how dependent * workflows are processed in parallel - * + * * @return the {@link ExecutorService} implementation to use for dependent workflow processing */ default ExecutorService getWorkflowExecutorService() { @@ -245,7 +245,7 @@ default ExecutorService getWorkflowExecutorService() { /** * Determines whether the associated Kubernetes client should be closed when the associated * {@link io.javaoperatorsdk.operator.Operator} is stopped. - * + * * @return {@code true} if the Kubernetes should be closed on stop, {@code false} otherwise */ default boolean closeClientOnStop() { @@ -255,7 +255,7 @@ default boolean closeClientOnStop() { /** * Override to provide a custom {@link DependentResourceFactory} implementation to change how * {@link io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource} are instantiated - * + * * @return the custom {@link DependentResourceFactory} implementation */ @SuppressWarnings("rawtypes") @@ -267,7 +267,7 @@ default DependentResourceFactory dependentResourceFactory() { * Retrieves the optional {@link LeaderElectionConfiguration} to specify how the associated * {@link io.javaoperatorsdk.operator.Operator} handles leader election to ensure only one * instance of the operator runs on the cluster at any given time - * + * * @return the {@link LeaderElectionConfiguration} */ default Optional getLeaderElectionConfiguration() { @@ -302,6 +302,17 @@ default Duration cacheSyncTimeout() { return Duration.ofMinutes(2); } + /** + * This is the timeout value that allows the reconciliation threads to gracefully shut down. If no + * value is set, the default is immediate shutdown. + * + * @return The duration of time to wait before terminating the reconciliation threads + * @since 5.0.0 + */ + default Duration reconciliationTerminationTimeout() { + return Duration.ZERO; + } + /** * Handler for an informer stop. Informer stops if there is a non-recoverable error. Like received * a resource that cannot be deserialized. @@ -329,7 +340,7 @@ default Optional getInformerStoppedHandler() { * Override to provide a custom {@link ManagedWorkflowFactory} implementation to change how * {@link io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflow} are * instantiated - * + * * @return the custom {@link ManagedWorkflowFactory} implementation */ @SuppressWarnings("rawtypes") @@ -339,7 +350,7 @@ default ManagedWorkflowFactory getWorkflowFactory() { /** * Override to provide a custom {@link ExecutorServiceManager} implementation - * + * * @return the custom {@link ExecutorServiceManager} implementation */ default ExecutorServiceManager getExecutorServiceManager() { @@ -356,9 +367,8 @@ default ExecutorServiceManager getExecutorServiceManager() { * SSA based create/update can be still used with the legacy matching, just overriding the match * method of Kubernetes Dependent Resource. * - * @since 4.4.0 - * * @return if SSA should be used for dependent resources + * @since 4.4.0 */ default boolean ssaBasedCreateUpdateMatchForDependentResources() { return true; @@ -443,9 +453,8 @@ default Set> defaultNonSSAResource() { *

* Disable this if you want to react to your own dependent resource updates * - * @since 4.5.0 - * * @return if special annotation should be used for dependent resource to filter events + * @since 4.5.0 */ default boolean previousAnnotationForDependentResourcesEventFiltering() { return true; @@ -460,9 +469,8 @@ default boolean previousAnnotationForDependentResourcesEventFiltering() { * logic, and you want to further minimize the amount of work done / updates issued by the * operator. * - * @since 4.5.0 - * * @return if resource version should be parsed (as integer) + * @since 4.5.0 */ default boolean parseResourceVersionsForEventFilteringAndCaching() { return false; @@ -475,8 +483,8 @@ default boolean parseResourceVersionsForEventFilteringAndCaching() { * * @return {@code true} if Server-Side Apply (SSA) should be used when patching the primary * resources, {@code false} otherwise - * @since 5.0.0 * @see ConfigurationServiceOverrider#withUseSSAToPatchPrimaryResource(boolean) + * @since 5.0.0 */ default boolean useSSAToPatchPrimaryResource() { return true; @@ -487,7 +495,7 @@ default boolean useSSAToPatchPrimaryResource() { * Determines whether resources retrieved from caches such as via calls to * {@link Context#getSecondaryResource(Class)} should be defensively cloned first. *

- * + * *

* Defensive cloning to prevent problematic cache modifications (modifying the resource would * otherwise modify the stored copy in the cache) was transparently done in previous JOSDK @@ -495,10 +503,9 @@ default boolean useSSAToPatchPrimaryResource() { * Server-Side Apply, where you should create a new copy of your resource with only modified * fields, such modifications of these resources are less likely to occur. *

- * + * * @return {@code true} if resources should be defensively cloned before returning them from * caches, {@code false} otherwise - * * @since 5.0.0 */ default boolean cloneSecondaryResourcesWhenGettingFromCache() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java index 24f9f36e5b..cbd6399afe 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java @@ -33,6 +33,7 @@ public class ConfigurationServiceOverrider { private InformerStoppedHandler informerStoppedHandler; private Boolean stopOnInformerErrorDuringStartup; private Duration cacheSyncTimeout; + private Duration reconciliationTerminationTimeout; private Boolean ssaBasedCreateUpdateMatchForDependentResources; private Set> defaultNonSSAResource; private Boolean previousAnnotationForDependentResources; @@ -132,6 +133,12 @@ public ConfigurationServiceOverrider withCacheSyncTimeout(Duration cacheSyncTime return this; } + public ConfigurationServiceOverrider withReconciliationTerminationTimeout( + Duration reconciliationTerminationTimeout) { + this.reconciliationTerminationTimeout = reconciliationTerminationTimeout; + return this; + } + public ConfigurationServiceOverrider withSSABasedCreateUpdateMatchForDependentResources( boolean value) { this.ssaBasedCreateUpdateMatchForDependentResources = value; @@ -273,6 +280,12 @@ public Duration cacheSyncTimeout() { return overriddenValueOrDefault(cacheSyncTimeout, ConfigurationService::cacheSyncTimeout); } + @Override + public Duration reconciliationTerminationTimeout() { + return overriddenValueOrDefault(reconciliationTerminationTimeout, + ConfigurationService::reconciliationTerminationTimeout); + } + @Override public boolean ssaBasedCreateUpdateMatchForDependentResources() { return overriddenValueOrDefault(ssaBasedCreateUpdateMatchForDependentResources, diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java index 4c374e09f2..0e2b8e9cc2 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.api.config; +import java.time.Duration; import java.util.Optional; import java.util.concurrent.Executors; @@ -63,6 +64,7 @@ public R clone(R object) { .withLeaderElectionConfiguration(new LeaderElectionConfiguration("newLease", "newLeaseNS")) .withInformerStoppedHandler((informer, ex) -> { }) + .withReconciliationTerminationTimeout(Duration.ofSeconds(30)) .build(); assertNotEquals(config.closeClientOnStop(), overridden.closeClientOnStop()); @@ -77,6 +79,8 @@ public R clone(R object) { overridden.getLeaderElectionConfiguration()); assertNotEquals(config.getInformerStoppedHandler(), overridden.getLeaderElectionConfiguration()); + assertNotEquals(config.reconciliationTerminationTimeout(), + overridden.reconciliationTerminationTimeout()); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java index 715921ecbb..e6a38326d5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java @@ -18,26 +18,21 @@ public class GracefulStopIT { public static final String TEST_1 = "test1"; - public static final String TEST_2 = "test2"; @RegisterExtension LocallyRunOperatorExtension operator = LocallyRunOperatorExtension.builder() - .withConfigurationService(o -> o.withCloseClientOnStop(false)) + .withConfigurationService(o -> o.withCloseClientOnStop(false) + .withReconciliationTerminationTimeout(Duration.ofMillis(RECONCILER_SLEEP))) .withReconciler(new GracefulStopTestReconciler()) .build(); @Test - void stopsGracefullyWIthTimeout() { - testGracefulStop(TEST_1, RECONCILER_SLEEP, 2); + void stopsGracefullyWithTimeoutConfiguration() { + testGracefulStop(TEST_1, 2); } - @Test - void stopsGracefullyWithExpiredTimeout() { - testGracefulStop(TEST_2, RECONCILER_SLEEP / 5, 1); - } - - private void testGracefulStop(String resourceName, int stopTimeout, int expectedFinalGeneration) { + private void testGracefulStop(String resourceName, int expectedFinalGeneration) { var testRes = operator.create(testResource(resourceName)); await().untilAsserted(() -> { var r = operator.get(GracefulStopTestCustomResource.class, resourceName); @@ -54,7 +49,7 @@ private void testGracefulStop(String resourceName, int stopTimeout, int expected () -> assertThat(operator.getReconcilerOfType(GracefulStopTestReconciler.class) .getNumberOfExecutions()).isEqualTo(2)); - operator.getOperator().stop(Duration.ofMillis(stopTimeout)); + operator.getOperator().stop(); await().untilAsserted(() -> { var r = operator.get(GracefulStopTestCustomResource.class, resourceName); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java index 3a6f4d05e9..a8288db7af 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -76,7 +76,7 @@ void beforeEach(TestInfo testInfo) { @AfterEach void cleanup() { if (operator != null) { - operator.stop(Duration.ofSeconds(1)); + operator.stop(); } adminClient.resource(dependentConfigMap()).delete(); adminClient.resource(testCustomResource()).delete(); @@ -321,6 +321,7 @@ Operator startOperator(boolean stopOnInformerErrorDuringStartup, boolean addStop co.withKubernetesClient(clientUsingServiceAccount()); co.withStopOnInformerErrorDuringStartup(stopOnInformerErrorDuringStartup); co.withCacheSyncTimeout(Duration.ofMillis(3000)); + co.withReconciliationTerminationTimeout(Duration.ofSeconds(1)); if (addStopHandler) { co.withInformerStoppedHandler((informer, ex) -> replacementStopHandlerCalled = true); } From 22d62b632cf9f45fa50a6e6e3b4a5a5a6453edbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 8 Aug 2024 21:18:57 +0200 Subject: [PATCH 67/96] refactor: move integration tests to feature packages and sub packages based on type (#2483) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: integration tests moved to feature packages and sub packages pased on type Signed-off-by: Attila Mészáros * fix resource paths Signed-off-by: Attila Mészáros * fixes Signed-off-by: Attila Mészáros * link and test fixes Signed-off-by: Attila Mészáros * format Signed-off-by: Attila Mészáros * wip Signed-off-by: Attila Mészáros * old service Signed-off-by: Attila Mészáros * test fix Signed-off-by: Attila Mészáros * refactor: remove unneeded classes Signed-off-by: Chris Laprun * fix: typo in package name Signed-off-by: Chris Laprun --------- Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun --- .../en/docs/dependent-resources/_index.md | 22 +- docs/content/en/docs/features/_index.md | 12 +- docs/content/en/docs/workflows/_index.md | 10 +- .../api/config/ConfigurationService.java | 2 +- .../config/ConfigurationServiceOverrider.java | 1 - .../operator/{ => baseapi}/ConcurrencyIT.java | 6 +- .../InformerErrorHandlerStartIT.java | 3 +- .../LeaderElectionPermissionIT.java | 6 +- .../BuiltInResourceCleanerIT.java | 13 +- .../BuiltInResourceCleanerReconciler.java} | 4 +- .../changenamespace}/ChangeNamespaceIT.java | 5 +- .../ChangeNamespaceTestCustomResource.java | 2 +- ...angeNamespaceTestCustomResourceStatus.java | 2 +- .../ChangeNamespaceTestReconciler.java | 2 +- .../CleanerForReconcilerCustomResource.java | 2 +- .../CleanerForReconcilerIT.java | 4 +- .../CleanerForReconcilerTestReconciler.java | 2 +- .../CleanupConflictCustomResource.java | 2 +- .../CleanupConflictCustomResourceStatus.java | 2 +- .../cleanupconflict}/CleanupConflictIT.java | 6 +- .../CleanupConflictReconciler.java | 2 +- .../ClusterScopedCustomResource.java | 2 +- ...ClusterScopedCustomResourceReconciler.java | 2 +- .../ClusterScopedCustomResourceSpec.java | 2 +- .../ClusterScopedCustomResourceStatus.java | 2 +- .../ClusterScopedResourceIT.java | 5 +- ...teUpdateEventFilterTestCustomResource.java | 2 +- ...dateEventFilterTestCustomResourceSpec.java | 2 +- ...CreateUpdateEventFilterTestReconciler.java | 2 +- ...pdateInformerEventSourceEventFilterIT.java | 7 +- .../PreviousAnnotationDisabledIT.java | 4 +- .../deployment/DeploymentReconciler.java | 2 +- .../KubernetesResourceStatusUpdateIT.java | 5 +- ...EventSourceRegistrationCustomResource.java | 2 +- ...namicGenericEventSourceRegistrationIT.java | 4 +- ...ericEventSourceRegistrationReconciler.java | 5 +- .../ErrorStatusHandlerIT.java | 4 +- .../ErrorStatusHandlerTestCustomResource.java | 2 +- ...StatusHandlerTestCustomResourceStatus.java | 2 +- .../ErrorStatusHandlerTestReconciler.java | 2 +- .../{ => baseapi/event}/EventSourceIT.java | 5 +- .../EventSourceTestCustomReconciler.java | 2 +- .../event/EventSourceTestCustomResource.java | 2 +- .../EventSourceTestCustomResourceSpec.java | 2 +- .../EventSourceTestCustomResourceStatus.java | 2 +- .../{ => baseapi/filter}/FilterIT.java | 7 +- .../filter/FilterTestCustomResource.java | 2 +- .../filter/FilterTestReconciler.java | 2 +- .../filter/FilterTestResourceSpec.java | 2 +- .../filter/FilterTestResourceStatus.java | 5 + .../filter/UpdateFilter.java | 4 +- ...ernetesResourceHandlingCustomResource.java | 4 +- .../GenericKubernetesResourceHandlingIT.java | 9 +- ...cKubernetesResourceHandlingReconciler.java | 2 +- .../gracefulstop}/GracefulStopIT.java | 7 +- .../GracefulStopTestCustomResource.java | 2 +- .../GracefulStopTestCustomResourceSpec.java | 2 +- .../GracefulStopTestCustomResourceStatus.java | 2 +- .../GracefulStopTestReconciler.java | 2 +- .../InformerEventSourceIT.java | 10 +- ...formerEventSourceTestCustomReconciler.java | 2 +- ...InformerEventSourceTestCustomResource.java | 2 +- ...erEventSourceTestCustomResourceStatus.java | 2 +- .../labelselector}/LabelSelectorIT.java | 9 +- .../LabelSelectorTestCustomResource.java | 2 +- .../LabelSelectorTestReconciler.java | 6 +- ...ElectionChangeNamespaceCustomResource.java | 2 +- .../LeaderElectionChangeNamespaceIT.java | 4 +- ...aderElectionChangeNamespaceReconciler.java | 2 +- ...anualObservedGenerationCustomResource.java | 2 +- .../ManualObservedGenerationIT.java | 5 +- .../ManualObservedGenerationReconciler.java | 2 +- .../ManualObservedGenerationSpec.java | 2 +- .../ManualObservedGenerationStatus.java | 2 +- .../maxinterval}/MaxIntervalIT.java | 4 +- .../MaxIntervalTestCustomResource.java | 4 +- .../MaxIntervalTestReconciler.java | 2 +- .../MaxIntervalAfterRetryIT.java | 4 +- ...xIntervalAfterRetryTestCustomResource.java | 2 +- .../MaxIntervalAfterRetryTestReconciler.java | 2 +- ...tipleReconcilerSameTypeCustomResource.java | 2 +- .../MultipleReconcilerSameTypeIT.java | 5 +- ...MultipleReconcilerSameTypeReconciler1.java | 2 +- ...MultipleReconcilerSameTypeReconciler2.java | 2 +- .../MultipleReconcilerSameTypeStatus.java | 2 +- ...pleSecondaryEventSourceCustomResource.java | 4 +- .../MultipleSecondaryEventSourceIT.java | 4 +- ...ultipleSecondaryEventSourceReconciler.java | 2 +- .../multiversioncrd}/MultiVersionCRDIT.java | 8 +- .../MultiVersionCRDTestCustomResource1.java | 2 +- .../MultiVersionCRDTestCustomResource2.java | 2 +- ...ultiVersionCRDTestCustomResourceSpec1.java | 2 +- ...ultiVersionCRDTestCustomResourceSpec2.java | 2 +- ...tiVersionCRDTestCustomResourceStatus1.java | 2 +- ...tiVersionCRDTestCustomResourceStatus2.java | 2 +- .../MultiVersionCRDTestReconciler1.java | 2 +- .../MultiVersionCRDTestReconciler2.java | 2 +- ...tReconciliationImminentCustomResource.java | 2 +- .../NextReconciliationImminentIT.java | 4 +- .../NextReconciliationImminentReconciler.java | 2 +- .../NextReconciliationImminentStatus.java | 2 +- ...hResourceAndStatusNoSSACustomResource.java | 2 +- .../PatchResourceAndStatusNoSSAIT.java | 6 +- ...PatchResourceAndStatusNoSSAReconciler.java | 2 +- .../PatchResourceAndStatusNoSSASpec.java | 2 +- .../PatchResourceAndStatusNoSSAStatus.java | 2 +- .../PatchResourceAndStatusWithSSAIT.java | 3 +- ...tchResourceAndStatusWithSSAReconciler.java | 2 +- .../PatchResourceWithSSACustomResource.java | 2 +- .../PatchResourceWithSSAIT.java | 3 +- .../PatchResourceWithSSAReconciler.java | 2 +- .../PatchResourceWithSSASpec.java | 2 +- .../PatchResourceWithSSAStatus.java | 2 +- .../PatchWithSSAITBase.java | 5 +- .../PerResourceEventSourceCustomResource.java | 2 +- .../PerResourcePollingEventSourceIT.java | 4 +- ...ourcePollingEventSourceTestReconciler.java | 2 +- .../AbstractPrimaryIndexerTestReconciler.java | 2 +- .../primaryindexer}/PrimaryIndexerIT.java | 11 +- .../PrimaryIndexerTestCustomResource.java | 2 +- .../PrimaryIndexerTestCustomResourceSpec.java | 2 +- ...rimaryIndexerTestCustomResourceStatus.java | 2 +- .../PrimaryIndexerTestReconciler.java | 2 +- .../primarytosecondary/Cluster.java | 4 +- .../primarytosecondary/Job.java | 4 +- .../primarytosecondary/JobReconciler.java | 2 +- .../primarytosecondary/JobSpec.java | 2 +- .../PrimaryToSecondaryIT.java | 6 +- .../PrimaryToSecondaryMissingIT.java | 8 +- .../ratelimit/RateLimitCustomResource.java | 4 +- .../RateLimitCustomResourceSpec.java | 2 +- .../RateLimitCustomResourceStatus.java | 5 + .../{ => baseapi/ratelimit}/RateLimitIT.java | 7 +- .../ratelimit/RateLimitReconciler.java | 2 +- .../operator/{ => baseapi/retry}/RetryIT.java | 6 +- .../retry}/RetryMaxAttemptIT.java | 6 +- .../retry/RetryTestCustomReconciler.java | 2 +- .../retry/RetryTestCustomResource.java | 2 +- .../retry/RetryTestCustomResourceSpec.java | 2 +- .../retry/RetryTestCustomResourceStatus.java | 2 +- .../simple}/ReconcilerExecutorIT.java | 4 +- .../simple/TestCustomResource.java | 2 +- .../simple/TestCustomResourceSpec.java | 2 +- .../simple/TestCustomResourceStatus.java | 2 +- .../simple/TestReconciler.java | 2 +- .../StatusPatchLockingCustomResource.java | 2 +- .../StatusPatchLockingCustomResourceSpec.java | 2 +- ...tatusPatchLockingCustomResourceStatus.java | 2 +- .../StatusPatchLockingReconciler.java | 2 +- .../StatusPatchNotLockingIT.java | 9 +- .../StatusPatchSSAMigrationIT.java | 6 +- .../StatusUpdateLockingCustomResource.java | 2 +- ...atusUpdateLockingCustomResourceStatus.java | 2 +- .../StatusUpdateLockingIT.java | 6 +- .../StatusUpdateLockingReconciler.java | 2 +- .../SubResourceTestCustomReconciler.java | 2 +- .../SubResourceTestCustomResource.java | 2 +- .../SubResourceTestCustomResourceSpec.java | 2 +- .../SubResourceTestCustomResourceStatus.java | 2 +- .../subresource}/SubResourceUpdateIT.java | 7 +- ...modifiableDependentPartCustomResource.java | 2 +- .../UnmodifiableDependentPartIT.java | 9 +- .../UnmodifiableDependentPartReconciler.java | 2 +- .../UnmodifiableDependentPartSpec.java | 2 +- .../UnmodifiablePartConfigMapDependent.java | 2 +- ...sInCleanupAndRescheduleCustomResource.java | 2 +- ...tusInCleanupAndRescheduleCustomStatus.java | 2 +- .../UpdateStatusInCleanupAndRescheduleIT.java | 4 +- ...tatusInCleanupAndRescheduleReconciler.java | 2 +- .../config/BaseConfigurationServiceTest.java | 25 +- .../bulkdependent/BulkDependentDeleterIT.java | 6 +- .../bulkdependent/BulkDependentTestBase.java | 11 +- .../BulkDependentTestCustomResource.java | 2 +- .../bulkdependent/BulkDependentTestSpec.java | 2 +- .../BulkDependentTestStatus.java | 2 +- .../CRUDConfigMapBulkDependentResource.java | 2 +- ...ConfigMapDeleterBulkDependentResource.java | 2 +- .../BulkDependentWithConditionIT.java | 13 +- ...DependentWithReadyConditionReconciler.java | 5 +- .../condition}/SampleBulkCondition.java | 4 +- .../external}/BulkExternalDependentIT.java | 6 +- .../ExternalBulkDependentResource.java | 4 +- .../ExternalBulkResourceReconciler.java | 4 +- .../external/ExternalResource.java | 2 +- .../external/ExternalServiceMock.java | 2 +- .../managed}/ManagedBulkDependentIT.java | 8 +- .../ManagedBulkDependentReconciler.java | 4 +- .../ManagedDeleterBulkReconciler.java | 4 +- .../readonly}/ReadOnlyBulkDependentIT.java | 8 +- .../ReadOnlyBulkDependentResource.java | 4 +- .../ReadOnlyBulkReadyPostCondition.java | 4 +- .../readonly/ReadOnlyBulkReconciler.java | 6 +- .../StandaloneBulkDependentIT.java | 6 +- .../StandaloneBulkDependentReconciler.java | 5 +- ...anerForManagedDependentCustomResource.java | 2 +- ...erForManagedDependentResourcesOnlyIT.java} | 7 +- ...anerForManagedDependentTestReconciler.java | 2 +- .../ConfigMapDependentResource.java | 2 +- .../ConfigMapDependentResource.java | 2 +- ...xistingDependentWithSSACustomResource.java | 2 +- ...eOnlyIfNotExistingDependentWithSSAIT.java} | 6 +- ...NotExistingDependentWithSSAReconciler.java | 2 +- .../DependentAnnotationSecondaryMapperIT.java | 4 +- ...ntAnnotationSecondaryMapperReconciler.java | 2 +- ...dentAnnotationSecondaryMapperResource.java | 4 +- ...stomMappingConfigMapDependentResource.java | 2 +- .../DependentCustomMappingAnnotationIT.java | 10 +- .../DependentCustomMappingCustomResource.java | 2 +- .../DependentCustomMappingReconciler.java | 2 +- .../DependentCustomMappingSpec.java | 2 +- .../ConfigMapDependentResource.java | 2 +- ...ndentDifferentNamespaceCustomResource.java | 2 +- .../DependentDifferentNamespaceIT.java | 8 +- ...DependentDifferentNamespaceReconciler.java | 2 +- .../DependentDifferentNamespaceSpec.java | 2 +- .../dependentfilter}/DependentFilterIT.java | 9 +- .../DependentFilterTestCustomResource.java | 4 +- .../DependentFilterTestReconciler.java | 2 +- .../DependentFilterTestResourceSpec.java | 2 +- .../FilteredDependentConfigMap.java | 4 +- .../dependentfilter/UpdateFilter.java | 6 +- .../ConfigMapDependentResource.java | 2 +- ...entOperationEventFilterCustomResource.java | 2 +- ...perationEventFilterCustomResourceSpec.java | 2 +- ...entFilterCustomResourceTestReconciler.java | 2 +- .../DependentOperationEventFilterIT.java | 6 +- .../ConfigMapDependentResource.java | 2 +- ...pendentReInitializationCustomResource.java | 2 +- .../DependentReInitializationIT.java | 6 +- .../DependentReInitializationReconciler.java | 2 +- .../DependentResourceCrossRefIT.java | 4 +- .../DependentResourceCrossRefReconciler.java | 4 +- .../DependentResourceCrossRefResource.java | 4 +- .../DependentSSACustomResource.java | 2 +- .../dependentssa}/DependentSSAMatchingIT.java | 6 +- .../DependentSSAMigrationIT.java | 7 +- .../dependentssa/DependentSSAReconciler.java | 2 +- .../dependentssa/DependentSSASpec.java | 2 +- .../dependentssa/SSAConfigMapDependent.java | 2 +- .../ExternalStateCustomResource.java | 2 +- .../ExternalStateDependentIT.java | 7 +- .../ExternalStateDependentReconciler.java | 2 +- .../externalstate}/ExternalStateIT.java | 7 +- .../ExternalStateReconciler.java | 2 +- .../externalstate/ExternalStateSpec.java | 2 +- .../externalstate}/ExternalStateTestBase.java | 6 +- .../ExternalWithStateDependentResource.java | 8 +- ...ulkDependentResourceExternalWithState.java | 9 +- ...ernalStateBulkDependentCustomResource.java | 2 +- .../ExternalStateBulkDependentReconciler.java | 2 +- .../ExternalStateBulkIT.java | 5 +- .../ExternalStateBulkSpec.java | 2 +- .../GenericKubernetesDependentSpec.java | 2 +- .../GenericKubernetesDependentTestBase.java | 7 +- .../ConfigMapGenericKubernetesDependent.java | 2 +- ...ernetesDependentManagedCustomResource.java | 4 +- .../GenericKubernetesDependentManagedIT.java | 9 +- ...cKubernetesDependentManagedReconciler.java | 2 +- .../ConfigMapGenericKubernetesDependent.java | 2 +- ...etesDependentStandaloneCustomResource.java | 4 +- ...enericKubernetesDependentStandaloneIT.java | 9 +- ...bernetesDependentStandaloneReconciler.java | 3 +- .../ConfigMapDependentResource.java | 2 +- .../InformerRelatedBehaviorITS.java | 11 +- ...rmerRelatedBehaviorTestCustomResource.java | 2 +- ...InformerRelatedBehaviorTestReconciler.java | 2 +- ...ntGarbageCollectionTestCustomResource.java | 4 +- ...rbageCollectionTestCustomResourceSpec.java | 2 +- ...endentGarbageCollectionTestReconciler.java | 2 +- ...ubernetesDependentGarbageCollectionIT.java | 6 +- .../MultipleDependentResourceConfigMap.java | 2 +- ...ltipleDependentResourceCustomResource.java | 4 +- .../MultipleDependentResourceIT.java | 16 +- .../MultipleDependentResourceReconciler.java | 2 +- .../MultipleDependentResourceSpec.java | 2 +- .../MultipleDependentResourceConfigMap.java | 8 +- ...esourceCustomResourceNoDiscriminator.java} | 6 +- ...ntResourceWithDiscriminatorReconciler.java | 18 +- ...ependentResourceWithNoDiscriminatorIT.java | 13 +- ...tipleDependentSameTypeMultiInformerIT.java | 7 +- ...endentResourceMultiInformerConfigMap1.java | 4 +- ...endentResourceMultiInformerConfigMap2.java | 4 +- ...ntResourceMultiInformerCustomResource.java | 2 +- ...endentResourceMultiInformerReconciler.java | 2 +- ...gedDependentResourceMultiInformerSpec.java | 2 +- ...gedDependentNoDiscriminatorConfigMap1.java | 2 +- ...gedDependentNoDiscriminatorConfigMap2.java | 4 +- ...ependentNoDiscriminatorCustomResource.java | 2 +- ...ipleManagedDependentNoDiscriminatorIT.java | 5 +- ...leManagedDependentNoDiscriminatorSpec.java | 2 +- ...dentSameTypeNoDiscriminatorReconciler.java | 4 +- ...pleManagedDependentResourceConfigMap1.java | 2 +- ...pleManagedDependentResourceConfigMap2.java | 6 +- ...anagedDependentResourceCustomResource.java | 2 +- ...pleManagedDependentResourceReconciler.java | 4 +- .../MultipleManagedDependentResourceSpec.java | 2 +- .../MultipleManagedDependentSameTypeIT.java | 7 +- .../AbstractExternalDependentResource.java | 2 +- .../ExternalDependentResource1.java | 2 +- .../ExternalDependentResource2.java | 2 +- ...ternalDependentResourceCustomResource.java | 4 +- ...edExternalDependentResourceReconciler.java | 4 +- ...pleManagedExternalDependentSameTypeIT.java | 6 +- .../MultiOwnerDependentTriggeringIT.java | 6 +- .../MultipleOwnerDependentConfigMap.java | 2 +- .../MultipleOwnerDependentCustomResource.java | 2 +- .../MultipleOwnerDependentReconciler.java | 2 +- .../MultipleOwnerDependentSpec.java | 2 +- .../DependentPrimaryIndexerIT.java | 4 +- ...DependentPrimaryIndexerTestReconciler.java | 6 +- .../ConfigMapDependent.java | 2 +- .../ConfigMapReconcilePrecondition.java | 6 +- ...aryToSecondaryDependentCustomResource.java | 2 +- .../PrimaryToSecondaryDependentIT.java | 11 +- ...PrimaryToSecondaryDependentReconciler.java | 6 +- .../PrimaryToSecondaryDependentSpec.java | 2 +- .../SecretDependent.java | 4 +- .../readonly/ConfigMapReader.java | 2 +- .../readonly/ReadOnlyDependent.java | 2 +- .../restart/ConfigMapDependentResource.java | 2 +- .../restart}/OperatorRestartIT.java | 5 +- .../restart/RestartTestCustomResource.java | 2 +- .../restart/RestartTestReconciler.java | 2 +- .../ServiceDependentResource.java | 6 +- .../ServiceStrictMatcherIT.java | 6 +- .../ServiceStrictMatcherSpec.java | 2 +- ...erviceStrictMatcherTestCustomResource.java | 2 +- .../ServiceStrictMatcherTestReconciler.java | 2 +- .../ServiceAccountDependentResource.java | 4 +- .../SpecialResourceCustomResource.java | 2 +- .../SpecialResourceSpec.java | 2 +- .../SpecialResourceTestReconciler.java | 2 +- .../SpecialResourcesDependentIT.java | 9 +- .../SSALegacyMatcherCustomResource.java | 2 +- .../SSALegacyMatcherReconciler.java | 2 +- .../SSALegacyMatcherSpec.java | 2 +- .../SSAWithLegacyMatcherIT.java | 6 +- .../ServiceDependentResource.java | 6 +- .../StandaloneDependentResourceIT.java | 5 +- ...StandaloneDependentTestCustomResource.java | 4 +- ...daloneDependentTestCustomResourceSpec.java | 2 +- .../StandaloneDependentTestReconciler.java | 5 +- ...efulSetDesiredSanitizerCustomResource.java | 2 +- ...lSetDesiredSanitizerDependentResource.java | 5 +- .../StatefulSetDesiredSanitizerIT.java | 6 +- ...StatefulSetDesiredSanitizerReconciler.java | 2 +- .../StatefulSetDesiredSanitizerSpec.java | 2 +- .../ComplexDependentSpec.java | 14 - .../ComplexDependentStatus.java | 15 - ...teEventFilterTestCustomResourceStatus.java | 5 - ...notationSecondaryMapperResourceStatus.java | 5 - .../DependentFilterTestResourceStatus.java | 5 - ...pendentResourceCrossRefResourceStatus.java | 5 - .../filter/FilterTestResourceStatus.java | 5 - ...ageCollectionTestCustomResourceStatus.java | 5 - .../MaxIntervalTestCustomResourceStatus.java | 5 - .../MultipleDependentResourceStatus.java | 5 - ...endentResourceWithDiscriminatorStatus.java | 5 - .../MultipleSecondaryEventSourceStatus.java | 5 - .../primarytosecondary/ClusterStatus.java | 5 - .../sample/primarytosecondary/JobStatus.java | 5 - .../RateLimitCustomResourceStatus.java | 5 - ...loneDependentTestCustomResourceStatus.java | 5 - .../operator/support/TestUtils.java | 4 +- .../ComplexWorkflowCustomResource.java} | 6 +- .../complexdependent/ComplexWorkflowIT.java} | 29 +- .../ComplexWorkflowReconciler.java} | 34 +- .../complexdependent/ComplexWorkflowSpec.java | 14 + .../ComplexWorkflowStatus.java | 15 + .../dependent/BaseDependentResource.java | 10 +- .../dependent/BaseService.java | 11 +- .../dependent/BaseStatefulSet.java | 11 +- .../dependent/FirstService.java | 2 +- .../dependent/FirstStatefulSet.java | 2 +- .../dependent/SecondService.java | 2 +- .../dependent/SecondStatefulSet.java | 2 +- .../dependent/StatefulSetReadyCondition.java | 12 +- .../CRDPresentActivationConditionIT.java | 5 +- .../CRDPresentActivationCustomResource.java | 2 +- .../CRDPresentActivationDependent.java | 2 +- ...sentActivationDependentCustomResource.java | 2 +- .../CRDPresentActivationReconciler.java | 2 +- .../ConfigMapDependent.java | 2 +- ...tDefaultDeleteConditionCustomResource.java | 2 +- ...ndentDefaultDeleteConditionReconciler.java | 2 +- .../ManagedDependentDeleteConditionIT.java | 4 +- .../SecretDependent.java | 2 +- .../ActivationCondition.java | 2 +- .../ConfigMapDependentResource1.java | 2 +- .../ConfigMapDependentResource2.java | 2 +- ...ipleDependentActivationCustomResource.java | 2 +- ...MultipleDependentActivationReconciler.java | 2 +- .../MultipleDependentActivationSpec.java | 2 +- .../MultipleDependentWithActivationIT.java | 3 +- .../SecretDependentResource.java | 2 +- .../ConfigMapDependentResource1.java | 2 +- .../ConfigMapDependentResource2.java | 2 +- ...OrderedManagedDependentCustomResource.java | 2 +- .../OrderedManagedDependentIT.java | 6 +- ...OrderedManagedDependentTestReconciler.java | 2 +- .../ConfigMapDependentResource.java | 2 +- .../TestActivcationCondition.java | 2 +- ...rkflowActivationCleanupCustomResource.java | 2 +- .../WorkflowActivationCleanupIT.java | 6 +- .../WorkflowActivationCleanupReconciler.java | 2 +- .../WorkflowActivationCleanupSpec.java | 2 +- .../ConfigMapDependentResource.java | 2 +- .../IsOpenShiftCondition.java | 2 +- .../RouteDependentResource.java | 2 +- ...flowActivationConditionCustomResource.java | 2 +- .../WorkflowActivationConditionIT.java | 7 +- ...WorkflowActivationConditionReconciler.java | 2 +- .../WorkflowActivationConditionSpec.java | 2 +- .../ConfigMapDeletePostCondition.java | 2 +- .../ConfigMapDependentResource.java | 2 +- .../ConfigMapReconcileCondition.java | 2 +- .../DeploymentDependentResource.java | 5 +- .../DeploymentReadyCondition.java | 2 +- .../WorkflowAllFeatureCustomResource.java | 2 +- .../WorkflowAllFeatureIT.java | 9 +- .../WorkflowAllFeatureReconciler.java | 4 +- .../WorkflowAllFeatureSpec.java | 2 +- .../WorkflowAllFeatureStatus.java | 2 +- .../ConfigMapDependent.java | 2 +- ...WorkflowExplicitCleanupCustomResource.java | 2 +- .../WorkflowExplicitCleanupIT.java | 4 +- .../WorkflowExplicitCleanupReconciler.java | 2 +- .../WorkflowExplicitCleanupSpec.java | 2 +- .../ConfigMapDependent.java | 2 +- ...kflowExplicitInvocationCustomResource.java | 2 +- .../WorkflowExplicitInvocationIT.java | 5 +- .../WorkflowExplicitInvocationReconciler.java | 2 +- .../WorkflowExplicitInvocationSpec.java | 2 +- .../ActivationCondition.java | 2 +- .../ConfigMapDependentResource.java | 2 +- .../SecretDependentResource.java | 2 +- ...kflowMultipleActivationCustomResource.java | 2 +- .../WorkflowMultipleActivationIT.java | 5 +- .../WorkflowMultipleActivationReconciler.java | 2 +- .../WorkflowMultipleActivationSpec.java | 2 +- .../ConfigMapDependent.java | 2 +- ...wExceptionsInReconcilerCustomResource.java | 2 +- ...kflowExceptionsInReconcilerReconciler.java | 2 +- .../WorkflowSilentExceptionHandlingIT.java | 4 +- ...er-elector-stop-noaccess-role-binding.yaml | 0 .../leader-elector-stop-role-noaccess.yaml | 0 .../rback-test-full-access-role.yaml | 0 .../rback-test-no-configmap-access.yaml | 0 .../rback-test-no-cr-access.yaml | 0 ...back-test-only-main-ns-access-binding.yaml | 0 .../rback-test-only-main-ns-access.yaml | 0 .../rback-test-role-binding.yaml | 0 .../statefulset.yaml | 0 .../workflow/complexdependent/service.yaml | 16 + .../complexdependent/statefulset.yaml | 46 + pom.xml | 927 +++++++++--------- 456 files changed, 1262 insertions(+), 1477 deletions(-) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi}/ConcurrencyIT.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi}/InformerErrorHandlerStartIT.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi}/LeaderElectionPermissionIT.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/builtinresourcecleaner}/BuiltInResourceCleanerIT.java (74%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/builtinresourcecleaner/ObservedGenerationTestReconciler.java => baseapi/builtinresourcecleaner/BuiltInResourceCleanerReconciler.java} (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/changenamespace}/ChangeNamespaceIT.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/changenamespace/ChangeNamespaceTestCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/changenamespace/ChangeNamespaceTestCustomResourceStatus.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/changenamespace/ChangeNamespaceTestReconciler.java (98%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/cleanerforreconciler/CleanerForReconcilerCustomResource.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/cleanerforreconciler}/CleanerForReconcilerIT.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/cleanerforreconciler/CleanerForReconcilerTestReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/cleanupconflict/CleanupConflictCustomResource.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/cleanupconflict/CleanupConflictCustomResourceStatus.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/cleanupconflict}/CleanupConflictIT.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/cleanupconflict/CleanupConflictReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/clusterscopedresource/ClusterScopedCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/clusterscopedresource/ClusterScopedCustomResourceReconciler.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/clusterscopedresource/ClusterScopedCustomResourceSpec.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/clusterscopedresource/ClusterScopedCustomResourceStatus.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/clusterscopedresource}/ClusterScopedResourceIT.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceSpec.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java (98%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/createupdateeventfilter}/CreateUpdateInformerEventSourceEventFilterIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/createupdateeventfilter}/PreviousAnnotationDisabledIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/deployment/DeploymentReconciler.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/deployment}/KubernetesResourceStatusUpdateIT.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationCustomResource.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/dynamicgenericeventsourceregistration}/DynamicGenericEventSourceRegistrationIT.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/errorstatushandler}/ErrorStatusHandlerIT.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/errorstatushandler/ErrorStatusHandlerTestCustomResource.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/errorstatushandler/ErrorStatusHandlerTestCustomResourceStatus.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/errorstatushandler/ErrorStatusHandlerTestReconciler.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/event}/EventSourceIT.java (84%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/event/EventSourceTestCustomReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/event/EventSourceTestCustomResource.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/event/EventSourceTestCustomResourceSpec.java (82%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/event/EventSourceTestCustomResourceStatus.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/filter}/FilterIT.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/filter/FilterTestCustomResource.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/filter/FilterTestReconciler.java (98%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/filter/FilterTestResourceSpec.java (80%) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestResourceStatus.java rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/filter/UpdateFilter.java (69%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/generickubernetesresource => baseapi}/generickubernetesresourcehandling/GenericKubernetesResourceHandlingCustomResource.java (70%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/generickubernetesresourcehandling}/GenericKubernetesResourceHandlingIT.java (64%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/generickubernetesresource => baseapi}/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/gracefulstop}/GracefulStopIT.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/gracefulstop/GracefulStopTestCustomResource.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/gracefulstop/GracefulStopTestCustomResourceSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/gracefulstop/GracefulStopTestCustomResourceStatus.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/gracefulstop/GracefulStopTestReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/informereventsource}/InformerEventSourceIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/informereventsource/InformerEventSourceTestCustomReconciler.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/informereventsource/InformerEventSourceTestCustomResource.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/informereventsource/InformerEventSourceTestCustomResourceStatus.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/labelselector}/LabelSelectorIT.java (75%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/labelselector/LabelSelectorTestCustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/labelselector/LabelSelectorTestReconciler.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/leaderelectionchangenamespace/LeaderElectionChangeNamespaceCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/leaderelectionchangenamespace}/LeaderElectionChangeNamespaceIT.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/leaderelectionchangenamespace/LeaderElectionChangeNamespaceReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/manualobservedgeneration/ManualObservedGenerationCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/manualobservedgeneration}/ManualObservedGenerationIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/manualobservedgeneration/ManualObservedGenerationReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/manualobservedgeneration/ManualObservedGenerationSpec.java (73%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/manualobservedgeneration/ManualObservedGenerationStatus.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/maxinterval}/MaxIntervalIT.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/maxinterval/MaxIntervalTestCustomResource.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/maxinterval/MaxIntervalTestReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/maxintervalafterretry}/MaxIntervalAfterRetryIT.java (84%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/maxintervalafterretry/MaxIntervalAfterRetryTestCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/maxintervalafterretry/MaxIntervalAfterRetryTestReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiplereconcilersametype/MultipleReconcilerSameTypeCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/multiplereconcilersametype}/MultipleReconcilerSameTypeIT.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiplereconcilersametype/MultipleReconcilerSameTypeStatus.java (77%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiplesecondaryeventsource/MultipleSecondaryEventSourceCustomResource.java (78%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/multiplesecondaryeventsource}/MultipleSecondaryEventSourceIT.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java (98%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/multiversioncrd}/MultiVersionCRDIT.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiversioncrd/MultiVersionCRDTestCustomResource1.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiversioncrd/MultiVersionCRDTestCustomResource2.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiversioncrd/MultiVersionCRDTestCustomResourceSpec1.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiversioncrd/MultiVersionCRDTestCustomResourceSpec2.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiversioncrd/MultiVersionCRDTestCustomResourceStatus1.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiversioncrd/MultiVersionCRDTestCustomResourceStatus2.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiversioncrd/MultiVersionCRDTestReconciler1.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/multiversioncrd/MultiVersionCRDTestReconciler2.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/nextreconciliationimminent/NextReconciliationImminentCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/nextreconciliationimminent}/NextReconciliationImminentIT.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/nextreconciliationimminent/NextReconciliationImminentReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/nextreconciliationimminent/NextReconciliationImminentStatus.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/patchresourceandstatusnossa}/PatchResourceAndStatusNoSSAIT.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/patchresourcewithssa}/PatchResourceAndStatusWithSSAIT.java (64%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/patchresourcewithssa/PatchResourceWithSSACustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/patchresourcewithssa}/PatchResourceWithSSAIT.java (64%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/patchresourcewithssa/PatchResourceWithSSAReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/patchresourcewithssa/PatchResourceWithSSASpec.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/patchresourcewithssa/PatchResourceWithSSAStatus.java (82%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/patchresourcewithssa}/PatchWithSSAITBase.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/perresourceeventsource/PerResourceEventSourceCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/perresourceeventsource}/PerResourcePollingEventSourceIT.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/primaryindexer/AbstractPrimaryIndexerTestReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/primaryindexer}/PrimaryIndexerIT.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/primaryindexer/PrimaryIndexerTestCustomResource.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/primaryindexer/PrimaryIndexerTestCustomResourceSpec.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/primaryindexer/PrimaryIndexerTestCustomResourceStatus.java (50%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/primaryindexer/PrimaryIndexerTestReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/primarytosecondary/Cluster.java (77%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/primarytosecondary/Job.java (77%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/primarytosecondary/JobReconciler.java (98%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/primarytosecondary/JobSpec.java (78%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/primarytosecondary}/PrimaryToSecondaryIT.java (82%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/primarytosecondary}/PrimaryToSecondaryMissingIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/ratelimit/RateLimitCustomResource.java (74%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/ratelimit/RateLimitCustomResourceSpec.java (80%) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResourceStatus.java rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/ratelimit}/RateLimitIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/ratelimit/RateLimitReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/retry}/RetryIT.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/retry}/RetryMaxAttemptIT.java (81%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/retry/RetryTestCustomReconciler.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/retry/RetryTestCustomResource.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/retry/RetryTestCustomResourceSpec.java (81%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/retry/RetryTestCustomResourceStatus.java (84%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/simple}/ReconcilerExecutorIT.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/simple/TestCustomResource.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/simple/TestCustomResourceSpec.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/simple/TestCustomResourceStatus.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/simple/TestReconciler.java (98%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/statuspatchnonlocking/StatusPatchLockingCustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/statuspatchnonlocking/StatusPatchLockingCustomResourceSpec.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/statuspatchnonlocking/StatusPatchLockingCustomResourceStatus.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/statuspatchnonlocking/StatusPatchLockingReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/statuspatchnonlocking}/StatusPatchNotLockingIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/statuspatchnonlocking}/StatusPatchSSAMigrationIT.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/statusupdatelocking/StatusUpdateLockingCustomResource.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/statusupdatelocking/StatusUpdateLockingCustomResourceStatus.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/statusupdatelocking}/StatusUpdateLockingIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/statusupdatelocking/StatusUpdateLockingReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/subresource/SubResourceTestCustomReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/subresource/SubResourceTestCustomResource.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/subresource/SubResourceTestCustomResourceSpec.java (81%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/subresource/SubResourceTestCustomResourceStatus.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/subresource}/SubResourceUpdateIT.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/unmodifiabledependentpart/UnmodifiableDependentPartCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/unmodifiabledependentpart}/UnmodifiableDependentPartIT.java (75%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/unmodifiabledependentpart/UnmodifiableDependentPartSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomStatus.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => baseapi/updatestatusincleanupandreschedule}/UpdateStatusInCleanupAndRescheduleIT.java (84%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => baseapi}/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent}/bulkdependent/BulkDependentDeleterIT.java (66%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent}/bulkdependent/BulkDependentTestBase.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/BulkDependentTestCustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/BulkDependentTestSpec.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/BulkDependentTestStatus.java (78%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/CRUDConfigMapBulkDependentResource.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/ConfigMapDeleterBulkDependentResource.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{bulkdependent => dependent/bulkdependent/condition}/BulkDependentWithConditionIT.java (63%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/bulkdependent => dependent/bulkdependent/condition}/ManagedBulkDependentWithReadyConditionReconciler.java (77%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/bulkdependent => dependent/bulkdependent/condition}/SampleBulkCondition.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{bulkdependent => dependent/bulkdependent/external}/BulkExternalDependentIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/external/ExternalBulkDependentResource.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/external/ExternalBulkResourceReconciler.java (78%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/external/ExternalResource.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/external/ExternalServiceMock.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{bulkdependent => dependent/bulkdependent/managed}/ManagedBulkDependentIT.java (56%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/bulkdependent => dependent/bulkdependent/managed}/ManagedBulkDependentReconciler.java (74%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/bulkdependent => dependent/bulkdependent/managed}/ManagedDeleterBulkReconciler.java (69%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/bulkdependent/readonly}/ReadOnlyBulkDependentIT.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/readonly/ReadOnlyBulkDependentResource.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/bulkdependent/readonly/ReadOnlyBulkReconciler.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{bulkdependent => dependent/bulkdependent/standalone}/StandaloneBulkDependentIT.java (67%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/bulkdependent => dependent/bulkdependent/standalone}/StandaloneBulkDependentReconciler.java (78%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/cleanermanageddependent/CleanerForManagedDependentCustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{DeleterForManagedDependentResourcesOnlyIT.java => dependent/cleanermanageddependent/CleanerForManagedDependentResourcesOnlyIT.java} (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/cleanermanageddependent/ConfigMapDependentResource.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSACustomResource.java (82%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{CreateOnlyIfNotExistingDependentWithSSA.java => dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAIT.java} (81%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/dependentannotationsecondarymapper}/DependentAnnotationSecondaryMapperIT.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResource.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/dependentcustommappingannotation}/DependentCustomMappingAnnotationIT.java (72%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentcustommappingannotation/DependentCustomMappingCustomResource.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentcustommappingannotation/DependentCustomMappingReconciler.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentcustommappingannotation/DependentCustomMappingSpec.java (74%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentdifferentnamespace/ConfigMapDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentdifferentnamespace/DependentDifferentNamespaceCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/dependentdifferentnamespace}/DependentDifferentNamespaceIT.java (78%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentdifferentnamespace/DependentDifferentNamespaceSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/dependentfilter}/DependentFilterIT.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentfilter/DependentFilterTestCustomResource.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentfilter/DependentFilterTestReconciler.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentfilter/DependentFilterTestResourceSpec.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentfilter/FilteredDependentConfigMap.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentfilter/UpdateFilter.java (55%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentoperationeventfiltering/ConfigMapDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentoperationeventfiltering/DependentOperationEventFilterCustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceSpec.java (77%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/dependentoperationeventfiltering}/DependentOperationEventFilterIT.java (81%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentreinitialization/ConfigMapDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentreinitialization/DependentReInitializationCustomResource.java (84%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/dependentreinitialization}/DependentReInitializationIT.java (75%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentreinitialization/DependentReInitializationReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/dependentresourcecrossref}/DependentResourceCrossRefIT.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentresourcecrossref/DependentResourceCrossRefReconciler.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentresourcecrossref/DependentResourceCrossRefResource.java (70%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentssa/DependentSSACustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/dependentssa}/DependentSSAMatchingIT.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/dependentssa}/DependentSSAMigrationIT.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentssa/DependentSSAReconciler.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentssa/DependentSSASpec.java (77%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/dependentssa/SSAConfigMapDependent.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/externalstate/ExternalStateCustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/externalstate}/ExternalStateDependentIT.java (60%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/externalstate/ExternalStateDependentReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/externalstate}/ExternalStateIT.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/externalstate/ExternalStateReconciler.java (99%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/externalstate/ExternalStateSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/externalstate}/ExternalStateTestBase.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/externalstate/ExternalWithStateDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/externalstate/externalstatebulkdependent/ExternalStateBulkDependentCustomResource.java (84%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/externalstate/externalstatebulkdependent}/ExternalStateBulkIT.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/externalstate/externalstatebulkdependent/ExternalStateBulkSpec.java (81%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/generickubernetesresource/GenericKubernetesDependentSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/generickubernetesresource}/GenericKubernetesDependentTestBase.java (82%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedCustomResource.java (69%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/generickubernetesresource/generickubernetesdependentresourcemanaged}/GenericKubernetesDependentManagedIT.java (63%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/generickubernetesresource/generickubernetesdependentstandalone/ConfigMapGenericKubernetesDependent.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneCustomResource.java (70%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/generickubernetesresource/generickubernetesdependentstandalone}/GenericKubernetesDependentStandaloneIT.java (63%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/informerrelatedbehavior/ConfigMapDependentResource.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/informerrelatedbehavior}/InformerRelatedBehaviorITS.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/informerrelatedbehavior/InformerRelatedBehaviorTestCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResource.java (78%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceSpec.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/kubernetesdependentgarbagecollection}/KubernetesDependentGarbageCollectionIT.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledependentresource/MultipleDependentResourceConfigMap.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledependentresource/MultipleDependentResourceCustomResource.java (72%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/multipledependentresource}/MultipleDependentResourceIT.java (71%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledependentresource/MultipleDependentResourceReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledependentresource/MultipleDependentResourceSpec.java (72%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/multipledependentresourcewithdiscriminator => dependent/multipledependentresourcewithsametype}/MultipleDependentResourceConfigMap.java (81%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceCustomResourceWithDiscriminator.java => dependent/multipledependentresourcewithsametype/MultipleDependentResourceCustomResourceNoDiscriminator.java} (65%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/multipledependentresourcewithdiscriminator => dependent/multipledependentresourcewithsametype}/MultipleDependentResourceWithDiscriminatorReconciler.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/multipledependentresourcewithsametype}/MultipleDependentResourceWithNoDiscriminatorIT.java (73%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/multipledependentsametypemultiinformer}/MultipleDependentSameTypeMultiInformerIT.java (81%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerCustomResource.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/multipledrsametypenodiscriminator}/MultipleManagedDependentNoDiscriminatorIT.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java (81%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanageddependentsametype/MultipleManagedDependentResourceCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanageddependentsametype/MultipleManagedDependentResourceSpec.java (75%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/multiplemanageddependentsametype}/MultipleManagedDependentSameTypeIT.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanagedexternaldependenttype/AbstractExternalDependentResource.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanagedexternaldependenttype/ExternalDependentResource1.java (71%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanagedexternaldependenttype/ExternalDependentResource2.java (71%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceCustomResource.java (71%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/multiplemanagedexternaldependenttype}/MultipleManagedExternalDependentSameTypeIT.java (84%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/multipleupdateondependent}/MultiOwnerDependentTriggeringIT.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipleupdateondependent/MultipleOwnerDependentConfigMap.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipleupdateondependent/MultipleOwnerDependentCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipleupdateondependent/MultipleOwnerDependentReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/multipleupdateondependent/MultipleOwnerDependentSpec.java (75%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/primaryindexer}/DependentPrimaryIndexerIT.java (71%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/primaryindexer/DependentPrimaryIndexerTestReconciler.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/primarytosecondaydependent/ConfigMapDependent.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/primarytosecondaydependent/ConfigMapReconcilePrecondition.java (78%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/primarytosecondaydependent/PrimaryToSecondaryDependentCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/primarytosecondaydependent}/PrimaryToSecondaryDependentIT.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/primarytosecondaydependent/PrimaryToSecondaryDependentSpec.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/primarytosecondaydependent/SecretDependent.java (83%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/readonly/ConfigMapReader.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/readonly/ReadOnlyDependent.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/restart/ConfigMapDependentResource.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/restart}/OperatorRestartIT.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/restart/RestartTestCustomResource.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/restart/RestartTestReconciler.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/servicestrictmatcher/ServiceDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/servicestrictmatcher}/ServiceStrictMatcherIT.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/servicestrictmatcher/ServiceStrictMatcherSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/servicestrictmatcher/ServiceStrictMatcherTestCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/specialresourcesdependent/ServiceAccountDependentResource.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/specialresourcesdependent/SpecialResourceCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/specialresourcesdependent/SpecialResourceSpec.java (82%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/specialresourcesdependent/SpecialResourceTestReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/specialresourcesdependent}/SpecialResourcesDependentIT.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/ssalegacymatcher/SSALegacyMatcherCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/ssalegacymatcher/SSALegacyMatcherReconciler.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/ssalegacymatcher/SSALegacyMatcherSpec.java (77%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/ssalegacymatcher}/SSAWithLegacyMatcherIT.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/ssalegacymatcher/ServiceDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/standalonedependent}/StandaloneDependentResourceIT.java (91%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/standalonedependent/StandaloneDependentTestCustomResource.java (71%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/standalonedependent/StandaloneDependentTestCustomResourceSpec.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/standalonedependent/StandaloneDependentTestReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerCustomResource.java (84%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerDependentResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => dependent/statefulsetdesiredsanitizer}/StatefulSetDesiredSanitizerIT.java (77%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => dependent}/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerSpec.java (76%) delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentSpec.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestCustomResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/ClusterStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceStatus.java delete mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResourceStatus.java rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/complexdependent/ComplexDependentCustomResource.java => workflow/complexdependent/ComplexWorkflowCustomResource.java} (62%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ComplexDependentIT.java => workflow/complexdependent/ComplexWorkflowIT.java} (65%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample/complexdependent/ComplexDependentReconciler.java => workflow/complexdependent/ComplexWorkflowReconciler.java} (60%) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowSpec.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowStatus.java rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/complexdependent/dependent/BaseDependentResource.java (67%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/complexdependent/dependent/BaseService.java (64%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/complexdependent/dependent/BaseStatefulSet.java (73%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/complexdependent/dependent/FirstService.java (79%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/complexdependent/dependent/FirstStatefulSet.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/complexdependent/dependent/SecondService.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/complexdependent/dependent/SecondStatefulSet.java (80%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/complexdependent/dependent/StatefulSetReadyCondition.java (58%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/crdpresentactivation}/CRDPresentActivationConditionIT.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/crdpresentactivation/CRDPresentActivationCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/crdpresentactivation/CRDPresentActivationDependent.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/crdpresentactivation/CRDPresentActivationDependentCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/crdpresentactivation/CRDPresentActivationReconciler.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/manageddependentdeletecondition/ConfigMapDependent.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionCustomResource.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/manageddependentdeletecondition}/ManagedDependentDeleteConditionIT.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/manageddependentdeletecondition/SecretDependent.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/multipledependentwithactivation/ActivationCondition.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/multipledependentwithactivation/ConfigMapDependentResource1.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/multipledependentwithactivation/ConfigMapDependentResource2.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/multipledependentwithactivation/MultipleDependentActivationCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/multipledependentwithactivation/MultipleDependentActivationReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/multipledependentwithactivation/MultipleDependentActivationSpec.java (71%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/multipledependentwithactivation}/MultipleDependentWithActivationIT.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/multipledependentwithactivation/SecretDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/orderedmanageddependent/ConfigMapDependentResource1.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/orderedmanageddependent/ConfigMapDependentResource2.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/orderedmanageddependent/OrderedManagedDependentCustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/orderedmanageddependent}/OrderedManagedDependentIT.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/orderedmanageddependent/OrderedManagedDependentTestReconciler.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcleanup/ConfigMapDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcleanup/TestActivcationCondition.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcleanup/WorkflowActivationCleanupCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/workflowactivationcleanup}/WorkflowActivationCleanupIT.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcleanup/WorkflowActivationCleanupSpec.java (72%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcondition/ConfigMapDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcondition/IsOpenShiftCondition.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcondition/RouteDependentResource.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcondition/WorkflowActivationConditionCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/workflowactivationcondition}/WorkflowActivationConditionIT.java (75%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcondition/WorkflowActivationConditionReconciler.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowactivationcondition/WorkflowActivationConditionSpec.java (72%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowallfeature/ConfigMapDeletePostCondition.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowallfeature/ConfigMapDependentResource.java (97%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowallfeature/ConfigMapReconcileCondition.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowallfeature/DeploymentDependentResource.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowallfeature/DeploymentReadyCondition.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowallfeature/WorkflowAllFeatureCustomResource.java (88%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/workflowallfeature}/WorkflowAllFeatureIT.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowallfeature/WorkflowAllFeatureReconciler.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowallfeature/WorkflowAllFeatureSpec.java (82%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowallfeature/WorkflowAllFeatureStatus.java (89%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowexplicitcleanup/ConfigMapDependent.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/workflowexplicitcleanup}/WorkflowExplicitCleanupIT.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowexplicitinvocation/ConfigMapDependent.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java (86%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/workflowexplicitinvocation}/WorkflowExplicitInvocationIT.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java (94%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java (76%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowmultipleactivation/ActivationCondition.java (90%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowmultipleactivation/ConfigMapDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowmultipleactivation/SecretDependentResource.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowmultipleactivation/WorkflowMultipleActivationCustomResource.java (87%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/workflowmultipleactivation}/WorkflowMultipleActivationIT.java (95%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java (93%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowmultipleactivation/WorkflowMultipleActivationSpec.java (72%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowsilentexceptionhandling/ConfigMapDependent.java (92%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java (85%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{sample => workflow}/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java (96%) rename operator-framework/src/test/java/io/javaoperatorsdk/operator/{ => workflow/workflowsilentexceptionhandling}/WorkflowSilentExceptionHandlingIT.java (82%) rename operator-framework/src/test/resources/io/javaoperatorsdk/operator/{ => baseapi}/leader-elector-stop-noaccess-role-binding.yaml (100%) rename operator-framework/src/test/resources/io/javaoperatorsdk/operator/{ => baseapi}/leader-elector-stop-role-noaccess.yaml (100%) rename operator-framework/src/test/resources/io/javaoperatorsdk/operator/{ => dependent/informerrelatedbehavior}/rback-test-full-access-role.yaml (100%) rename operator-framework/src/test/resources/io/javaoperatorsdk/operator/{ => dependent/informerrelatedbehavior}/rback-test-no-configmap-access.yaml (100%) rename operator-framework/src/test/resources/io/javaoperatorsdk/operator/{ => dependent/informerrelatedbehavior}/rback-test-no-cr-access.yaml (100%) rename operator-framework/src/test/resources/io/javaoperatorsdk/operator/{ => dependent/informerrelatedbehavior}/rback-test-only-main-ns-access-binding.yaml (100%) rename operator-framework/src/test/resources/io/javaoperatorsdk/operator/{ => dependent/informerrelatedbehavior}/rback-test-only-main-ns-access.yaml (100%) rename operator-framework/src/test/resources/io/javaoperatorsdk/operator/{ => dependent/informerrelatedbehavior}/rback-test-role-binding.yaml (100%) rename operator-framework/src/test/resources/io/javaoperatorsdk/operator/{sample/statefulsetdesiredsanitizer => }/statefulset.yaml (100%) create mode 100644 operator-framework/src/test/resources/io/javaoperatorsdk/operator/workflow/complexdependent/service.yaml create mode 100644 operator-framework/src/test/resources/io/javaoperatorsdk/operator/workflow/complexdependent/statefulset.yaml diff --git a/docs/content/en/docs/dependent-resources/_index.md b/docs/content/en/docs/dependent-resources/_index.md index a80bf80822..ab0ccd06c9 100644 --- a/docs/content/en/docs/dependent-resources/_index.md +++ b/docs/content/en/docs/dependent-resources/_index.md @@ -291,7 +291,7 @@ customized by implementing by the dependent resource. See sample in one of the integration -tests [here](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java#L25-L25) +tests [here](https://github.com/operator-framework/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer) . ## Multiple Dependent Resources of Same Type @@ -310,7 +310,7 @@ There might be casees, though, where it might be problematic to call the `desire - Override the `selectManagedSecondaryResource` method, if your `DependentResource` extends `AbstractDependentResource`. This should be relatively simple to override this method to optimize the matching to your needs. You can see an example of such an implementation in - the [`ExternalWithStateDependentResource`](https://github.com/operator-framework/java-operator-sdk/blob/6cd0f884a7c9b60c81bd2d52da54adbd64d6e118/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java#L43-L49) + the [`ExternalWithStateDependentResource`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalWithStateDependentResource.java) class. - Override the `managedSecondaryResourceID` method, if your `DependentResource` extends `KubernetesDependentResource`, where it's very often possible to easily determine the `ResourceID` of the secondary resource. This would probably be @@ -333,9 +333,9 @@ would look as follows: ``` A sample is provided as an integration test both: -for [managed](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentNoDiscriminatorIT.java) +for [managed](https://github.com/operator-framework/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator) -For [standalone](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java) +For [standalone](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource) cases. ## Bulk Dependent Resources @@ -352,11 +352,11 @@ implement the interface. Various examples are provided -as [integration tests](https://github.com/java-operator-sdk/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent) +as [integration tests](https://github.com/operator-framework/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent) . To see how bulk dependent resources interact with workflow conditions, please refer to this -[integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentWithConditionIT.java). +[integration test](https://github.com/operator-framework/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/conidition). ## External State Tracking Dependent Resources @@ -377,11 +377,11 @@ interface. Note that most of the JOSDK-provided dependent resource implementatio `PollingDependentResource` or `PerResourcePollingDependentResource` already extends `AbstractExternalDependentResource`, thus supporting external state tracking out of the box. -See [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateDependentIT.java) +See [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentIT.java) as a sample. For a better understanding it might be worth to study -a [sample implementation](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java) +a [sample implementation](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateReconciler.java) without dependent resources. Please also refer to the [docs](/docs/patterns-and-best-practices#managing-state) for managing state in @@ -395,7 +395,7 @@ created. For example, if three bulk dependent resources associated with external three associated `ConfigMaps` (assuming `ConfigMaps` are used as a state-tracking resource) will also be created, one per dependent resource. -See [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java) +See [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent) as a sample. ## GenericKubernetesResource based Dependent Resources @@ -435,13 +435,13 @@ samples [here](https://github.com/java-operator-sdk/java-operator-sdk/tree/main/ practice in general) - so for example if there are two config map dependents, either there should be a shared event source between them, or a label selector on the event sources to select only the relevant events, see - in [related integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java) + in [related integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource2.java) . ## "Read-only" Dependent Resources vs. Event Source See Integration test for a read-only -dependent [here](https://github.com/java-operator-sdk/java-operator-sdk/blob/249b41f3c68c4d0e9c77c41eca647a69a24347b0/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java). +dependent [here](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/ConfigMapDependent.java). Some secondary resources only exist as input for the reconciliation process and are never updated *by a controller* (they might, and actually usually do, get updated by users interacting diff --git a/docs/content/en/docs/features/_index.md b/docs/content/en/docs/features/_index.md index 1eaa68b15b..6832e31438 100644 --- a/docs/content/en/docs/features/_index.md +++ b/docs/content/en/docs/features/_index.md @@ -97,15 +97,15 @@ using [Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/s It is important to understand how SSA works in Kubernetes. Mainly, resources applied using SSA should contain only the fields identifying the resource and those the user is interested in (a 'fully specified intent' in Kubernetes parlance), thus usually using a resource created from scratch, see -[sample](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAReconciler.java#L18-L22). -To contrast, see the same sample, this time [without SSA](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java#L16-L16). +[sample](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa). +To contrast, see the same sample, this time [without SSA](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java). Non-SSA based patch is still supported. You can control whether or not to use SSA using [`ConfigurationServcice.useSSAToPatchPrimaryResource()`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L385-L385) and the related `ConfigurationServiceOverrider.withUseSSAToPatchPrimaryResource` method. Related integration test can be -found [here](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java). +found [here](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa). Handling resources directly using the client, instead of delegating these updates operations to JOSDK by returning an `UpdateControl` at the end of your reconciliation, should work appropriately. However, we do recommend to @@ -204,7 +204,7 @@ A Controller can be registered for a non-custom resource, so well known Kubernet `Ingress`, `Deployment`,...). See -the [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/deployment/DeploymentReconciler.java) +the [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment) for reconciling deployments. ```java @@ -531,7 +531,7 @@ between a primary resource and its associated secondary resources using an imple `PrimaryToSecondaryMapper` interface. This is typically needed when there are many-to-one or many-to-many relationships between primary and secondary resources, e.g. when the primary resource is referencing secondary resources. -See [PrimaryToSecondaryIT](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryIT.java) +See [PrimaryToSecondaryIT](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/PrimaryToSecondaryIT.java) integration test for a sample. ### Built-in EventSources @@ -667,7 +667,7 @@ As seen in the above code snippet, the informer will have the initial namespaces controller, but also will adjust the target namespaces if it changes for the controller. See also -the [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/ec37025a15046d8f409c77616110024bf32c3416/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java) +the [integration test](https://github.com/operator-framework/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace) for this feature. ## Leader Election diff --git a/docs/content/en/docs/workflows/_index.md b/docs/content/en/docs/workflows/_index.md index 4b61c6f1b0..19b5fab104 100644 --- a/docs/content/en/docs/workflows/_index.md +++ b/docs/content/en/docs/workflows/_index.md @@ -46,7 +46,7 @@ reconciliation process. [CRDPresentActivationCondition](https://github.com/operator-framework/java-operator-sdk/blob/ba5e33527bf9e3ea0bd33025ccb35e677f9d44b4/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java) that will prevent the associated dependent resource from being activated if the Custom Resource Definition associated with the dependent's resource type is not present on the cluster. - See related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/ba5e33527bf9e3ea0bd33025ccb35e677f9d44b4/operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java). + See related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation). To have multiple resources of same type with an activation condition is a bit tricky, since you don't want to have multiple `InformerEventSource` for the same type, you have to explicitly @@ -67,7 +67,7 @@ You can access the results for conditions from the `WorkflowResult` instance tha evaluated. You can access that result from the `ManagedWorkflowAndDependentResourceContext` accessible from the reconciliation `Context`. You can then access individual condition results using the ` getDependentConditionResult` methods. You can see an example of this -in [this integration test](https://github.com/operator-framework/java-operator-sdk/blob/fd0e92c0de55c47d5df50658cf4e147ee5e6102d/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java#L44-L49). +in [this integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureReconciler.java). ## Defining Workflows @@ -350,7 +350,7 @@ checks that the resource is actually removed or that it, at least, doesn't have provides such a delete post-condition implementation in the form of [`KubernetesResourceDeletedCondition`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/KubernetesResourceDeletedCondition.java) -Also, check usage in an [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java). +Also, check usage in an [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java). In such cases the Kubernetes Dependent Resource should extend `CRUDNoGCKubernetesDependentResource` and NOT `CRUDKubernetesDependentResource` since otherwise the Kubernetes Garbage Collector would delete the resources. @@ -373,13 +373,13 @@ ManagedWorkflowAndDependentResourceContext` retrieved from the reconciliation `C resource reconciler `reconcile` method arguments. See -related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java) +related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation) for more details. For `cleanup`, if the `Cleaner` interface is implemented, the `cleanupManageWorkflow()` needs to be called explicitly. However, if `Cleaner` interface is not implemented, it will be called implicitly. See -related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitCleanupIT.java). +related [integration test](https://github.com/operator-framework/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup). While nothing prevents calling the workflow multiple times in a reconciler, it isn't typical or even recommended to do so. Conversely, if explicit invocation is requested but `reconcileManagedWorkflow` is not called in the primary resource diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index bdc23a1cb7..2fc29ca4c5 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -410,7 +410,7 @@ default boolean shouldUseSSA(Class depend return false; } Boolean useSSAConfig = Optional.ofNullable(config) - .flatMap(KubernetesDependentResourceConfig::useSSA) + .map(KubernetesDependentResourceConfig::useSSA) .orElse(null); // don't use SSA for certain resources by default, only if explicitly overridden if (useSSAConfig == null) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java index cbd6399afe..7de9bcda43 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java @@ -210,7 +210,6 @@ public boolean checkCRDAndValidateLocalModel() { @SuppressWarnings("rawtypes") @Override - @SuppressWarnings("rawtypes") public DependentResourceFactory dependentResourceFactory() { return overriddenValueOrDefault(dependentResourceFactory, ConfigurationService::dependentResourceFactory); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ConcurrencyIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ConcurrencyIT.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ConcurrencyIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ConcurrencyIT.java index f33c581538..eb60907e12 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ConcurrencyIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ConcurrencyIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi; import java.util.List; import java.util.concurrent.TimeUnit; @@ -10,9 +10,9 @@ import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.api.model.ConfigMap; +import io.javaoperatorsdk.operator.baseapi.simple.TestCustomResource; +import io.javaoperatorsdk.operator.baseapi.simple.TestReconciler; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; -import io.javaoperatorsdk.operator.sample.simple.TestReconciler; import io.javaoperatorsdk.operator.support.TestUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerErrorHandlerStartIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/InformerErrorHandlerStartIT.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerErrorHandlerStartIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/InformerErrorHandlerStartIT.java index b1edf3e108..b18e9b6763 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerErrorHandlerStartIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/InformerErrorHandlerStartIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi; import java.time.Duration; @@ -9,6 +9,7 @@ import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionPermissionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/LeaderElectionPermissionIT.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionPermissionIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/LeaderElectionPermissionIT.java index c1b30277c7..2523e15423 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionPermissionIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/LeaderElectionPermissionIT.java @@ -1,14 +1,16 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi; import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.authorization.v1.*; import io.fabric8.kubernetes.api.model.rbac.Role; import io.fabric8.kubernetes.api.model.rbac.RoleBinding; import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import io.javaoperatorsdk.operator.Operator; +import io.javaoperatorsdk.operator.OperatorException; +import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/BuiltInResourceCleanerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerIT.java similarity index 74% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/BuiltInResourceCleanerIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerIT.java index f5c663b358..3867711f7f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/BuiltInResourceCleanerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.builtinresourcecleaner; import java.util.Map; @@ -8,8 +8,9 @@ import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.api.model.Service; +import io.javaoperatorsdk.operator.ReconcilerUtils; +import io.javaoperatorsdk.operator.dependent.standalonedependent.StandaloneDependentResourceIT; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.builtinresourcecleaner.ObservedGenerationTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -21,7 +22,7 @@ class BuiltInResourceCleanerIT { @RegisterExtension LocallyRunOperatorExtension operator = LocallyRunOperatorExtension.builder() - .withReconciler(new ObservedGenerationTestReconciler()) + .withReconciler(new BuiltInResourceCleanerReconciler()) .build(); /** @@ -33,7 +34,7 @@ void cleanerIsCalledOnBuiltInResource() { var service = operator.create(testService()); await().untilAsserted(() -> { - assertThat(operator.getReconcilerOfType(ObservedGenerationTestReconciler.class) + assertThat(operator.getReconcilerOfType(BuiltInResourceCleanerReconciler.class) .getReconcileCount()).isPositive(); var actualService = operator.get(Service.class, service.getMetadata().getName()); assertThat(actualService.getMetadata().getFinalizers()).isNotEmpty(); @@ -42,14 +43,14 @@ void cleanerIsCalledOnBuiltInResource() { operator.delete(service); await().untilAsserted(() -> { - assertThat(operator.getReconcilerOfType(ObservedGenerationTestReconciler.class) + assertThat(operator.getReconcilerOfType(BuiltInResourceCleanerReconciler.class) .getCleanCount()).isPositive(); }); } Service testService() { Service service = ReconcilerUtils.loadYaml(Service.class, StandaloneDependentResourceIT.class, - "service-template.yaml"); + "/io/javaoperatorsdk/operator/service-template.yaml"); service.getMetadata().setLabels(Map.of("builtintest", "true")); return service; } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/builtinresourcecleaner/ObservedGenerationTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerReconciler.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/builtinresourcecleaner/ObservedGenerationTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerReconciler.java index 93337b1c84..ac13c497cd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/builtinresourcecleaner/ObservedGenerationTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.builtinresourcecleaner; +package io.javaoperatorsdk.operator.baseapi.builtinresourcecleaner; import java.util.concurrent.atomic.AtomicInteger; @@ -7,7 +7,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; @ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "builtintest=true")) -public class ObservedGenerationTestReconciler +public class BuiltInResourceCleanerReconciler implements Reconciler, Cleaner { private final AtomicInteger reconciled = new AtomicInteger(0); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ChangeNamespaceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceIT.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ChangeNamespaceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceIT.java index e669f6d06c..1f6806aed7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ChangeNamespaceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.changenamespace; import java.time.Duration; import java.util.Map; @@ -14,10 +14,9 @@ import io.fabric8.kubernetes.api.model.NamespaceBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.client.KubernetesClient; +import io.javaoperatorsdk.operator.RegisteredController; import io.javaoperatorsdk.operator.api.reconciler.Constants; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.changenamespace.ChangeNamespaceTestCustomResource; -import io.javaoperatorsdk.operator.sample.changenamespace.ChangeNamespaceTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestCustomResource.java index a333dbe164..eff8a4bb3f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.changenamespace; +package io.javaoperatorsdk.operator.baseapi.changenamespace; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestCustomResourceStatus.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestCustomResourceStatus.java index a3858cda05..009d1340e9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.changenamespace; +package io.javaoperatorsdk.operator.baseapi.changenamespace; public class ChangeNamespaceTestCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestReconciler.java similarity index 98% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestReconciler.java index be208d3ba2..fac4263c3c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/changenamespace/ChangeNamespaceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.changenamespace; +package io.javaoperatorsdk.operator.baseapi.changenamespace; import java.util.List; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanerforreconciler/CleanerForReconcilerCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanerforreconciler/CleanerForReconcilerCustomResource.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanerforreconciler/CleanerForReconcilerCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanerforreconciler/CleanerForReconcilerCustomResource.java index 7a4b255d28..4367d6d089 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanerforreconciler/CleanerForReconcilerCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanerforreconciler/CleanerForReconcilerCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.cleanerforreconciler; +package io.javaoperatorsdk.operator.baseapi.cleanerforreconciler; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanerForReconcilerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanerforreconciler/CleanerForReconcilerIT.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanerForReconcilerIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanerforreconciler/CleanerForReconcilerIT.java index bf5fa243cf..04ea2f9646 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanerForReconcilerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanerforreconciler/CleanerForReconcilerIT.java @@ -1,12 +1,10 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.cleanerforreconciler; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.cleanerforreconciler.CleanerForReconcilerCustomResource; -import io.javaoperatorsdk.operator.sample.cleanerforreconciler.CleanerForReconcilerTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanerforreconciler/CleanerForReconcilerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanerforreconciler/CleanerForReconcilerTestReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanerforreconciler/CleanerForReconcilerTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanerforreconciler/CleanerForReconcilerTestReconciler.java index a6f404e7f6..8bb5fa1062 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanerforreconciler/CleanerForReconcilerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanerforreconciler/CleanerForReconcilerTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.cleanerforreconciler; +package io.javaoperatorsdk.operator.baseapi.cleanerforreconciler; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanupconflict/CleanupConflictCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictCustomResource.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanupconflict/CleanupConflictCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictCustomResource.java index 9675273085..82f51c1f83 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanupconflict/CleanupConflictCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.cleanupconflict; +package io.javaoperatorsdk.operator.baseapi.cleanupconflict; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanupconflict/CleanupConflictCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictCustomResourceStatus.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanupconflict/CleanupConflictCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictCustomResourceStatus.java index 3488981eb1..19794e2173 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanupconflict/CleanupConflictCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.cleanupconflict; +package io.javaoperatorsdk.operator.baseapi.cleanupconflict; public class CleanupConflictCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanupConflictIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictIT.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanupConflictIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictIT.java index e1c571c4a5..4d79d6d1d3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanupConflictIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.cleanupconflict; import java.time.Duration; @@ -7,10 +7,8 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.cleanupconflict.CleanupConflictCustomResource; -import io.javaoperatorsdk.operator.sample.cleanupconflict.CleanupConflictReconciler; -import static io.javaoperatorsdk.operator.sample.cleanupconflict.CleanupConflictReconciler.WAIT_TIME; +import static io.javaoperatorsdk.operator.baseapi.cleanupconflict.CleanupConflictReconciler.WAIT_TIME; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanupconflict/CleanupConflictReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanupconflict/CleanupConflictReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictReconciler.java index 14d8f8617f..1c66fde159 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanupconflict/CleanupConflictReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/cleanupconflict/CleanupConflictReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.cleanupconflict; +package io.javaoperatorsdk.operator.baseapi.cleanupconflict; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResource.java index 957b396df4..0e26316cfb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.clusterscopedresource; +package io.javaoperatorsdk.operator.baseapi.clusterscopedresource; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceReconciler.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceReconciler.java index 5ee675cf5e..c108b9edbc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.clusterscopedresource; +package io.javaoperatorsdk.operator.baseapi.clusterscopedresource; import java.util.List; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceSpec.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceSpec.java index 825b0c443e..8facc07e18 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.clusterscopedresource; +package io.javaoperatorsdk.operator.baseapi.clusterscopedresource; public class ClusterScopedCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceStatus.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceStatus.java index 7c4d49f3a1..7ed5c6c1b4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/clusterscopedresource/ClusterScopedCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.clusterscopedresource; +package io.javaoperatorsdk.operator.baseapi.clusterscopedresource; public class ClusterScopedCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ClusterScopedResourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedResourceIT.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ClusterScopedResourceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedResourceIT.java index b1a3797bea..c17cf632c2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ClusterScopedResourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedResourceIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.clusterscopedresource; import java.time.Duration; @@ -8,9 +8,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.clusterscopedresource.ClusterScopedCustomResource; -import io.javaoperatorsdk.operator.sample.clusterscopedresource.ClusterScopedCustomResourceReconciler; -import io.javaoperatorsdk.operator.sample.clusterscopedresource.ClusterScopedCustomResourceSpec; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java index 8a0ee77474..31ef818cd6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.createupdateeventfilter; +package io.javaoperatorsdk.operator.baseapi.createupdateeventfilter; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceSpec.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceSpec.java index fcd3807bc8..4575e68db0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.createupdateeventfilter; +package io.javaoperatorsdk.operator.baseapi.createupdateeventfilter; public class CreateUpdateEventFilterTestCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java similarity index 98% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index 5f8b20ffa8..35676cd669 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.createupdateeventfilter; +package io.javaoperatorsdk.operator.baseapi.createupdateeventfilter; import java.util.HashMap; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateUpdateInformerEventSourceEventFilterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateInformerEventSourceEventFilterIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateUpdateInformerEventSourceEventFilterIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateInformerEventSourceEventFilterIT.java index 8a68c9a2b3..9c69087e74 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateUpdateInformerEventSourceEventFilterIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateInformerEventSourceEventFilterIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.createupdateeventfilter; import java.time.Duration; @@ -8,11 +8,8 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.createupdateeventfilter.CreateUpdateEventFilterTestCustomResource; -import io.javaoperatorsdk.operator.sample.createupdateeventfilter.CreateUpdateEventFilterTestCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.createupdateeventfilter.CreateUpdateEventFilterTestReconciler; -import static io.javaoperatorsdk.operator.sample.createupdateeventfilter.CreateUpdateEventFilterTestReconciler.CONFIG_MAP_TEST_DATA_KEY; +import static io.javaoperatorsdk.operator.baseapi.createupdateeventfilter.CreateUpdateEventFilterTestReconciler.CONFIG_MAP_TEST_DATA_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PreviousAnnotationDisabledIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/PreviousAnnotationDisabledIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PreviousAnnotationDisabledIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/PreviousAnnotationDisabledIT.java index c636737d0a..209c5fd15c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PreviousAnnotationDisabledIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/PreviousAnnotationDisabledIT.java @@ -1,11 +1,9 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.createupdateeventfilter; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.createupdateeventfilter.CreateUpdateEventFilterTestCustomResource; -import io.javaoperatorsdk.operator.sample.createupdateeventfilter.CreateUpdateEventFilterTestReconciler; class PreviousAnnotationDisabledIT { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/deployment/DeploymentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/DeploymentReconciler.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/deployment/DeploymentReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/DeploymentReconciler.java index 9544e75c2e..c62be34e4f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/deployment/DeploymentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/DeploymentReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.deployment; +package io.javaoperatorsdk.operator.baseapi.deployment; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesResourceStatusUpdateIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/KubernetesResourceStatusUpdateIT.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesResourceStatusUpdateIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/KubernetesResourceStatusUpdateIT.java index 02cd982af9..dff60df5cd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesResourceStatusUpdateIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/KubernetesResourceStatusUpdateIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.deployment; import java.util.HashMap; import java.util.List; @@ -18,9 +18,8 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.DeploymentSpec; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.deployment.DeploymentReconciler; -import static io.javaoperatorsdk.operator.sample.deployment.DeploymentReconciler.STATUS_MESSAGE; +import static io.javaoperatorsdk.operator.baseapi.deployment.DeploymentReconciler.STATUS_MESSAGE; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationCustomResource.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationCustomResource.java index fd82d7bf71..339f14434a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dynamicgenericeventsourceregistration; +package io.javaoperatorsdk.operator.baseapi.dynamicgenericeventsourceregistration; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DynamicGenericEventSourceRegistrationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationIT.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DynamicGenericEventSourceRegistrationIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationIT.java index 308630a365..b00573e334 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DynamicGenericEventSourceRegistrationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.dynamicgenericeventsourceregistration; import java.time.Duration; @@ -9,8 +9,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dynamicgenericeventsourceregistration.DynamicGenericEventSourceRegistrationCustomResource; -import io.javaoperatorsdk.operator.sample.dynamicgenericeventsourceregistration.DynamicGenericEventSourceRegistrationReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java index 74d4890ec8..ed3659572c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dynamicgenericeventsourceregistration; +package io.javaoperatorsdk.operator.baseapi.dynamicgenericeventsourceregistration; import java.util.Base64; import java.util.Map; @@ -72,7 +72,8 @@ private InformerEventSource( InformerConfiguration - .from(GroupVersionKind.gvkFor(clazz), DynamicGenericEventSourceRegistrationCustomResource.class) + .from(GroupVersionKind.gvkFor(clazz), + DynamicGenericEventSourceRegistrationCustomResource.class) .withName(clazz.getSimpleName()) .build(), context.eventSourceRetriever().eventSourceContextForDynamicRegistration()); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ErrorStatusHandlerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerIT.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ErrorStatusHandlerIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerIT.java index e66fd2dcce..6e69a50e82 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ErrorStatusHandlerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.errorstatushandler; import java.util.concurrent.TimeUnit; @@ -8,8 +8,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; -import io.javaoperatorsdk.operator.sample.errorstatushandler.ErrorStatusHandlerTestCustomResource; -import io.javaoperatorsdk.operator.sample.errorstatushandler.ErrorStatusHandlerTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerTestCustomResource.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerTestCustomResource.java index d6056ea486..0606115f5f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.errorstatushandler; +package io.javaoperatorsdk.operator.baseapi.errorstatushandler; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerTestCustomResourceStatus.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerTestCustomResourceStatus.java index 4e54c877a5..42fe4b4b34 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerTestCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.errorstatushandler; +package io.javaoperatorsdk.operator.baseapi.errorstatushandler; import java.util.ArrayList; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerTestReconciler.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerTestReconciler.java index b0c120dad2..e51286ef5f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/errorstatushandler/ErrorStatusHandlerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/errorstatushandler/ErrorStatusHandlerTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.errorstatushandler; +package io.javaoperatorsdk.operator.baseapi.errorstatushandler; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/EventSourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceIT.java similarity index 84% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/EventSourceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceIT.java index 7432e5da0a..227adaeadc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/EventSourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.event; import java.util.concurrent.TimeUnit; @@ -7,9 +7,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomReconciler; -import io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResource; -import io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResourceSpec; import io.javaoperatorsdk.operator.support.TestUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomReconciler.java index 4435f72f98..59f27e5723 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.event; +package io.javaoperatorsdk.operator.baseapi.event; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomResource.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomResource.java index 1a22ec4f8d..2493fc138b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.event; +package io.javaoperatorsdk.operator.baseapi.event; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomResourceSpec.java similarity index 82% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomResourceSpec.java index d22f34ce97..203fd21440 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.event; +package io.javaoperatorsdk.operator.baseapi.event; public class EventSourceTestCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomResourceStatus.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomResourceStatus.java index 581b4dd74e..bb4c9cd5f1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/event/EventSourceTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/event/EventSourceTestCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.event; +package io.javaoperatorsdk.operator.baseapi.event; public class EventSourceTestCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/FilterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterIT.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/FilterIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterIT.java index 28ce794de9..634873ec86 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/FilterIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.filter; import java.time.Duration; @@ -7,11 +7,8 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.filter.FilterTestCustomResource; -import io.javaoperatorsdk.operator.sample.filter.FilterTestReconciler; -import io.javaoperatorsdk.operator.sample.filter.FilterTestResourceSpec; -import static io.javaoperatorsdk.operator.sample.filter.FilterTestReconciler.CONFIG_MAP_FILTER_VALUE; +import static io.javaoperatorsdk.operator.baseapi.filter.FilterTestReconciler.CONFIG_MAP_FILTER_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestCustomResource.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestCustomResource.java index 3314861ee5..a9f560b9bb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.filter; +package io.javaoperatorsdk.operator.baseapi.filter; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestReconciler.java similarity index 98% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestReconciler.java index 7857516d34..16f94e4e09 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.filter; +package io.javaoperatorsdk.operator.baseapi.filter; import java.util.List; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestResourceSpec.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestResourceSpec.java index 044b0ea883..1b4cebbfb6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.filter; +package io.javaoperatorsdk.operator.baseapi.filter; public class FilterTestResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestResourceStatus.java new file mode 100644 index 0000000000..1714a2135d --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestResourceStatus.java @@ -0,0 +1,5 @@ +package io.javaoperatorsdk.operator.baseapi.filter; + +public class FilterTestResourceStatus { + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/UpdateFilter.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/UpdateFilter.java similarity index 69% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/UpdateFilter.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/UpdateFilter.java index 618cf4f814..7f697d32a1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/UpdateFilter.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/UpdateFilter.java @@ -1,8 +1,8 @@ -package io.javaoperatorsdk.operator.sample.filter; +package io.javaoperatorsdk.operator.baseapi.filter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; -import static io.javaoperatorsdk.operator.sample.filter.FilterTestReconciler.CUSTOM_RESOURCE_FILTER_VALUE; +import static io.javaoperatorsdk.operator.baseapi.filter.FilterTestReconciler.CUSTOM_RESOURCE_FILTER_VALUE; public class UpdateFilter implements OnUpdateFilter { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingCustomResource.java similarity index 70% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingCustomResource.java index 47b3a14a5a..45f424b8eb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingCustomResource.java @@ -1,11 +1,11 @@ -package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesresourcehandling; +package io.javaoperatorsdk.operator.baseapi.generickubernetesresourcehandling; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; import io.fabric8.kubernetes.model.annotation.ShortNames; import io.fabric8.kubernetes.model.annotation.Version; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.GenericKubernetesDependentSpec; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.GenericKubernetesDependentSpec; @Group("sample.javaoperatorsdk") @Version("v1") diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesResourceHandlingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingIT.java similarity index 64% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesResourceHandlingIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingIT.java index b3ee935553..0e4700a482 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesResourceHandlingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingIT.java @@ -1,12 +1,11 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.generickubernetesresourcehandling; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.GenericKubernetesDependentSpec; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.GenericKubernetesDependentTestBase; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.GenericKubernetesDependentSpec; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesresourcehandling.GenericKubernetesResourceHandlingCustomResource; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesresourcehandling.GenericKubernetesResourceHandlingReconciler; public class GenericKubernetesResourceHandlingIT extends GenericKubernetesDependentTestBase { @@ -23,7 +22,7 @@ public LocallyRunOperatorExtension extension() { } @Override - GenericKubernetesResourceHandlingCustomResource testResource(String name, String data) { + public GenericKubernetesResourceHandlingCustomResource testResource(String name, String data) { var resource = new GenericKubernetesResourceHandlingCustomResource(); resource.setMetadata(new ObjectMetaBuilder() .withName(name) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java index 939878873d..7d0f3b1d8f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesresourcehandling; +package io.javaoperatorsdk.operator.baseapi.generickubernetesresourcehandling; import java.io.IOException; import java.io.InputStream; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopIT.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopIT.java index e6a38326d5..a28d6da07d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.gracefulstop; import java.time.Duration; @@ -7,11 +7,8 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.gracefulstop.GracefulStopTestCustomResource; -import io.javaoperatorsdk.operator.sample.gracefulstop.GracefulStopTestCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.gracefulstop.GracefulStopTestReconciler; -import static io.javaoperatorsdk.operator.sample.gracefulstop.GracefulStopTestReconciler.RECONCILER_SLEEP; +import static io.javaoperatorsdk.operator.baseapi.gracefulstop.GracefulStopTestReconciler.RECONCILER_SLEEP; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestCustomResource.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestCustomResource.java index 529c5ff480..0a3f0c680f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.gracefulstop; +package io.javaoperatorsdk.operator.baseapi.gracefulstop; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestCustomResourceSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestCustomResourceSpec.java index 4d1f45e646..f1c4b42af2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.gracefulstop; +package io.javaoperatorsdk.operator.baseapi.gracefulstop; public class GracefulStopTestCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestCustomResourceStatus.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestCustomResourceStatus.java index fa80e79c19..3e4e992399 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.gracefulstop; +package io.javaoperatorsdk.operator.baseapi.gracefulstop; public class GracefulStopTestCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestReconciler.java index 7ff0d9d246..7b33c68722 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/gracefulstop/GracefulStopTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/gracefulstop/GracefulStopTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.gracefulstop; +package io.javaoperatorsdk.operator.baseapi.gracefulstop; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerEventSourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerEventSourceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceIT.java index 45983145da..81e0a0febe 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerEventSourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.informereventsource; import java.util.HashMap; import java.util.concurrent.TimeUnit; @@ -9,12 +9,10 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.informereventsource.InformerEventSourceTestCustomReconciler; -import io.javaoperatorsdk.operator.sample.informereventsource.InformerEventSourceTestCustomResource; -import static io.javaoperatorsdk.operator.sample.informereventsource.InformerEventSourceTestCustomReconciler.MISSING_CONFIG_MAP; -import static io.javaoperatorsdk.operator.sample.informereventsource.InformerEventSourceTestCustomReconciler.RELATED_RESOURCE_NAME; -import static io.javaoperatorsdk.operator.sample.informereventsource.InformerEventSourceTestCustomReconciler.TARGET_CONFIG_MAP_KEY; +import static io.javaoperatorsdk.operator.baseapi.informereventsource.InformerEventSourceTestCustomReconciler.MISSING_CONFIG_MAP; +import static io.javaoperatorsdk.operator.baseapi.informereventsource.InformerEventSourceTestCustomReconciler.RELATED_RESOURCE_NAME; +import static io.javaoperatorsdk.operator.baseapi.informereventsource.InformerEventSourceTestCustomReconciler.TARGET_CONFIG_MAP_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java index 631f8c29fe..8d0178fd1b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.informereventsource; +package io.javaoperatorsdk.operator.baseapi.informereventsource; import java.util.List; import java.util.Optional; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomResource.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomResource.java index ff1c6758bb..4d1077c64e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.informereventsource; +package io.javaoperatorsdk.operator.baseapi.informereventsource; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomResourceStatus.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomResourceStatus.java index b4b6b93958..529b53db13 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.informereventsource; +package io.javaoperatorsdk.operator.baseapi.informereventsource; public class InformerEventSourceTestCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/LabelSelectorIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorIT.java similarity index 75% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/LabelSelectorIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorIT.java index 8324a8c1d2..41411fa16f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/LabelSelectorIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.labelselector; import java.time.Duration; import java.util.Collections; @@ -9,11 +9,9 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.labelselector.LabelSelectorTestCustomResource; -import io.javaoperatorsdk.operator.sample.labelselector.LabelSelectorTestReconciler; -import static io.javaoperatorsdk.operator.sample.labelselector.LabelSelectorTestReconciler.LABEL_KEY; -import static io.javaoperatorsdk.operator.sample.labelselector.LabelSelectorTestReconciler.LABEL_VALUE; +import static io.javaoperatorsdk.operator.baseapi.labelselector.LabelSelectorTestReconciler.LABEL_KEY; +import static io.javaoperatorsdk.operator.baseapi.labelselector.LabelSelectorTestReconciler.LABEL_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -24,7 +22,6 @@ class LabelSelectorIT { LocallyRunOperatorExtension.builder().withReconciler(new LabelSelectorTestReconciler()) .build(); - @Test void filtersCustomResourceByLabel() { operator.create(resource("r1", true)); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestCustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestCustomResource.java index 0b304aa9e7..321c684eef 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.labelselector; +package io.javaoperatorsdk.operator.baseapi.labelselector; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java index 81ba706591..d1d5109b45 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/labelselector/LabelSelectorTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.labelselector; +package io.javaoperatorsdk.operator.baseapi.labelselector; import java.util.concurrent.atomic.AtomicInteger; @@ -6,8 +6,8 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -import static io.javaoperatorsdk.operator.sample.labelselector.LabelSelectorTestReconciler.LABEL_KEY; -import static io.javaoperatorsdk.operator.sample.labelselector.LabelSelectorTestReconciler.LABEL_VALUE; +import static io.javaoperatorsdk.operator.baseapi.labelselector.LabelSelectorTestReconciler.LABEL_KEY; +import static io.javaoperatorsdk.operator.baseapi.labelselector.LabelSelectorTestReconciler.LABEL_VALUE; @ControllerConfiguration( informerConfig = @InformerConfig(labelSelector = LABEL_KEY + "=" + LABEL_VALUE)) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/leaderelectionchangenamespace/LeaderElectionChangeNamespaceCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/leaderelectionchangenamespace/LeaderElectionChangeNamespaceCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/leaderelectionchangenamespace/LeaderElectionChangeNamespaceCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/leaderelectionchangenamespace/LeaderElectionChangeNamespaceCustomResource.java index 8a37720955..7b4a38d429 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/leaderelectionchangenamespace/LeaderElectionChangeNamespaceCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/leaderelectionchangenamespace/LeaderElectionChangeNamespaceCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.leaderelectionchangenamespace; +package io.javaoperatorsdk.operator.baseapi.leaderelectionchangenamespace; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionChangeNamespaceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/leaderelectionchangenamespace/LeaderElectionChangeNamespaceIT.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionChangeNamespaceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/leaderelectionchangenamespace/LeaderElectionChangeNamespaceIT.java index 1a3a450b90..dab495ba18 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionChangeNamespaceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/leaderelectionchangenamespace/LeaderElectionChangeNamespaceIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.leaderelectionchangenamespace; import java.time.Duration; import java.time.ZonedDateTime; @@ -16,8 +16,6 @@ import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.leaderelectionchangenamespace.LeaderElectionChangeNamespaceCustomResource; -import io.javaoperatorsdk.operator.sample.leaderelectionchangenamespace.LeaderElectionChangeNamespaceReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/leaderelectionchangenamespace/LeaderElectionChangeNamespaceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/leaderelectionchangenamespace/LeaderElectionChangeNamespaceReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/leaderelectionchangenamespace/LeaderElectionChangeNamespaceReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/leaderelectionchangenamespace/LeaderElectionChangeNamespaceReconciler.java index 8651a4774e..70b45035b7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/leaderelectionchangenamespace/LeaderElectionChangeNamespaceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/leaderelectionchangenamespace/LeaderElectionChangeNamespaceReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.leaderelectionchangenamespace; +package io.javaoperatorsdk.operator.baseapi.leaderelectionchangenamespace; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationCustomResource.java index 10b54fe79d..d33f9dd5b3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.manualobservedgeneration; +package io.javaoperatorsdk.operator.baseapi.manualobservedgeneration; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManualObservedGenerationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ManualObservedGenerationIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationIT.java index ddfb2370d6..743f73742d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManualObservedGenerationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationIT.java @@ -1,13 +1,10 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.manualobservedgeneration; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.manualobservedgeneration.ManualObservedGenerationCustomResource; -import io.javaoperatorsdk.operator.sample.manualobservedgeneration.ManualObservedGenerationReconciler; -import io.javaoperatorsdk.operator.sample.manualobservedgeneration.ManualObservedGenerationSpec; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationReconciler.java index 6e3aa15dce..865d099766 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.manualobservedgeneration; +package io.javaoperatorsdk.operator.baseapi.manualobservedgeneration; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationSpec.java similarity index 73% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationSpec.java index 35b04685aa..4c7076efd1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.manualobservedgeneration; +package io.javaoperatorsdk.operator.baseapi.manualobservedgeneration; public class ManualObservedGenerationSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationStatus.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationStatus.java index cdb6d56b2e..b70a4f18da 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manualobservedgeneration/ManualObservedGenerationStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/manualobservedgeneration/ManualObservedGenerationStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.manualobservedgeneration; +package io.javaoperatorsdk.operator.baseapi.manualobservedgeneration; public class ManualObservedGenerationStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MaxIntervalIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxinterval/MaxIntervalIT.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MaxIntervalIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxinterval/MaxIntervalIT.java index 35ae316f53..460b374071 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MaxIntervalIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxinterval/MaxIntervalIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.maxinterval; import java.util.concurrent.TimeUnit; @@ -7,8 +7,6 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.maxinterval.MaxIntervalTestCustomResource; -import io.javaoperatorsdk.operator.sample.maxinterval.MaxIntervalTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxinterval/MaxIntervalTestCustomResource.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxinterval/MaxIntervalTestCustomResource.java index 1c6cf81453..d9f7cb74ba 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxinterval/MaxIntervalTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.maxinterval; +package io.javaoperatorsdk.operator.baseapi.maxinterval; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -12,6 +12,6 @@ @Kind("MaxIntervalTestCustomResource") @ShortNames("mit") public class MaxIntervalTestCustomResource - extends CustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxinterval/MaxIntervalTestReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxinterval/MaxIntervalTestReconciler.java index de77a0220c..ce9197cff5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxinterval/MaxIntervalTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.maxinterval; +package io.javaoperatorsdk.operator.baseapi.maxinterval; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MaxIntervalAfterRetryIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxintervalafterretry/MaxIntervalAfterRetryIT.java similarity index 84% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MaxIntervalAfterRetryIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxintervalafterretry/MaxIntervalAfterRetryIT.java index 84814e127e..ce53c483cc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MaxIntervalAfterRetryIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxintervalafterretry/MaxIntervalAfterRetryIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.maxintervalafterretry; import java.util.concurrent.TimeUnit; @@ -7,8 +7,6 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.maxintervalafterretry.MaxIntervalAfterRetryTestCustomResource; -import io.javaoperatorsdk.operator.sample.maxintervalafterretry.MaxIntervalAfterRetryTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxintervalafterretry/MaxIntervalAfterRetryTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxintervalafterretry/MaxIntervalAfterRetryTestCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxintervalafterretry/MaxIntervalAfterRetryTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxintervalafterretry/MaxIntervalAfterRetryTestCustomResource.java index cc914f6c48..85328a26a3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxintervalafterretry/MaxIntervalAfterRetryTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxintervalafterretry/MaxIntervalAfterRetryTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.maxintervalafterretry; +package io.javaoperatorsdk.operator.baseapi.maxintervalafterretry; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxintervalafterretry/MaxIntervalAfterRetryTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxintervalafterretry/MaxIntervalAfterRetryTestReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxintervalafterretry/MaxIntervalAfterRetryTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxintervalafterretry/MaxIntervalAfterRetryTestReconciler.java index 5608731a3e..cf9a42f0e2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxintervalafterretry/MaxIntervalAfterRetryTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/maxintervalafterretry/MaxIntervalAfterRetryTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.maxintervalafterretry; +package io.javaoperatorsdk.operator.baseapi.maxintervalafterretry; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeCustomResource.java index 53c731e5e7..d7e3fa5c37 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplereconcilersametype; +package io.javaoperatorsdk.operator.baseapi.multiplereconcilersametype; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleReconcilerSameTypeIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeIT.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleReconcilerSameTypeIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeIT.java index b0be12bd91..57e4ad795b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleReconcilerSameTypeIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeIT.java @@ -1,13 +1,10 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.multiplereconcilersametype; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multiplereconcilersametype.MultipleReconcilerSameTypeCustomResource; -import io.javaoperatorsdk.operator.sample.multiplereconcilersametype.MultipleReconcilerSameTypeReconciler1; -import io.javaoperatorsdk.operator.sample.multiplereconcilersametype.MultipleReconcilerSameTypeReconciler2; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java index a8f78d328e..e9a80a8812 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplereconcilersametype; +package io.javaoperatorsdk.operator.baseapi.multiplereconcilersametype; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java index a65535908e..d7a7ae54b8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplereconcilersametype; +package io.javaoperatorsdk.operator.baseapi.multiplereconcilersametype; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeStatus.java similarity index 77% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeStatus.java index 9335d89752..e14dd2ea6b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplereconcilersametype/MultipleReconcilerSameTypeStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplereconcilersametype; +package io.javaoperatorsdk.operator.baseapi.multiplereconcilersametype; public class MultipleReconcilerSameTypeStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceCustomResource.java similarity index 78% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceCustomResource.java index 0d9f636531..d142f1f0d1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplesecondaryeventsource; +package io.javaoperatorsdk.operator.baseapi.multiplesecondaryeventsource; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -12,6 +12,6 @@ @Kind("MultipleSecondaryEventSourceCustomResource") @ShortNames("mses") public class MultipleSecondaryEventSourceCustomResource - extends CustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleSecondaryEventSourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceIT.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleSecondaryEventSourceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceIT.java index 85be323379..856f6d8a6f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleSecondaryEventSourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.multiplesecondaryeventsource; import java.time.Duration; @@ -8,8 +8,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multiplesecondaryeventsource.MultipleSecondaryEventSourceCustomResource; -import io.javaoperatorsdk.operator.sample.multiplesecondaryeventsource.MultipleSecondaryEventSourceReconciler; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java similarity index 98% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java index 6ba1cfa801..12d726e3a4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplesecondaryeventsource; +package io.javaoperatorsdk.operator.baseapi.multiplesecondaryeventsource; import java.util.HashMap; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiVersionCRDIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDIT.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiVersionCRDIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDIT.java index de6cc681b6..687ea3c581 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiVersionCRDIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.multiversioncrd; import java.time.Duration; import java.util.HashMap; @@ -15,12 +15,6 @@ import io.fabric8.kubernetes.client.utils.Serialization; import io.javaoperatorsdk.operator.api.config.InformerStoppedHandler; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multiversioncrd.MultiVersionCRDTestCustomResource1; -import io.javaoperatorsdk.operator.sample.multiversioncrd.MultiVersionCRDTestCustomResource2; -import io.javaoperatorsdk.operator.sample.multiversioncrd.MultiVersionCRDTestCustomResourceSpec1; -import io.javaoperatorsdk.operator.sample.multiversioncrd.MultiVersionCRDTestCustomResourceSpec2; -import io.javaoperatorsdk.operator.sample.multiversioncrd.MultiVersionCRDTestReconciler1; -import io.javaoperatorsdk.operator.sample.multiversioncrd.MultiVersionCRDTestReconciler2; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResource1.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResource1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResource1.java index e050ccfb35..cdc56026eb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResource1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResource1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiversioncrd; +package io.javaoperatorsdk.operator.baseapi.multiversioncrd; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResource2.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResource2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResource2.java index 5f29c88c51..ecf3f0c7e2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResource2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResource2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiversioncrd; +package io.javaoperatorsdk.operator.baseapi.multiversioncrd; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceSpec1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceSpec1.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceSpec1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceSpec1.java index 5c915179e2..da6b415cee 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceSpec1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceSpec1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiversioncrd; +package io.javaoperatorsdk.operator.baseapi.multiversioncrd; public class MultiVersionCRDTestCustomResourceSpec1 { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceSpec2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceSpec2.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceSpec2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceSpec2.java index a4058dbd9f..2219acca36 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceSpec2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceSpec2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiversioncrd; +package io.javaoperatorsdk.operator.baseapi.multiversioncrd; public class MultiVersionCRDTestCustomResourceSpec2 { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceStatus1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceStatus1.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceStatus1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceStatus1.java index 765766b1e2..17c0f00bab 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceStatus1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceStatus1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiversioncrd; +package io.javaoperatorsdk.operator.baseapi.multiversioncrd; import java.util.ArrayList; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceStatus2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceStatus2.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceStatus2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceStatus2.java index 5df57ef76d..5af2e55177 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestCustomResourceStatus2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestCustomResourceStatus2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiversioncrd; +package io.javaoperatorsdk.operator.baseapi.multiversioncrd; import java.util.ArrayList; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler1.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler1.java index 0a433e4047..e84e537925 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiversioncrd; +package io.javaoperatorsdk.operator.baseapi.multiversioncrd; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler2.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler2.java index 2e8bd30fdd..262e66c37c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiversioncrd/MultiVersionCRDTestReconciler2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiversioncrd; +package io.javaoperatorsdk.operator.baseapi.multiversioncrd; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentCustomResource.java index fba4242925..5a54443393 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.nextreconciliationimminent; +package io.javaoperatorsdk.operator.baseapi.nextreconciliationimminent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/NextReconciliationImminentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentIT.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/NextReconciliationImminentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentIT.java index 9f9b464a83..5f7933610f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/NextReconciliationImminentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.nextreconciliationimminent; import java.time.Duration; @@ -9,8 +9,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.nextreconciliationimminent.NextReconciliationImminentCustomResource; -import io.javaoperatorsdk.operator.sample.nextreconciliationimminent.NextReconciliationImminentReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentReconciler.java index be3ad70ee8..d3de766869 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.nextreconciliationimminent; +package io.javaoperatorsdk.operator.baseapi.nextreconciliationimminent; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.TimeUnit; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentStatus.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentStatus.java index ee4528af7a..66aed10ba3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/nextreconciliationimminent/NextReconciliationImminentStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/nextreconciliationimminent/NextReconciliationImminentStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.nextreconciliationimminent; +package io.javaoperatorsdk.operator.baseapi.nextreconciliationimminent; public class NextReconciliationImminentStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java index d5273d4e1d..45f5543024 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSACustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa; +package io.javaoperatorsdk.operator.baseapi.patchresourceandstatusnossa; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusNoSSAIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAIT.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusNoSSAIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAIT.java index 9583629a7c..de4ba09b23 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusNoSSAIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.patchresourceandstatusnossa; import java.util.concurrent.TimeUnit; @@ -7,10 +7,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa.PatchResourceAndStatusNoSSACustomResource; -import io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa.PatchResourceAndStatusNoSSAReconciler; -import io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa.PatchResourceAndStatusNoSSASpec; -import io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa.PatchResourceAndStatusNoSSAStatus; import io.javaoperatorsdk.operator.support.TestUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java index ecbceb8f65..a104ca4185 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa; +package io.javaoperatorsdk.operator.baseapi.patchresourceandstatusnossa; import java.util.HashMap; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java index ebc58bc862..aa8aeca39c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSASpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa; +package io.javaoperatorsdk.operator.baseapi.patchresourceandstatusnossa; public class PatchResourceAndStatusNoSSASpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java index f31031cbcc..bad4568700 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourceandstatusnossa/PatchResourceAndStatusNoSSAStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.patchresourceandstatusnossa; +package io.javaoperatorsdk.operator.baseapi.patchresourceandstatusnossa; public class PatchResourceAndStatusNoSSAStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusWithSSAIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceAndStatusWithSSAIT.java similarity index 64% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusWithSSAIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceAndStatusWithSSAIT.java index 644316faf2..b8746dda3f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceAndStatusWithSSAIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceAndStatusWithSSAIT.java @@ -1,7 +1,6 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.patchresourcewithssa; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceAndStatusWithSSAReconciler; public class PatchResourceAndStatusWithSSAIT extends PatchWithSSAITBase { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java index 0c9cbf0456..2d599a9039 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceAndStatusWithSSAReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.patchresourcewithssa; +package io.javaoperatorsdk.operator.baseapi.patchresourcewithssa; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.*; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSACustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSACustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSACustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSACustomResource.java index 602776f3cb..0c789127ac 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSACustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSACustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.patchresourcewithssa; +package io.javaoperatorsdk.operator.baseapi.patchresourcewithssa; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceWithSSAIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSAIT.java similarity index 64% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceWithSSAIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSAIT.java index 80f81f78d1..6ceaea2867 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchResourceWithSSAIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSAIT.java @@ -1,8 +1,7 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.patchresourcewithssa; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceWithSSAReconciler; public class PatchResourceWithSSAIT extends PatchWithSSAITBase { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSAReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSAReconciler.java index 5e3929a163..f5f53ee6c5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSAReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.patchresourcewithssa; +package io.javaoperatorsdk.operator.baseapi.patchresourcewithssa; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.*; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSASpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSASpec.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSASpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSASpec.java index 77d4fe0428..253625af56 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSASpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSASpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.patchresourcewithssa; +package io.javaoperatorsdk.operator.baseapi.patchresourcewithssa; public class PatchResourceWithSSASpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSAStatus.java similarity index 82% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSAStatus.java index 982ef83129..f3d5f7806c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/patchresourcewithssa/PatchResourceWithSSAStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchResourceWithSSAStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.patchresourcewithssa; +package io.javaoperatorsdk.operator.baseapi.patchresourcewithssa; public class PatchResourceWithSSAStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchWithSSAITBase.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchWithSSAITBase.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchWithSSAITBase.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchWithSSAITBase.java index b3b6b4fc32..50b005fef7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PatchWithSSAITBase.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/patchresourcewithssa/PatchWithSSAITBase.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.patchresourcewithssa; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -6,9 +6,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceWithSSACustomResource; -import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceWithSSAReconciler; -import io.javaoperatorsdk.operator.sample.patchresourcewithssa.PatchResourceWithSSASpec; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourceEventSourceCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/perresourceeventsource/PerResourceEventSourceCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourceEventSourceCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/perresourceeventsource/PerResourceEventSourceCustomResource.java index 381e324aae..74817da86d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourceEventSourceCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/perresourceeventsource/PerResourceEventSourceCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.perresourceeventsource; +package io.javaoperatorsdk.operator.baseapi.perresourceeventsource; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PerResourcePollingEventSourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/perresourceeventsource/PerResourcePollingEventSourceIT.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PerResourcePollingEventSourceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/perresourceeventsource/PerResourcePollingEventSourceIT.java index 3a827572e5..299109bdd1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PerResourcePollingEventSourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/perresourceeventsource/PerResourcePollingEventSourceIT.java @@ -1,12 +1,10 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.perresourceeventsource; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.perresourceeventsource.PerResourceEventSourceCustomResource; -import io.javaoperatorsdk.operator.sample.perresourceeventsource.PerResourcePollingEventSourceTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java index 89b144da0d..8d1cbcc37f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/perresourceeventsource/PerResourcePollingEventSourceTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.perresourceeventsource; +package io.javaoperatorsdk.operator.baseapi.perresourceeventsource; import java.time.Duration; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/AbstractPrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/AbstractPrimaryIndexerTestReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/AbstractPrimaryIndexerTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/AbstractPrimaryIndexerTestReconciler.java index 0fcdc8e39d..ac2e7e1534 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/AbstractPrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/AbstractPrimaryIndexerTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primaryindexer; +package io.javaoperatorsdk.operator.baseapi.primaryindexer; import java.util.List; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryIndexerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerIT.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryIndexerIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerIT.java index fb202de390..cb810dcd35 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryIndexerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.primaryindexer; import java.time.Duration; @@ -8,17 +8,12 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.primaryindexer.AbstractPrimaryIndexerTestReconciler; -import io.javaoperatorsdk.operator.sample.primaryindexer.PrimaryIndexerTestCustomResource; -import io.javaoperatorsdk.operator.sample.primaryindexer.PrimaryIndexerTestCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.primaryindexer.PrimaryIndexerTestReconciler; -import static io.javaoperatorsdk.operator.sample.primaryindexer.AbstractPrimaryIndexerTestReconciler.CONFIG_MAP_NAME; +import static io.javaoperatorsdk.operator.baseapi.primaryindexer.AbstractPrimaryIndexerTestReconciler.CONFIG_MAP_NAME; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -class PrimaryIndexerIT { - +public class PrimaryIndexerIT { public static final String RESOURCE_NAME1 = "test1"; public static final String RESOURCE_NAME2 = "test2"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestCustomResource.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestCustomResource.java index 65a6fb3c43..f670a4be64 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primaryindexer; +package io.javaoperatorsdk.operator.baseapi.primaryindexer; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestCustomResourceSpec.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestCustomResourceSpec.java index 4e1430701c..65cbf68d80 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primaryindexer; +package io.javaoperatorsdk.operator.baseapi.primaryindexer; public class PrimaryIndexerTestCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestCustomResourceStatus.java similarity index 50% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestCustomResourceStatus.java index c52b3bce1e..ebcfe347e5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primaryindexer; +package io.javaoperatorsdk.operator.baseapi.primaryindexer; public class PrimaryIndexerTestCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestReconciler.java index 15f76b6ae2..0c6318f0a9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primaryindexer; +package io.javaoperatorsdk.operator.baseapi.primaryindexer; import java.util.List; import java.util.stream.Collectors; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/Cluster.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/Cluster.java similarity index 77% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/Cluster.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/Cluster.java index ffc43141a4..18190ae1fa 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/Cluster.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/Cluster.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondary; +package io.javaoperatorsdk.operator.baseapi.primarytosecondary; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -10,6 +10,6 @@ @Version("v1") @ShortNames("clu") public class Cluster - extends CustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/Job.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/Job.java similarity index 77% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/Job.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/Job.java index 5a3d43de79..3215fd8538 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/Job.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/Job.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondary; +package io.javaoperatorsdk.operator.baseapi.primarytosecondary; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -10,6 +10,6 @@ @Version("v1") @ShortNames("cjo") public class Job - extends CustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobReconciler.java similarity index 98% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobReconciler.java index 4f2bf2d488..2503b9b54c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondary; +package io.javaoperatorsdk.operator.baseapi.primarytosecondary; import java.util.List; import java.util.Set; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobSpec.java similarity index 78% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobSpec.java index c7546dea71..c450129627 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondary; +package io.javaoperatorsdk.operator.baseapi.primarytosecondary; public class JobSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/PrimaryToSecondaryIT.java similarity index 82% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/PrimaryToSecondaryIT.java index 720683a8cc..cfcb2854bb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/PrimaryToSecondaryIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.primarytosecondary; import java.time.Duration; @@ -7,10 +7,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.primarytosecondary.Cluster; -import io.javaoperatorsdk.operator.sample.primarytosecondary.Job; -import io.javaoperatorsdk.operator.sample.primarytosecondary.JobReconciler; -import io.javaoperatorsdk.operator.sample.primarytosecondary.JobSpec; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryMissingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/PrimaryToSecondaryMissingIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryMissingIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/PrimaryToSecondaryMissingIT.java index 3105ab04ff..4e1908f282 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryMissingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/PrimaryToSecondaryMissingIT.java @@ -1,14 +1,12 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.primarytosecondary; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.primarytosecondary.Cluster; -import io.javaoperatorsdk.operator.sample.primarytosecondary.JobReconciler; -import static io.javaoperatorsdk.operator.PrimaryToSecondaryIT.cluster; -import static io.javaoperatorsdk.operator.PrimaryToSecondaryIT.job; +import static io.javaoperatorsdk.operator.baseapi.primarytosecondary.PrimaryToSecondaryIT.cluster; +import static io.javaoperatorsdk.operator.baseapi.primarytosecondary.PrimaryToSecondaryIT.job; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResource.java similarity index 74% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResource.java index 60456e6a4d..79732a199b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.ratelimit; +package io.javaoperatorsdk.operator.baseapi.ratelimit; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -10,7 +10,7 @@ @Version("v1") @ShortNames("rlc") public class RateLimitCustomResource - extends CustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResourceSpec.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResourceSpec.java index 7dbee7f75a..ef9f747c20 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.ratelimit; +package io.javaoperatorsdk.operator.baseapi.ratelimit; public class RateLimitCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResourceStatus.java new file mode 100644 index 0000000000..a33142805b --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitCustomResourceStatus.java @@ -0,0 +1,5 @@ +package io.javaoperatorsdk.operator.baseapi.ratelimit; + +public class RateLimitCustomResourceStatus { + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/RateLimitIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/RateLimitIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitIT.java index f1d5bed6f1..1f09b75b59 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/RateLimitIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.ratelimit; import java.time.Duration; import java.util.stream.IntStream; @@ -10,11 +10,8 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.ratelimit.RateLimitCustomResource; -import io.javaoperatorsdk.operator.sample.ratelimit.RateLimitCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.ratelimit.RateLimitReconciler; -import static io.javaoperatorsdk.operator.sample.ratelimit.RateLimitReconciler.REFRESH_PERIOD; +import static io.javaoperatorsdk.operator.baseapi.ratelimit.RateLimitReconciler.REFRESH_PERIOD; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitReconciler.java index 19a63952ef..75a70f94d1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/ratelimit/RateLimitReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.ratelimit; +package io.javaoperatorsdk.operator.baseapi.ratelimit; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/RetryIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryIT.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/RetryIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryIT.java index a54e24dc70..e1610dc000 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/RetryIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.retry; import java.util.concurrent.TimeUnit; @@ -8,10 +8,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; -import io.javaoperatorsdk.operator.sample.retry.RetryTestCustomReconciler; -import io.javaoperatorsdk.operator.sample.retry.RetryTestCustomResource; -import io.javaoperatorsdk.operator.sample.retry.RetryTestCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.retry.RetryTestCustomResourceStatus; import io.javaoperatorsdk.operator.support.TestUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/RetryMaxAttemptIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryMaxAttemptIT.java similarity index 81% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/RetryMaxAttemptIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryMaxAttemptIT.java index d09b14c4a9..bedfd5cff5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/RetryMaxAttemptIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryMaxAttemptIT.java @@ -1,14 +1,12 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.retry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; -import io.javaoperatorsdk.operator.sample.retry.RetryTestCustomReconciler; -import io.javaoperatorsdk.operator.sample.retry.RetryTestCustomResource; -import static io.javaoperatorsdk.operator.RetryIT.createTestCustomResource; +import static io.javaoperatorsdk.operator.baseapi.retry.RetryIT.createTestCustomResource; import static org.assertj.core.api.Assertions.assertThat; class RetryMaxAttemptIT { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomReconciler.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomReconciler.java index 29d658fc7b..b9fee4769a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.retry; +package io.javaoperatorsdk.operator.baseapi.retry; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomResource.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomResource.java index 093bdbc6d8..0b3e1244b6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.retry; +package io.javaoperatorsdk.operator.baseapi.retry; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomResourceSpec.java similarity index 81% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomResourceSpec.java index ec34d11df8..169233e7d4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.retry; +package io.javaoperatorsdk.operator.baseapi.retry; public class RetryTestCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomResourceStatus.java similarity index 84% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomResourceStatus.java index d83b611f65..b2d8f3ba56 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/retry/RetryTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/retry/RetryTestCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.retry; +package io.javaoperatorsdk.operator.baseapi.retry; public class RetryTestCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReconcilerExecutorIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/ReconcilerExecutorIT.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ReconcilerExecutorIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/ReconcilerExecutorIT.java index 476bd842a5..727930d8e6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReconcilerExecutorIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/ReconcilerExecutorIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.simple; import java.time.Duration; import java.util.concurrent.TimeUnit; @@ -8,8 +8,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; -import io.javaoperatorsdk.operator.sample.simple.TestReconciler; import io.javaoperatorsdk.operator.support.TestUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestCustomResource.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestCustomResource.java index c72b0533d9..5728746573 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.simple; +package io.javaoperatorsdk.operator.baseapi.simple; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestCustomResourceSpec.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestCustomResourceSpec.java index 5fd9f49084..eda3c477b2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.simple; +package io.javaoperatorsdk.operator.baseapi.simple; public class TestCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestCustomResourceStatus.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestCustomResourceStatus.java index 620bbaabd8..75fadc8e5e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.simple; +package io.javaoperatorsdk.operator.baseapi.simple; public class TestCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestReconciler.java similarity index 98% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestReconciler.java index 4ff4521d00..50cfd334bf 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/simple/TestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.simple; +package io.javaoperatorsdk.operator.baseapi.simple; import java.util.HashMap; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingCustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingCustomResource.java index 93ec97884d..61d4c7f1ac 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statuspatchnonlocking; +package io.javaoperatorsdk.operator.baseapi.statuspatchnonlocking; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingCustomResourceSpec.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingCustomResourceSpec.java index 3f0a59843e..298896a8b5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statuspatchnonlocking; +package io.javaoperatorsdk.operator.baseapi.statuspatchnonlocking; public class StatusPatchLockingCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingCustomResourceStatus.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingCustomResourceStatus.java index 1ab7abb4d0..b4629b8207 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statuspatchnonlocking; +package io.javaoperatorsdk.operator.baseapi.statuspatchnonlocking; public class StatusPatchLockingCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingReconciler.java index 21f83fc53f..9cafaa26ec 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statuspatchnonlocking/StatusPatchLockingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchLockingReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statuspatchnonlocking; +package io.javaoperatorsdk.operator.baseapi.statuspatchnonlocking; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchNotLockingIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchNotLockingIT.java index 0a82bed51a..24ce2d1047 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchNotLockingIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.statuspatchnonlocking; import java.time.Duration; import java.util.Map; @@ -8,12 +8,9 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingCustomResource; -import io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingReconciler; -import static io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingReconciler.MESSAGE; -import static io.javaoperatorsdk.operator.sample.statusupdatelocking.StatusUpdateLockingReconciler.WAIT_TIME; +import static io.javaoperatorsdk.operator.baseapi.statuspatchnonlocking.StatusPatchLockingReconciler.MESSAGE; +import static io.javaoperatorsdk.operator.baseapi.statusupdatelocking.StatusUpdateLockingReconciler.WAIT_TIME; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchSSAMigrationIT.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchSSAMigrationIT.java index fba39cc03f..0a5c947c21 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchSSAMigrationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuspatchnonlocking/StatusPatchSSAMigrationIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.statuspatchnonlocking; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -11,10 +11,8 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil; +import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingCustomResource; -import io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.statuspatchnonlocking.StatusPatchLockingReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingCustomResource.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingCustomResource.java index 0f95ccd824..fb638ef5a0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statusupdatelocking; +package io.javaoperatorsdk.operator.baseapi.statusupdatelocking; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingCustomResourceStatus.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingCustomResourceStatus.java index 859624d70e..81d6c8f123 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statusupdatelocking; +package io.javaoperatorsdk.operator.baseapi.statusupdatelocking; public class StatusUpdateLockingCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingIT.java index e03883d8db..881b0b01fc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.statusupdatelocking; import java.time.Duration; import java.util.Map; @@ -8,10 +8,8 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.statusupdatelocking.StatusUpdateLockingCustomResource; -import io.javaoperatorsdk.operator.sample.statusupdatelocking.StatusUpdateLockingReconciler; -import static io.javaoperatorsdk.operator.sample.statusupdatelocking.StatusUpdateLockingReconciler.WAIT_TIME; +import static io.javaoperatorsdk.operator.baseapi.statusupdatelocking.StatusUpdateLockingReconciler.WAIT_TIME; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingReconciler.java index fc007f5dfa..31dc727dde 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statusupdatelocking/StatusUpdateLockingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statusupdatelocking/StatusUpdateLockingReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statusupdatelocking; +package io.javaoperatorsdk.operator.baseapi.statusupdatelocking; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomReconciler.java index b50b9fc4b5..51ae9e9330 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.subresource; +package io.javaoperatorsdk.operator.baseapi.subresource; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomResource.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomResource.java index 5b96483729..976af2c97f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.subresource; +package io.javaoperatorsdk.operator.baseapi.subresource; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomResourceSpec.java similarity index 81% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomResourceSpec.java index 21b8e2bc84..9b6c4f8060 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.subresource; +package io.javaoperatorsdk.operator.baseapi.subresource; public class SubResourceTestCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomResourceStatus.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomResourceStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomResourceStatus.java index c1c9d708c0..46080b784e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/subresource/SubResourceTestCustomResourceStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceTestCustomResourceStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.subresource; +package io.javaoperatorsdk.operator.baseapi.subresource; public class SubResourceTestCustomResourceStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/SubResourceUpdateIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceUpdateIT.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/SubResourceUpdateIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceUpdateIT.java index ee6fc8e422..8a73cadf3f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/SubResourceUpdateIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/subresource/SubResourceUpdateIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.subresource; import java.util.Collections; import java.util.concurrent.TimeUnit; @@ -8,12 +8,9 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.subresource.SubResourceTestCustomReconciler; -import io.javaoperatorsdk.operator.sample.subresource.SubResourceTestCustomResource; -import io.javaoperatorsdk.operator.sample.subresource.SubResourceTestCustomResourceSpec; import io.javaoperatorsdk.operator.support.TestUtils; -import static io.javaoperatorsdk.operator.sample.subresource.SubResourceTestCustomResourceStatus.State.SUCCESS; +import static io.javaoperatorsdk.operator.baseapi.subresource.SubResourceTestCustomResourceStatus.State.SUCCESS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartCustomResource.java index 013fd62503..7b0d757f82 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.unmodifiabledependentpart; +package io.javaoperatorsdk.operator.baseapi.unmodifiabledependentpart; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UnmodifiableDependentPartIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartIT.java similarity index 75% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/UnmodifiableDependentPartIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartIT.java index bc0e951d8a..a80905c23a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UnmodifiableDependentPartIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.unmodifiabledependentpart; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -6,12 +6,9 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiableDependentPartCustomResource; -import io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiableDependentPartReconciler; -import io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiableDependentPartSpec; -import static io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiablePartConfigMapDependent.ACTUAL_DATA_KEY; -import static io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiablePartConfigMapDependent.UNMODIFIABLE_INITIAL_DATA_KEY; +import static io.javaoperatorsdk.operator.baseapi.unmodifiabledependentpart.UnmodifiablePartConfigMapDependent.ACTUAL_DATA_KEY; +import static io.javaoperatorsdk.operator.baseapi.unmodifiabledependentpart.UnmodifiablePartConfigMapDependent.UNMODIFIABLE_INITIAL_DATA_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java index 9cc4a3e9d6..9c7f6fb9c1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.unmodifiabledependentpart; +package io.javaoperatorsdk.operator.baseapi.unmodifiabledependentpart; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartSpec.java index 3f9c9b3460..1c896c75c3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiableDependentPartSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiableDependentPartSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.unmodifiabledependentpart; +package io.javaoperatorsdk.operator.baseapi.unmodifiabledependentpart; public class UnmodifiableDependentPartSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java index d373fe7d26..d913c0cecd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/unmodifiabledependentpart/UnmodifiablePartConfigMapDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.unmodifiabledependentpart; +package io.javaoperatorsdk.operator.baseapi.unmodifiabledependentpart; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomResource.java index 9c6365e5d0..de877ceb90 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.updatestatusincleanupandreschedule; +package io.javaoperatorsdk.operator.baseapi.updatestatusincleanupandreschedule; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomStatus.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomStatus.java index 17e4067a44..dcd9d7dd6c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleCustomStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.updatestatusincleanupandreschedule; +package io.javaoperatorsdk.operator.baseapi.updatestatusincleanupandreschedule; public class UpdateStatusInCleanupAndRescheduleCustomStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdateStatusInCleanupAndRescheduleIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleIT.java similarity index 84% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdateStatusInCleanupAndRescheduleIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleIT.java index 798ea4eac5..81dc6dd448 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdateStatusInCleanupAndRescheduleIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleIT.java @@ -1,12 +1,10 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.baseapi.updatestatusincleanupandreschedule; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.updatestatusincleanupandreschedule.UpdateStatusInCleanupAndRescheduleCustomResource; -import io.javaoperatorsdk.operator.sample.updatestatusincleanupandreschedule.UpdateStatusInCleanupAndRescheduleReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java index 762948d1c1..ed38df7172 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/updatestatusincleanupandreschedule/UpdateStatusInCleanupAndRescheduleReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.updatestatusincleanupandreschedule; +package io.javaoperatorsdk.operator.baseapi.updatestatusincleanupandreschedule; import java.time.LocalTime; import java.time.temporal.ChronoUnit; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java index 81e4ea5a10..65e3d221ae 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java @@ -31,9 +31,14 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; +import io.javaoperatorsdk.operator.dependent.dependentssa.DependentSSAReconciler; +import io.javaoperatorsdk.operator.dependent.readonly.ConfigMapReader; +import io.javaoperatorsdk.operator.dependent.readonly.ReadOnlyDependent; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.BooleanWithUndefined; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig; import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimited; @@ -41,9 +46,6 @@ import io.javaoperatorsdk.operator.processing.retry.GradualRetry; import io.javaoperatorsdk.operator.processing.retry.Retry; import io.javaoperatorsdk.operator.processing.retry.RetryExecution; -import io.javaoperatorsdk.operator.sample.dependentssa.DependentSSAReconciler; -import io.javaoperatorsdk.operator.sample.readonly.ConfigMapReader; -import io.javaoperatorsdk.operator.sample.readonly.ReadOnlyDependent; import static io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval.DEFAULT_INTERVAL; import static org.assertj.core.api.Assertions.assertThat; @@ -243,7 +245,6 @@ void excludedResourceClassesShouldNotUseSSAByDefault() { final var kubernetesDependentResourceConfig = extractDependentKubernetesResourceConfig(config, 1); assertNotNull(kubernetesDependentResourceConfig); - assertTrue(kubernetesDependentResourceConfig.useSSA().isEmpty()); assertFalse(configurationService.shouldUseSSA(ReadOnlyDependent.class, ConfigMap.class, kubernetesDependentResourceConfig)); } @@ -257,8 +258,7 @@ void excludedResourceClassesShouldUseSSAIfAnnotatedToDoSo() { final var kubernetesDependentResourceConfig = extractDependentKubernetesResourceConfig(config, 0); assertNotNull(kubernetesDependentResourceConfig); - assertFalse(kubernetesDependentResourceConfig.useSSA().isEmpty()); - assertTrue((Boolean) kubernetesDependentResourceConfig.useSSA().get()); + assertTrue(kubernetesDependentResourceConfig.useSSA()); assertTrue(configurationService.shouldUseSSA(SelectorReconciler.WithAnnotation.class, ConfigMap.class, kubernetesDependentResourceConfig)); } @@ -270,15 +270,13 @@ void dependentsShouldUseSSAByDefaultIfNotExcluded() { var kubernetesDependentResourceConfig = extractDependentKubernetesResourceConfig(config, 0); assertNotNull(kubernetesDependentResourceConfig); - assertTrue(kubernetesDependentResourceConfig.useSSA().isEmpty()); assertTrue(configurationService.shouldUseSSA( DefaultSSAForDependentsReconciler.DefaultDependent.class, ConfigMapReader.class, kubernetesDependentResourceConfig)); kubernetesDependentResourceConfig = extractDependentKubernetesResourceConfig(config, 1); assertNotNull(kubernetesDependentResourceConfig); - assertTrue(kubernetesDependentResourceConfig.useSSA().isPresent()); - assertFalse((Boolean) kubernetesDependentResourceConfig.useSSA().get()); + assertFalse(kubernetesDependentResourceConfig.useSSA()); assertFalse(configurationService .shouldUseSSA(DefaultSSAForDependentsReconciler.NonSSADependent.class, Service.class, kubernetesDependentResourceConfig)); @@ -412,10 +410,11 @@ public UpdateControl reconcile(ConfigMap resource, Context } } - @ControllerConfiguration(dependents = { - @Dependent(type = DefaultSSAForDependentsReconciler.DefaultDependent.class), - @Dependent(type = DefaultSSAForDependentsReconciler.NonSSADependent.class) - }) + @Workflow( + dependents = { + @Dependent(type = DefaultSSAForDependentsReconciler.DefaultDependent.class), + @Dependent(type = DefaultSSAForDependentsReconciler.NonSSADependent.class) + }) private static class DefaultSSAForDependentsReconciler implements Reconciler { @Override diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentDeleterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentDeleterIT.java similarity index 66% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentDeleterIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentDeleterIT.java index a934bdd1f3..be7365951e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentDeleterIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentDeleterIT.java @@ -1,9 +1,9 @@ -package io.javaoperatorsdk.operator.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent; import org.junit.jupiter.api.extension.RegisterExtension; +import io.javaoperatorsdk.operator.dependent.bulkdependent.managed.ManagedDeleterBulkReconciler; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.bulkdependent.ManagedDeleterBulkReconciler; public class BulkDependentDeleterIT extends BulkDependentTestBase { @@ -13,7 +13,7 @@ public class BulkDependentDeleterIT extends BulkDependentTestBase { .build(); @Override - LocallyRunOperatorExtension extension() { + public LocallyRunOperatorExtension extension() { return extension; } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentTestBase.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestBase.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentTestBase.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestBase.java index 605731623c..0441e31205 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentTestBase.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestBase.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent; import java.time.Duration; @@ -6,12 +6,9 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestSpec; -import io.javaoperatorsdk.operator.sample.bulkdependent.ConfigMapDeleterBulkDependentResource; -import static io.javaoperatorsdk.operator.sample.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_KEY; -import static io.javaoperatorsdk.operator.sample.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_VALUE; +import static io.javaoperatorsdk.operator.dependent.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_KEY; +import static io.javaoperatorsdk.operator.dependent.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -110,5 +107,5 @@ public static void updateSpecWithNumber(LocallyRunOperatorExtension extension, i extension.replace(resource); } - abstract LocallyRunOperatorExtension extension(); + public abstract LocallyRunOperatorExtension extension(); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/BulkDependentTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestCustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/BulkDependentTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestCustomResource.java index a0af65d0d3..f7451e06d6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/BulkDependentTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/BulkDependentTestSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestSpec.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/BulkDependentTestSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestSpec.java index 5266950b41..b6cd2b136b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/BulkDependentTestSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent; public class BulkDependentTestSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/BulkDependentTestStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestStatus.java similarity index 78% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/BulkDependentTestStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestStatus.java index cd16280ce9..38bf94bf0c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/BulkDependentTestStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/BulkDependentTestStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent; public class BulkDependentTestStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/CRUDConfigMapBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/CRUDConfigMapBulkDependentResource.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/CRUDConfigMapBulkDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/CRUDConfigMapBulkDependentResource.java index 83cec0bb69..236118c2c7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/CRUDConfigMapBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/CRUDConfigMapBulkDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/ConfigMapDeleterBulkDependentResource.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/ConfigMapDeleterBulkDependentResource.java index f9a92f9061..cba3db3835 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ConfigMapDeleterBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/ConfigMapDeleterBulkDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent; import java.util.HashMap; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentWithConditionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/condition/BulkDependentWithConditionIT.java similarity index 63% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentWithConditionIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/condition/BulkDependentWithConditionIT.java index b922bb73b4..d4b857bf0c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentWithConditionIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/condition/BulkDependentWithConditionIT.java @@ -1,16 +1,15 @@ -package io.javaoperatorsdk.operator.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent.condition; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; -import io.javaoperatorsdk.operator.sample.bulkdependent.ManagedBulkDependentWithReadyConditionReconciler; -import static io.javaoperatorsdk.operator.bulkdependent.BulkDependentTestBase.INITIAL_NUMBER_OF_CONFIG_MAPS; -import static io.javaoperatorsdk.operator.bulkdependent.BulkDependentTestBase.testResource; -import static io.javaoperatorsdk.operator.sample.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_KEY; -import static io.javaoperatorsdk.operator.sample.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_VALUE; +import static io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestBase.INITIAL_NUMBER_OF_CONFIG_MAPS; +import static io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestBase.testResource; +import static io.javaoperatorsdk.operator.dependent.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_KEY; +import static io.javaoperatorsdk.operator.dependent.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_VALUE; import static org.assertj.core.api.Assertions.*; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/condition/ManagedBulkDependentWithReadyConditionReconciler.java similarity index 77% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/condition/ManagedBulkDependentWithReadyConditionReconciler.java index aca1e98c88..331d064b80 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithReadyConditionReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/condition/ManagedBulkDependentWithReadyConditionReconciler.java @@ -1,9 +1,12 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent.condition; import java.util.concurrent.atomic.AtomicInteger; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestStatus; +import io.javaoperatorsdk.operator.dependent.bulkdependent.CRUDConfigMapBulkDependentResource; @Workflow(dependents = @Dependent(readyPostcondition = SampleBulkCondition.class, type = CRUDConfigMapBulkDependentResource.class)) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/SampleBulkCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/condition/SampleBulkCondition.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/SampleBulkCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/condition/SampleBulkCondition.java index 74048e7b54..c6e64b7413 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/SampleBulkCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/condition/SampleBulkCondition.java @@ -1,8 +1,10 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent.condition; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.CRUDConfigMapBulkDependentResource; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; public class SampleBulkCondition diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkExternalDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/BulkExternalDependentIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkExternalDependentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/BulkExternalDependentIT.java index 29f66e8205..d25f92d2be 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkExternalDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/BulkExternalDependentIT.java @@ -1,13 +1,11 @@ -package io.javaoperatorsdk.operator.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent.external; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.bulkdependent.external.ExternalBulkResourceReconciler; -import io.javaoperatorsdk.operator.sample.bulkdependent.external.ExternalServiceMock; -import static io.javaoperatorsdk.operator.bulkdependent.BulkDependentTestBase.*; +import static io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestBase.*; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalBulkDependentResource.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalBulkDependentResource.java index 7dee7ae962..5112b09be1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalBulkDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent.external; +package io.javaoperatorsdk.operator.dependent.bulkdependent.external; import java.util.HashMap; import java.util.HashSet; @@ -8,12 +8,12 @@ import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; import io.javaoperatorsdk.operator.processing.dependent.BulkUpdater; import io.javaoperatorsdk.operator.processing.dependent.Creator; import io.javaoperatorsdk.operator.processing.dependent.external.PollingDependentResource; import io.javaoperatorsdk.operator.processing.event.ResourceID; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; public class ExternalBulkDependentResource extends PollingDependentResource diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalBulkResourceReconciler.java similarity index 78% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkResourceReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalBulkResourceReconciler.java index f11621e4c2..1668a1b5d9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalBulkResourceReconciler.java @@ -1,8 +1,8 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent.external; +package io.javaoperatorsdk.operator.dependent.bulkdependent.external; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; @Workflow(dependents = @Dependent(type = ExternalBulkDependentResource.class)) @ControllerConfiguration() diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalResource.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalResource.java index ef101a8ca2..dfe8468fff 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent.external; +package io.javaoperatorsdk.operator.dependent.bulkdependent.external; import java.util.Objects; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalServiceMock.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalServiceMock.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalServiceMock.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalServiceMock.java index 4ae0cbccfa..16008be9ff 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalServiceMock.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/external/ExternalServiceMock.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent.external; +package io.javaoperatorsdk.operator.dependent.bulkdependent.external; import java.util.ArrayList; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/ManagedBulkDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/managed/ManagedBulkDependentIT.java similarity index 56% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/ManagedBulkDependentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/managed/ManagedBulkDependentIT.java index 7f074ac8f5..9f3d763f1b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/ManagedBulkDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/managed/ManagedBulkDependentIT.java @@ -1,11 +1,11 @@ -package io.javaoperatorsdk.operator.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent.managed; import org.junit.jupiter.api.extension.RegisterExtension; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestBase; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.bulkdependent.ManagedBulkDependentReconciler; -class ManagedBulkDependentIT extends BulkDependentTestBase { +public class ManagedBulkDependentIT extends BulkDependentTestBase { @RegisterExtension LocallyRunOperatorExtension extension = @@ -14,7 +14,7 @@ class ManagedBulkDependentIT extends BulkDependentTestBase { @Override - LocallyRunOperatorExtension extension() { + public LocallyRunOperatorExtension extension() { return extension; } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/managed/ManagedBulkDependentReconciler.java similarity index 74% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/managed/ManagedBulkDependentReconciler.java index 95be38fc4d..be323949aa 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/managed/ManagedBulkDependentReconciler.java @@ -1,9 +1,11 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent.managed; import java.util.concurrent.atomic.AtomicInteger; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.CRUDConfigMapBulkDependentResource; @Workflow(dependents = @Dependent(type = CRUDConfigMapBulkDependentResource.class)) @ControllerConfiguration diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedDeleterBulkReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/managed/ManagedDeleterBulkReconciler.java similarity index 69% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedDeleterBulkReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/managed/ManagedDeleterBulkReconciler.java index db5ba60044..7de2b3898f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/ManagedDeleterBulkReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/managed/ManagedDeleterBulkReconciler.java @@ -1,7 +1,9 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent.managed; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.ConfigMapDeleterBulkDependentResource; @Workflow(dependents = @Dependent(type = ConfigMapDeleterBulkDependentResource.class)) @ControllerConfiguration diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReadOnlyBulkDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkDependentIT.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ReadOnlyBulkDependentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkDependentIT.java index 265eb98e4e..c84ad38de0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ReadOnlyBulkDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkDependentIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.bulkdependent.readonly; import java.time.Duration; @@ -7,11 +7,9 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestSpec; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestSpec; -import io.javaoperatorsdk.operator.sample.bulkdependent.readonly.ReadOnlyBulkDependentResource; -import io.javaoperatorsdk.operator.sample.bulkdependent.readonly.ReadOnlyBulkReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkDependentResource.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkDependentResource.java index 661cfb931b..e655d96d6e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent.readonly; +package io.javaoperatorsdk.operator.dependent.bulkdependent.readonly; import java.util.Map; import java.util.Set; @@ -7,13 +7,13 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; @KubernetesDependent diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java index 9d036d74bd..9be51eb1f6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkReadyPostCondition.java @@ -1,11 +1,11 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent.readonly; +package io.javaoperatorsdk.operator.dependent.bulkdependent.readonly; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; public class ReadOnlyBulkReadyPostCondition implements Condition { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkReconciler.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkReconciler.java index df3366c115..5a78f94be7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/readonly/ReadOnlyBulkReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/readonly/ReadOnlyBulkReconciler.java @@ -1,10 +1,10 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent.readonly; +package io.javaoperatorsdk.operator.dependent.bulkdependent.readonly; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestCustomResource; -import io.javaoperatorsdk.operator.sample.bulkdependent.BulkDependentTestStatus; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestStatus; @Workflow(dependents = @Dependent(type = ReadOnlyBulkDependentResource.class, readyPostcondition = ReadOnlyBulkReadyPostCondition.class)) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/StandaloneBulkDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/standalone/StandaloneBulkDependentIT.java similarity index 67% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/StandaloneBulkDependentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/standalone/StandaloneBulkDependentIT.java index 683cc1662b..5e0ded6100 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/StandaloneBulkDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/standalone/StandaloneBulkDependentIT.java @@ -1,9 +1,9 @@ -package io.javaoperatorsdk.operator.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent.standalone; import org.junit.jupiter.api.extension.RegisterExtension; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestBase; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.bulkdependent.StandaloneBulkDependentReconciler; class StandaloneBulkDependentIT extends BulkDependentTestBase { @@ -13,7 +13,7 @@ class StandaloneBulkDependentIT extends BulkDependentTestBase { .build(); @Override - LocallyRunOperatorExtension extension() { + public LocallyRunOperatorExtension extension() { return extension; } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/standalone/StandaloneBulkDependentReconciler.java similarity index 78% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/standalone/StandaloneBulkDependentReconciler.java index 4622fd657c..ab74c41906 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/StandaloneBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/bulkdependent/standalone/StandaloneBulkDependentReconciler.java @@ -1,9 +1,12 @@ -package io.javaoperatorsdk.operator.sample.bulkdependent; +package io.javaoperatorsdk.operator.dependent.bulkdependent.standalone; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import io.javaoperatorsdk.operator.api.reconciler.*; +import io.javaoperatorsdk.operator.dependent.bulkdependent.BulkDependentTestCustomResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.CRUDConfigMapBulkDependentResource; +import io.javaoperatorsdk.operator.dependent.bulkdependent.ConfigMapDeleterBulkDependentResource; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/CleanerForManagedDependentCustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/CleanerForManagedDependentCustomResource.java index 9e18e657aa..c5cd602ba5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/CleanerForManagedDependentCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.cleanermanageddependent; +package io.javaoperatorsdk.operator.dependent.cleanermanageddependent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DeleterForManagedDependentResourcesOnlyIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/CleanerForManagedDependentResourcesOnlyIT.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DeleterForManagedDependentResourcesOnlyIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/CleanerForManagedDependentResourcesOnlyIT.java index 66db8ecb5e..000fe2b28e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DeleterForManagedDependentResourcesOnlyIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/CleanerForManagedDependentResourcesOnlyIT.java @@ -1,18 +1,15 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.cleanermanageddependent; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.cleanermanageddependent.CleanerForManagedDependentCustomResource; -import io.javaoperatorsdk.operator.sample.cleanermanageddependent.CleanerForManagedDependentTestReconciler; -import io.javaoperatorsdk.operator.sample.cleanermanageddependent.ConfigMapDependentResource; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -class DeleterForManagedDependentResourcesOnlyIT { +class CleanerForManagedDependentResourcesOnlyIT { public static final String TEST_RESOURCE_NAME = "cleaner-for-reconciler-test1"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java index c4bbb3c9f0..bf9a45e29e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/CleanerForManagedDependentTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.cleanermanageddependent; +package io.javaoperatorsdk.operator.dependent.cleanermanageddependent; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/ConfigMapDependentResource.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/ConfigMapDependentResource.java index 9941779784..fbb964f196 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/cleanermanageddependent/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/cleanermanageddependent/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.cleanermanageddependent; +package io.javaoperatorsdk.operator.dependent.cleanermanageddependent; import java.util.HashMap; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java index ac1310998e..7d7c62e6b4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.createonlyifnotexistsdependentwithssa; +package io.javaoperatorsdk.operator.dependent.createonlyifnotexistsdependentwithssa; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSACustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSACustomResource.java similarity index 82% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSACustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSACustomResource.java index 23f06c365f..3e53f422bd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSACustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSACustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.createonlyifnotexistsdependentwithssa; +package io.javaoperatorsdk.operator.dependent.createonlyifnotexistsdependentwithssa; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateOnlyIfNotExistingDependentWithSSA.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAIT.java similarity index 81% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateOnlyIfNotExistingDependentWithSSA.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAIT.java index 8a347f632e..82e41c4a1d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateOnlyIfNotExistingDependentWithSSA.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.createonlyifnotexistsdependentwithssa; import java.time.Duration; import java.util.Map; @@ -10,13 +10,11 @@ import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.createonlyifnotexistsdependentwithssa.CreateOnlyIfNotExistingDependentWithSSACustomResource; -import io.javaoperatorsdk.operator.sample.createonlyifnotexistsdependentwithssa.CreateOnlyIfNotExistingDependentWithSSAReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -class CreateOnlyIfNotExistingDependentWithSSA { +class CreateOnlyIfNotExistingDependentWithSSAIT { public static final String TEST_RESOURCE_NAME = "test1"; public static final String KEY = "key"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java index 49091783f8..3699cd1a78 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/createonlyifnotexistsdependentwithssa/CreateOnlyIfNotExistingDependentWithSSAReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.createonlyifnotexistsdependentwithssa; +package io.javaoperatorsdk.operator.dependent.createonlyifnotexistsdependentwithssa; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentAnnotationSecondaryMapperIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperIT.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentAnnotationSecondaryMapperIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperIT.java index b5b01e1530..8f2f966a22 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentAnnotationSecondaryMapperIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.dependentannotationsecondarymapper; import java.time.Duration; @@ -8,8 +8,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dependentannotationsecondarymapper.DependentAnnotationSecondaryMapperReconciler; -import io.javaoperatorsdk.operator.sample.dependentannotationsecondarymapper.DependentAnnotationSecondaryMapperResource; import static io.javaoperatorsdk.operator.processing.event.source.informer.Mappers.DEFAULT_ANNOTATION_FOR_NAME; import static io.javaoperatorsdk.operator.processing.event.source.informer.Mappers.DEFAULT_ANNOTATION_FOR_NAMESPACE; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java index b8a3168a56..7dc17b5695 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentannotationsecondarymapper; +package io.javaoperatorsdk.operator.dependent.dependentannotationsecondarymapper; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResource.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResource.java index 22ff6256ae..f41f92d0ef 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentannotationsecondarymapper; +package io.javaoperatorsdk.operator.dependent.dependentannotationsecondarymapper; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -12,6 +12,6 @@ @Kind("MaxIntervalTestCustomResource") @ShortNames("mit") public class DependentAnnotationSecondaryMapperResource - extends CustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java index d8b71c9cf9..1f05ebfeca 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentcustommappingannotation; +package io.javaoperatorsdk.operator.dependent.dependentcustommappingannotation; import java.util.Map; import java.util.Set; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentCustomMappingAnnotationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingAnnotationIT.java similarity index 72% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentCustomMappingAnnotationIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingAnnotationIT.java index 8a7d168b26..3d754fc395 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentCustomMappingAnnotationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingAnnotationIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.dependentcustommappingannotation; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -6,13 +6,9 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dependentcustommappingannotation.CustomMappingConfigMapDependentResource; -import io.javaoperatorsdk.operator.sample.dependentcustommappingannotation.DependentCustomMappingCustomResource; -import io.javaoperatorsdk.operator.sample.dependentcustommappingannotation.DependentCustomMappingReconciler; -import io.javaoperatorsdk.operator.sample.dependentcustommappingannotation.DependentCustomMappingSpec; -import static io.javaoperatorsdk.operator.sample.dependentcustommappingannotation.CustomMappingConfigMapDependentResource.CUSTOM_NAMESPACE_KEY; -import static io.javaoperatorsdk.operator.sample.dependentcustommappingannotation.CustomMappingConfigMapDependentResource.CUSTOM_NAME_KEY; +import static io.javaoperatorsdk.operator.dependent.dependentcustommappingannotation.CustomMappingConfigMapDependentResource.CUSTOM_NAMESPACE_KEY; +import static io.javaoperatorsdk.operator.dependent.dependentcustommappingannotation.CustomMappingConfigMapDependentResource.CUSTOM_NAME_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingCustomResource.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingCustomResource.java index 47776ed1e7..124a8d1108 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentcustommappingannotation; +package io.javaoperatorsdk.operator.dependent.dependentcustommappingannotation; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingReconciler.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingReconciler.java index 6ac2626111..e8b5d581b1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentcustommappingannotation; +package io.javaoperatorsdk.operator.dependent.dependentcustommappingannotation; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingSpec.java similarity index 74% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingSpec.java index bc5b92901f..84b34a9491 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentcustommappingannotation/DependentCustomMappingSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/DependentCustomMappingSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentcustommappingannotation; +package io.javaoperatorsdk.operator.dependent.dependentcustommappingannotation; public class DependentCustomMappingSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/ConfigMapDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/ConfigMapDependentResource.java index ca0d28e934..6bbe6a814e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentdifferentnamespace; +package io.javaoperatorsdk.operator.dependent.dependentdifferentnamespace; import java.util.HashMap; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceCustomResource.java index 629fdca1f1..020d147ba9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentdifferentnamespace; +package io.javaoperatorsdk.operator.dependent.dependentdifferentnamespace; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentDifferentNamespaceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceIT.java similarity index 78% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentDifferentNamespaceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceIT.java index 452de53930..b9abf05cad 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentDifferentNamespaceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.dependentdifferentnamespace; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -6,12 +6,8 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dependentdifferentnamespace.ConfigMapDependentResource; -import io.javaoperatorsdk.operator.sample.dependentdifferentnamespace.DependentDifferentNamespaceCustomResource; -import io.javaoperatorsdk.operator.sample.dependentdifferentnamespace.DependentDifferentNamespaceReconciler; -import io.javaoperatorsdk.operator.sample.dependentdifferentnamespace.DependentDifferentNamespaceSpec; -import static io.javaoperatorsdk.operator.sample.dependentdifferentnamespace.ConfigMapDependentResource.KEY; +import static io.javaoperatorsdk.operator.dependent.dependentdifferentnamespace.ConfigMapDependentResource.KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java index d858c34223..d4ae1c5e0a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentdifferentnamespace; +package io.javaoperatorsdk.operator.dependent.dependentdifferentnamespace; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceSpec.java index a568ca4885..4c6961fda6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentdifferentnamespace/DependentDifferentNamespaceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentdifferentnamespace/DependentDifferentNamespaceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentdifferentnamespace; +package io.javaoperatorsdk.operator.dependent.dependentdifferentnamespace; public class DependentDifferentNamespaceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentFilterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterIT.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentFilterIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterIT.java index 19d6678a59..328a4a0544 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentFilterIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.dependentfilter; import java.time.Duration; import java.util.Map; @@ -9,12 +9,9 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dependentfilter.DependentFilterTestCustomResource; -import io.javaoperatorsdk.operator.sample.dependentfilter.DependentFilterTestReconciler; -import io.javaoperatorsdk.operator.sample.dependentfilter.DependentFilterTestResourceSpec; -import static io.javaoperatorsdk.operator.sample.dependentfilter.DependentFilterTestReconciler.CM_VALUE_KEY; -import static io.javaoperatorsdk.operator.sample.dependentfilter.DependentFilterTestReconciler.CONFIG_MAP_FILTER_VALUE; +import static io.javaoperatorsdk.operator.dependent.dependentfilter.DependentFilterTestReconciler.CM_VALUE_KEY; +import static io.javaoperatorsdk.operator.dependent.dependentfilter.DependentFilterTestReconciler.CONFIG_MAP_FILTER_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestCustomResource.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestCustomResource.java index 0930c29774..43822aafb8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentfilter; +package io.javaoperatorsdk.operator.dependent.dependentfilter; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -10,7 +10,7 @@ @Version("v1") @ShortNames("dft") public class DependentFilterTestCustomResource - extends CustomResource + extends CustomResource implements Namespaced { public String getConfigMapName(int id) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestReconciler.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestReconciler.java index 74f447dd37..9eae636cf2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentfilter; +package io.javaoperatorsdk.operator.dependent.dependentfilter; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestResourceSpec.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestResourceSpec.java index cf6b02e936..a09d68b503 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentfilter; +package io.javaoperatorsdk.operator.dependent.dependentfilter; public class DependentFilterTestResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/FilteredDependentConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/FilteredDependentConfigMap.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/FilteredDependentConfigMap.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/FilteredDependentConfigMap.java index 18b9aaa510..a8548f6e70 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/FilteredDependentConfigMap.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/FilteredDependentConfigMap.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentfilter; +package io.javaoperatorsdk.operator.dependent.dependentfilter; import java.util.Map; @@ -9,7 +9,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import static io.javaoperatorsdk.operator.sample.dependentfilter.DependentFilterTestReconciler.CM_VALUE_KEY; +import static io.javaoperatorsdk.operator.dependent.dependentfilter.DependentFilterTestReconciler.CM_VALUE_KEY; @KubernetesDependent(informerConfig = @InformerConfig(onUpdateFilter = UpdateFilter.class)) public class FilteredDependentConfigMap diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/UpdateFilter.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/UpdateFilter.java similarity index 55% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/UpdateFilter.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/UpdateFilter.java index 72e6b1f737..2dd4c8bf99 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/UpdateFilter.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/UpdateFilter.java @@ -1,10 +1,10 @@ -package io.javaoperatorsdk.operator.sample.dependentfilter; +package io.javaoperatorsdk.operator.dependent.dependentfilter; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; -import static io.javaoperatorsdk.operator.sample.dependentfilter.DependentFilterTestReconciler.CM_VALUE_KEY; -import static io.javaoperatorsdk.operator.sample.dependentfilter.DependentFilterTestReconciler.CONFIG_MAP_FILTER_VALUE; +import static io.javaoperatorsdk.operator.dependent.dependentfilter.DependentFilterTestReconciler.CM_VALUE_KEY; +import static io.javaoperatorsdk.operator.dependent.dependentfilter.DependentFilterTestReconciler.CONFIG_MAP_FILTER_VALUE; public class UpdateFilter implements OnUpdateFilter { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/ConfigMapDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/ConfigMapDependentResource.java index 34fbd21c50..3f0ce9a073 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentoperationeventfiltering; +package io.javaoperatorsdk.operator.dependent.dependentoperationeventfiltering; import java.util.HashMap; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResource.java index f0eaf24353..021c984ec3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentoperationeventfiltering; +package io.javaoperatorsdk.operator.dependent.dependentoperationeventfiltering; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceSpec.java similarity index 77% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceSpec.java index 205b016907..ba131f75b0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentoperationeventfiltering; +package io.javaoperatorsdk.operator.dependent.dependentoperationeventfiltering; public class DependentOperationEventFilterCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java index 4b37ba342f..6f4f6b25b2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentoperationeventfiltering; +package io.javaoperatorsdk.operator.dependent.dependentoperationeventfiltering; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentOperationEventFilterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterIT.java similarity index 81% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentOperationEventFilterIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterIT.java index eb354bf96d..12413cd4b4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentOperationEventFilterIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.dependentoperationeventfiltering; import java.time.Duration; @@ -8,10 +8,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dependentoperationeventfiltering.ConfigMapDependentResource; -import io.javaoperatorsdk.operator.sample.dependentoperationeventfiltering.DependentOperationEventFilterCustomResource; -import io.javaoperatorsdk.operator.sample.dependentoperationeventfiltering.DependentOperationEventFilterCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.dependentoperationeventfiltering.DependentOperationEventFilterCustomResourceTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/ConfigMapDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/ConfigMapDependentResource.java index a102060c10..9f80a90f0d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentreinitialization; +package io.javaoperatorsdk.operator.dependent.dependentreinitialization; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/DependentReInitializationCustomResource.java similarity index 84% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/DependentReInitializationCustomResource.java index ce30463965..a3c4e9f20b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/DependentReInitializationCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentreinitialization; +package io.javaoperatorsdk.operator.dependent.dependentreinitialization; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentReInitializationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/DependentReInitializationIT.java similarity index 75% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentReInitializationIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/DependentReInitializationIT.java index 73b7bd20d9..c215d82da2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentReInitializationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/DependentReInitializationIT.java @@ -1,13 +1,11 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.dependentreinitialization; import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dependentreinitialization.ConfigMapDependentResource; -import io.javaoperatorsdk.operator.sample.dependentreinitialization.DependentReInitializationCustomResource; -import io.javaoperatorsdk.operator.sample.dependentreinitialization.DependentReInitializationReconciler; class DependentReInitializationIT { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/DependentReInitializationReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/DependentReInitializationReconciler.java index 43b727b8cd..7f6072665f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentreinitialization/DependentReInitializationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentreinitialization/DependentReInitializationReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentreinitialization; +package io.javaoperatorsdk.operator.dependent.dependentreinitialization; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentResourceCrossRefIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentresourcecrossref/DependentResourceCrossRefIT.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentResourceCrossRefIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentresourcecrossref/DependentResourceCrossRefIT.java index deaa3c7493..0530934dba 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentResourceCrossRefIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentresourcecrossref/DependentResourceCrossRefIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.dependentresourcecrossref; import java.time.Duration; @@ -9,8 +9,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dependentresourcecrossref.DependentResourceCrossRefReconciler; -import io.javaoperatorsdk.operator.sample.dependentresourcecrossref.DependentResourceCrossRefResource; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentresourcecrossref/DependentResourceCrossRefReconciler.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentresourcecrossref/DependentResourceCrossRefReconciler.java index c54434cf6a..4464c02906 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentresourcecrossref/DependentResourceCrossRefReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentresourcecrossref; +package io.javaoperatorsdk.operator.dependent.dependentresourcecrossref; import java.util.ArrayList; import java.util.Base64; @@ -12,7 +12,7 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import static io.javaoperatorsdk.operator.sample.dependentresourcecrossref.DependentResourceCrossRefReconciler.SECRET_NAME; +import static io.javaoperatorsdk.operator.dependent.dependentresourcecrossref.DependentResourceCrossRefReconciler.SECRET_NAME; @Workflow(dependents = { @Dependent(name = SECRET_NAME, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentresourcecrossref/DependentResourceCrossRefResource.java similarity index 70% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentresourcecrossref/DependentResourceCrossRefResource.java index 1cea1df01e..fd89f7fa70 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentresourcecrossref/DependentResourceCrossRefResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentresourcecrossref; +package io.javaoperatorsdk.operator.dependent.dependentresourcecrossref; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -8,6 +8,6 @@ @Group("sample.javaoperatorsdk") @Version("v1") public class DependentResourceCrossRefResource - extends CustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSACustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSACustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSACustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSACustomResource.java index ca8ea4afc7..ed71a9db64 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSACustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSACustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentssa; +package io.javaoperatorsdk.operator.dependent.dependentssa; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMatchingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSAMatchingIT.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMatchingIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSAMatchingIT.java index fe6dca887e..ec02dd7f5c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMatchingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSAMatchingIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.dependentssa; import java.time.Duration; import java.util.Map; @@ -12,10 +12,6 @@ import io.fabric8.kubernetes.client.dsl.base.PatchContext; import io.fabric8.kubernetes.client.dsl.base.PatchType; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dependentssa.DependentSSACustomResource; -import io.javaoperatorsdk.operator.sample.dependentssa.DependentSSAReconciler; -import io.javaoperatorsdk.operator.sample.dependentssa.DependentSSASpec; -import io.javaoperatorsdk.operator.sample.dependentssa.SSAConfigMapDependent; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMigrationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSAMigrationIT.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMigrationIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSAMigrationIT.java index 06a32f9b23..bd3aedb5f9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMigrationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSAMigrationIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.dependentssa; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -11,11 +11,8 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil; +import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.dependentssa.DependentSSACustomResource; -import io.javaoperatorsdk.operator.sample.dependentssa.DependentSSAReconciler; -import io.javaoperatorsdk.operator.sample.dependentssa.DependentSSASpec; -import io.javaoperatorsdk.operator.sample.dependentssa.SSAConfigMapDependent; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSAReconciler.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSAReconciler.java index 846dc9ccd6..8825f4007e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSAReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSAReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentssa; +package io.javaoperatorsdk.operator.dependent.dependentssa; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSASpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSASpec.java similarity index 77% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSASpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSASpec.java index c7b4dd0053..df4684dce5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/DependentSSASpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/DependentSSASpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentssa; +package io.javaoperatorsdk.operator.dependent.dependentssa; public class DependentSSASpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/SSAConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/SSAConfigMapDependent.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/SSAConfigMapDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/SSAConfigMapDependent.java index dbeb9864e2..a912bfcd03 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentssa/SSAConfigMapDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentssa/SSAConfigMapDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.dependentssa; +package io.javaoperatorsdk.operator.dependent.dependentssa; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateCustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateCustomResource.java index 70a51ecc72..353e86d2f9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.externalstate; +package io.javaoperatorsdk.operator.dependent.externalstate; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentIT.java similarity index 60% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateDependentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentIT.java index fd7132bd2a..adfe1f31a1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentIT.java @@ -1,11 +1,10 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.externalstate; import org.junit.jupiter.api.extension.RegisterExtension; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.externalstate.ExternalStateDependentReconciler; -class ExternalStateDependentIT extends ExternalStateTestBase { +public class ExternalStateDependentIT extends ExternalStateTestBase { @RegisterExtension LocallyRunOperatorExtension operator = @@ -13,7 +12,7 @@ class ExternalStateDependentIT extends ExternalStateTestBase { .build(); @Override - LocallyRunOperatorExtension extension() { + public LocallyRunOperatorExtension extension() { return operator; } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentReconciler.java index 706e1d041f..a9e677ebaf 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.externalstate; +package io.javaoperatorsdk.operator.dependent.externalstate; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateIT.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateIT.java index 3da607e324..066d777e80 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.externalstate; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -6,12 +6,9 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.externalstate.ExternalStateCustomResource; -import io.javaoperatorsdk.operator.sample.externalstate.ExternalStateReconciler; -import io.javaoperatorsdk.operator.sample.externalstate.ExternalStateSpec; import io.javaoperatorsdk.operator.support.ExternalIDGenServiceMock; -import static io.javaoperatorsdk.operator.sample.externalstate.ExternalStateReconciler.ID_KEY; +import static io.javaoperatorsdk.operator.dependent.externalstate.ExternalStateReconciler.ID_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateReconciler.java similarity index 99% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateReconciler.java index 9412df210b..422592b4d3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.externalstate; +package io.javaoperatorsdk.operator.dependent.externalstate; import java.time.Duration; import java.util.Arrays; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateSpec.java index eda0a887eb..d073fcd1f8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.externalstate; +package io.javaoperatorsdk.operator.dependent.externalstate; public class ExternalStateSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateTestBase.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateTestBase.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateTestBase.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateTestBase.java index 43982a6109..c58c7cf670 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateTestBase.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateTestBase.java @@ -1,15 +1,13 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.externalstate; import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.externalstate.ExternalStateCustomResource; -import io.javaoperatorsdk.operator.sample.externalstate.ExternalStateSpec; import io.javaoperatorsdk.operator.support.ExternalIDGenServiceMock; -import static io.javaoperatorsdk.operator.sample.externalstate.ExternalStateReconciler.ID_KEY; +import static io.javaoperatorsdk.operator.dependent.externalstate.ExternalStateReconciler.ID_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalWithStateDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalWithStateDependentResource.java index b0e0607334..9bdeea93cd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalWithStateDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.externalstate; +package io.javaoperatorsdk.operator.dependent.externalstate; import java.time.Duration; import java.util.Collections; @@ -17,8 +17,6 @@ import io.javaoperatorsdk.operator.support.ExternalIDGenServiceMock; import io.javaoperatorsdk.operator.support.ExternalResource; -import static io.javaoperatorsdk.operator.sample.externalstate.ExternalStateDependentReconciler.ID_KEY; - public class ExternalWithStateDependentResource extends PerResourcePollingDependentResource implements @@ -52,7 +50,7 @@ protected Optional selectManagedSecondaryResource( private Optional getResourceID(ExternalStateCustomResource primaryResource) { Optional configMapOptional = getExternalStateEventSource().getSecondaryResource(primaryResource); - return configMapOptional.map(cm -> cm.getData().get(ID_KEY)); + return configMapOptional.map(cm -> cm.getData().get(ExternalStateDependentReconciler.ID_KEY)); } @Override @@ -74,7 +72,7 @@ public ConfigMap stateResource(ExternalStateCustomResource primary, .withName(primary.getMetadata().getName()) .withNamespace(primary.getMetadata().getNamespace()) .build()) - .withData(Map.of(ID_KEY, resource.getId())) + .withData(Map.of(ExternalStateDependentReconciler.ID_KEY, resource.getId())) .build(); configMap.addOwnerReference(primary); return configMap; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java index 48e207616d..df3171fbec 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/BulkDependentResourceExternalWithState.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.externalstate.externalstatebulkdependent; +package io.javaoperatorsdk.operator.dependent.externalstate.externalstatebulkdependent; import java.time.Duration; import java.util.HashMap; @@ -11,13 +11,12 @@ import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.dependent.externalstate.ExternalStateDependentReconciler; import io.javaoperatorsdk.operator.processing.dependent.*; import io.javaoperatorsdk.operator.processing.dependent.external.PerResourcePollingDependentResource; import io.javaoperatorsdk.operator.support.ExternalIDGenServiceMock; import io.javaoperatorsdk.operator.support.ExternalResource; -import static io.javaoperatorsdk.operator.sample.externalstate.ExternalStateDependentReconciler.ID_KEY; - public class BulkDependentResourceExternalWithState extends PerResourcePollingDependentResource implements @@ -41,7 +40,7 @@ public Set fetchResources( Set res = new HashSet<>(); configMaps.forEach(cm -> { - var id = cm.getData().get(ID_KEY); + var id = cm.getData().get(ExternalStateDependentReconciler.ID_KEY); var externalResource = externalService.read(id); externalResource.ifPresent(res::add); }); @@ -61,7 +60,7 @@ public ConfigMap stateResource(ExternalStateBulkDependentCustomResource primary, .withName(configMapName(primary, resource)) .withNamespace(primary.getMetadata().getNamespace()) .build()) - .withData(Map.of(ID_KEY, resource.getId())) + .withData(Map.of(ExternalStateDependentReconciler.ID_KEY, resource.getId())) .build(); configMap.addOwnerReference(primary); return configMap; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentCustomResource.java similarity index 84% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentCustomResource.java index 9ee3e260e8..4e8c07dcc7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.externalstate.externalstatebulkdependent; +package io.javaoperatorsdk.operator.dependent.externalstate.externalstatebulkdependent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java index 92ae85275b..3d49b58077 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.externalstate.externalstatebulkdependent; +package io.javaoperatorsdk.operator.dependent.externalstate.externalstatebulkdependent; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkIT.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkIT.java index a0cc9c5e8e..3677537b01 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.externalstate.externalstatebulkdependent; import java.time.Duration; @@ -7,9 +7,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.externalstate.externalstatebulkdependent.ExternalStateBulkDependentCustomResource; -import io.javaoperatorsdk.operator.sample.externalstate.externalstatebulkdependent.ExternalStateBulkDependentReconciler; -import io.javaoperatorsdk.operator.sample.externalstate.externalstatebulkdependent.ExternalStateBulkSpec; import io.javaoperatorsdk.operator.support.ExternalIDGenServiceMock; import static org.assertj.core.api.Assertions.assertThat; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkSpec.java similarity index 81% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkSpec.java index ad52a389fd..a90a4575b5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/externalstatebulkdependent/ExternalStateBulkSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.externalstate.externalstatebulkdependent; +package io.javaoperatorsdk.operator.dependent.externalstate.externalstatebulkdependent; public class ExternalStateBulkSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/GenericKubernetesDependentSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/GenericKubernetesDependentSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentSpec.java index 050e0cf520..d2b33fe090 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/GenericKubernetesDependentSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.generickubernetesresource; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource; public class GenericKubernetesDependentSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentTestBase.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentTestBase.java similarity index 82% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentTestBase.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentTestBase.java index fea23b7796..d031b1cc61 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentTestBase.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentTestBase.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource; import java.time.Duration; @@ -6,9 +6,8 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.client.CustomResource; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentstandalone.ConfigMapGenericKubernetesDependent; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.GenericKubernetesDependentSpec; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentstandalone.ConfigMapGenericKubernetesDependent; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -47,6 +46,6 @@ void testReconciliation() { public abstract LocallyRunOperatorExtension extension(); - abstract R testResource(String name, String data); + public abstract R testResource(String name, String data); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java index 00c202436f..54c91f66f1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/ConfigMapGenericKubernetesDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentresourcemanaged; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentresourcemanaged; import java.io.IOException; import java.io.InputStream; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedCustomResource.java similarity index 69% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedCustomResource.java index d7c44ddab3..24c1bbcb08 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedCustomResource.java @@ -1,11 +1,11 @@ -package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentresourcemanaged; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentresourcemanaged; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; import io.fabric8.kubernetes.model.annotation.ShortNames; import io.fabric8.kubernetes.model.annotation.Version; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.GenericKubernetesDependentSpec; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.GenericKubernetesDependentSpec; @Group("sample.javaoperatorsdk") @Version("v1") diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentManagedIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedIT.java similarity index 63% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentManagedIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedIT.java index f06185d402..9bcccb9c46 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentManagedIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedIT.java @@ -1,12 +1,11 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentresourcemanaged; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.GenericKubernetesDependentSpec; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.GenericKubernetesDependentTestBase; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.GenericKubernetesDependentSpec; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentresourcemanaged.GenericKubernetesDependentManagedCustomResource; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentresourcemanaged.GenericKubernetesDependentManagedReconciler; public class GenericKubernetesDependentManagedIT extends GenericKubernetesDependentTestBase { @@ -23,7 +22,7 @@ public LocallyRunOperatorExtension extension() { } @Override - GenericKubernetesDependentManagedCustomResource testResource(String name, String data) { + public GenericKubernetesDependentManagedCustomResource testResource(String name, String data) { var resource = new GenericKubernetesDependentManagedCustomResource(); resource.setMetadata(new ObjectMetaBuilder() .withName(name) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java index 40d0454eb7..d122f8909e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentresourcemanaged/GenericKubernetesDependentManagedReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentresourcemanaged; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentresourcemanaged; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/ConfigMapGenericKubernetesDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/ConfigMapGenericKubernetesDependent.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/ConfigMapGenericKubernetesDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/ConfigMapGenericKubernetesDependent.java index 4efc968ef0..79324641f3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/ConfigMapGenericKubernetesDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/ConfigMapGenericKubernetesDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentstandalone; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentstandalone; import java.io.IOException; import java.io.InputStream; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneCustomResource.java similarity index 70% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneCustomResource.java index 38eaf804e4..eaf56831c5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneCustomResource.java @@ -1,11 +1,11 @@ -package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentstandalone; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentstandalone; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; import io.fabric8.kubernetes.model.annotation.ShortNames; import io.fabric8.kubernetes.model.annotation.Version; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.GenericKubernetesDependentSpec; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.GenericKubernetesDependentSpec; @Group("sample.javaoperatorsdk") @Version("v1") diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentStandaloneIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneIT.java similarity index 63% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentStandaloneIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneIT.java index 708d2f119c..07c264c6c2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentStandaloneIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneIT.java @@ -1,12 +1,11 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentstandalone; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.GenericKubernetesDependentSpec; +import io.javaoperatorsdk.operator.dependent.generickubernetesresource.GenericKubernetesDependentTestBase; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.GenericKubernetesDependentSpec; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentstandalone.GenericKubernetesDependentStandaloneCustomResource; -import io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentstandalone.GenericKubernetesDependentStandaloneReconciler; public class GenericKubernetesDependentStandaloneIT extends GenericKubernetesDependentTestBase { @@ -23,7 +22,7 @@ public LocallyRunOperatorExtension extension() { } @Override - GenericKubernetesDependentStandaloneCustomResource testResource(String name, String data) { + public GenericKubernetesDependentStandaloneCustomResource testResource(String name, String data) { var resource = new GenericKubernetesDependentStandaloneCustomResource(); resource.setMetadata(new ObjectMetaBuilder() .withName(name) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java index 0f2543ce49..0e90d8e9d9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/generickubernetesdependentstandalone/GenericKubernetesDependentStandaloneReconciler.java @@ -1,8 +1,7 @@ -package io.javaoperatorsdk.operator.sample.generickubernetesresource.generickubernetesdependentstandalone; +package io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentstandalone; import java.util.List; -import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/ConfigMapDependentResource.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/ConfigMapDependentResource.java index bda0b94845..dd55f16ca1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.informerrelatedbehavior; +package io.javaoperatorsdk.operator.dependent.informerrelatedbehavior; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorITS.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorITS.java index a8288db7af..12488af133 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorITS.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.informerrelatedbehavior; import java.time.Duration; @@ -19,14 +19,15 @@ import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil; import io.javaoperatorsdk.jenvtest.junit.EnableKubeAPIServer; +import io.javaoperatorsdk.operator.Operator; +import io.javaoperatorsdk.operator.OperatorException; +import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.health.InformerHealthIndicator; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; -import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestCustomResource; -import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestReconciler; -import static io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestReconciler.CONFIG_MAP_DEPENDENT_RESOURCE; -import static io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestReconciler.INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER; +import static io.javaoperatorsdk.operator.dependent.informerrelatedbehavior.InformerRelatedBehaviorTestReconciler.CONFIG_MAP_DEPENDENT_RESOURCE; +import static io.javaoperatorsdk.operator.dependent.informerrelatedbehavior.InformerRelatedBehaviorTestReconciler.INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorTestCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorTestCustomResource.java index fa59c15831..9269dc5d6e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.informerrelatedbehavior; +package io.javaoperatorsdk.operator.dependent.informerrelatedbehavior; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java index e76d980ef0..2fb7724f49 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.informerrelatedbehavior; +package io.javaoperatorsdk.operator.dependent.informerrelatedbehavior; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResource.java similarity index 78% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResource.java index 5f1e5a0435..33f9899689 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.kubernetesdependentgarbagecollection; +package io.javaoperatorsdk.operator.dependent.kubernetesdependentgarbagecollection; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -11,6 +11,6 @@ @ShortNames("dgc") public class DependentGarbageCollectionTestCustomResource extends - CustomResource + CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceSpec.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceSpec.java index 9c29ebbacc..0571bbf97d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.kubernetesdependentgarbagecollection; +package io.javaoperatorsdk.operator.dependent.kubernetesdependentgarbagecollection; public class DependentGarbageCollectionTestCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java index 79c050a448..e786c1c2c1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.kubernetesdependentgarbagecollection; +package io.javaoperatorsdk.operator.dependent.kubernetesdependentgarbagecollection; import java.util.List; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesDependentGarbageCollectionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/KubernetesDependentGarbageCollectionIT.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesDependentGarbageCollectionIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/KubernetesDependentGarbageCollectionIT.java index c32f328d76..afc89471a6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesDependentGarbageCollectionIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/kubernetesdependentgarbagecollection/KubernetesDependentGarbageCollectionIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.kubernetesdependentgarbagecollection; import java.time.Duration; @@ -7,10 +7,8 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.IntegrationTestConstants; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.kubernetesdependentgarbagecollection.DependentGarbageCollectionTestCustomResource; -import io.javaoperatorsdk.operator.sample.kubernetesdependentgarbagecollection.DependentGarbageCollectionTestCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.kubernetesdependentgarbagecollection.DependentGarbageCollectionTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceConfigMap.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceConfigMap.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceConfigMap.java index 39ed7f9f0b..d0bc50ddd8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceConfigMap.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceConfigMap.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentresource; +package io.javaoperatorsdk.operator.dependent.multipledependentresource; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceCustomResource.java similarity index 72% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceCustomResource.java index 60ba494e8a..7b8fb15466 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentresource; +package io.javaoperatorsdk.operator.dependent.multipledependentresource; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -10,6 +10,6 @@ @Version("v1") @ShortNames("mdr") public class MultipleDependentResourceCustomResource - extends CustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceIT.java similarity index 71% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceIT.java index 224e9c487a..f8b9259b6a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.multipledependentresource; import java.time.Duration; @@ -8,15 +8,11 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceCustomResource; -import io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceReconciler; -import io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceSpec; -import io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator.*; - -import static io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceConfigMap.DATA_KEY; -import static io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceConfigMap.getConfigMapName; -import static io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceReconciler.FIRST_CONFIG_MAP_ID; -import static io.javaoperatorsdk.operator.sample.multipledependentresource.MultipleDependentResourceReconciler.SECOND_CONFIG_MAP_ID; + +import static io.javaoperatorsdk.operator.dependent.multipledependentresource.MultipleDependentResourceConfigMap.DATA_KEY; +import static io.javaoperatorsdk.operator.dependent.multipledependentresource.MultipleDependentResourceConfigMap.getConfigMapName; +import static io.javaoperatorsdk.operator.dependent.multipledependentresource.MultipleDependentResourceReconciler.FIRST_CONFIG_MAP_ID; +import static io.javaoperatorsdk.operator.dependent.multipledependentresource.MultipleDependentResourceReconciler.SECOND_CONFIG_MAP_ID; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceReconciler.java index 8a6986b151..91a889ac87 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentresource; +package io.javaoperatorsdk.operator.dependent.multipledependentresource; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceSpec.java similarity index 72% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceSpec.java index def3fa9088..96f7224d31 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentresource; +package io.javaoperatorsdk.operator.dependent.multipledependentresource; public class MultipleDependentResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceConfigMap.java similarity index 81% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceConfigMap.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceConfigMap.java index 661e8e54be..defef91b75 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceConfigMap.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceConfigMap.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator; +package io.javaoperatorsdk.operator.dependent.multipledependentresourcewithsametype; import java.util.HashMap; import java.util.Map; @@ -10,7 +10,7 @@ public class MultipleDependentResourceConfigMap extends - CRUDKubernetesDependentResource { + CRUDKubernetesDependentResource { public static final String DATA_KEY = "key"; private final int value; @@ -21,8 +21,8 @@ public MultipleDependentResourceConfigMap(int value) { } @Override - protected ConfigMap desired(MultipleDependentResourceCustomResourceWithDiscriminator primary, - Context context) { + protected ConfigMap desired(MultipleDependentResourceCustomResourceNoDiscriminator primary, + Context context) { Map data = new HashMap<>(); data.put(DATA_KEY, String.valueOf(value)); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceCustomResourceWithDiscriminator.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceCustomResourceNoDiscriminator.java similarity index 65% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceCustomResourceWithDiscriminator.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceCustomResourceNoDiscriminator.java index 7491d5e3ae..bd91aae234 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceCustomResourceWithDiscriminator.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceCustomResourceNoDiscriminator.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator; +package io.javaoperatorsdk.operator.dependent.multipledependentresourcewithsametype; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -9,8 +9,8 @@ @Group("sample.javaoperatorsdk") @Version("v1") @ShortNames("mdwd") -public class MultipleDependentResourceCustomResourceWithDiscriminator - extends CustomResource +public class MultipleDependentResourceCustomResourceNoDiscriminator + extends CustomResource implements Namespaced { public String getConfigMapName(int id) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithDiscriminatorReconciler.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithDiscriminatorReconciler.java index dbc7742f42..3d75109a05 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithDiscriminatorReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator; +package io.javaoperatorsdk.operator.dependent.multipledependentresourcewithsametype; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -12,7 +12,7 @@ @ControllerConfiguration public class MultipleDependentResourceWithDiscriminatorReconciler - implements Reconciler, + implements Reconciler, TestExecutionInfoProvider { public static final int FIRST_CONFIG_MAP_ID = 1; @@ -28,9 +28,9 @@ public MultipleDependentResourceWithDiscriminatorReconciler() { } @Override - public UpdateControl reconcile( - MultipleDependentResourceCustomResourceWithDiscriminator resource, - Context context) { + public UpdateControl reconcile( + MultipleDependentResourceCustomResourceNoDiscriminator resource, + Context context) { numberOfExecutions.getAndIncrement(); firstDependentResourceConfigMap.reconcile(resource, context); secondDependentResourceConfigMap.reconcile(resource, context); @@ -43,11 +43,11 @@ public int getNumberOfExecutions() { } @Override - public List> prepareEventSources( - EventSourceContext context) { - InformerEventSource eventSource = + public List> prepareEventSources( + EventSourceContext context) { + InformerEventSource eventSource = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, - MultipleDependentResourceCustomResourceWithDiscriminator.class) + MultipleDependentResourceCustomResourceNoDiscriminator.class) .build(), context); firstDependentResourceConfigMap.setEventSource(eventSource); secondDependentResourceConfigMap.setEventSource(eventSource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceWithNoDiscriminatorIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithNoDiscriminatorIT.java similarity index 73% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceWithNoDiscriminatorIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithNoDiscriminatorIT.java index 908cb58f79..b653a8b606 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceWithNoDiscriminatorIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithNoDiscriminatorIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.multipledependentresourcewithsametype; import java.time.Duration; import java.util.stream.IntStream; @@ -9,9 +9,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator.MultipleDependentResourceConfigMap; -import io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator.MultipleDependentResourceCustomResourceWithDiscriminator; -import io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator.MultipleDependentResourceWithDiscriminatorReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -28,7 +25,7 @@ class MultipleDependentResourceWithNoDiscriminatorIT { @Test void twoConfigMapsHaveBeenCreated() { - MultipleDependentResourceCustomResourceWithDiscriminator customResource = + MultipleDependentResourceCustomResourceNoDiscriminator customResource = createTestCustomResource(); operator.create(customResource); @@ -51,9 +48,9 @@ void twoConfigMapsHaveBeenCreated() { }); } - public MultipleDependentResourceCustomResourceWithDiscriminator createTestCustomResource() { - MultipleDependentResourceCustomResourceWithDiscriminator resource = - new MultipleDependentResourceCustomResourceWithDiscriminator(); + public MultipleDependentResourceCustomResourceNoDiscriminator createTestCustomResource() { + MultipleDependentResourceCustomResourceNoDiscriminator resource = + new MultipleDependentResourceCustomResourceNoDiscriminator(); resource.setMetadata( new ObjectMetaBuilder() .withName(TEST_RESOURCE_NAME) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentSameTypeMultiInformerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleDependentSameTypeMultiInformerIT.java similarity index 81% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentSameTypeMultiInformerIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleDependentSameTypeMultiInformerIT.java index 53d29f4552..6f244f554c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentSameTypeMultiInformerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleDependentSameTypeMultiInformerIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.multipledependentsametypemultiinformer; import java.time.Duration; import java.util.stream.Collectors; @@ -8,12 +8,9 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer.MultipleManagedDependentResourceMultiInformerCustomResource; -import io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer.MultipleManagedDependentResourceMultiInformerReconciler; -import io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer.MultipleManagedDependentResourceMultiInformerSpec; import static io.javaoperatorsdk.operator.IntegrationTestConstants.GARBAGE_COLLECTION_TIMEOUT_SECONDS; -import static io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer.MultipleManagedDependentResourceMultiInformerReconciler.DATA_KEY; +import static io.javaoperatorsdk.operator.dependent.multipledependentsametypemultiinformer.MultipleManagedDependentResourceMultiInformerReconciler.DATA_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java index 510ea37075..47c65f1a95 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer; +package io.javaoperatorsdk.operator.dependent.multipledependentsametypemultiinformer; import java.util.HashMap; import java.util.Map; @@ -6,9 +6,9 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler; @KubernetesDependent public class MultipleManagedDependentResourceMultiInformerConfigMap1 diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java index 2d27e162a7..320768de24 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerConfigMap2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer; +package io.javaoperatorsdk.operator.dependent.multipledependentsametypemultiinformer; import java.util.HashMap; import java.util.Map; @@ -9,7 +9,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; +import static io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; @KubernetesDependent public class MultipleManagedDependentResourceMultiInformerConfigMap2 diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerCustomResource.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerCustomResource.java index 24ee0ea0dc..060a8f6b62 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer; +package io.javaoperatorsdk.operator.dependent.multipledependentsametypemultiinformer; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java index 29b0db91c9..f0fe034c97 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer; +package io.javaoperatorsdk.operator.dependent.multipledependentsametypemultiinformer; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerSpec.java index a98a3c0f92..c8893adc72 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentsametypemultiinformer/MultipleManagedDependentResourceMultiInformerSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentsametypemultiinformer; +package io.javaoperatorsdk.operator.dependent.multipledependentsametypemultiinformer; public class MultipleManagedDependentResourceMultiInformerSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java index 6d0bc303df..750f8489b7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; +package io.javaoperatorsdk.operator.dependent.multipledrsametypenodiscriminator; import java.util.HashMap; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java index 937291d83d..373a70bcda 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; +package io.javaoperatorsdk.operator.dependent.multipledrsametypenodiscriminator; import java.util.HashMap; import java.util.Map; @@ -9,7 +9,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; +import static io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; @KubernetesDependent public class MultipleManagedDependentNoDiscriminatorConfigMap2 diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java index 611d96f74e..7681cf7792 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; +package io.javaoperatorsdk.operator.dependent.multipledrsametypenodiscriminator; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentNoDiscriminatorIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorIT.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentNoDiscriminatorIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorIT.java index 361aa099af..cc6b79066a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentNoDiscriminatorIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.multipledrsametypenodiscriminator; import java.time.Duration; @@ -8,9 +8,8 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator.*; -import static io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator.MultipleManagedDependentSameTypeNoDiscriminatorReconciler.DATA_KEY; +import static io.javaoperatorsdk.operator.dependent.multipledrsametypenodiscriminator.MultipleManagedDependentSameTypeNoDiscriminatorReconciler.DATA_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java index 4ccc1d84f4..5ee30673d4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; +package io.javaoperatorsdk.operator.dependent.multipledrsametypenodiscriminator; public class MultipleManagedDependentNoDiscriminatorSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java index 14726d591e..16492569c6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledrsametypenodiscriminator; +package io.javaoperatorsdk.operator.dependent.multipledrsametypenodiscriminator; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -11,7 +11,7 @@ import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.CONFIG_MAP_EVENT_SOURCE; +import static io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.CONFIG_MAP_EVENT_SOURCE; @Workflow(dependents = { @Dependent(type = MultipleManagedDependentNoDiscriminatorConfigMap1.class, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java index 8fe7cf5330..4d69ef25e3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype; +package io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype; import java.util.HashMap; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java similarity index 81% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java index b76f108d6b..11231470e7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceConfigMap2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype; +package io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype; import java.util.HashMap; import java.util.Map; @@ -9,8 +9,6 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; - @KubernetesDependent public class MultipleManagedDependentResourceConfigMap2 extends @@ -26,7 +24,7 @@ public MultipleManagedDependentResourceConfigMap2() { protected ConfigMap desired(MultipleManagedDependentResourceCustomResource primary, Context context) { Map data = new HashMap<>(); - data.put(DATA_KEY, primary.getSpec().getValue()); + data.put(MultipleManagedDependentResourceReconciler.DATA_KEY, primary.getSpec().getValue()); return new ConfigMapBuilder() .withNewMetadata() diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceCustomResource.java index 44564727a2..2c131978b6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype; +package io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java index 10f1497ce4..94b152fba2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype; +package io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -11,7 +11,7 @@ import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.CONFIG_MAP_EVENT_SOURCE; +import static io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.CONFIG_MAP_EVENT_SOURCE; @Workflow(dependents = { @Dependent(type = MultipleManagedDependentResourceConfigMap1.class, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceSpec.java similarity index 75% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceSpec.java index cdd524e03e..9b50de6ad1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanageddependentsametype/MultipleManagedDependentResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype; +package io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype; public class MultipleManagedDependentResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentSameTypeIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentSameTypeIT.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentSameTypeIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentSameTypeIT.java index 32fe0eaec4..ed568e75e1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentSameTypeIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentSameTypeIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype; import java.time.Duration; import java.util.stream.Collectors; @@ -8,12 +8,9 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceCustomResource; -import io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler; -import io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceSpec; import static io.javaoperatorsdk.operator.IntegrationTestConstants.GARBAGE_COLLECTION_TIMEOUT_SECONDS; -import static io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; +import static io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype.MultipleManagedDependentResourceReconciler.DATA_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/AbstractExternalDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/AbstractExternalDependentResource.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/AbstractExternalDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/AbstractExternalDependentResource.java index f7d3c91dd3..9cc3830be8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/AbstractExternalDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/AbstractExternalDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype; +package io.javaoperatorsdk.operator.dependent.multiplemanagedexternaldependenttype; import java.util.Map; import java.util.Set; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/ExternalDependentResource1.java similarity index 71% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/ExternalDependentResource1.java index 4dee39e8e6..d3894f797d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/ExternalDependentResource1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype; +package io.javaoperatorsdk.operator.dependent.multiplemanagedexternaldependenttype; public class ExternalDependentResource1 extends AbstractExternalDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/ExternalDependentResource2.java similarity index 71% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/ExternalDependentResource2.java index b37aa65bdf..9281bf3a9a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/ExternalDependentResource2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/ExternalDependentResource2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype; +package io.javaoperatorsdk.operator.dependent.multiplemanagedexternaldependenttype; public class ExternalDependentResource2 extends AbstractExternalDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceCustomResource.java similarity index 71% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceCustomResource.java index c989a5c96c..df443880c9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceCustomResource.java @@ -1,11 +1,11 @@ -package io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype; +package io.javaoperatorsdk.operator.dependent.multiplemanagedexternaldependenttype; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; import io.fabric8.kubernetes.model.annotation.ShortNames; import io.fabric8.kubernetes.model.annotation.Version; -import io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceSpec; +import io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype.MultipleManagedDependentResourceSpec; @Group("sample.javaoperatorsdk") @Version("v1") diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java index 6752a82e0b..cd17f1706b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentResourceReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype; +package io.javaoperatorsdk.operator.dependent.multiplemanagedexternaldependenttype; import java.time.Duration; import java.util.HashMap; @@ -23,7 +23,7 @@ import io.javaoperatorsdk.operator.support.ExternalServiceMock; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -import static io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype.MultipleManagedExternalDependentResourceReconciler.EVENT_SOURCE_NAME; +import static io.javaoperatorsdk.operator.dependent.multiplemanagedexternaldependenttype.MultipleManagedExternalDependentResourceReconciler.EVENT_SOURCE_NAME; @Workflow(dependents = { @Dependent(type = ExternalDependentResource1.class, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedExternalDependentSameTypeIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentSameTypeIT.java similarity index 84% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedExternalDependentSameTypeIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentSameTypeIT.java index e62835c063..024060202b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedExternalDependentSameTypeIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanagedexternaldependenttype/MultipleManagedExternalDependentSameTypeIT.java @@ -1,13 +1,11 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.multiplemanagedexternaldependenttype; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.dependent.multiplemanageddependentsametype.MultipleManagedDependentResourceSpec; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multiplemanageddependentsametype.MultipleManagedDependentResourceSpec; -import io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype.MultipleManagedExternalDependentResourceCustomResource; -import io.javaoperatorsdk.operator.sample.multiplemanagedexternaldependenttype.MultipleManagedExternalDependentResourceReconciler; import io.javaoperatorsdk.operator.support.ExternalServiceMock; import static org.assertj.core.api.Assertions.assertThat; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiOwnerDependentTriggeringIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultiOwnerDependentTriggeringIT.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiOwnerDependentTriggeringIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultiOwnerDependentTriggeringIT.java index 7f6f917c55..d9c62d9a29 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiOwnerDependentTriggeringIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultiOwnerDependentTriggeringIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.multipleupdateondependent; import java.util.Set; @@ -8,10 +8,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multipleupdateondependent.MultipleOwnerDependentConfigMap; -import io.javaoperatorsdk.operator.sample.multipleupdateondependent.MultipleOwnerDependentCustomResource; -import io.javaoperatorsdk.operator.sample.multipleupdateondependent.MultipleOwnerDependentReconciler; -import io.javaoperatorsdk.operator.sample.multipleupdateondependent.MultipleOwnerDependentSpec; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentConfigMap.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentConfigMap.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentConfigMap.java index a3387477d5..b906796708 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentConfigMap.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentConfigMap.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipleupdateondependent; +package io.javaoperatorsdk.operator.dependent.multipleupdateondependent; import java.util.HashMap; import java.util.List; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentCustomResource.java index 85b8be124c..d84e1bf5db 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipleupdateondependent; +package io.javaoperatorsdk.operator.dependent.multipleupdateondependent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentReconciler.java index 763f136c8d..b4c01cb6b9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipleupdateondependent; +package io.javaoperatorsdk.operator.dependent.multipleupdateondependent; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentSpec.java similarity index 75% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentSpec.java index cda4377cdc..5600dde5a4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipleupdateondependent/MultipleOwnerDependentSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipleupdateondependent/MultipleOwnerDependentSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipleupdateondependent; +package io.javaoperatorsdk.operator.dependent.multipleupdateondependent; public class MultipleOwnerDependentSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentPrimaryIndexerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerIT.java similarity index 71% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentPrimaryIndexerIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerIT.java index 44d88aaecf..16bb0d46a7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentPrimaryIndexerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerIT.java @@ -1,7 +1,7 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.primaryindexer; +import io.javaoperatorsdk.operator.baseapi.primaryindexer.PrimaryIndexerIT; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.primaryindexer.DependentPrimaryIndexerTestReconciler; public class DependentPrimaryIndexerIT extends PrimaryIndexerIT { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerTestReconciler.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerTestReconciler.java index ea606ecd6b..2730d743cb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primaryindexer; +package io.javaoperatorsdk.operator.dependent.primaryindexer; import java.util.List; import java.util.stream.Collectors; @@ -13,12 +13,14 @@ import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.javaoperatorsdk.operator.baseapi.primaryindexer.AbstractPrimaryIndexerTestReconciler; +import io.javaoperatorsdk.operator.baseapi.primaryindexer.PrimaryIndexerTestCustomResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; -import static io.javaoperatorsdk.operator.sample.primaryindexer.DependentPrimaryIndexerTestReconciler.CONFIG_MAP_EVENT_SOURCE; +import static io.javaoperatorsdk.operator.dependent.primaryindexer.DependentPrimaryIndexerTestReconciler.CONFIG_MAP_EVENT_SOURCE; @Workflow(dependents = @Dependent(useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE, type = DependentPrimaryIndexerTestReconciler.ReadOnlyConfigMapDependent.class)) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/ConfigMapDependent.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/ConfigMapDependent.java index 364e9088f7..c9b85acc69 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/ConfigMapDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondaydependent; +package io.javaoperatorsdk.operator.dependent.primarytosecondaydependent; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapReconcilePrecondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/ConfigMapReconcilePrecondition.java similarity index 78% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapReconcilePrecondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/ConfigMapReconcilePrecondition.java index b8aa65585d..ab4ba62edf 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/ConfigMapReconcilePrecondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/ConfigMapReconcilePrecondition.java @@ -1,12 +1,10 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondaydependent; +package io.javaoperatorsdk.operator.dependent.primarytosecondaydependent; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; -import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.DATA_KEY; - public class ConfigMapReconcilePrecondition implements Condition { @@ -18,7 +16,7 @@ public boolean isMet( PrimaryToSecondaryDependentCustomResource primary, Context context) { return dependentResource.getSecondaryResource(primary, context).map(cm -> { - var data = cm.getData().get(DATA_KEY); + var data = cm.getData().get(PrimaryToSecondaryDependentReconciler.DATA_KEY); return data != null && !data.equals(DO_NOT_RECONCILE); }) .orElse(false); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentCustomResource.java index 4ec7065f2e..8be9ecf5c6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondaydependent; +package io.javaoperatorsdk.operator.dependent.primarytosecondaydependent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentIT.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentIT.java index 0e48b726e9..681c57e0d1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.primarytosecondaydependent; import java.time.Duration; import java.util.Map; @@ -10,13 +10,10 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentCustomResource; -import io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler; -import io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentSpec; -import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.ConfigMapDependent.TEST_CONFIG_MAP_NAME; -import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.ConfigMapReconcilePrecondition.DO_NOT_RECONCILE; -import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.DATA_KEY; +import static io.javaoperatorsdk.operator.dependent.primarytosecondaydependent.ConfigMapDependent.TEST_CONFIG_MAP_NAME; +import static io.javaoperatorsdk.operator.dependent.primarytosecondaydependent.ConfigMapReconcilePrecondition.DO_NOT_RECONCILE; +import static io.javaoperatorsdk.operator.dependent.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.DATA_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java index b98e0e6839..5e011b7247 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondaydependent; +package io.javaoperatorsdk.operator.dependent.primarytosecondaydependent; import java.util.List; import java.util.Set; @@ -15,8 +15,8 @@ import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.CONFIG_MAP; -import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.CONFIG_MAP_EVENT_SOURCE; +import static io.javaoperatorsdk.operator.dependent.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.CONFIG_MAP; +import static io.javaoperatorsdk.operator.dependent.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.CONFIG_MAP_EVENT_SOURCE; /** * Sample showcases how it is possible to do a primary to secondary mapper for a dependent resource. diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentSpec.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentSpec.java index 966a5c242b..bf2773f571 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/PrimaryToSecondaryDependentSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondaydependent; +package io.javaoperatorsdk.operator.dependent.primarytosecondaydependent; public class PrimaryToSecondaryDependentSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/SecretDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/SecretDependent.java similarity index 83% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/SecretDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/SecretDependent.java index c78f3c470f..aa9470676d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondaydependent/SecretDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/SecretDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondaydependent; +package io.javaoperatorsdk.operator.dependent.primarytosecondaydependent; import java.util.Map; @@ -8,7 +8,7 @@ import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import static io.javaoperatorsdk.operator.sample.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.DATA_KEY; +import static io.javaoperatorsdk.operator.dependent.primarytosecondaydependent.PrimaryToSecondaryDependentReconciler.DATA_KEY; public class SecretDependent extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ConfigMapReader.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/readonly/ConfigMapReader.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ConfigMapReader.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/readonly/ConfigMapReader.java index ffff1bf78a..c904a1741e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ConfigMapReader.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/readonly/ConfigMapReader.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.readonly; +package io.javaoperatorsdk.operator.dependent.readonly; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ReadOnlyDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/readonly/ReadOnlyDependent.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ReadOnlyDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/readonly/ReadOnlyDependent.java index b586e38636..63e43fef95 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/readonly/ReadOnlyDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/readonly/ReadOnlyDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.readonly; +package io.javaoperatorsdk.operator.dependent.readonly; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/ConfigMapDependentResource.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/ConfigMapDependentResource.java index 261ebb63b3..b531a83beb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.restart; +package io.javaoperatorsdk.operator.dependent.restart; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/OperatorRestartIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/OperatorRestartIT.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/OperatorRestartIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/OperatorRestartIT.java index 9f506cc927..db51c81081 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/OperatorRestartIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/OperatorRestartIT.java @@ -1,11 +1,10 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.restart; import org.junit.jupiter.api.*; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.restart.RestartTestCustomResource; -import io.javaoperatorsdk.operator.sample.restart.RestartTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/RestartTestCustomResource.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/RestartTestCustomResource.java index a3bcd31053..6f9c08251d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/RestartTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.restart; +package io.javaoperatorsdk.operator.dependent.restart; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/RestartTestReconciler.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/RestartTestReconciler.java index e7daf5b2eb..6f59c29dc8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/RestartTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.restart; +package io.javaoperatorsdk.operator.dependent.restart; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceDependentResource.java index deddf20263..a88fa14463 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceDependentResource.java @@ -1,11 +1,10 @@ -package io.javaoperatorsdk.operator.sample.servicestrictmatcher; +package io.javaoperatorsdk.operator.dependent.servicestrictmatcher; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.Service; -import io.javaoperatorsdk.operator.ServiceStrictMatcherIT; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.Matcher; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; @@ -27,7 +26,8 @@ public ServiceDependentResource() { @Override protected Service desired(ServiceStrictMatcherTestCustomResource primary, Context context) { - Service service = loadYaml(Service.class, ServiceStrictMatcherIT.class, "service.yaml"); + Service service = loadYaml(Service.class, ServiceStrictMatcherIT.class, + "/io/javaoperatorsdk/operator/service.yaml"); service.getMetadata().setName(primary.getMetadata().getName()); service.getMetadata().setNamespace(primary.getMetadata().getNamespace()); Map labels = new HashMap<>(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ServiceStrictMatcherIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherIT.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ServiceStrictMatcherIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherIT.java index 97caab21ee..7d1b306210 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ServiceStrictMatcherIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.servicestrictmatcher; import java.time.Duration; @@ -7,10 +7,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.servicestrictmatcher.ServiceDependentResource; -import io.javaoperatorsdk.operator.sample.servicestrictmatcher.ServiceStrictMatcherSpec; -import io.javaoperatorsdk.operator.sample.servicestrictmatcher.ServiceStrictMatcherTestCustomResource; -import io.javaoperatorsdk.operator.sample.servicestrictmatcher.ServiceStrictMatcherTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherSpec.java index 1233b70914..d8840d92ba 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.servicestrictmatcher; +package io.javaoperatorsdk.operator.dependent.servicestrictmatcher; public class ServiceStrictMatcherSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherTestCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherTestCustomResource.java index 6079ceb757..6e05628633 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.servicestrictmatcher; +package io.javaoperatorsdk.operator.dependent.servicestrictmatcher; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java index 0746de2897..556f28113d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/servicestrictmatcher/ServiceStrictMatcherTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.servicestrictmatcher; +package io.javaoperatorsdk.operator.dependent.servicestrictmatcher; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/ServiceAccountDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/ServiceAccountDependentResource.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/ServiceAccountDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/ServiceAccountDependentResource.java index 6ab5695a84..b5f8cd3225 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/ServiceAccountDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/ServiceAccountDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.specialresourcesdependent; +package io.javaoperatorsdk.operator.dependent.specialresourcesdependent; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.ServiceAccount; @@ -6,7 +6,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -import static io.javaoperatorsdk.operator.sample.specialresourcesdependent.SpecialResourceSpec.INITIAL_VALUE; +import static io.javaoperatorsdk.operator.dependent.specialresourcesdependent.SpecialResourceSpec.INITIAL_VALUE; @KubernetesDependent public class ServiceAccountDependentResource extends diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceCustomResource.java index 89ed0ca06e..fc7feeb805 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.specialresourcesdependent; +package io.javaoperatorsdk.operator.dependent.specialresourcesdependent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceSpec.java similarity index 82% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceSpec.java index 69386d72dc..f1596e0829 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.specialresourcesdependent; +package io.javaoperatorsdk.operator.dependent.specialresourcesdependent; public class SpecialResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceTestReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceTestReconciler.java index 5914b08e68..e10571396e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/specialresourcesdependent/SpecialResourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.specialresourcesdependent; +package io.javaoperatorsdk.operator.dependent.specialresourcesdependent; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/SpecialResourcesDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourcesDependentIT.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/SpecialResourcesDependentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourcesDependentIT.java index a050417254..89cd94e51d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/SpecialResourcesDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourcesDependentIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.specialresourcesdependent; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -6,12 +6,9 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.ServiceAccount; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.specialresourcesdependent.SpecialResourceCustomResource; -import io.javaoperatorsdk.operator.sample.specialresourcesdependent.SpecialResourceSpec; -import io.javaoperatorsdk.operator.sample.specialresourcesdependent.SpecialResourceTestReconciler; -import static io.javaoperatorsdk.operator.sample.specialresourcesdependent.SpecialResourceSpec.CHANGED_VALUE; -import static io.javaoperatorsdk.operator.sample.specialresourcesdependent.SpecialResourceSpec.INITIAL_VALUE; +import static io.javaoperatorsdk.operator.dependent.specialresourcesdependent.SpecialResourceSpec.CHANGED_VALUE; +import static io.javaoperatorsdk.operator.dependent.specialresourcesdependent.SpecialResourceSpec.INITIAL_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSALegacyMatcherCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSALegacyMatcherCustomResource.java index d68372bbeb..fe58579035 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSALegacyMatcherCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.ssalegacymatcher; +package io.javaoperatorsdk.operator.dependent.ssalegacymatcher; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSALegacyMatcherReconciler.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSALegacyMatcherReconciler.java index e0cdf50c96..179496f1b9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSALegacyMatcherReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.ssalegacymatcher; +package io.javaoperatorsdk.operator.dependent.ssalegacymatcher; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSALegacyMatcherSpec.java similarity index 77% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSALegacyMatcherSpec.java index 6ee56aafd0..b2bee7f12d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/SSALegacyMatcherSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSALegacyMatcherSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.ssalegacymatcher; +package io.javaoperatorsdk.operator.dependent.ssalegacymatcher; public class SSALegacyMatcherSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/SSAWithLegacyMatcherIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSAWithLegacyMatcherIT.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/SSAWithLegacyMatcherIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSAWithLegacyMatcherIT.java index ba3444bfb8..090f60c7d5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/SSAWithLegacyMatcherIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/SSAWithLegacyMatcherIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.ssalegacymatcher; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -6,10 +6,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Service; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.ssalegacymatcher.SSALegacyMatcherCustomResource; -import io.javaoperatorsdk.operator.sample.ssalegacymatcher.SSALegacyMatcherReconciler; -import io.javaoperatorsdk.operator.sample.ssalegacymatcher.SSALegacyMatcherSpec; -import io.javaoperatorsdk.operator.sample.ssalegacymatcher.ServiceDependentResource; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/ServiceDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/ServiceDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/ServiceDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/ServiceDependentResource.java index e0699093de..98036036cc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ssalegacymatcher/ServiceDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/ssalegacymatcher/ServiceDependentResource.java @@ -1,11 +1,10 @@ -package io.javaoperatorsdk.operator.sample.ssalegacymatcher; +package io.javaoperatorsdk.operator.dependent.ssalegacymatcher; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.Service; -import io.javaoperatorsdk.operator.SSAWithLegacyMatcherIT; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.GenericKubernetesResourceMatcher; @@ -27,7 +26,8 @@ public ServiceDependentResource() { protected Service desired(SSALegacyMatcherCustomResource primary, Context context) { - Service service = loadYaml(Service.class, SSAWithLegacyMatcherIT.class, "service.yaml"); + Service service = loadYaml(Service.class, SSAWithLegacyMatcherIT.class, + "/io/javaoperatorsdk/operator/service.yaml"); service.getMetadata().setName(primary.getMetadata().getName()); service.getMetadata().setNamespace(primary.getMetadata().getNamespace()); Map labels = new HashMap<>(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StandaloneDependentResourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentResourceIT.java similarity index 91% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/StandaloneDependentResourceIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentResourceIT.java index 5d1c570410..19853842e7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StandaloneDependentResourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentResourceIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.standalonedependent; import java.time.Duration; import java.util.Set; @@ -12,9 +12,6 @@ import io.javaoperatorsdk.operator.api.config.*; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.standalonedependent.StandaloneDependentTestCustomResource; -import io.javaoperatorsdk.operator.sample.standalonedependent.StandaloneDependentTestCustomResourceSpec; -import io.javaoperatorsdk.operator.sample.standalonedependent.StandaloneDependentTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentTestCustomResource.java similarity index 71% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentTestCustomResource.java index e88d00c985..3f2d2c9c2e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentTestCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.standalonedependent; +package io.javaoperatorsdk.operator.dependent.standalonedependent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -11,6 +11,6 @@ @ShortNames("sdt") public class StandaloneDependentTestCustomResource extends - CustomResource + CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResourceSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentTestCustomResourceSpec.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResourceSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentTestCustomResourceSpec.java index 4a88cf6044..664331bbaf 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResourceSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentTestCustomResourceSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.standalonedependent; +package io.javaoperatorsdk.operator.dependent.standalonedependent; public class StandaloneDependentTestCustomResourceSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentTestReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentTestReconciler.java index 6de0b01464..e10a20a93c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/standalonedependent/StandaloneDependentTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.standalonedependent; +package io.javaoperatorsdk.operator.dependent.standalonedependent; import java.util.List; import java.util.Optional; @@ -6,7 +6,6 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.client.KubernetesClientException; import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.StandaloneDependentResourceIT; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; @@ -80,7 +79,7 @@ protected Deployment desired(StandaloneDependentTestCustomResource primary, Context context) { Deployment deployment = ReconcilerUtils.loadYaml(Deployment.class, StandaloneDependentResourceIT.class, - "nginx-deployment.yaml"); + "/io/javaoperatorsdk/operator/nginx-deployment.yaml"); deployment.getMetadata().setName(primary.getMetadata().getName()); deployment.getSpec().setReplicas(primary.getSpec().getReplicaCount()); deployment.getMetadata().setNamespace(primary.getMetadata().getNamespace()); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerCustomResource.java similarity index 84% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerCustomResource.java index bf35304da0..e500206207 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statefulsetdesiredsanitizer; +package io.javaoperatorsdk.operator.dependent.statefulsetdesiredsanitizer; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerDependentResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerDependentResource.java index 12525c4c8d..98ac4897d7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statefulsetdesiredsanitizer; +package io.javaoperatorsdk.operator.dependent.statefulsetdesiredsanitizer; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.apps.StatefulSet; @@ -20,7 +20,8 @@ public StatefulSetDesiredSanitizerDependentResource() { protected StatefulSet desired(StatefulSetDesiredSanitizerCustomResource primary, Context context) { var template = - ReconcilerUtils.loadYaml(StatefulSet.class, getClass(), "statefulset.yaml"); + ReconcilerUtils.loadYaml(StatefulSet.class, getClass(), + "/io/javaoperatorsdk/operator/statefulset.yaml"); template.setMetadata(new ObjectMetaBuilder() .withName(primary.getMetadata().getName()) .withNamespace(primary.getMetadata().getNamespace()) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatefulSetDesiredSanitizerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerIT.java similarity index 77% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/StatefulSetDesiredSanitizerIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerIT.java index 5313fb7dfb..49c08f7a8b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatefulSetDesiredSanitizerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.dependent.statefulsetdesiredsanitizer; import java.time.Duration; @@ -8,10 +8,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.apps.StatefulSet; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.statefulsetdesiredsanitizer.StatefulSetDesiredSanitizerCustomResource; -import io.javaoperatorsdk.operator.sample.statefulsetdesiredsanitizer.StatefulSetDesiredSanitizerDependentResource; -import io.javaoperatorsdk.operator.sample.statefulsetdesiredsanitizer.StatefulSetDesiredSanitizerReconciler; -import io.javaoperatorsdk.operator.sample.statefulsetdesiredsanitizer.StatefulSetDesiredSanitizerSpec; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java index 3b30acfc5c..f84f71411e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statefulsetdesiredsanitizer; +package io.javaoperatorsdk.operator.dependent.statefulsetdesiredsanitizer; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerSpec.java index 3cca134108..59fd852097 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/statefulsetdesiredsanitizer/StatefulSetDesiredSanitizerSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.statefulsetdesiredsanitizer; +package io.javaoperatorsdk.operator.dependent.statefulsetdesiredsanitizer; public class StatefulSetDesiredSanitizerSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentSpec.java deleted file mode 100644 index 1eefabdf6c..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentSpec.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.javaoperatorsdk.operator.sample.complexdependent; - -public class ComplexDependentSpec { - private String projectId; - - public String getProjectId() { - return projectId; - } - - public ComplexDependentSpec setProjectId(String projectId) { - this.projectId = projectId; - return this; - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentStatus.java deleted file mode 100644 index f541cbae1d..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentStatus.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.javaoperatorsdk.operator.sample.complexdependent; - - -public class ComplexDependentStatus { - private ComplexDependentReconciler.RECONCILE_STATUS status; - - public ComplexDependentReconciler.RECONCILE_STATUS getStatus() { - return status; - } - - public ComplexDependentStatus setStatus(ComplexDependentReconciler.RECONCILE_STATUS status) { - this.status = status; - return this; - } -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceStatus.java deleted file mode 100644 index e8f8da78f4..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestCustomResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.createupdateeventfilter; - -public class CreateUpdateEventFilterTestCustomResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResourceStatus.java deleted file mode 100644 index 33ea00e819..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentannotationsecondarymapper/DependentAnnotationSecondaryMapperResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.dependentannotationsecondarymapper; - -public class DependentAnnotationSecondaryMapperResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestResourceStatus.java deleted file mode 100644 index 99e8d54514..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentfilter/DependentFilterTestResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.dependentfilter; - -public class DependentFilterTestResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefResourceStatus.java deleted file mode 100644 index aa249a0916..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/dependentresourcecrossref/DependentResourceCrossRefResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.dependentresourcecrossref; - -public class DependentResourceCrossRefResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestResourceStatus.java deleted file mode 100644 index cf0d24aa2c..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/filter/FilterTestResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.filter; - -public class FilterTestResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceStatus.java deleted file mode 100644 index 79f67c017e..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/kubernetesdependentgarbagecollection/DependentGarbageCollectionTestCustomResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.kubernetesdependentgarbagecollection; - -public class DependentGarbageCollectionTestCustomResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestCustomResourceStatus.java deleted file mode 100644 index 5c403febfb..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/maxinterval/MaxIntervalTestCustomResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.maxinterval; - -public class MaxIntervalTestCustomResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceStatus.java deleted file mode 100644 index bde0468c89..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresource/MultipleDependentResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.multipledependentresource; - -public class MultipleDependentResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorStatus.java deleted file mode 100644 index 84543b8a12..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentresourcewithdiscriminator/MultipleDependentResourceWithDiscriminatorStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.multipledependentresourcewithdiscriminator; - -public class MultipleDependentResourceWithDiscriminatorStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceStatus.java deleted file mode 100644 index 2a78bf0531..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.multiplesecondaryeventsource; - -public class MultipleSecondaryEventSourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/ClusterStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/ClusterStatus.java deleted file mode 100644 index eac5c48b70..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/ClusterStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondary; - -public class ClusterStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobStatus.java deleted file mode 100644 index b2d7cf6259..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.primarytosecondary; - -public class JobStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceStatus.java deleted file mode 100644 index 975728c18c..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/ratelimit/RateLimitCustomResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.ratelimit; - -public class RateLimitCustomResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResourceStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResourceStatus.java deleted file mode 100644 index 5f12f1ef72..0000000000 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/standalonedependent/StandaloneDependentTestCustomResourceStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.javaoperatorsdk.operator.sample.standalonedependent; - -public class StandaloneDependentTestCustomResourceStatus { - -} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/support/TestUtils.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/support/TestUtils.java index ea3a72043b..952ad75b19 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/support/TestUtils.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/support/TestUtils.java @@ -4,9 +4,9 @@ import java.util.UUID; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.baseapi.simple.TestCustomResource; +import io.javaoperatorsdk.operator.baseapi.simple.TestCustomResourceSpec; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; -import io.javaoperatorsdk.operator.sample.simple.TestCustomResourceSpec; public class TestUtils { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowCustomResource.java similarity index 62% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowCustomResource.java index e4a5031a6f..cb48ea8c97 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.complexdependent; +package io.javaoperatorsdk.operator.workflow.complexdependent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; @@ -9,6 +9,6 @@ @Group("sample.javaoperatorsdk") @Version("v1") @ShortNames("cdc") -public class ComplexDependentCustomResource - extends CustomResource implements Namespaced { +public class ComplexWorkflowCustomResource + extends CustomResource implements Namespaced { } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ComplexDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowIT.java similarity index 65% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ComplexDependentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowIT.java index 3bc7afaa6a..163abe34a7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ComplexDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.complexdependent; import java.time.Duration; @@ -12,27 +12,24 @@ import io.fabric8.kubernetes.api.model.apps.StatefulSet; import io.fabric8.kubernetes.client.readiness.Readiness; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentCustomResource; -import io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentReconciler; -import io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentSpec; -import io.javaoperatorsdk.operator.sample.complexdependent.dependent.FirstService; -import io.javaoperatorsdk.operator.sample.complexdependent.dependent.FirstStatefulSet; -import io.javaoperatorsdk.operator.sample.complexdependent.dependent.SecondService; -import io.javaoperatorsdk.operator.sample.complexdependent.dependent.SecondStatefulSet; +import io.javaoperatorsdk.operator.workflow.complexdependent.dependent.FirstService; +import io.javaoperatorsdk.operator.workflow.complexdependent.dependent.FirstStatefulSet; +import io.javaoperatorsdk.operator.workflow.complexdependent.dependent.SecondService; +import io.javaoperatorsdk.operator.workflow.complexdependent.dependent.SecondStatefulSet; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -class ComplexDependentIT { +class ComplexWorkflowIT { public static final String TEST_RESOURCE_NAME = "test1"; - Logger log = LoggerFactory.getLogger(ComplexDependentIT.class); + Logger log = LoggerFactory.getLogger(ComplexWorkflowIT.class); @RegisterExtension LocallyRunOperatorExtension operator = LocallyRunOperatorExtension.builder() - .withReconciler(new ComplexDependentReconciler()) + .withReconciler(new ComplexWorkflowReconciler()) .build(); @Test @@ -41,10 +38,10 @@ void successfullyReconciles() { await().atMost(Duration.ofSeconds(90)) .untilAsserted(() -> { - var res = operator.get(ComplexDependentCustomResource.class, TEST_RESOURCE_NAME); + var res = operator.get(ComplexWorkflowCustomResource.class, TEST_RESOURCE_NAME); assertThat(res.getStatus()).isNotNull(); assertThat(res.getStatus().getStatus()) - .isEqualTo(ComplexDependentReconciler.RECONCILE_STATUS.READY); + .isEqualTo(ComplexWorkflowReconciler.RECONCILE_STATUS.READY); }); var firstStatefulSet = operator.get(StatefulSet.class, String.format("%s-%s", @@ -63,12 +60,12 @@ void successfullyReconciles() { assertThat(Readiness.isStatefulSetReady(secondStatefulSet)).isTrue(); } - ComplexDependentCustomResource testResource() { - var resource = new ComplexDependentCustomResource(); + ComplexWorkflowCustomResource testResource() { + var resource = new ComplexWorkflowCustomResource(); resource.setMetadata(new ObjectMetaBuilder() .withName(TEST_RESOURCE_NAME) .build()); - resource.setSpec(new ComplexDependentSpec()); + resource.setSpec(new ComplexWorkflowSpec()); resource.getSpec().setProjectId(TEST_RESOURCE_NAME); return resource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowReconciler.java similarity index 60% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowReconciler.java index c96a6ee248..249c749003 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/ComplexDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.complexdependent; +package io.javaoperatorsdk.operator.workflow.complexdependent; import java.util.List; import java.util.Objects; @@ -10,10 +10,14 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; -import io.javaoperatorsdk.operator.sample.complexdependent.dependent.*; +import io.javaoperatorsdk.operator.workflow.complexdependent.dependent.FirstService; +import io.javaoperatorsdk.operator.workflow.complexdependent.dependent.FirstStatefulSet; +import io.javaoperatorsdk.operator.workflow.complexdependent.dependent.SecondService; +import io.javaoperatorsdk.operator.workflow.complexdependent.dependent.SecondStatefulSet; +import io.javaoperatorsdk.operator.workflow.complexdependent.dependent.StatefulSetReadyCondition; -import static io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentReconciler.SERVICE_EVENT_SOURCE_NAME; -import static io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentReconciler.STATEFUL_SET_EVENT_SOURCE_NAME; +import static io.javaoperatorsdk.operator.workflow.complexdependent.ComplexWorkflowReconciler.SERVICE_EVENT_SOURCE_NAME; +import static io.javaoperatorsdk.operator.workflow.complexdependent.ComplexWorkflowReconciler.STATEFUL_SET_EVENT_SOURCE_NAME; @Workflow(dependents = { @Dependent(name = "first-svc", type = FirstService.class, @@ -31,19 +35,19 @@ readyPostcondition = StatefulSetReadyCondition.class), }) @ControllerConfiguration(name = "project-operator") -public class ComplexDependentReconciler implements Reconciler { +public class ComplexWorkflowReconciler implements Reconciler { public static final String SERVICE_EVENT_SOURCE_NAME = "serviceEventSource"; public static final String STATEFUL_SET_EVENT_SOURCE_NAME = "statefulSetEventSource"; @Override - public UpdateControl reconcile( - ComplexDependentCustomResource resource, - Context context) throws Exception { + public UpdateControl reconcile( + ComplexWorkflowCustomResource resource, + Context context) throws Exception { var ready = context.managedWorkflowAndDependentResourceContext().getWorkflowReconcileResult() .allDependentResourcesReady(); - var status = Objects.requireNonNullElseGet(resource.getStatus(), ComplexDependentStatus::new); + var status = Objects.requireNonNullElseGet(resource.getStatus(), ComplexWorkflowStatus::new); status.setStatus(ready ? RECONCILE_STATUS.READY : RECONCILE_STATUS.NOT_READY); resource.setStatus(status); @@ -51,17 +55,17 @@ public UpdateControl reconcile( } @Override - public List> prepareEventSources( - EventSourceContext context) { - InformerEventSource serviceEventSource = + public List> prepareEventSources( + EventSourceContext context) { + InformerEventSource serviceEventSource = new InformerEventSource<>( - InformerConfiguration.from(Service.class, ComplexDependentCustomResource.class) + InformerConfiguration.from(Service.class, ComplexWorkflowCustomResource.class) .withName(SERVICE_EVENT_SOURCE_NAME) .build(), context); - InformerEventSource statefulSetEventSource = + InformerEventSource statefulSetEventSource = new InformerEventSource<>( - InformerConfiguration.from(StatefulSet.class, ComplexDependentCustomResource.class) + InformerConfiguration.from(StatefulSet.class, ComplexWorkflowCustomResource.class) .withName(STATEFUL_SET_EVENT_SOURCE_NAME) .build(), context); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowSpec.java new file mode 100644 index 0000000000..1e8f599c67 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowSpec.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.workflow.complexdependent; + +public class ComplexWorkflowSpec { + private String projectId; + + public String getProjectId() { + return projectId; + } + + public ComplexWorkflowSpec setProjectId(String projectId) { + this.projectId = projectId; + return this; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowStatus.java new file mode 100644 index 0000000000..d9b498682a --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowStatus.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.workflow.complexdependent; + + +public class ComplexWorkflowStatus { + private ComplexWorkflowReconciler.RECONCILE_STATUS status; + + public ComplexWorkflowReconciler.RECONCILE_STATUS getStatus() { + return status; + } + + public ComplexWorkflowStatus setStatus(ComplexWorkflowReconciler.RECONCILE_STATUS status) { + this.status = status; + return this; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/BaseDependentResource.java similarity index 67% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/BaseDependentResource.java index 08e7e5fe2e..e6bd8462cb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/BaseDependentResource.java @@ -1,12 +1,12 @@ -package io.javaoperatorsdk.operator.sample.complexdependent.dependent; +package io.javaoperatorsdk.operator.workflow.complexdependent.dependent; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentCustomResource; +import io.javaoperatorsdk.operator.workflow.complexdependent.ComplexWorkflowCustomResource; public abstract class BaseDependentResource - extends CRUDKubernetesDependentResource { + extends CRUDKubernetesDependentResource { public static final String K8S_NAME = "app.kubernetes.io/name"; protected final String component; @@ -16,11 +16,11 @@ public BaseDependentResource(Class resourceType, String component) { this.component = component; } - protected String name(ComplexDependentCustomResource primary) { + protected String name(ComplexWorkflowCustomResource primary) { return String.format("%s-%s", component, primary.getSpec().getProjectId()); } - protected ObjectMetaBuilder createMeta(ComplexDependentCustomResource primary) { + protected ObjectMetaBuilder createMeta(ComplexWorkflowCustomResource primary) { String name = name(primary); return new ObjectMetaBuilder() .withName(name) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseService.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/BaseService.java similarity index 64% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseService.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/BaseService.java index 192bc97de9..75a4d7ee03 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseService.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/BaseService.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.complexdependent.dependent; +package io.javaoperatorsdk.operator.workflow.complexdependent.dependent; import java.util.Map; @@ -6,7 +6,7 @@ import io.fabric8.kubernetes.api.model.ServiceBuilder; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentCustomResource; +import io.javaoperatorsdk.operator.workflow.complexdependent.ComplexWorkflowCustomResource; public abstract class BaseService extends BaseDependentResource { @@ -15,9 +15,10 @@ public BaseService(String component) { } @Override - protected Service desired(ComplexDependentCustomResource primary, - Context context) { - var template = ReconcilerUtils.loadYaml(Service.class, getClass(), "service.yaml"); + protected Service desired(ComplexWorkflowCustomResource primary, + Context context) { + var template = ReconcilerUtils.loadYaml(Service.class, getClass(), + "/io/javaoperatorsdk/operator/workflow/complexdependent/service.yaml"); return new ServiceBuilder(template) .withMetadata(createMeta(primary).build()) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseStatefulSet.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/BaseStatefulSet.java similarity index 73% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseStatefulSet.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/BaseStatefulSet.java index 0609e8dab7..fe05db1c1b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/BaseStatefulSet.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/BaseStatefulSet.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.complexdependent.dependent; +package io.javaoperatorsdk.operator.workflow.complexdependent.dependent; import java.util.Map; @@ -6,7 +6,7 @@ import io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentCustomResource; +import io.javaoperatorsdk.operator.workflow.complexdependent.ComplexWorkflowCustomResource; public abstract class BaseStatefulSet extends BaseDependentResource { public BaseStatefulSet(String component) { @@ -14,9 +14,10 @@ public BaseStatefulSet(String component) { } @Override - protected StatefulSet desired(ComplexDependentCustomResource primary, - Context context) { - var template = ReconcilerUtils.loadYaml(StatefulSet.class, getClass(), "statefulset.yaml"); + protected StatefulSet desired(ComplexWorkflowCustomResource primary, + Context context) { + var template = ReconcilerUtils.loadYaml(StatefulSet.class, getClass(), + "/io/javaoperatorsdk/operator/workflow/complexdependent/statefulset.yaml"); var name = name(primary); var metadata = createMeta(primary).build(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstService.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/FirstService.java similarity index 79% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstService.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/FirstService.java index f568ce08e5..36b1ec4845 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstService.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/FirstService.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.complexdependent.dependent; +package io.javaoperatorsdk.operator.workflow.complexdependent.dependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstStatefulSet.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/FirstStatefulSet.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstStatefulSet.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/FirstStatefulSet.java index d5740616b2..d9cd2933fd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/FirstStatefulSet.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/FirstStatefulSet.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.complexdependent.dependent; +package io.javaoperatorsdk.operator.workflow.complexdependent.dependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondService.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/SecondService.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondService.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/SecondService.java index ee6f5210d0..1b361ced71 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondService.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/SecondService.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.complexdependent.dependent; +package io.javaoperatorsdk.operator.workflow.complexdependent.dependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondStatefulSet.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/SecondStatefulSet.java similarity index 80% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondStatefulSet.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/SecondStatefulSet.java index 3786d90c00..78ab7953eb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/SecondStatefulSet.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/SecondStatefulSet.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.complexdependent.dependent; +package io.javaoperatorsdk.operator.workflow.complexdependent.dependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/StatefulSetReadyCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/StatefulSetReadyCondition.java similarity index 58% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/StatefulSetReadyCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/StatefulSetReadyCondition.java index 894cab310a..1116bd7f1d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/complexdependent/dependent/StatefulSetReadyCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/dependent/StatefulSetReadyCondition.java @@ -1,19 +1,19 @@ -package io.javaoperatorsdk.operator.sample.complexdependent.dependent; +package io.javaoperatorsdk.operator.workflow.complexdependent.dependent; import io.fabric8.kubernetes.api.model.apps.StatefulSet; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; -import io.javaoperatorsdk.operator.sample.complexdependent.ComplexDependentCustomResource; +import io.javaoperatorsdk.operator.workflow.complexdependent.ComplexWorkflowCustomResource; public class StatefulSetReadyCondition - implements Condition { + implements Condition { @Override public boolean isMet( - DependentResource dependentResource, - ComplexDependentCustomResource primary, - Context context) { + DependentResource dependentResource, + ComplexWorkflowCustomResource primary, + Context context) { return dependentResource.getSecondaryResource(primary, context).map(secondary -> { var readyReplicas = secondary.getStatus().getReadyReplicas(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationConditionIT.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationConditionIT.java index 67b2920836..85cb3aa6c5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CRDPresentActivationConditionIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationConditionIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.crdpresentactivation; import java.time.Duration; import java.util.Map; @@ -9,9 +9,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.crdpresentactivation.CRDPresentActivationCustomResource; -import io.javaoperatorsdk.operator.sample.crdpresentactivation.CRDPresentActivationDependentCustomResource; -import io.javaoperatorsdk.operator.sample.crdpresentactivation.CRDPresentActivationReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationCustomResource.java index af2aea00ab..5b8dc2f704 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.crdpresentactivation; +package io.javaoperatorsdk.operator.workflow.crdpresentactivation; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationDependent.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationDependent.java index 6e86e2a475..fdfcda1700 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.crdpresentactivation; +package io.javaoperatorsdk.operator.workflow.crdpresentactivation; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.api.reconciler.Context; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationDependentCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependentCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationDependentCustomResource.java index 899cea0e69..18280ee6b3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationDependentCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationDependentCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.crdpresentactivation; +package io.javaoperatorsdk.operator.workflow.crdpresentactivation; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationReconciler.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationReconciler.java index ef96f3b7eb..9cc05eaddc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/crdpresentactivation/CRDPresentActivationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/crdpresentactivation/CRDPresentActivationReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.crdpresentactivation; +package io.javaoperatorsdk.operator.workflow.crdpresentactivation; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ConfigMapDependent.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ConfigMapDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ConfigMapDependent.java index 63791417f6..af70b6842a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ConfigMapDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ConfigMapDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.manageddependentdeletecondition; +package io.javaoperatorsdk.operator.workflow.manageddependentdeletecondition; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionCustomResource.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionCustomResource.java index 0922e8977e..01b995c061 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.manageddependentdeletecondition; +package io.javaoperatorsdk.operator.workflow.manageddependentdeletecondition; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java index 2fa2c6213b..530f9b8146 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDefaultDeleteConditionReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.manageddependentdeletecondition; +package io.javaoperatorsdk.operator.workflow.manageddependentdeletecondition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManagedDependentDeleteConditionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDeleteConditionIT.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/ManagedDependentDeleteConditionIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDeleteConditionIT.java index b2ef89f0f9..4d688bf606 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManagedDependentDeleteConditionIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/ManagedDependentDeleteConditionIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.manageddependentdeletecondition; import java.time.Duration; import java.util.Set; @@ -10,8 +10,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.manageddependentdeletecondition.ManagedDependentDefaultDeleteConditionCustomResource; -import io.javaoperatorsdk.operator.sample.manageddependentdeletecondition.ManagedDependentDefaultDeleteConditionReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/SecretDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/SecretDependent.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/SecretDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/SecretDependent.java index d1af07a2a5..6add6bf93b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/manageddependentdeletecondition/SecretDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/manageddependentdeletecondition/SecretDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.manageddependentdeletecondition; +package io.javaoperatorsdk.operator.workflow.manageddependentdeletecondition; import java.nio.charset.StandardCharsets; import java.util.Base64; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ActivationCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ActivationCondition.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ActivationCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ActivationCondition.java index 5e357351f5..063bb6b72c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ActivationCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ActivationCondition.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; +package io.javaoperatorsdk.operator.workflow.multipledependentwithactivation; import io.fabric8.openshift.api.model.Route; import io.javaoperatorsdk.operator.api.reconciler.Context; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource1.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource1.java index e9b53898b8..085586beaa 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; +package io.javaoperatorsdk.operator.workflow.multipledependentwithactivation; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource2.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource2.java index c88929a61f..a07b6a925b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/ConfigMapDependentResource2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; +package io.javaoperatorsdk.operator.workflow.multipledependentwithactivation; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentActivationCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentActivationCustomResource.java index e373a7bc01..1e99c1c4b1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentActivationCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; +package io.javaoperatorsdk.operator.workflow.multipledependentwithactivation; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentActivationReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentActivationReconciler.java index 5a4961c6c6..14e3ed9811 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentActivationReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; +package io.javaoperatorsdk.operator.workflow.multipledependentwithactivation; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentActivationSpec.java similarity index 71% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentActivationSpec.java index 93bf4b18f3..76f39911fe 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/MultipleDependentActivationSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentActivationSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; +package io.javaoperatorsdk.operator.workflow.multipledependentwithactivation; public class MultipleDependentActivationSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentWithActivationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentWithActivationIT.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentWithActivationIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentWithActivationIT.java index e5d1542b19..b82fc369f9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentWithActivationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/MultipleDependentWithActivationIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.multipledependentwithactivation; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -7,7 +7,6 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.multipledependentwithactivation.*; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/SecretDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/SecretDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/SecretDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/SecretDependentResource.java index 821f5482dc..6340d07b58 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multipledependentwithactivation/SecretDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/SecretDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.multipledependentwithactivation; +package io.javaoperatorsdk.operator.workflow.multipledependentwithactivation; import java.util.Base64; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource1.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource1.java index 8c5a844cfb..ac57e05903 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource1.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.orderedmanageddependent; +package io.javaoperatorsdk.operator.workflow.orderedmanageddependent; import java.util.HashMap; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource2.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource2.java index 72a427aad6..1494a0d430 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource2.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.orderedmanageddependent; +package io.javaoperatorsdk.operator.workflow.orderedmanageddependent; import java.util.HashMap; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentCustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentCustomResource.java index 1e33bb2a5b..b73f92565d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.orderedmanageddependent; +package io.javaoperatorsdk.operator.workflow.orderedmanageddependent; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/OrderedManagedDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentIT.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/OrderedManagedDependentIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentIT.java index e7bb8fdd14..73ab6e65f6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/OrderedManagedDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.orderedmanageddependent; import java.time.Duration; @@ -7,10 +7,6 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.orderedmanageddependent.ConfigMapDependentResource1; -import io.javaoperatorsdk.operator.sample.orderedmanageddependent.ConfigMapDependentResource2; -import io.javaoperatorsdk.operator.sample.orderedmanageddependent.OrderedManagedDependentCustomResource; -import io.javaoperatorsdk.operator.sample.orderedmanageddependent.OrderedManagedDependentTestReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentTestReconciler.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentTestReconciler.java index 148ceb1499..a78b02c056 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/OrderedManagedDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentTestReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.orderedmanageddependent; +package io.javaoperatorsdk.operator.workflow.orderedmanageddependent; import java.util.ArrayList; import java.util.Collections; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/ConfigMapDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/ConfigMapDependentResource.java index 241bff64ce..a909a3a706 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcleanup; +package io.javaoperatorsdk.operator.workflow.workflowactivationcleanup; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/TestActivcationCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/TestActivcationCondition.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/TestActivcationCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/TestActivcationCondition.java index ff215b7d72..fd92065f15 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/TestActivcationCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/TestActivcationCondition.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcleanup; +package io.javaoperatorsdk.operator.workflow.workflowactivationcleanup; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupCustomResource.java index f73b484d86..d98c9cd166 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcleanup; +package io.javaoperatorsdk.operator.workflow.workflowactivationcleanup; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowActivationCleanupIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupIT.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowActivationCleanupIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupIT.java index fe1b72cc5a..f41d15ae27 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowActivationCleanupIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.workflowactivationcleanup; import org.junit.jupiter.api.*; @@ -8,10 +8,8 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil; +import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.workflowactivationcleanup.WorkflowActivationCleanupCustomResource; -import io.javaoperatorsdk.operator.sample.workflowactivationcleanup.WorkflowActivationCleanupReconciler; -import io.javaoperatorsdk.operator.sample.workflowactivationcleanup.WorkflowActivationCleanupSpec; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java index 6a30f3d9f4..64a7a28a5c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcleanup; +package io.javaoperatorsdk.operator.workflow.workflowactivationcleanup; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupSpec.java similarity index 72% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupSpec.java index 23ea4cda3e..1719bb535f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcleanup/WorkflowActivationCleanupSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcleanup/WorkflowActivationCleanupSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcleanup; +package io.javaoperatorsdk.operator.workflow.workflowactivationcleanup; public class WorkflowActivationCleanupSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/ConfigMapDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/ConfigMapDependentResource.java index 7433c31c73..a5b255b10f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcondition; +package io.javaoperatorsdk.operator.workflow.workflowactivationcondition; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/IsOpenShiftCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/IsOpenShiftCondition.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/IsOpenShiftCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/IsOpenShiftCondition.java index 79434409b8..5665590527 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/IsOpenShiftCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/IsOpenShiftCondition.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcondition; +package io.javaoperatorsdk.operator.workflow.workflowactivationcondition; import io.fabric8.openshift.api.model.Route; import io.javaoperatorsdk.operator.api.reconciler.Context; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/RouteDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/RouteDependentResource.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/RouteDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/RouteDependentResource.java index de5d52f76a..92fe86d5db 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/RouteDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/RouteDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcondition; +package io.javaoperatorsdk.operator.workflow.workflowactivationcondition; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.openshift.api.model.Route; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionCustomResource.java index 63d4bc343c..d04b3c08e0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcondition; +package io.javaoperatorsdk.operator.workflow.workflowactivationcondition; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowActivationConditionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionIT.java similarity index 75% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowActivationConditionIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionIT.java index 38a11e0438..355855e6c6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowActivationConditionIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.workflowactivationcondition; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -6,11 +6,8 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.workflowactivationcondition.WorkflowActivationConditionCustomResource; -import io.javaoperatorsdk.operator.sample.workflowactivationcondition.WorkflowActivationConditionReconciler; -import io.javaoperatorsdk.operator.sample.workflowactivationcondition.WorkflowActivationConditionSpec; -import static io.javaoperatorsdk.operator.sample.workflowactivationcondition.ConfigMapDependentResource.DATA_KEY; +import static io.javaoperatorsdk.operator.workflow.workflowactivationcondition.ConfigMapDependentResource.DATA_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionReconciler.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionReconciler.java index 8669c24cb7..2ac931bcdb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcondition; +package io.javaoperatorsdk.operator.workflow.workflowactivationcondition; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionSpec.java similarity index 72% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionSpec.java index 826fe04958..aa3b6b5f9c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowactivationcondition/WorkflowActivationConditionSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowactivationcondition/WorkflowActivationConditionSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowactivationcondition; +package io.javaoperatorsdk.operator.workflow.workflowactivationcondition; public class WorkflowActivationConditionSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapDeletePostCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/ConfigMapDeletePostCondition.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapDeletePostCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/ConfigMapDeletePostCondition.java index da6a693fe4..c9d9393ce1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapDeletePostCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/ConfigMapDeletePostCondition.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowallfeature; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/ConfigMapDependentResource.java similarity index 97% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/ConfigMapDependentResource.java index 04876b7959..9bee03d474 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowallfeature; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; import java.util.Map; import java.util.Optional; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapReconcileCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/ConfigMapReconcileCondition.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapReconcileCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/ConfigMapReconcileCondition.java index dfdc0ad8a4..024e110edb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/ConfigMapReconcileCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/ConfigMapReconcileCondition.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowallfeature; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; import io.fabric8.kubernetes.api.model.ConfigMap; import io.javaoperatorsdk.operator.api.reconciler.Context; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/DeploymentDependentResource.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/DeploymentDependentResource.java index 30cd555abe..5abcf4c28c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/DeploymentDependentResource.java @@ -1,8 +1,7 @@ -package io.javaoperatorsdk.operator.sample.workflowallfeature; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.WorkflowAllFeatureIT; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; @@ -18,7 +17,7 @@ protected Deployment desired(WorkflowAllFeatureCustomResource primary, Context context) { Deployment deployment = ReconcilerUtils.loadYaml(Deployment.class, WorkflowAllFeatureIT.class, - "nginx-deployment.yaml"); + "/io/javaoperatorsdk/operator/nginx-deployment.yaml"); deployment.getMetadata().setName(primary.getMetadata().getName()); deployment.getSpec().setReplicas(2); deployment.getMetadata().setNamespace(primary.getMetadata().getNamespace()); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentReadyCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/DeploymentReadyCondition.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentReadyCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/DeploymentReadyCondition.java index 0e6f5d8580..5e023a3d9d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/DeploymentReadyCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/DeploymentReadyCondition.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowallfeature; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.javaoperatorsdk.operator.api.reconciler.Context; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureCustomResource.java similarity index 88% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureCustomResource.java index ee764f4681..cc3987710b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowallfeature; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureIT.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureIT.java index 0473c50ddb..20e5ea5ae3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; import java.time.Duration; import java.util.HashMap; @@ -10,13 +10,8 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.workflowallfeature.ConfigMapReconcileCondition; -import io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureCustomResource; -import io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureReconciler; -import io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureSpec; -import io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureStatus; -import static io.javaoperatorsdk.operator.sample.workflowallfeature.ConfigMapDependentResource.READY_TO_DELETE_ANNOTATION; +import static io.javaoperatorsdk.operator.workflow.workflowallfeature.ConfigMapDependentResource.READY_TO_DELETE_ANNOTATION; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureReconciler.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureReconciler.java index 61b42e0c64..c035a27375 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowallfeature; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; import java.util.concurrent.atomic.AtomicInteger; @@ -13,7 +13,7 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; -import static io.javaoperatorsdk.operator.sample.workflowallfeature.WorkflowAllFeatureReconciler.DEPLOYMENT_NAME; +import static io.javaoperatorsdk.operator.workflow.workflowallfeature.WorkflowAllFeatureReconciler.DEPLOYMENT_NAME; @Workflow(dependents = { @Dependent(name = DEPLOYMENT_NAME, type = DeploymentDependentResource.class, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureSpec.java similarity index 82% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureSpec.java index 6d5cfd7a5a..fb7ced3753 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowallfeature; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; public class WorkflowAllFeatureSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureStatus.java similarity index 89% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureStatus.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureStatus.java index c53931b206..a1a83e4abc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowallfeature/WorkflowAllFeatureStatus.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowallfeature/WorkflowAllFeatureStatus.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowallfeature; +package io.javaoperatorsdk.operator.workflow.workflowallfeature; public class WorkflowAllFeatureStatus { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/ConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/ConfigMapDependent.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/ConfigMapDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/ConfigMapDependent.java index 91bf73906f..228ed39564 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/ConfigMapDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/ConfigMapDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowexplicitcleanup; +package io.javaoperatorsdk.operator.workflow.workflowexplicitcleanup; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java index b2057a54dd..14ae6011a9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowexplicitcleanup; +package io.javaoperatorsdk.operator.workflow.workflowexplicitcleanup; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitCleanupIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupIT.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitCleanupIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupIT.java index b26bfdd443..e6a5b7a3cc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitCleanupIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.workflowexplicitcleanup; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -6,8 +6,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.workflowexplicitcleanup.WorkflowExplicitCleanupCustomResource; -import io.javaoperatorsdk.operator.sample.workflowexplicitcleanup.WorkflowExplicitCleanupReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java index 128bb9629c..4361b5ac47 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowexplicitcleanup; +package io.javaoperatorsdk.operator.workflow.workflowexplicitcleanup; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java index d8da8797f5..93236cbf2c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitcleanup/WorkflowExplicitCleanupSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowexplicitcleanup; +package io.javaoperatorsdk.operator.workflow.workflowexplicitcleanup; public class WorkflowExplicitCleanupSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/ConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/ConfigMapDependent.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/ConfigMapDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/ConfigMapDependent.java index e26fcfcf11..1632de5bbd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/ConfigMapDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/ConfigMapDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowexplicitinvocation; +package io.javaoperatorsdk.operator.workflow.workflowexplicitinvocation; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java index 827a17ddaf..c64964b02b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowexplicitinvocation; +package io.javaoperatorsdk.operator.workflow.workflowexplicitinvocation; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationIT.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationIT.java index 0ba8fa6229..ba77057acc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowExplicitInvocationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.workflowexplicitinvocation; import java.time.Duration; @@ -8,9 +8,6 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.workflowexplicitinvocation.WorkflowExplicitInvocationCustomResource; -import io.javaoperatorsdk.operator.sample.workflowexplicitinvocation.WorkflowExplicitInvocationReconciler; -import io.javaoperatorsdk.operator.sample.workflowexplicitinvocation.WorkflowExplicitInvocationSpec; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java similarity index 94% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java index dc7bce4296..4ac64b4cf8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowexplicitinvocation; +package io.javaoperatorsdk.operator.workflow.workflowexplicitinvocation; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java similarity index 76% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java index 2112d348e2..a50af9a9db 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowexplicitinvocation/WorkflowExplicitInvocationSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowexplicitinvocation; +package io.javaoperatorsdk.operator.workflow.workflowexplicitinvocation; public class WorkflowExplicitInvocationSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/ActivationCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/ActivationCondition.java similarity index 90% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/ActivationCondition.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/ActivationCondition.java index c8be8467df..b69573c253 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/ActivationCondition.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/ActivationCondition.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowmultipleactivation; +package io.javaoperatorsdk.operator.workflow.workflowmultipleactivation; import io.fabric8.openshift.api.model.Route; import io.javaoperatorsdk.operator.api.reconciler.Context; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/ConfigMapDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/ConfigMapDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/ConfigMapDependentResource.java index e245cb222d..82d8d9c236 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/ConfigMapDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowmultipleactivation; +package io.javaoperatorsdk.operator.workflow.workflowmultipleactivation; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/SecretDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/SecretDependentResource.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/SecretDependentResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/SecretDependentResource.java index decd5a346d..872a5b5770 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/SecretDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/SecretDependentResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowmultipleactivation; +package io.javaoperatorsdk.operator.workflow.workflowmultipleactivation; import java.util.Base64; import java.util.Map; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationCustomResource.java similarity index 87% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationCustomResource.java index 9c642e9635..faf442b849 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowmultipleactivation; +package io.javaoperatorsdk.operator.workflow.workflowmultipleactivation; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowMultipleActivationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationIT.java similarity index 95% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowMultipleActivationIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationIT.java index a7f93935ee..e793e9cb19 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowMultipleActivationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationIT.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.workflowmultipleactivation; import java.time.Duration; @@ -9,9 +9,8 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.workflowmultipleactivation.*; -import static io.javaoperatorsdk.operator.sample.workflowactivationcondition.ConfigMapDependentResource.DATA_KEY; +import static io.javaoperatorsdk.operator.workflow.workflowactivationcondition.ConfigMapDependentResource.DATA_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java similarity index 93% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java index aeb4403f7c..6018fb7112 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowmultipleactivation; +package io.javaoperatorsdk.operator.workflow.workflowmultipleactivation; import java.util.concurrent.atomic.AtomicInteger; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationSpec.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationSpec.java similarity index 72% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationSpec.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationSpec.java index b342bb331f..c9c9cf3a15 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowmultipleactivation/WorkflowMultipleActivationSpec.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowmultipleactivation/WorkflowMultipleActivationSpec.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowmultipleactivation; +package io.javaoperatorsdk.operator.workflow.workflowmultipleactivation; public class WorkflowMultipleActivationSpec { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/ConfigMapDependent.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/ConfigMapDependent.java similarity index 92% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/ConfigMapDependent.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/ConfigMapDependent.java index a418e8787e..fcd817c4f7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/ConfigMapDependent.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/ConfigMapDependent.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling; +package io.javaoperatorsdk.operator.workflow.workflowsilentexceptionhandling; import io.fabric8.kubernetes.api.model.ConfigMap; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java similarity index 85% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java index 3d4283e182..db5e94e40b 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerCustomResource.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling; +package io.javaoperatorsdk.operator.workflow.workflowsilentexceptionhandling; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java similarity index 96% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java index 2519ccfe8d..d0a80d0be4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/HandleWorkflowExceptionsInReconcilerReconciler.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling; +package io.javaoperatorsdk.operator.workflow.workflowsilentexceptionhandling; import io.javaoperatorsdk.operator.api.reconciler.Cleaner; import io.javaoperatorsdk.operator.api.reconciler.Context; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowSilentExceptionHandlingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/WorkflowSilentExceptionHandlingIT.java similarity index 82% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowSilentExceptionHandlingIT.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/WorkflowSilentExceptionHandlingIT.java index cd79283585..b23fee2d20 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowSilentExceptionHandlingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/workflowsilentexceptionhandling/WorkflowSilentExceptionHandlingIT.java @@ -1,12 +1,10 @@ -package io.javaoperatorsdk.operator; +package io.javaoperatorsdk.operator.workflow.workflowsilentexceptionhandling; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; -import io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling.HandleWorkflowExceptionsInReconcilerCustomResource; -import io.javaoperatorsdk.operator.sample.workflowsilentexceptionhandling.HandleWorkflowExceptionsInReconcilerReconciler; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/leader-elector-stop-noaccess-role-binding.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/baseapi/leader-elector-stop-noaccess-role-binding.yaml similarity index 100% rename from operator-framework/src/test/resources/io/javaoperatorsdk/operator/leader-elector-stop-noaccess-role-binding.yaml rename to operator-framework/src/test/resources/io/javaoperatorsdk/operator/baseapi/leader-elector-stop-noaccess-role-binding.yaml diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/leader-elector-stop-role-noaccess.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/baseapi/leader-elector-stop-role-noaccess.yaml similarity index 100% rename from operator-framework/src/test/resources/io/javaoperatorsdk/operator/leader-elector-stop-role-noaccess.yaml rename to operator-framework/src/test/resources/io/javaoperatorsdk/operator/baseapi/leader-elector-stop-role-noaccess.yaml diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-full-access-role.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-full-access-role.yaml similarity index 100% rename from operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-full-access-role.yaml rename to operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-full-access-role.yaml diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-no-configmap-access.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-no-configmap-access.yaml similarity index 100% rename from operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-no-configmap-access.yaml rename to operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-no-configmap-access.yaml diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-no-cr-access.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-no-cr-access.yaml similarity index 100% rename from operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-no-cr-access.yaml rename to operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-no-cr-access.yaml diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-only-main-ns-access-binding.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-only-main-ns-access-binding.yaml similarity index 100% rename from operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-only-main-ns-access-binding.yaml rename to operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-only-main-ns-access-binding.yaml diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-only-main-ns-access.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-only-main-ns-access.yaml similarity index 100% rename from operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-only-main-ns-access.yaml rename to operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-only-main-ns-access.yaml diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-role-binding.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-role-binding.yaml similarity index 100% rename from operator-framework/src/test/resources/io/javaoperatorsdk/operator/rback-test-role-binding.yaml rename to operator-framework/src/test/resources/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/rback-test-role-binding.yaml diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/statefulset.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/statefulset.yaml similarity index 100% rename from operator-framework/src/test/resources/io/javaoperatorsdk/operator/sample/statefulsetdesiredsanitizer/statefulset.yaml rename to operator-framework/src/test/resources/io/javaoperatorsdk/operator/statefulset.yaml diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/workflow/complexdependent/service.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/workflow/complexdependent/service.yaml new file mode 100644 index 0000000000..736ef33178 --- /dev/null +++ b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/workflow/complexdependent/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: mongo-template + labels: + app.kubernetes.io/name: mongo-template + app.kubernetes.io/component: first-or-second +spec: + type: ClusterIP + selector: + app.kubernetes.io/name: mongo-template + clusterIP: None + ports: + - name: mongodb + port: 27017 + targetPort: 27017 \ No newline at end of file diff --git a/operator-framework/src/test/resources/io/javaoperatorsdk/operator/workflow/complexdependent/statefulset.yaml b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/workflow/complexdependent/statefulset.yaml new file mode 100644 index 0000000000..a335a4aec7 --- /dev/null +++ b/operator-framework/src/test/resources/io/javaoperatorsdk/operator/workflow/complexdependent/statefulset.yaml @@ -0,0 +1,46 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: mongo-template + labels: + app.kubernetes.io/name: mongo-template + app.kubernetes.io/component: first-or-second +spec: + serviceName: mongo-template + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: mongo-template + template: + metadata: + labels: + app.kubernetes.io/name: mongo-template + app.kubernetes.io/component: first-or-second + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: mongo + image: mongo:4.4 + ports: + - name: mongodb + containerPort: 27017 + volumeMounts: + - name: data + mountPath: /data/db + volumeClaimTemplates: + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: data + labels: + app.kubernetes.io/name: mongo-template + spec: + volumeMode: Filesystem + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + limits: + storage: 50Gi + diff --git a/pom.xml b/pom.xml index ea64799795..010a350e1d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,71 +1,70 @@ - - 4.0.0 + + 4.0.0 - io.javaoperatorsdk - java-operator-sdk - 5.0.0-SNAPSHOT - pom - Operator SDK for Java - Java SDK for implementing Kubernetes operators - https://github.com/operator-framework/java-operator-sdk + io.javaoperatorsdk + java-operator-sdk + 5.0.0-SNAPSHOT + pom + Operator SDK for Java + Java SDK for implementing Kubernetes operators + https://github.com/operator-framework/java-operator-sdk - - - Apache 2 License - https://www.apache.org/licenses/LICENSE-2.0.html - - - - - Adam Sandor - adam.sandor@container-solutions.com - - - Attila Meszaros - csviri@gmail.com - - + + + Apache 2 License + https://www.apache.org/licenses/LICENSE-2.0.html + + + + + Adam Sandor + adam.sandor@container-solutions.com + + + Attila Meszaros + csviri@gmail.com + + - - operator-framework-bom - operator-framework-core - operator-framework-junit5 - operator-framework - micrometer-support - sample-operators - caffeine-bounded-cache-support - bootstrapper-maven-plugin - + + operator-framework-bom + operator-framework-core + operator-framework-junit5 + operator-framework + micrometer-support + sample-operators + caffeine-bounded-cache-support + bootstrapper-maven-plugin + - - scm:git:git://github.com/operator-framework/java-operator-sdk.git - scm:git:git@github.com/operator-framework/java-operator-sdk.git - https://github.com/operator-framework/java-operator-sdk/tree/main - + + scm:git:git://github.com/operator-framework/java-operator-sdk.git + scm:git:git@github.com/operator-framework/java-operator-sdk.git + https://github.com/operator-framework/java-operator-sdk/tree/main + - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + - - UTF-8 - 17 - ${java.version} - ${java.version} - java-operator-sdk - https://sonarcloud.io - jdk + + UTF-8 + 17 + ${java.version} + ${java.version} + java-operator-sdk + https://sonarcloud.io + jdk - 5.10.1 - 6.13.4 - 2.0.12 - 2.23.1 - 5.13.0 + 5.10.1 + 6.13.4 + 2.0.12 + 2.23.1 + 5.13.0 3.16.0 0.21.0 1.13.0 @@ -79,10 +78,10 @@ 0.9.11 2.16.1 - 2.11 - 3.12.1 - 3.5.0 - 3.10.0 + 2.11 + 3.12.1 + 3.5.0 + 3.10.0 3.3.1 3.3.1 3.4.2 @@ -90,246 +89,246 @@ 3.2.5 1.7.0 3.0.0 - 3.1.3 - 9.0.1 - 3.4.1 - 2.43.0 - + 3.1.3 + 9.0.1 + 3.4.1 + 2.43.0 + - - - - org.junit - junit-bom - ${junit.version} - pom - import - - - io.fabric8 - kubernetes-client-bom - ${fabric8-client.version} - pom - import - - - io.fabric8 - kubernetes-server-mock - ${fabric8-client.version} - test - - - io.fabric8 - kubernetes-client-api - ${fabric8-client.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - com.google.testing.compile - compile-testing - ${compile-testing.version} - - - io.micrometer - micrometer-core - ${micrometer-core.version} - - - com.squareup - javapoet - ${javapoet.version} - - - org.awaitility - awaitility - ${awaitility.version} - - - commons-io - commons-io - ${commons.io.version} - - - org.assertj - assertj-core - ${assertj.version} - - - org.mockito - mockito-core - ${mokito.version} - + + + + org.junit + junit-bom + ${junit.version} + pom + import + + + io.fabric8 + kubernetes-client-bom + ${fabric8-client.version} + pom + import + + + io.fabric8 + kubernetes-server-mock + ${fabric8-client.version} + test + + + io.fabric8 + kubernetes-client-api + ${fabric8-client.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + com.google.testing.compile + compile-testing + ${compile-testing.version} + + + io.micrometer + micrometer-core + ${micrometer-core.version} + + + com.squareup + javapoet + ${javapoet.version} + + + org.awaitility + awaitility + ${awaitility.version} + + + commons-io + commons-io + ${commons.io.version} + + + org.assertj + assertj-core + ${assertj.version} + + + org.mockito + mockito-core + ${mokito.version} + - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.apache.logging.log4j - log4j-slf4j2-impl - ${log4j.version} - - - org.apache.logging.log4j - log4j-core - ${log4j.version} - test - - - org.apache.logging.log4j - log4j2-core - ${log4j.version} - - - com.github.spullara.mustache.java - compiler - ${mustache.version} - - - io.javaoperatorsdk - operator-framework-core - ${project.version} - - - io.javaoperatorsdk - operator-framework - ${project.version} - - - com.squareup.okhttp3 - logging-interceptor - ${okhttp.version} - - - com.squareup.okhttp3 - mockwebserver - ${okhttp.version} - - - com.github.ben-manes.caffeine - caffeine - ${caffeine.version} - - - io.javaoperatorsdk - jenvtest - ${jenvtest.version} - test - - + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.apache.logging.log4j + log4j-slf4j2-impl + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + test + + + org.apache.logging.log4j + log4j2-core + ${log4j.version} + + + com.github.spullara.mustache.java + compiler + ${mustache.version} + + + io.javaoperatorsdk + operator-framework-core + ${project.version} + + + io.javaoperatorsdk + operator-framework + ${project.version} + + + com.squareup.okhttp3 + logging-interceptor + ${okhttp.version} + + + com.squareup.okhttp3 + mockwebserver + ${okhttp.version} + + + com.github.ben-manes.caffeine + caffeine + ${caffeine.version} + + + io.javaoperatorsdk + jenvtest + ${jenvtest.version} + test + + - - io.fabric8 - kubernetes-httpclient-okhttp - ${fabric8-client.version} - - - io.fabric8 - kubernetes-httpclient-vertx - ${fabric8-client.version} - - - io.fabric8 - kubernetes-httpclient-jdk - ${fabric8-client.version} - - - io.fabric8 - kubernetes-httpclient-jetty - ${fabric8-client.version} - - - + + io.fabric8 + kubernetes-httpclient-okhttp + ${fabric8-client.version} + + + io.fabric8 + kubernetes-httpclient-vertx + ${fabric8-client.version} + + + io.fabric8 + kubernetes-httpclient-jdk + ${fabric8-client.version} + + + io.fabric8 + kubernetes-httpclient-jetty + ${fabric8-client.version} + + + - - - - true - always - - ossrh - https://oss.sonatype.org/content/repositories/snapshots/ - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - - org.apache.maven.plugins - maven-resources-plugin - ${maven-resources-plugin.version} - - - org.apache.maven.plugins - maven-jar-plugin - ${maven-jar-plugin.version} - - - org.apache.maven.plugins - maven-clean-plugin - ${maven-clean-plugin.version} - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - - org.apache.maven.plugins - maven-install-plugin - ${maven-install-plugin.version} - - - com.diffplug.spotless - spotless-maven-plugin - ${spotless.version} - - - - - - com.diffplug.spotless - spotless-maven-plugin - - - - pom.xml + + + + true + always + + ossrh + https://oss.sonatype.org/content/repositories/snapshots/ + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + org.apache.maven.plugins + maven-install-plugin + ${maven-install-plugin.version} + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + com.diffplug.spotless + spotless-maven-plugin + + + + pom.xml ./**/pom.xml - + false - - - - contributing/eclipse-google-style.xml - - - contributing/eclipse.importorder - + + + + contributing/eclipse-google-style.xml + + + contributing/eclipse.importorder + - - + + @@ -338,176 +337,176 @@ compile - - - org.apache.maven.plugins - maven-surefire-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Test.java + + + **/*IT.java + **/*E2E.java + + WatchPermissionAwareTest + + + + + + + all-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Test.java + **/*IT.java + **/*E2E.java + + + + + + + + no-unit-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IT.java + + + **/*Test.java + **/*E2E.java + + + + + + + + + minimal-watch-timeout-dependent-it + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*ITS.java + + + **/*Test.java + **/*E2E.java + **/*IT.java + + + + + + + + end-to-end-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*E2E.java + + + **/*Test.java + **/*IT.java + + + + + + + + release + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IT.java + **/*E2E.java + **/InformerRelatedBehaviorTest.java + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + + sign + + verify - - **/*Test.java - - - **/*IT.java - **/*E2E.java - - WatchPermissionAwareTest + + --pinentry-mode + loopback + - + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + true + + - - - - all-tests - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*Test.java - **/*IT.java - **/*E2E.java - - - - - - - - no-unit-tests - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IT.java - - - **/*Test.java - **/*E2E.java - - - - - - - - - minimal-watch-timeout-dependent-it - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*ITS.java - - - **/*Test.java - **/*E2E.java - **/*IT.java - - - - - - - - end-to-end-tests - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*E2E.java - - - **/*Test.java - **/*IT.java - - - - - - - - release - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IT.java - **/*E2E.java - **/InformerRelatedBehaviorTest.java - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - - - sign-artifacts - - sign - - verify - - - --pinentry-mode - loopback - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-maven-plugin.version} - true - - ossrh - https://oss.sonatype.org/ - true - - - - - - + + + From ec2e4fc26d6d8d39c2d80925c8b626e5438c2c3f Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 9 Aug 2024 15:35:06 +0200 Subject: [PATCH 68/96] refactor: clean up informer configuration classes (#2470) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: set version to 5.0.0-SNAPSHOT (#2200) Signed-off-by: Attila Mészáros * improve: replace current formatting plugins with spotless plugin (#2302) Signed-off-by: Attila Mészáros * fix: format after rebase Signed-off-by: Attila Mészáros * bump: chore use slf4j v2 (#2406) Signed-off-by: Attila Mészáros * feat: allow returning additional information from conditions (#2426) Fixes #2424. --------- Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Attila Mészáros Signed-off-by: Chris Laprun * refactor: move @InformerConfig to more appropriate package Signed-off-by: Chris Laprun * refactor: move InformerConfigHolder to appropriate package Signed-off-by: Chris Laprun * chore: remove unneeded code & dependencies Signed-off-by: Chris Laprun * refactor: InformerConfiguration to InformerEventSourceConfiguration Signed-off-by: Chris Laprun * refactor: rename inner InformerConfigurationBuilder to simply Builder Signed-off-by: Chris Laprun * refactor: rename InformerConfig and associated field to Informer Signed-off-by: Chris Laprun * refactor: rename InformerConfigHolder to InformerConfiguration Signed-off-by: Chris Laprun --------- Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Attila Mészáros --- .../main/resources/templates/Reconciler.java | 9 - .../cache/sample/AbstractTestReconciler.java | 16 +- .../api/config/BaseConfigurationService.java | 6 +- .../ControllerConfigurationOverrider.java | 6 +- .../config/DefaultResourceConfiguration.java | 8 +- .../ResolvedControllerConfiguration.java | 8 +- .../api/config/ResourceConfiguration.java | 4 +- .../config/informer/Informer.java} | 6 +- .../informer/InformerConfiguration.java | 357 ++++++++++-------- .../InformerEventSourceConfiguration.java | 235 ++++++++++++ .../reconciler/ControllerConfiguration.java | 4 +- .../GenericKubernetesDependentResource.java | 7 +- .../kubernetes/InformerConfigHolder.java | 296 --------------- .../kubernetes/KubernetesDependent.java | 4 +- .../KubernetesDependentConverter.java | 7 +- .../KubernetesDependentResource.java | 10 +- .../KubernetesDependentResourceConfig.java | 7 +- ...ernetesDependentResourceConfigBuilder.java | 9 +- .../source/PrimaryToSecondaryMapper.java | 14 +- .../source/informer/InformerEventSource.java | 10 +- .../informer/TemporaryResourceCache.java | 8 +- .../ControllerConfigurationOverriderTest.java | 18 +- .../api/config/ResourceConfigurationTest.java | 4 +- .../event/EventSourceManagerTest.java | 5 +- .../controller/ControllerEventSourceTest.java | 4 +- .../informer/InformerEventSourceTest.java | 6 +- .../BuiltInResourceCleanerReconciler.java | 4 +- .../ChangeNamespaceTestReconciler.java | 5 +- ...ClusterScopedCustomResourceReconciler.java | 4 +- ...CreateUpdateEventFilterTestReconciler.java | 7 +- .../deployment/DeploymentReconciler.java | 4 +- ...ericEventSourceRegistrationReconciler.java | 4 +- .../baseapi/filter/FilterTestReconciler.java | 8 +- ...cKubernetesResourceHandlingReconciler.java | 4 +- ...formerEventSourceTestCustomReconciler.java | 7 +- .../LabelSelectorTestReconciler.java | 4 +- ...MultipleReconcilerSameTypeReconciler1.java | 4 +- ...MultipleReconcilerSameTypeReconciler2.java | 4 +- ...ultipleSecondaryEventSourceReconciler.java | 4 +- .../MultiVersionCRDTestReconciler1.java | 4 +- .../MultiVersionCRDTestReconciler2.java | 4 +- .../PrimaryIndexerTestReconciler.java | 5 +- .../primarytosecondary/JobReconciler.java | 9 +- .../config/BaseConfigurationServiceTest.java | 4 +- .../DependentFilterTestReconciler.java | 4 +- .../FilteredDependentConfigMap.java | 4 +- ...entFilterCustomResourceTestReconciler.java | 4 +- .../ExternalStateDependentReconciler.java | 5 +- .../ExternalStateReconciler.java | 5 +- .../ExternalStateBulkDependentReconciler.java | 5 +- .../ConfigMapDependentResource.java | 4 +- .../MultipleDependentResourceReconciler.java | 4 +- ...ntResourceWithDiscriminatorReconciler.java | 4 +- ...dentSameTypeNoDiscriminatorReconciler.java | 4 +- ...pleManagedDependentResourceReconciler.java | 4 +- ...DependentPrimaryIndexerTestReconciler.java | 5 +- ...PrimaryToSecondaryDependentReconciler.java | 4 +- .../restart/ConfigMapDependentResource.java | 4 +- .../SpecialResourceTestReconciler.java | 4 +- .../ComplexWorkflowReconciler.java | 8 +- .../ConfigMapDependentResource1.java | 4 +- .../ConfigMapDependentResource2.java | 4 +- .../ConfigMapDependentResource1.java | 4 +- .../ConfigMapDependentResource2.java | 4 +- ...OrderedManagedDependentTestReconciler.java | 4 +- .../sample/DeploymentDependentResource.java | 4 +- .../sample/ServiceDependentResource.java | 4 +- .../operator/sample/WebappReconciler.java | 6 +- .../WebPageDependentsWorkflowReconciler.java | 8 +- .../operator/sample/WebPageReconciler.java | 34 +- ...WebPageStandaloneDependentsReconciler.java | 4 +- .../ConfigMapDependentResource.java | 4 +- .../DeploymentDependentResource.java | 4 +- .../IngressDependentResource.java | 4 +- .../ServiceDependentResource.java | 4 +- 75 files changed, 673 insertions(+), 652 deletions(-) rename operator-framework-core/src/main/java/io/javaoperatorsdk/operator/{processing/dependent/kubernetes/InformerConfig.java => api/config/informer/Informer.java} (96%) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfigHolder.java diff --git a/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java b/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java index 6d03196fe9..f7583be4ee 100644 --- a/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java +++ b/bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java @@ -1,24 +1,15 @@ package {{groupId}}; -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.ConfigMapBuilder; -import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.Workflow; -import io.javaoperatorsdk.operator.processing.event.source.EventSource; -import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; import java.util.Map; import java.util.Optional; @Workflow(dependents = {@Dependent(type = ConfigMapDependentResource.class)}) -@ControllerConfiguration public class {{artifactClassId}}Reconciler implements Reconciler<{{artifactClassId}}CustomResource> { public UpdateControl<{{artifactClassId}}CustomResource> reconcile({{artifactClassId}}CustomResource primary, diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java index cc59738e1c..9d912986e1 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java @@ -14,7 +14,7 @@ import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; @@ -77,12 +77,14 @@ public List> prepareEventSources( boundedItemStore(new KubernetesClientBuilder().build(), ConfigMap.class, Duration.ofMinutes(1), 1); // setting max size for testing purposes - var es = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, primaryClass()) - .withInformerConfiguration(c -> c.withItemStore(boundedItemStore)) - .withSecondaryToPrimaryMapper( - Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), - this instanceof BoundedCacheClusterScopeTestReconciler)) - .build(), context); + var es = new InformerEventSource<>( + InformerEventSourceConfiguration.from(ConfigMap.class, primaryClass()) + .withInformerConfiguration(c -> c.withItemStore(boundedItemStore)) + .withSecondaryToPrimaryMapper( + Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), + this instanceof BoundedCacheClusterScopeTestReconciler)) + .build(), + context); return List.of(es); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index cb685cffb9..20beef7f90 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -17,13 +17,13 @@ import io.javaoperatorsdk.operator.api.config.Utils.Configurator; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.Constants; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.Workflow; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.retry.Retry; @@ -275,8 +275,8 @@ private

ResolvedControllerConfiguration

controllerCon fieldManager.equals(CONTROLLER_NAME_AS_FIELD_MANAGER) ? name : fieldManager; - InformerConfigHolder

informerConfig = InformerConfigHolder.builder(resourceClass) - .initFromAnnotation(annotation != null ? annotation.informerConfig() : null, context) + InformerConfiguration

informerConfig = InformerConfiguration.builder(resourceClass) + .initFromAnnotation(annotation != null ? annotation.informer() : null, context) .buildForController(); return new ResolvedControllerConfiguration

( diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java index c4d28b7829..423867107a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java @@ -10,7 +10,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; @@ -30,12 +30,12 @@ public class ControllerConfigurationOverrider { private String fieldManager; private Duration reconciliationMaxInterval; private Map configurations; - private final InformerConfigHolder.Builder config; + private final InformerConfiguration.Builder config; private ControllerConfigurationOverrider(ControllerConfiguration original) { this.finalizer = original.getFinalizerName(); this.generationAware = original.isGenerationAware(); - this.config = InformerConfigHolder.builder(original.getResourceClass()) + this.config = InformerConfiguration.builder(original.getResourceClass()) .withName(name) .withNamespaces(original.getNamespaces()) .withLabelSelector(original.getLabelSelector()) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java index 5bd3267e12..c0d725f746 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java @@ -4,17 +4,17 @@ import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; public class DefaultResourceConfiguration implements ResourceConfiguration { private final Class resourceClass; private final String resourceTypeName; - private final InformerConfigHolder informerConfig; + private final InformerConfiguration informerConfig; protected DefaultResourceConfiguration(Class resourceClass, - InformerConfigHolder informerConfig) { + InformerConfiguration informerConfig) { this.resourceClass = resourceClass; this.resourceTypeName = resourceClass.isAssignableFrom(GenericKubernetesResource.class) // in general this is irrelevant now for secondary resources it is used just by controller @@ -35,7 +35,7 @@ public Class getResourceClass() { } @Override - public InformerConfigHolder getInformerConfig() { + public InformerConfiguration getInformerConfig() { return informerConfig; } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java index 53d086d3b3..9bb7efb5cf 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java @@ -8,9 +8,9 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.retry.Retry; @@ -49,7 +49,7 @@ public ResolvedControllerConfiguration(Class

resourceClass, String name, Map configurations, String fieldManager, ConfigurationService configurationService, - InformerConfigHolder

informerConfig, + InformerConfiguration

informerConfig, WorkflowSpec workflowSpec) { this(resourceClass, name, generationAware, associatedReconcilerClassName, retry, rateLimiter, maxReconciliationInterval, finalizer, configurations, fieldManager, @@ -62,7 +62,7 @@ protected ResolvedControllerConfiguration(Class

resourceClass, String name, RateLimiter rateLimiter, Duration maxReconciliationInterval, String finalizer, Map configurations, String fieldManager, - ConfigurationService configurationService, InformerConfigHolder

informerConfig) { + ConfigurationService configurationService, InformerConfiguration

informerConfig) { super(resourceClass, informerConfig); this.configurationService = configurationService; this.name = ControllerConfiguration.ensureValidName(name, associatedReconcilerClassName); @@ -81,7 +81,7 @@ protected ResolvedControllerConfiguration(Class

resourceClass, String name, Class reconcilerClas, ConfigurationService configurationService) { this(resourceClass, name, false, getAssociatedReconcilerClassName(reconcilerClas), null, null, null, null, null, null, configurationService, - InformerConfigHolder.builder(resourceClass).buildForController()); + InformerConfiguration.builder(resourceClass).buildForController()); } public static Duration getMaxReconciliationInterval(long interval, TimeUnit timeUnit) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java index 1e6699f9d9..cac44c93db 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java @@ -10,8 +10,8 @@ import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.ReconcilerUtils; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; @@ -26,7 +26,7 @@ default String getResourceTypeName() { return ReconcilerUtils.getResourceTypeName(getResourceClass()); } - InformerConfigHolder getInformerConfig(); + InformerConfiguration getInformerConfig(); default Optional> onAddFilter() { return Optional.ofNullable(getInformerConfig().getOnAddFilter()); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java similarity index 96% rename from operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java rename to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java index 29db90c253..363200bea5 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfig.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java @@ -1,4 +1,4 @@ -package io.javaoperatorsdk.operator.processing.dependent.kubernetes; +package io.javaoperatorsdk.operator.api.config.informer; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -13,13 +13,13 @@ import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; -import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; +import static io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_LONG_VALUE_SET; import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) -public @interface InformerConfig { +public @interface Informer { String name() default NO_VALUE_SET; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java index 2376765ae4..0cb6892ebe 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java @@ -1,217 +1,280 @@ package io.javaoperatorsdk.operator.api.config.informer; -import java.util.Objects; -import java.util.Optional; import java.util.Set; -import java.util.function.Consumer; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.config.DefaultResourceConfiguration; +import io.fabric8.kubernetes.client.informers.cache.ItemStore; import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; import io.javaoperatorsdk.operator.api.config.Utils; -import io.javaoperatorsdk.operator.processing.GroupVersionKind; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; -import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper; -import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; +import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; import static io.javaoperatorsdk.operator.api.reconciler.Constants.*; -public interface InformerConfiguration - extends ResourceConfiguration { - boolean DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE = true; +@SuppressWarnings("unused") +public class InformerConfiguration { + private final Builder builder = new Builder(); + private String name; + private Set namespaces; + private Boolean followControllerNamespacesOnChange; + private String labelSelector; + private OnAddFilter onAddFilter; + private OnUpdateFilter onUpdateFilter; + private OnDeleteFilter onDeleteFilter; + private GenericFilter genericFilter; + private ItemStore itemStore; + private Long informerListLimit; + + public InformerConfiguration(String name, Set namespaces, + boolean followControllerNamespacesOnChange, + String labelSelector, OnAddFilter onAddFilter, + OnUpdateFilter onUpdateFilter, OnDeleteFilter onDeleteFilter, + GenericFilter genericFilter, ItemStore itemStore, Long informerListLimit) { + this.name = name; + this.namespaces = namespaces; + this.followControllerNamespacesOnChange = followControllerNamespacesOnChange; + this.labelSelector = labelSelector; + this.onAddFilter = onAddFilter; + this.onUpdateFilter = onUpdateFilter; + this.onDeleteFilter = onDeleteFilter; + this.genericFilter = genericFilter; + this.itemStore = itemStore; + this.informerListLimit = informerListLimit; + } + + private InformerConfiguration() {} - static boolean inheritsNamespacesFromController(Set namespaces) { - return SAME_AS_CONTROLLER_NAMESPACES_SET.equals(namespaces); + @SuppressWarnings({"rawtypes", "unchecked"}) + public static InformerConfiguration.Builder builder() { + return new InformerConfiguration().builder; } - static InformerConfigurationBuilder from( - Class resourceClass, Class primaryResourceClass) { - return new InformerConfigurationBuilder<>(resourceClass, primaryResourceClass); + @SuppressWarnings({"rawtypes", "unchecked"}) + public static InformerConfiguration.Builder builder( + Class resourceClass) { + return new InformerConfiguration().builder; } - static InformerConfigurationBuilder from( - GroupVersionKind groupVersionKind, Class primaryResourceClass) { - return new InformerConfigurationBuilder<>(groupVersionKind, primaryResourceClass); + @SuppressWarnings({"rawtypes", "unchecked"}) + public static InformerConfiguration.Builder builder( + InformerConfiguration original) { + return new InformerConfiguration(original.name, original.namespaces, + original.followControllerNamespacesOnChange, original.labelSelector, original.onAddFilter, + original.onUpdateFilter, original.onDeleteFilter, original.genericFilter, + original.itemStore, original.informerListLimit).builder; } - /** - * Used in case the watched namespaces are changed dynamically, thus when operator is running (See - * {@link io.javaoperatorsdk.operator.RegisteredController}). If true, changing the target - * namespaces of a controller would result to change target namespaces for the - * InformerEventSource. - * - * @return if namespace changes should be followed - */ - default boolean followControllerNamespaceChanges() { - return getInformerConfig().isFollowControllerNamespacesOnChange(); + public String getName() { + return name; } - /** - * Returns the configured {@link SecondaryToPrimaryMapper} which will allow JOSDK to identify - * which secondary resources are associated with a given primary resource in cases where there is - * no explicit reference to the primary resource (e.g. using owner references) in the associated - * secondary resources. - * - * @return the configured {@link SecondaryToPrimaryMapper} - * @see SecondaryToPrimaryMapper for more explanations on when using such a mapper is useful / - * needed - */ - SecondaryToPrimaryMapper getSecondaryToPrimaryMapper(); - - default Optional> onDeleteFilter() { - return Optional.ofNullable(getInformerConfig().getOnDeleteFilter()); + public Set getNamespaces() { + return namespaces; } -

PrimaryToSecondaryMapper

getPrimaryToSecondaryMapper(); + public boolean isFollowControllerNamespacesOnChange() { + return followControllerNamespacesOnChange; + } - Optional getGroupVersionKind(); + public String getLabelSelector() { + return labelSelector; + } - default String name() { - return getInformerConfig().getName(); + public OnAddFilter getOnAddFilter() { + return onAddFilter; } - @SuppressWarnings("unchecked") - @Override - default Class getResourceClass() { - return (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface(getClass(), - InformerConfiguration.class); + public OnUpdateFilter getOnUpdateFilter() { + return onUpdateFilter; } - class DefaultInformerConfiguration extends - DefaultResourceConfiguration implements InformerConfiguration { - private final PrimaryToSecondaryMapper primaryToSecondaryMapper; - private final SecondaryToPrimaryMapper secondaryToPrimaryMapper; - private final GroupVersionKind groupVersionKind; + public OnDeleteFilter getOnDeleteFilter() { + return onDeleteFilter; + } - protected DefaultInformerConfiguration( - Class resourceClass, - GroupVersionKind groupVersionKind, - PrimaryToSecondaryMapper primaryToSecondaryMapper, - SecondaryToPrimaryMapper secondaryToPrimaryMapper, - InformerConfigHolder informerConfig) { - super(resourceClass, informerConfig); - this.groupVersionKind = groupVersionKind; - this.primaryToSecondaryMapper = primaryToSecondaryMapper; - this.secondaryToPrimaryMapper = secondaryToPrimaryMapper; - } + public GenericFilter getGenericFilter() { + return genericFilter; + } - @Override - public SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { - return secondaryToPrimaryMapper; - } + public ItemStore getItemStore() { + return itemStore; + } - @Override - public Optional> onDeleteFilter() { - return Optional.ofNullable(getInformerConfig().getOnDeleteFilter()); - } + public Long getInformerListLimit() { + return informerListLimit; + } - @Override - @SuppressWarnings("unchecked") - public

PrimaryToSecondaryMapper

getPrimaryToSecondaryMapper() { - return (PrimaryToSecondaryMapper

) primaryToSecondaryMapper; - } - @Override - public Optional getGroupVersionKind() { - return Optional.ofNullable(groupVersionKind); + @SuppressWarnings("UnusedReturnValue") + public class Builder { + + public InformerConfiguration buildForController() { + // if the informer config uses the default "same as controller" value, reset the namespaces to + // the default set for controllers + if (namespaces == null || namespaces.isEmpty() + || InformerEventSourceConfiguration.inheritsNamespacesFromController(namespaces)) { + namespaces = Constants.DEFAULT_NAMESPACES_SET; + } + return InformerConfiguration.this; } - public boolean inheritsNamespacesFromController() { - return InformerConfiguration.inheritsNamespacesFromController(getNamespaces()); + public InformerConfiguration buildForInformerEventSource() { + if (namespaces == null || namespaces.isEmpty()) { + namespaces = Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; + } + if (followControllerNamespacesOnChange == null) { + followControllerNamespacesOnChange = + InformerEventSourceConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; + } + return InformerConfiguration.this; } - @Override - public Set getEffectiveNamespaces(ControllerConfiguration controllerConfiguration) { - if (inheritsNamespacesFromController()) { - return controllerConfiguration.getEffectiveNamespaces(); - } else { - return super.getEffectiveNamespaces(controllerConfiguration); + @SuppressWarnings({"unchecked"}) + public InformerConfiguration.Builder initFromAnnotation(Informer informerConfig, + String context) { + if (informerConfig != null) { + + // override default name if more specific one is provided + if (!Constants.NO_VALUE_SET.equals(informerConfig.name())) { + withName(informerConfig.name()); + } + + var namespaces = Set.of(informerConfig.namespaces()); + withNamespaces(namespaces); + + final var fromAnnotation = informerConfig.labelSelector(); + var labelSelector = Constants.NO_VALUE_SET.equals(fromAnnotation) ? null : fromAnnotation; + withLabelSelector(labelSelector); + + withOnAddFilter(Utils.instantiate(informerConfig.onAddFilter(), + OnAddFilter.class, context)); + + withOnUpdateFilter(Utils.instantiate(informerConfig.onUpdateFilter(), + OnUpdateFilter.class, context)); + + withOnDeleteFilter(Utils.instantiate(informerConfig.onDeleteFilter(), + OnDeleteFilter.class, context)); + + withGenericFilter(Utils.instantiate(informerConfig.genericFilter(), + GenericFilter.class, + context)); + + withFollowControllerNamespacesOnChange( + informerConfig.followControllerNamespacesOnChange()); + + withItemStore(Utils.instantiate(informerConfig.itemStore(), + ItemStore.class, context)); + + final var informerListLimitValue = informerConfig.informerListLimit(); + final var informerListLimit = + informerListLimitValue == Constants.NO_LONG_VALUE_SET ? null : informerListLimitValue; + withInformerListLimit(informerListLimit); } + return this; } - } + public Builder withName(String name) { + InformerConfiguration.this.name = name; + return this; + } - @SuppressWarnings({"unused", "UnusedReturnValue"}) - class InformerConfigurationBuilder { + public Builder withNamespaces(Set namespaces) { + InformerConfiguration.this.namespaces = + ResourceConfiguration.ensureValidNamespaces(namespaces); + return this; + } - private final Class resourceClass; - private final GroupVersionKind groupVersionKind; - private final Class primaryResourceClass; - private String name; - private PrimaryToSecondaryMapper primaryToSecondaryMapper; - private SecondaryToPrimaryMapper secondaryToPrimaryMapper; - private final InformerConfigHolder.Builder config; + public Set namespaces() { + return Set.copyOf(namespaces); + } - private InformerConfigurationBuilder(Class resourceClass, - Class primaryResourceClass) { - this(resourceClass, primaryResourceClass, null); + /** + * Sets the initial set of namespaces to watch (typically extracted from the parent + * {@link io.javaoperatorsdk.operator.processing.Controller}'s configuration), specifying + * whether changes made to the parent controller configured namespaces should be tracked or not. + * + * @param namespaces the initial set of namespaces to watch + * @param followChanges {@code true} to follow the changes made to the parent controller + * namespaces, {@code false} otherwise + * @return the builder instance so that calls can be chained fluently + */ + public Builder withNamespaces(Set namespaces, boolean followChanges) { + withNamespaces(namespaces).withFollowControllerNamespacesOnChange(followChanges); + return this; } - @SuppressWarnings("unchecked") - private InformerConfigurationBuilder(GroupVersionKind groupVersionKind, - Class primaryResourceClass) { - this((Class) GenericKubernetesResource.class, primaryResourceClass, groupVersionKind); + public Builder withNamespacesInheritedFromController() { + withNamespaces(SAME_AS_CONTROLLER_NAMESPACES_SET); + return this; } - private InformerConfigurationBuilder(Class resourceClass, - Class primaryResourceClass, GroupVersionKind groupVersionKind) { - this.resourceClass = resourceClass; - this.groupVersionKind = groupVersionKind; - this.primaryResourceClass = primaryResourceClass; - this.config = InformerConfigHolder.builder(resourceClass); + public Builder withWatchAllNamespaces() { + withNamespaces(WATCH_ALL_NAMESPACE_SET); + return this; } - public InformerConfigurationBuilder withInformerConfiguration( - Consumer.Builder> configurator) { - configurator.accept(config); + public Builder withWatchCurrentNamespace() { + withNamespaces(WATCH_CURRENT_NAMESPACE_SET); return this; } - public InformerConfigurationBuilder withName(String name) { - this.name = name; - config.withName(name); + + /** + * Whether the associated informer should track changes made to the parent + * {@link io.javaoperatorsdk.operator.processing.Controller}'s namespaces configuration. + * + * @param followChanges {@code true} to reconfigure the associated informer when the parent + * controller's namespaces are reconfigured, {@code false} otherwise + * @return the builder instance so that calls can be chained fluently + */ + public Builder withFollowControllerNamespacesOnChange(boolean followChanges) { + InformerConfiguration.this.followControllerNamespacesOnChange = + followChanges; return this; } - public

InformerConfigurationBuilder withPrimaryToSecondaryMapper( - PrimaryToSecondaryMapper

primaryToSecondaryMapper) { - this.primaryToSecondaryMapper = primaryToSecondaryMapper; + public Builder withLabelSelector(String labelSelector) { + InformerConfiguration.this.labelSelector = + ResourceConfiguration.ensureValidLabelSelector(labelSelector); return this; } - public InformerConfigurationBuilder withSecondaryToPrimaryMapper( - SecondaryToPrimaryMapper secondaryToPrimaryMapper) { - this.secondaryToPrimaryMapper = secondaryToPrimaryMapper; + public Builder withOnAddFilter( + OnAddFilter onAddFilter) { + InformerConfiguration.this.onAddFilter = onAddFilter; return this; } - public String getName() { - return name; + public Builder withOnUpdateFilter( + OnUpdateFilter onUpdateFilter) { + InformerConfiguration.this.onUpdateFilter = onUpdateFilter; + return this; } - public SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { - return secondaryToPrimaryMapper; + public Builder withOnDeleteFilter( + OnDeleteFilter onDeleteFilter) { + InformerConfiguration.this.onDeleteFilter = onDeleteFilter; + return this; } - public InformerConfiguration build() { - if (groupVersionKind != null - && !GenericKubernetesResource.class.isAssignableFrom(resourceClass)) { - throw new IllegalStateException( - "If GroupVersionKind is set the resource type must be GenericKubernetesDependentResource"); - } + public Builder withGenericFilter( + GenericFilter genericFilter) { + InformerConfiguration.this.genericFilter = genericFilter; + return this; + } - return new DefaultInformerConfiguration<>(resourceClass, - groupVersionKind, - primaryToSecondaryMapper, - Objects.requireNonNullElse(secondaryToPrimaryMapper, - Mappers.fromOwnerReferences(HasMetadata.getApiVersion(primaryResourceClass), - HasMetadata.getKind(primaryResourceClass), false)), - config.buildForInformerEventSource()); + public Builder withItemStore(ItemStore itemStore) { + InformerConfiguration.this.itemStore = itemStore; + return this; + } + + public Builder withInformerListLimit(Long informerListLimit) { + InformerConfiguration.this.informerListLimit = informerListLimit; + return this; } } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java new file mode 100644 index 0000000000..1e5e1ce666 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java @@ -0,0 +1,235 @@ +package io.javaoperatorsdk.operator.api.config.informer; + +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; + +import io.fabric8.kubernetes.api.model.GenericKubernetesResource; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.config.DefaultResourceConfiguration; +import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; +import io.javaoperatorsdk.operator.api.config.Utils; +import io.javaoperatorsdk.operator.processing.GroupVersionKind; +import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper; +import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; +import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; +import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; + +import static io.javaoperatorsdk.operator.api.reconciler.Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; + +public interface InformerEventSourceConfiguration + extends ResourceConfiguration { + + boolean DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE = true; + + static boolean inheritsNamespacesFromController(Set namespaces) { + return SAME_AS_CONTROLLER_NAMESPACES_SET.equals(namespaces); + } + + static Builder from( + Class resourceClass, Class primaryResourceClass) { + return new Builder<>(resourceClass, primaryResourceClass); + } + + static Builder from( + GroupVersionKind groupVersionKind, Class primaryResourceClass) { + return new Builder<>(groupVersionKind, primaryResourceClass); + } + + /** + * Used in case the watched namespaces are changed dynamically, thus when operator is running (See + * {@link io.javaoperatorsdk.operator.RegisteredController}). If true, changing the target + * namespaces of a controller would result to change target namespaces for the + * InformerEventSource. + * + * @return if namespace changes should be followed + */ + default boolean followControllerNamespaceChanges() { + return getInformerConfig().isFollowControllerNamespacesOnChange(); + } + + /** + * Returns the configured {@link SecondaryToPrimaryMapper} which will allow JOSDK to identify + * which secondary resources are associated with a given primary resource in cases where there is + * no explicit reference to the primary resource (e.g. using owner references) in the associated + * secondary resources. + * + * @return the configured {@link SecondaryToPrimaryMapper} + * @see SecondaryToPrimaryMapper for more explanations on when using such a mapper is useful / + * needed + */ + SecondaryToPrimaryMapper getSecondaryToPrimaryMapper(); + + default Optional> onDeleteFilter() { + return Optional.ofNullable(getInformerConfig().getOnDeleteFilter()); + } + +

PrimaryToSecondaryMapper

getPrimaryToSecondaryMapper(); + + Optional getGroupVersionKind(); + + default String name() { + return getInformerConfig().getName(); + } + + @SuppressWarnings("unchecked") + @Override + default Class getResourceClass() { + return (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface(getClass(), + InformerEventSourceConfiguration.class); + } + + class DefaultInformerEventSourceConfiguration extends + DefaultResourceConfiguration implements InformerEventSourceConfiguration { + private final PrimaryToSecondaryMapper primaryToSecondaryMapper; + private final SecondaryToPrimaryMapper secondaryToPrimaryMapper; + private final GroupVersionKind groupVersionKind; + + protected DefaultInformerEventSourceConfiguration( + Class resourceClass, + GroupVersionKind groupVersionKind, + PrimaryToSecondaryMapper primaryToSecondaryMapper, + SecondaryToPrimaryMapper secondaryToPrimaryMapper, + InformerConfiguration informerConfig) { + super(resourceClass, informerConfig); + this.groupVersionKind = groupVersionKind; + this.primaryToSecondaryMapper = primaryToSecondaryMapper; + this.secondaryToPrimaryMapper = secondaryToPrimaryMapper; + } + + @Override + public SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { + return secondaryToPrimaryMapper; + } + + @Override + public Optional> onDeleteFilter() { + return Optional.ofNullable(getInformerConfig().getOnDeleteFilter()); + } + + @Override + @SuppressWarnings("unchecked") + public

PrimaryToSecondaryMapper

getPrimaryToSecondaryMapper() { + return (PrimaryToSecondaryMapper

) primaryToSecondaryMapper; + } + + @Override + public Optional getGroupVersionKind() { + return Optional.ofNullable(groupVersionKind); + } + + public boolean inheritsNamespacesFromController() { + return InformerEventSourceConfiguration.inheritsNamespacesFromController(getNamespaces()); + } + + @Override + public Set getEffectiveNamespaces(ControllerConfiguration controllerConfiguration) { + if (inheritsNamespacesFromController()) { + return controllerConfiguration.getEffectiveNamespaces(); + } else { + return super.getEffectiveNamespaces(controllerConfiguration); + } + } + } + + + @SuppressWarnings({"unused", "UnusedReturnValue"}) + class Builder { + + private final Class resourceClass; + private final GroupVersionKind groupVersionKind; + private final Class primaryResourceClass; + private final InformerConfiguration.Builder config; + private String name; + private PrimaryToSecondaryMapper primaryToSecondaryMapper; + private SecondaryToPrimaryMapper secondaryToPrimaryMapper; + + private Builder(Class resourceClass, + Class primaryResourceClass) { + this(resourceClass, primaryResourceClass, null); + } + + @SuppressWarnings("unchecked") + private Builder(GroupVersionKind groupVersionKind, + Class primaryResourceClass) { + this((Class) GenericKubernetesResource.class, primaryResourceClass, groupVersionKind); + } + + private Builder(Class resourceClass, + Class primaryResourceClass, GroupVersionKind groupVersionKind) { + this.resourceClass = resourceClass; + this.groupVersionKind = groupVersionKind; + this.primaryResourceClass = primaryResourceClass; + this.config = InformerConfiguration.builder(resourceClass); + } + + public Builder withInformerConfiguration( + Consumer.Builder> configurator) { + configurator.accept(config); + return this; + } + + public Builder withName(String name) { + this.name = name; + config.withName(name); + return this; + } + + public

Builder withPrimaryToSecondaryMapper( + PrimaryToSecondaryMapper

primaryToSecondaryMapper) { + this.primaryToSecondaryMapper = primaryToSecondaryMapper; + return this; + } + + public Builder withSecondaryToPrimaryMapper( + SecondaryToPrimaryMapper secondaryToPrimaryMapper) { + this.secondaryToPrimaryMapper = secondaryToPrimaryMapper; + return this; + } + + public String getName() { + return name; + } + + public SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { + return secondaryToPrimaryMapper; + } + + public void updateFrom(InformerConfiguration informerConfig) { + if (informerConfig != null) { + final var informerConfigName = informerConfig.getName(); + if (informerConfigName != null) { + this.name = informerConfigName; + } + config.withNamespaces(informerConfig.getNamespaces()) + .withFollowControllerNamespacesOnChange( + informerConfig.isFollowControllerNamespacesOnChange()) + .withLabelSelector(informerConfig.getLabelSelector()) + .withItemStore(informerConfig.getItemStore()) + .withOnAddFilter(informerConfig.getOnAddFilter()) + .withOnUpdateFilter(informerConfig.getOnUpdateFilter()) + .withOnDeleteFilter(informerConfig.getOnDeleteFilter()) + .withGenericFilter(informerConfig.getGenericFilter()) + .withInformerListLimit(informerConfig.getInformerListLimit()); + } + } + + public InformerEventSourceConfiguration build() { + if (groupVersionKind != null + && !GenericKubernetesResource.class.isAssignableFrom(resourceClass)) { + throw new IllegalStateException( + "If GroupVersionKind is set the resource type must be GenericKubernetesDependentResource"); + } + + return new DefaultInformerEventSourceConfiguration<>(resourceClass, + groupVersionKind, + primaryToSecondaryMapper, + Objects.requireNonNullElse(secondaryToPrimaryMapper, + Mappers.fromOwnerReferences(HasMetadata.getApiVersion(primaryResourceClass), + HasMetadata.getKind(primaryResourceClass), false)), + config.buildForInformerEventSource()); + } + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java index a5232700c0..eb709b0d5a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java @@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; @@ -21,7 +21,7 @@ String name() default Constants.NO_VALUE_SET; - InformerConfig informerConfig() default @InformerConfig; + Informer informer() default @Informer; /** * Optional finalizer name, if it is not provided, one will be automatically generated. Note that diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java index f608b1c229..4b1396d408 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java @@ -2,7 +2,7 @@ import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.processing.GroupVersionKind; @@ -20,9 +20,10 @@ public GenericKubernetesDependentResource(GroupVersionKindPlural groupVersionKin this.groupVersionKind = groupVersionKind; } - protected InformerConfiguration.InformerConfigurationBuilder informerConfigurationBuilder( + protected InformerEventSourceConfiguration.Builder informerConfigurationBuilder( EventSourceContext

context) { - return InformerConfiguration.from(groupVersionKind, context.getPrimaryResourceClass()); + return InformerEventSourceConfiguration.from(groupVersionKind, + context.getPrimaryResourceClass()); } @SuppressWarnings("unused") diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfigHolder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfigHolder.java deleted file mode 100644 index 22517372f8..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/InformerConfigHolder.java +++ /dev/null @@ -1,296 +0,0 @@ -package io.javaoperatorsdk.operator.processing.dependent.kubernetes; - -import java.util.Set; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.informers.cache.ItemStore; -import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; -import io.javaoperatorsdk.operator.api.config.Utils; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; - -import static io.javaoperatorsdk.operator.api.reconciler.Constants.*; - - -@SuppressWarnings("unused") -public class InformerConfigHolder { - private final Builder builder = new Builder(); - private String name; - private Set namespaces; - private Boolean followControllerNamespacesOnChange; - private String labelSelector; - private OnAddFilter onAddFilter; - private OnUpdateFilter onUpdateFilter; - private OnDeleteFilter onDeleteFilter; - private GenericFilter genericFilter; - private ItemStore itemStore; - private Long informerListLimit; - - public InformerConfigHolder(String name, Set namespaces, - boolean followControllerNamespacesOnChange, - String labelSelector, OnAddFilter onAddFilter, - OnUpdateFilter onUpdateFilter, OnDeleteFilter onDeleteFilter, - GenericFilter genericFilter, ItemStore itemStore, Long informerListLimit) { - this.name = name; - this.namespaces = namespaces; - this.followControllerNamespacesOnChange = followControllerNamespacesOnChange; - this.labelSelector = labelSelector; - this.onAddFilter = onAddFilter; - this.onUpdateFilter = onUpdateFilter; - this.onDeleteFilter = onDeleteFilter; - this.genericFilter = genericFilter; - this.itemStore = itemStore; - this.informerListLimit = informerListLimit; - } - - private InformerConfigHolder() {} - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static InformerConfigHolder.Builder builder() { - return new InformerConfigHolder().builder; - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static InformerConfigHolder.Builder builder( - Class resourceClass) { - return new InformerConfigHolder().builder; - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static InformerConfigHolder.Builder builder( - InformerConfigHolder original) { - return new InformerConfigHolder(original.name, original.namespaces, - original.followControllerNamespacesOnChange, original.labelSelector, original.onAddFilter, - original.onUpdateFilter, original.onDeleteFilter, original.genericFilter, - original.itemStore, original.informerListLimit).builder; - } - - public String getName() { - return name; - } - - public Set getNamespaces() { - return namespaces; - } - - public boolean isFollowControllerNamespacesOnChange() { - return followControllerNamespacesOnChange; - } - - public String getLabelSelector() { - return labelSelector; - } - - public OnAddFilter getOnAddFilter() { - return onAddFilter; - } - - public OnUpdateFilter getOnUpdateFilter() { - return onUpdateFilter; - } - - public OnDeleteFilter getOnDeleteFilter() { - return onDeleteFilter; - } - - public GenericFilter getGenericFilter() { - return genericFilter; - } - - public ItemStore getItemStore() { - return itemStore; - } - - public Long getInformerListLimit() { - return informerListLimit; - } - - void updateInformerConfigBuilder( - InformerConfiguration.InformerConfigurationBuilder builder) { - if (name != null) { - builder.withName(name); - } - builder.withInformerConfiguration(c -> c.withNamespaces(namespaces) - .withFollowControllerNamespacesOnChange(followControllerNamespacesOnChange) - .withLabelSelector(labelSelector) - .withItemStore(itemStore) - .withOnAddFilter(onAddFilter) - .withOnUpdateFilter(onUpdateFilter) - .withOnDeleteFilter(onDeleteFilter) - .withGenericFilter(genericFilter) - .withInformerListLimit(informerListLimit)); - } - - @SuppressWarnings("UnusedReturnValue") - public class Builder { - - public InformerConfigHolder buildForController() { - // if the informer config uses the default "same as controller" value, reset the namespaces to - // the default set for controllers - if (namespaces == null || namespaces.isEmpty() - || InformerConfiguration.inheritsNamespacesFromController(namespaces)) { - namespaces = Constants.DEFAULT_NAMESPACES_SET; - } - return InformerConfigHolder.this; - } - - public InformerConfigHolder buildForInformerEventSource() { - if (namespaces == null || namespaces.isEmpty()) { - namespaces = Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; - } - if (followControllerNamespacesOnChange == null) { - followControllerNamespacesOnChange = - InformerConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; - } - return InformerConfigHolder.this; - } - - @SuppressWarnings({"unchecked"}) - public InformerConfigHolder.Builder initFromAnnotation(InformerConfig informerConfig, - String context) { - if (informerConfig != null) { - - // override default name if more specific one is provided - if (!Constants.NO_VALUE_SET.equals(informerConfig.name())) { - withName(informerConfig.name()); - } - - var namespaces = Set.of(informerConfig.namespaces()); - withNamespaces(namespaces); - - final var fromAnnotation = informerConfig.labelSelector(); - var labelSelector = Constants.NO_VALUE_SET.equals(fromAnnotation) ? null : fromAnnotation; - withLabelSelector(labelSelector); - - withOnAddFilter(Utils.instantiate(informerConfig.onAddFilter(), - OnAddFilter.class, context)); - - withOnUpdateFilter(Utils.instantiate(informerConfig.onUpdateFilter(), - OnUpdateFilter.class, context)); - - withOnDeleteFilter(Utils.instantiate(informerConfig.onDeleteFilter(), - OnDeleteFilter.class, context)); - - withGenericFilter(Utils.instantiate(informerConfig.genericFilter(), - GenericFilter.class, - context)); - - withFollowControllerNamespacesOnChange( - informerConfig.followControllerNamespacesOnChange()); - - withItemStore(Utils.instantiate(informerConfig.itemStore(), - ItemStore.class, context)); - - final var informerListLimitValue = informerConfig.informerListLimit(); - final var informerListLimit = - informerListLimitValue == Constants.NO_LONG_VALUE_SET ? null : informerListLimitValue; - withInformerListLimit(informerListLimit); - } - return this; - } - - public Builder withName(String name) { - InformerConfigHolder.this.name = name; - return this; - } - - public Builder withNamespaces(Set namespaces) { - InformerConfigHolder.this.namespaces = - ResourceConfiguration.ensureValidNamespaces(namespaces); - return this; - } - - public Set namespaces() { - return Set.copyOf(namespaces); - } - - /** - * Sets the initial set of namespaces to watch (typically extracted from the parent - * {@link io.javaoperatorsdk.operator.processing.Controller}'s configuration), specifying - * whether changes made to the parent controller configured namespaces should be tracked or not. - * - * @param namespaces the initial set of namespaces to watch - * @param followChanges {@code true} to follow the changes made to the parent controller - * namespaces, {@code false} otherwise - * @return the builder instance so that calls can be chained fluently - */ - public Builder withNamespaces(Set namespaces, boolean followChanges) { - withNamespaces(namespaces).withFollowControllerNamespacesOnChange(followChanges); - return this; - } - - public Builder withNamespacesInheritedFromController() { - withNamespaces(SAME_AS_CONTROLLER_NAMESPACES_SET); - return this; - } - - public Builder withWatchAllNamespaces() { - withNamespaces(WATCH_ALL_NAMESPACE_SET); - return this; - } - - public Builder withWatchCurrentNamespace() { - withNamespaces(WATCH_CURRENT_NAMESPACE_SET); - return this; - } - - - /** - * Whether the associated informer should track changes made to the parent - * {@link io.javaoperatorsdk.operator.processing.Controller}'s namespaces configuration. - * - * @param followChanges {@code true} to reconfigure the associated informer when the parent - * controller's namespaces are reconfigured, {@code false} otherwise - * @return the builder instance so that calls can be chained fluently - */ - public Builder withFollowControllerNamespacesOnChange(boolean followChanges) { - InformerConfigHolder.this.followControllerNamespacesOnChange = - followChanges; - return this; - } - - public Builder withLabelSelector(String labelSelector) { - InformerConfigHolder.this.labelSelector = - ResourceConfiguration.ensureValidLabelSelector(labelSelector); - return this; - } - - public Builder withOnAddFilter( - OnAddFilter onAddFilter) { - InformerConfigHolder.this.onAddFilter = onAddFilter; - return this; - } - - public Builder withOnUpdateFilter( - OnUpdateFilter onUpdateFilter) { - InformerConfigHolder.this.onUpdateFilter = onUpdateFilter; - return this; - } - - public Builder withOnDeleteFilter( - OnDeleteFilter onDeleteFilter) { - InformerConfigHolder.this.onDeleteFilter = onDeleteFilter; - return this; - } - - public Builder withGenericFilter( - GenericFilter genericFilter) { - InformerConfigHolder.this.genericFilter = genericFilter; - return this; - } - - public Builder withItemStore(ItemStore itemStore) { - InformerConfigHolder.this.itemStore = itemStore; - return this; - } - - public Builder withInformerListLimit(Long informerListLimit) { - InformerConfigHolder.this.informerListLimit = informerListLimit; - return this; - } - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java index 0c35751563..818768474c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependent.java @@ -5,6 +5,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import io.javaoperatorsdk.operator.api.config.informer.Informer; + @Retention(RetentionPolicy.RUNTIME) @@ -28,6 +30,6 @@ */ BooleanWithUndefined useSSA() default BooleanWithUndefined.UNDEFINED; - InformerConfig informerConfig() default @InformerConfig; + Informer informer() default @Informer; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java index c8aa20840e..36625b0689 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java @@ -5,6 +5,7 @@ import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.config.dependent.ConfigurationConverter; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import static io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig.DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA; @@ -35,16 +36,16 @@ public KubernetesDependentResourceConfig configFrom(KubernetesDependent confi } @SuppressWarnings({"unchecked"}) - private InformerConfigHolder createInformerConfig( + private InformerConfiguration createInformerConfig( KubernetesDependent configAnnotation, DependentResourceSpec> spec, ControllerConfiguration controllerConfig) { Class> dependentResourceClass = (Class>) spec.getDependentResourceClass(); - InformerConfigHolder.Builder config = InformerConfigHolder.builder(); + InformerConfiguration.Builder config = InformerConfiguration.builder(); if (configAnnotation != null) { - final var informerConfig = configAnnotation.informerConfig(); + final var informerConfig = configAnnotation.informer(); final var context = Utils.contextFor(controllerConfig, dependentResourceClass, configAnnotation.annotationType()); config = config.initFromAnnotation(informerConfig, context); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 37069bd1c4..35b959c1ec 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -13,7 +13,7 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.dependent.Configured; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.Ignore; @@ -178,7 +178,7 @@ protected void addReferenceHandlingMetadata(R desired, P primary) { @Override protected InformerEventSource createEventSource(EventSourceContext

context) { - final InformerConfiguration.InformerConfigurationBuilder configBuilder = + final InformerEventSourceConfiguration.Builder configBuilder = informerConfigurationBuilder(context) .withSecondaryToPrimaryMapper(getSecondaryToPrimaryMapper(context).orElseThrow()) .withName(name()); @@ -186,7 +186,7 @@ protected InformerEventSource createEventSource(EventSourceContext

cont // update configuration from annotation if specified if (kubernetesDependentResourceConfig != null && kubernetesDependentResourceConfig.informerConfig() != null) { - kubernetesDependentResourceConfig.informerConfig().updateInformerConfigBuilder(configBuilder); + configBuilder.updateFrom(kubernetesDependentResourceConfig.informerConfig()); } var es = new InformerEventSource<>(configBuilder.build(), context); @@ -197,9 +197,9 @@ protected InformerEventSource createEventSource(EventSourceContext

cont /** * To handle {@link io.fabric8.kubernetes.api.model.GenericKubernetesResource} based dependents. */ - protected InformerConfiguration.InformerConfigurationBuilder informerConfigurationBuilder( + protected InformerEventSourceConfiguration.Builder informerConfigurationBuilder( EventSourceContext

context) { - return InformerConfiguration.from(resourceType(), context.getPrimaryResourceClass()); + return InformerEventSourceConfiguration.from(resourceType(), context.getPrimaryResourceClass()); } private boolean useNonOwnerRefBasedSecondaryToPrimaryMapping() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java index bdb07d9230..2b419c2d0d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java @@ -2,6 +2,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; public class KubernetesDependentResourceConfig { @@ -10,12 +11,12 @@ public class KubernetesDependentResourceConfig { private final Boolean useSSA; private final boolean createResourceOnlyIfNotExistingWithSSA; - private final InformerConfigHolder informerConfig; + private final InformerConfiguration informerConfig; public KubernetesDependentResourceConfig( Boolean useSSA, boolean createResourceOnlyIfNotExistingWithSSA, - InformerConfigHolder informerConfig) { + InformerConfiguration informerConfig) { this.useSSA = useSSA; this.createResourceOnlyIfNotExistingWithSSA = createResourceOnlyIfNotExistingWithSSA; this.informerConfig = informerConfig; @@ -29,7 +30,7 @@ public Boolean useSSA() { return useSSA; } - public InformerConfigHolder informerConfig() { + public InformerConfiguration informerConfig() { return informerConfig; } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java index dcfbc94a07..3610cb074b 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfigBuilder.java @@ -2,12 +2,13 @@ import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; public final class KubernetesDependentResourceConfigBuilder { private boolean createResourceOnlyIfNotExistingWithSSA; private Boolean useSSA = null; - private InformerConfigHolder informerConfigHolder; + private InformerConfiguration informerConfiguration; public KubernetesDependentResourceConfigBuilder() {} @@ -24,14 +25,14 @@ public KubernetesDependentResourceConfigBuilder withUseSSA(boolean useSSA) { } public KubernetesDependentResourceConfigBuilder withKubernetesDependentInformerConfig( - InformerConfigHolder informerConfigHolder) { - this.informerConfigHolder = informerConfigHolder; + InformerConfiguration informerConfiguration) { + this.informerConfiguration = informerConfiguration; return this; } public KubernetesDependentResourceConfig build() { return new KubernetesDependentResourceConfig<>( useSSA, createResourceOnlyIfNotExistingWithSSA, - informerConfigHolder); + informerConfiguration); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/PrimaryToSecondaryMapper.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/PrimaryToSecondaryMapper.java index 9a5bfbac5d..2ff61f81e8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/PrimaryToSecondaryMapper.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/PrimaryToSecondaryMapper.java @@ -3,6 +3,7 @@ import java.util.Set; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.processing.event.ResourceID; /** @@ -12,13 +13,12 @@ * primary resources *without* a standard way (e.g. owner reference or annotations) to materialize * that relations. When owner references are present, a {@code PrimaryToSecondaryMapper} instance * should not be needed. In other words, associating such a mapper with your - * {@link io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration} is usually needed - * when your secondary resources are referenced in some way by your primary resource but that this - * link does not exist in the secondary resource information. The mapper implementation instructs - * the SDK on how to find all the secondary resources associated with a given primary resource so - * that this primary resource can properly be reconciled when changes impact the associated - * secondary resources, even though these don't contain any information allowing to make such an - * inference. + * {@link InformerEventSourceConfiguration} is usually needed when your secondary resources are + * referenced in some way by your primary resource but that this link does not exist in the + * secondary resource information. The mapper implementation instructs the SDK on how to find all + * the secondary resources associated with a given primary resource so that this primary resource + * can properly be reconciled when changes impact the associated secondary resources, even though + * these don't contain any information allowing to make such an inference. *

*

* This helps particularly in cases where several secondary resources, listed in some way in the diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java index f5b6f3a6d8..db3b9d6601 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java @@ -10,7 +10,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.informers.ResourceEventHandler; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.processing.event.Event; import io.javaoperatorsdk.operator.processing.event.EventHandler; @@ -64,7 +64,7 @@ * @param

type of the primary resource */ public class InformerEventSource - extends ManagedInformerEventSource> + extends ManagedInformerEventSource> implements ResourceEventHandler { public static String PREVIOUS_ANNOTATION_KEY = "javaoperatorsdk.io/previous"; @@ -77,18 +77,18 @@ public class InformerEventSource private final String id = UUID.randomUUID().toString(); public InformerEventSource( - InformerConfiguration configuration, EventSourceContext

context) { + InformerEventSourceConfiguration configuration, EventSourceContext

context) { this(configuration, context.getClient(), context.getControllerConfiguration().getConfigurationService() .parseResourceVersionsForEventFilteringAndCaching()); } - InformerEventSource(InformerConfiguration configuration, KubernetesClient client) { + InformerEventSource(InformerEventSourceConfiguration configuration, KubernetesClient client) { this(configuration, client, false); } @SuppressWarnings({"unchecked", "rawtypes"}) - private InformerEventSource(InformerConfiguration configuration, + private InformerEventSource(InformerEventSourceConfiguration configuration, KubernetesClient client, boolean parseResourceVersions) { super(configuration.name(), diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/TemporaryResourceCache.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/TemporaryResourceCache.java index b905629e69..07c9e0a6cc 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/TemporaryResourceCache.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/TemporaryResourceCache.java @@ -9,7 +9,7 @@ import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -161,9 +161,9 @@ public synchronized boolean isKnownResourceVersion(T resource) { } /** - * @return true if {@link InformerConfiguration#parseResourceVersions()} is enabled and the - * resourceVersion of newResource is numerically greater than cachedResource, otherwise - * false + * @return true if {@link InformerEventSourceConfiguration#parseResourceVersions()} is enabled and + * the resourceVersion of newResource is numerically greater than cachedResource, + * otherwise false */ private boolean isLaterResourceVersion(ResourceID resourceId, T newResource, T cachedResource) { try { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java index f362726b65..00733b496b 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java @@ -11,6 +11,8 @@ 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.config.informer.Informer; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Constants; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; @@ -22,15 +24,13 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; -import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.inheritsNamespacesFromController; +import static io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration.inheritsNamespacesFromController; import static org.junit.jupiter.api.Assertions.*; class ControllerConfigurationOverriderTest { @@ -271,7 +271,7 @@ void replaceNamedDependentResourceConfigShouldWork() { // override the namespaces for the dependent resource final var overriddenNS = "newNS"; final var labelSelector = "foo=bar"; - final var overridingInformerConfig = InformerConfigHolder.builder(ConfigMap.class) + final var overridingInformerConfig = InformerConfiguration.builder(ConfigMap.class) .withNamespaces(Set.of(overriddenNS)) .withLabelSelector(labelSelector) .buildForInformerEventSource(); @@ -304,7 +304,7 @@ public MyItemStore() { } @ControllerConfiguration( - informerConfig = @InformerConfig(namespaces = "foo", itemStore = MyItemStore.class)) + informer = @Informer(namespaces = "foo", itemStore = MyItemStore.class)) private static class WatchCurrentReconciler implements Reconciler { @Override @@ -346,7 +346,7 @@ public boolean isMet(DependentResource dependentResource, @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class, readyPostcondition = TestCondition.class)) @ControllerConfiguration( - informerConfig = @InformerConfig(namespaces = OneDepReconciler.CONFIGURED_NS)) + informer = @Informer(namespaces = OneDepReconciler.CONFIGURED_NS)) private static class OneDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "foo"; @@ -366,7 +366,7 @@ public ReadOnlyDependent() { } @KubernetesDependent( - informerConfig = @InformerConfig(namespaces = Constants.WATCH_ALL_NAMESPACES)) + informer = @Informer(namespaces = Constants.WATCH_ALL_NAMESPACES)) public static class WatchAllNSDependent extends KubernetesDependentResource implements GarbageCollected { @@ -378,7 +378,7 @@ public WatchAllNSDependent() { @Workflow(dependents = @Dependent(type = OverriddenNSDependent.class)) @ControllerConfiguration( - informerConfig = @InformerConfig(namespaces = OverriddenNSOnDepReconciler.CONFIGURED_NS)) + informer = @Informer(namespaces = OverriddenNSOnDepReconciler.CONFIGURED_NS)) public static class OverriddenNSOnDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "parentNS"; @@ -389,7 +389,7 @@ public UpdateControl reconcile(ConfigMap resource, Context } } - @KubernetesDependent(informerConfig = @InformerConfig(namespaces = OverriddenNSDependent.DEP_NS)) + @KubernetesDependent(informer = @Informer(namespaces = OverriddenNSDependent.DEP_NS)) public static class OverriddenNSDependent extends KubernetesDependentResource implements GarbageCollected { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java index 2a65a179ea..5cf8376ea2 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java @@ -7,15 +7,15 @@ import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import static org.junit.jupiter.api.Assertions.*; class ResourceConfigurationTest { public static final ResourceConfiguration DEFAULT = - () -> InformerConfigHolder.builder().buildForInformerEventSource(); + () -> InformerConfiguration.builder().buildForInformerEventSource(); @Test void allNamespacesWatched() { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java index 7e45bda68c..e24de96dbb 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java @@ -10,7 +10,7 @@ import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.MockControllerConfiguration; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.event.source.AbstractEventSource; @@ -168,7 +168,8 @@ void changesNamespacesOnControllerAndInformerEventSources() { when(controllerResourceEventSourceMock.allowsNamespaceChanges()).thenCallRealMethod(); var manager = new EventSourceManager(controller, eventSources); - InformerConfiguration informerConfigurationMock = mock(InformerConfiguration.class); + InformerEventSourceConfiguration informerConfigurationMock = + mock(InformerEventSourceConfiguration.class); when(informerConfigurationMock.followControllerNamespaceChanges()).thenReturn(true); InformerEventSource informerEventSource = mock(InformerEventSource.class); when(informerEventSource.name()).thenReturn("ies"); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java index 053e6ebb22..5282fd2138 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java @@ -12,10 +12,10 @@ import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.ResolvedControllerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.Controller; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.EventHandler; import io.javaoperatorsdk.operator.processing.event.EventSourceManager; import io.javaoperatorsdk.operator.processing.event.source.AbstractEventSourceTestBase; @@ -202,7 +202,7 @@ public TestConfiguration(boolean generationAware, OnAddFilter temporaryResourceCacheMock = mock(TemporaryResourceCache.class); private final EventHandler eventHandlerMock = mock(EventHandler.class); - private final InformerConfiguration informerConfiguration = - mock(InformerConfiguration.class); + private final InformerEventSourceConfiguration informerConfiguration = + mock(InformerEventSourceConfiguration.class); @BeforeEach void setup() { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerReconciler.java index ac13c497cd..79150eb745 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/builtinresourcecleaner/BuiltInResourceCleanerReconciler.java @@ -3,10 +3,10 @@ import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.Service; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.*; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; -@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "builtintest=true")) +@ControllerConfiguration(informer = @Informer(labelSelector = "builtintest=true")) public class BuiltInResourceCleanerReconciler implements Reconciler, Cleaner { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestReconciler.java index fac4263c3c..bac97514b6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace/ChangeNamespaceTestReconciler.java @@ -6,7 +6,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -25,7 +25,8 @@ public List> prepareEventSourc InformerEventSource configMapES = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, ChangeNamespaceTestCustomResource.class) + InformerEventSourceConfiguration + .from(ConfigMap.class, ChangeNamespaceTestCustomResource.class) .build(), context); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceReconciler.java index c108b9edbc..3be5a055d7 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedCustomResourceReconciler.java @@ -6,7 +6,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; @@ -60,7 +60,7 @@ private ConfigMap desired(ClusterScopedCustomResource resource) { public List> prepareEventSources( EventSourceContext context) { var ies = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, ClusterScopedCustomResource.class) + InformerEventSourceConfiguration.from(ConfigMap.class, ClusterScopedCustomResource.class) .withSecondaryToPrimaryMapper( Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), true)) .withInformerConfiguration( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java index 35676cd669..041021cf68 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java @@ -7,7 +7,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; @@ -69,8 +69,9 @@ private ConfigMap createConfigMap(CreateUpdateEventFilterTestCustomResource reso @Override public List> prepareEventSources( EventSourceContext context) { - InformerConfiguration informerConfiguration = - InformerConfiguration.from(ConfigMap.class, CreateUpdateEventFilterTestCustomResource.class) + InformerEventSourceConfiguration informerConfiguration = + InformerEventSourceConfiguration + .from(ConfigMap.class, CreateUpdateEventFilterTestCustomResource.class) .withInformerConfiguration(c -> c .withLabelSelector("integrationtest = " + this.getClass().getSimpleName())) .build(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/DeploymentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/DeploymentReconciler.java index c62be34e4f..ef04ca644a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/DeploymentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/deployment/DeploymentReconciler.java @@ -9,15 +9,15 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.DeploymentCondition; import io.fabric8.kubernetes.api.model.apps.DeploymentStatus; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @ControllerConfiguration( - informerConfig = @InformerConfig(labelSelector = "test=KubernetesResourceStatusUpdateIT")) + informer = @Informer(labelSelector = "test=KubernetesResourceStatusUpdateIT")) public class DeploymentReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java index ed3659572c..0abf91f32f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/dynamicgenericeventsourceregistration/DynamicGenericEventSourceRegistrationReconciler.java @@ -6,7 +6,7 @@ import io.fabric8.kubernetes.api.model.*; import io.fabric8.kubernetes.client.dsl.NonDeletingOperation; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; @@ -71,7 +71,7 @@ private InformerEventSource context) { return new InformerEventSource<>( - InformerConfiguration + InformerEventSourceConfiguration .from(GroupVersionKind.gvkFor(clazz), DynamicGenericEventSourceRegistrationCustomResource.class) .withName(clazz.getSimpleName()) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestReconciler.java index 16f94e4e09..22a9bc7067 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/filter/FilterTestReconciler.java @@ -6,17 +6,17 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.Informer; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; -@ControllerConfiguration(informerConfig = @InformerConfig(onUpdateFilter = UpdateFilter.class)) +@ControllerConfiguration(informer = @Informer(onUpdateFilter = UpdateFilter.class)) public class FilterTestReconciler implements Reconciler { @@ -57,7 +57,7 @@ public int getNumberOfExecutions() { public List> prepareEventSources( EventSourceContext context) { - final var informerConfiguration = InformerConfiguration + final var informerConfiguration = InformerEventSourceConfiguration .from(ConfigMap.class, FilterTestCustomResource.class) .withInformerConfiguration(c -> c.withOnUpdateFilter((newCM, oldCM) -> !newCM.getData().get(CM_VALUE_KEY) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java index 7d0f3b1d8f..2d7cf217bc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/generickubernetesresourcehandling/GenericKubernetesResourceHandlingReconciler.java @@ -7,7 +7,7 @@ import java.util.Map; import io.fabric8.kubernetes.api.model.GenericKubernetesResource; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.processing.GroupVersionKind; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -68,7 +68,7 @@ GenericKubernetesResource desiredConfigMap( public List> prepareEventSources( EventSourceContext context) { - var informerEventSource = new InformerEventSource<>(InformerConfiguration.from( + var informerEventSource = new InformerEventSource<>(InformerEventSourceConfiguration.from( new GroupVersionKind("", VERSION, KIND), GenericKubernetesResourceHandlingCustomResource.class).build(), context); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java index 8d0178fd1b..59430fd581 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; @@ -35,8 +35,9 @@ public class InformerEventSourceTestCustomReconciler public List> prepareEventSources( EventSourceContext context) { - InformerConfiguration config = - InformerConfiguration.from(ConfigMap.class, InformerEventSourceTestCustomResource.class) + InformerEventSourceConfiguration config = + InformerEventSourceConfiguration + .from(ConfigMap.class, InformerEventSourceTestCustomResource.class) .withSecondaryToPrimaryMapper(Mappers.fromAnnotation(RELATED_RESOURCE_NAME)) .build(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java index d1d5109b45..771effc3a1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java @@ -2,15 +2,15 @@ import java.util.concurrent.atomic.AtomicInteger; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.*; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; import static io.javaoperatorsdk.operator.baseapi.labelselector.LabelSelectorTestReconciler.LABEL_KEY; import static io.javaoperatorsdk.operator.baseapi.labelselector.LabelSelectorTestReconciler.LABEL_VALUE; @ControllerConfiguration( - informerConfig = @InformerConfig(labelSelector = LABEL_KEY + "=" + LABEL_VALUE)) + informer = @Informer(labelSelector = LABEL_KEY + "=" + LABEL_VALUE)) public class LabelSelectorTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java index e9a80a8812..a3ffd9667e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler1.java @@ -2,11 +2,11 @@ import java.util.concurrent.atomic.AtomicInteger; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.*; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "reconciler = 1")) +@ControllerConfiguration(informer = @Informer(labelSelector = "reconciler = 1")) public class MultipleReconcilerSameTypeReconciler1 implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java index d7a7ae54b8..ee446a7cf4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplereconcilersametype/MultipleReconcilerSameTypeReconciler2.java @@ -2,14 +2,14 @@ import java.util.concurrent.atomic.AtomicInteger; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "reconciler != 1")) +@ControllerConfiguration(informer = @Informer(labelSelector = "reconciler != 1")) public class MultipleReconcilerSameTypeReconciler2 implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java index 12d726e3a4..bde573171d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java @@ -7,7 +7,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; @@ -68,7 +68,7 @@ public int getNumberOfExecutions() { public List> prepareEventSources( EventSourceContext context) { - var config = InformerConfiguration + var config = InformerEventSourceConfiguration .from(ConfigMap.class, MultipleSecondaryEventSourceCustomResource.class) .withInformerConfiguration(c -> c .withNamespaces(context.getControllerConfiguration().getNamespaces()) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler1.java index e84e537925..a9b3af7586 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler1.java @@ -3,13 +3,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; -@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "!version")) +@ControllerConfiguration(informer = @Informer(labelSelector = "!version")) public class MultiVersionCRDTestReconciler1 implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler2.java index 262e66c37c..29d7e830fa 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiversioncrd/MultiVersionCRDTestReconciler2.java @@ -3,13 +3,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; -@ControllerConfiguration(informerConfig = @InformerConfig(labelSelector = "version in (v2)")) +@ControllerConfiguration(informer = @Informer(labelSelector = "version in (v2)")) public class MultiVersionCRDTestReconciler2 implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestReconciler.java index 0c6318f0a9..d03cc0fcb0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primaryindexer/PrimaryIndexerTestReconciler.java @@ -4,7 +4,7 @@ import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -22,7 +22,8 @@ public List> prepareEventSource context.getPrimaryCache().addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer); var informerConfiguration = - InformerConfiguration.from(ConfigMap.class, PrimaryIndexerTestCustomResource.class) + InformerEventSourceConfiguration + .from(ConfigMap.class, PrimaryIndexerTestCustomResource.class) .withSecondaryToPrimaryMapper( (ConfigMap secondaryResource) -> context .getPrimaryCache() diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobReconciler.java index 2503b9b54c..b0f369817e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/primarytosecondary/JobReconciler.java @@ -6,8 +6,8 @@ import java.util.stream.Collectors; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper; @@ -65,14 +65,14 @@ public List> prepareEventSources(EventSourceContext con context.getPrimaryCache().addIndexer(JOB_CLUSTER_INDEX, (job -> List .of(indexKey(job.getSpec().getClusterName(), job.getMetadata().getNamespace())))); - InformerConfiguration.InformerConfigurationBuilder informerConfiguration = - InformerConfiguration.from(Cluster.class, Job.class) + InformerEventSourceConfiguration.Builder informerConfiguration = + InformerEventSourceConfiguration.from(Cluster.class, Job.class) .withSecondaryToPrimaryMapper(cluster -> context.getPrimaryCache() .byIndex(JOB_CLUSTER_INDEX, indexKey(cluster.getMetadata().getName(), cluster.getMetadata().getNamespace())) .stream().map(ResourceID::fromResource).collect(Collectors.toSet())) .withInformerConfiguration( - InformerConfigHolder.Builder::withNamespacesInheritedFromController); + InformerConfiguration.Builder::withNamespacesInheritedFromController); if (addPrimaryToSecondaryMapper) { informerConfiguration = informerConfiguration.withPrimaryToSecondaryMapper( @@ -102,6 +102,7 @@ public boolean isErrorOccurred() { return errorOccurred; } + @SuppressWarnings("UnusedReturnValue") public JobReconciler setGetResourceDirectlyFromCache(boolean getResourceDirectlyFromCache) { this.getResourceDirectlyFromCache = getResourceDirectlyFromCache; return this; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java index 65e3d221ae..2f89bb6892 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java @@ -20,6 +20,7 @@ import io.javaoperatorsdk.operator.api.config.dependent.ConfigurationConverter; import io.javaoperatorsdk.operator.api.config.dependent.Configured; import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Constants; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; @@ -36,7 +37,6 @@ import io.javaoperatorsdk.operator.dependent.readonly.ReadOnlyDependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.BooleanWithUndefined; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig; @@ -314,7 +314,7 @@ public UpdateControl reconcile(ConfigMap resource, Context @Workflow(dependents = @Dependent(type = ReadOnlyDependent.class)) @ControllerConfiguration( - informerConfig = @InformerConfig(namespaces = OneDepReconciler.CONFIGURED_NS)) + informer = @Informer(namespaces = OneDepReconciler.CONFIGURED_NS)) private static class OneDepReconciler implements Reconciler { private static final String CONFIGURED_NS = "foo"; diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestReconciler.java index 9eae636cf2..2351512046 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/DependentFilterTestReconciler.java @@ -2,12 +2,12 @@ import java.util.concurrent.atomic.AtomicInteger; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; @Workflow(dependents = {@Dependent(type = FilteredDependentConfigMap.class)}) -@ControllerConfiguration(informerConfig = @InformerConfig(onUpdateFilter = UpdateFilter.class)) +@ControllerConfiguration(informer = @Informer(onUpdateFilter = UpdateFilter.class)) public class DependentFilterTestReconciler implements Reconciler { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/FilteredDependentConfigMap.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/FilteredDependentConfigMap.java index a8548f6e70..7cbb60c583 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/FilteredDependentConfigMap.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentfilter/FilteredDependentConfigMap.java @@ -4,14 +4,14 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import static io.javaoperatorsdk.operator.dependent.dependentfilter.DependentFilterTestReconciler.CM_VALUE_KEY; -@KubernetesDependent(informerConfig = @InformerConfig(onUpdateFilter = UpdateFilter.class)) +@KubernetesDependent(informer = @Informer(onUpdateFilter = UpdateFilter.class)) public class FilteredDependentConfigMap extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java index 6f4f6b25b2..3149d1c6d0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentoperationeventfiltering/DependentOperationEventFilterCustomResourceTestReconciler.java @@ -2,16 +2,16 @@ import java.util.concurrent.atomic.AtomicInteger; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @Workflow(dependents = { @Dependent(type = ConfigMapDependentResource.class) }) @ControllerConfiguration( - informerConfig = @InformerConfig(namespaces = Constants.WATCH_CURRENT_NAMESPACE)) + informer = @Informer(namespaces = Constants.WATCH_CURRENT_NAMESPACE)) public class DependentOperationEventFilterCustomResourceTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentReconciler.java index a9e677ebaf..9140f40587 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateDependentReconciler.java @@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -37,7 +37,8 @@ public int getNumberOfExecutions() { public List> prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, ExternalStateCustomResource.class).build(), + InformerEventSourceConfiguration.from(ConfigMap.class, ExternalStateCustomResource.class) + .build(), context); return List.of(configMapEventSource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateReconciler.java index 422592b4d3..5fb2932152 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalStateReconciler.java @@ -11,7 +11,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Cleaner; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; @@ -111,7 +111,8 @@ public List> prepareEventSources( EventSourceContext context) { configMapEventSource = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, ExternalStateCustomResource.class).build(), + InformerEventSourceConfiguration.from(ConfigMap.class, ExternalStateCustomResource.class) + .build(), context); configMapEventSource.setEventSourcePriority(EventSourceStartPriority.RESOURCE_STATE_LOADER); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java index 3d49b58077..2e0f672c79 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/externalstatebulkdependent/ExternalStateBulkDependentReconciler.java @@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -36,7 +36,8 @@ public int getNumberOfExecutions() { public List> prepareEventSources( EventSourceContext context) { var configMapEventSource = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, ExternalStateBulkDependentCustomResource.class) + InformerEventSourceConfiguration + .from(ConfigMap.class, ExternalStateBulkDependentCustomResource.class) .build(), context); return List.of(configMapEventSource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/ConfigMapDependentResource.java index dd55f16ca1..37e109e8de 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/ConfigMapDependentResource.java @@ -5,12 +5,12 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = "app=rbac-test")) +@KubernetesDependent(informer = @Informer(labelSelector = "app=rbac-test")) public class ConfigMapDependentResource extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceReconciler.java index 91a889ac87..aeac786cda 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresource/MultipleDependentResourceReconciler.java @@ -3,7 +3,7 @@ import java.util.List; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; @@ -36,7 +36,7 @@ public UpdateControl reconcile( public List> prepareEventSources( EventSourceContext context) { InformerEventSource eventSource = - new InformerEventSource<>(InformerConfiguration + new InformerEventSource<>(InformerEventSourceConfiguration .from(ConfigMap.class, MultipleDependentResourceCustomResource.class) .build(), context); firstDependentResourceConfigMap.setEventSource(eventSource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithDiscriminatorReconciler.java index 3d75109a05..c96033d9bc 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledependentresourcewithsametype/MultipleDependentResourceWithDiscriminatorReconciler.java @@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.processing.event.source.EventSource; import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; @@ -46,7 +46,7 @@ public int getNumberOfExecutions() { public List> prepareEventSources( EventSourceContext context) { InformerEventSource eventSource = - new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, + new InformerEventSource<>(InformerEventSourceConfiguration.from(ConfigMap.class, MultipleDependentResourceCustomResourceNoDiscriminator.class) .build(), context); firstDependentResourceConfigMap.setEventSource(eventSource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java index 16492569c6..09c0b5cc23 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentSameTypeNoDiscriminatorReconciler.java @@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -50,7 +50,7 @@ public List context) { InformerEventSource ies = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, + InformerEventSourceConfiguration.from(ConfigMap.class, MultipleManagedDependentNoDiscriminatorCustomResource.class) .withName(CONFIG_MAP_EVENT_SOURCE) .build(), diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java index 94b152fba2..f25587b2ee 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multiplemanageddependentsametype/MultipleManagedDependentResourceReconciler.java @@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -50,7 +50,7 @@ public List> prep EventSourceContext context) { InformerEventSource ies = new InformerEventSource<>( - InformerConfiguration + InformerEventSourceConfiguration .from(ConfigMap.class, MultipleManagedDependentResourceCustomResource.class) .withName(CONFIG_MAP_EVENT_SOURCE) .build(), diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerTestReconciler.java index 2730d743cb..bb97a32cf9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primaryindexer/DependentPrimaryIndexerTestReconciler.java @@ -6,7 +6,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; @@ -40,7 +40,8 @@ public List> prepareEventSource InformerEventSource es = new InformerEventSource<>( - InformerConfiguration.from(ConfigMap.class, PrimaryIndexerTestCustomResource.class) + InformerEventSourceConfiguration + .from(ConfigMap.class, PrimaryIndexerTestCustomResource.class) .withName(CONFIG_MAP_EVENT_SOURCE) .withSecondaryToPrimaryMapper(resource -> cache .byIndex(CONFIG_MAP_RELATION_INDEXER, resource.getMetadata().getName()) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java index 5e011b7247..76e2015be8 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/primarytosecondaydependent/PrimaryToSecondaryDependentReconciler.java @@ -6,7 +6,7 @@ import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -66,7 +66,7 @@ public List> prepareEv context.getPrimaryCache().addIndexer(CONFIG_MAP_INDEX, (primary -> List .of(indexKey(primary.getSpec().getConfigMapName(), primary.getMetadata().getNamespace())))); - var es = new InformerEventSource<>(InformerConfiguration + var es = new InformerEventSource<>(InformerEventSourceConfiguration .from(ConfigMap.class, PrimaryToSecondaryDependentCustomResource.class) .withName(CONFIG_MAP_EVENT_SOURCE) // if there is a many-to-many relationship (thus no direct owner reference) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/ConfigMapDependentResource.java index b531a83beb..b7e69febd1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/ConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/restart/ConfigMapDependentResource.java @@ -5,12 +5,12 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = "app=restart-test")) +@KubernetesDependent(informer = @Informer(labelSelector = "app=restart-test")) public class ConfigMapDependentResource extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceTestReconciler.java index e10571396e..7d2720c5c2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/specialresourcesdependent/SpecialResourceTestReconciler.java @@ -2,16 +2,16 @@ import java.util.concurrent.atomic.AtomicInteger; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @Workflow(dependents = { @Dependent(type = ServiceAccountDependentResource.class), }) @ControllerConfiguration( - informerConfig = @InformerConfig(namespaces = Constants.WATCH_CURRENT_NAMESPACE)) + informer = @Informer(namespaces = Constants.WATCH_CURRENT_NAMESPACE)) public class SpecialResourceTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowReconciler.java index 249c749003..bab93d032e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/complexdependent/ComplexWorkflowReconciler.java @@ -5,7 +5,7 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.apps.StatefulSet; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.source.EventSource; @@ -59,13 +59,15 @@ public List> prepareEventSources( EventSourceContext context) { InformerEventSource serviceEventSource = new InformerEventSource<>( - InformerConfiguration.from(Service.class, ComplexWorkflowCustomResource.class) + InformerEventSourceConfiguration + .from(Service.class, ComplexWorkflowCustomResource.class) .withName(SERVICE_EVENT_SOURCE_NAME) .build(), context); InformerEventSource statefulSetEventSource = new InformerEventSource<>( - InformerConfiguration.from(StatefulSet.class, ComplexWorkflowCustomResource.class) + InformerEventSourceConfiguration + .from(StatefulSet.class, ComplexWorkflowCustomResource.class) .withName(STATEFUL_SET_EVENT_SOURCE_NAME) .build(), context); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource1.java index 085586beaa..a3198a3ca3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource1.java @@ -4,12 +4,12 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(informerConfig = @InformerConfig(name = "configMapInformer")) +@KubernetesDependent(informer = @Informer(name = "configMapInformer")) public class ConfigMapDependentResource1 extends CRUDNoGCKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource2.java index a07b6a925b..5fcead39a2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/multipledependentwithactivation/ConfigMapDependentResource2.java @@ -4,12 +4,12 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDNoGCKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(informerConfig = @InformerConfig(name = "configMapInformer")) +@KubernetesDependent(informer = @Informer(name = "configMapInformer")) public class ConfigMapDependentResource2 extends CRUDNoGCKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource1.java index ac57e05903..0478fe4248 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource1.java @@ -5,13 +5,13 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = "dependent = cm1")) +@KubernetesDependent(informer = @Informer(labelSelector = "dependent = cm1")) public class ConfigMapDependentResource1 extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource2.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource2.java index 1494a0d430..efbd6ec450 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource2.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/ConfigMapDependentResource2.java @@ -5,13 +5,13 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = "dependent = cm2")) +@KubernetesDependent(informer = @Informer(labelSelector = "dependent = cm2")) public class ConfigMapDependentResource2 extends CRUDKubernetesDependentResource { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentTestReconciler.java index a78b02c056..4336d940b0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/orderedmanageddependent/OrderedManagedDependentTestReconciler.java @@ -5,9 +5,9 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; @Workflow(dependents = { @@ -15,7 +15,7 @@ @Dependent(type = ConfigMapDependentResource2.class, dependsOn = "cm1") }) @ControllerConfiguration( - informerConfig = @InformerConfig(namespaces = Constants.WATCH_CURRENT_NAMESPACE)) + informer = @Informer(namespaces = Constants.WATCH_CURRENT_NAMESPACE)) public class OrderedManagedDependentTestReconciler implements Reconciler, TestExecutionInfoProvider { diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentDependentResource.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentDependentResource.java index e0425235fb..d6eaad24bb 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentDependentResource.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentDependentResource.java @@ -4,12 +4,12 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder; import io.javaoperatorsdk.operator.ReconcilerUtils; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(informerConfig = @InformerConfig( +@KubernetesDependent(informer = @Informer( labelSelector = "app.kubernetes.io/managed-by=tomcat-operator")) public class DeploymentDependentResource extends CRUDKubernetesDependentResource { diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/ServiceDependentResource.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/ServiceDependentResource.java index 56f3330a45..8a93b48804 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/ServiceDependentResource.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/ServiceDependentResource.java @@ -4,12 +4,12 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServiceBuilder; import io.javaoperatorsdk.operator.ReconcilerUtils; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; -@KubernetesDependent(informerConfig = @InformerConfig( +@KubernetesDependent(informer = @Informer( labelSelector = "app.kubernetes.io/managed-by=tomcat-operator")) public class ServiceDependentResource extends CRUDKubernetesDependentResource { diff --git a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java index 00bd5614fa..82d0152b3c 100644 --- a/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java +++ b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java @@ -19,7 +19,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.ExecListener; import io.fabric8.kubernetes.client.dsl.ExecWatch; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Cleaner; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; @@ -58,8 +58,8 @@ public List> prepareEventSources(EventSourceContext configuration = - InformerConfiguration.from(Tomcat.class, Webapp.class) + InformerEventSourceConfiguration configuration = + InformerEventSourceConfiguration.from(Tomcat.class, Webapp.class) .withSecondaryToPrimaryMapper(webappsMatchingTomcatName) .withPrimaryToSecondaryMapper( (Webapp primary) -> Set.of(new ResourceID(primary.getSpec().getTomcat(), diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index 4eb1a1c0a3..b38f48b912 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -8,9 +8,9 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.fabric8.kubernetes.client.KubernetesClient; +import io.javaoperatorsdk.operator.api.config.informer.Informer; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow; @@ -25,7 +25,7 @@ * Shows how to implement reconciler using standalone dependent resources. */ @ControllerConfiguration( - informerConfig = @InformerConfig( + informer = @Informer( labelSelector = WebPageDependentsWorkflowReconciler.DEPENDENT_RESOURCE_LABEL_SELECTOR)) @SuppressWarnings("unused") public class WebPageDependentsWorkflowReconciler @@ -85,7 +85,7 @@ private void initDependentResources(KubernetesClient client) { Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR) .forEach(dr -> dr.configureWith(new KubernetesDependentResourceConfigBuilder() - .withKubernetesDependentInformerConfig(InformerConfigHolder.builder() + .withKubernetesDependentInformerConfig(InformerConfiguration.builder() .withLabelSelector(DEPENDENT_RESOURCE_LABEL_SELECTOR) .buildForInformerEventSource()) .build())); diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java index 6cb199b0fc..56b66fbfb3 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java @@ -13,7 +13,7 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.*; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.event.rate.RateLimited; @@ -41,21 +41,29 @@ public WebPageReconciler() { @Override public List> prepareEventSources(EventSourceContext context) { var configMapEventSource = - new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, WebPage.class) - .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) - .build(), context); + new InformerEventSource<>( + InformerEventSourceConfiguration.from(ConfigMap.class, WebPage.class) + .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) + .build(), + context); var deploymentEventSource = - new InformerEventSource<>(InformerConfiguration.from(Deployment.class, WebPage.class) - .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) - .build(), context); + new InformerEventSource<>( + InformerEventSourceConfiguration.from(Deployment.class, WebPage.class) + .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) + .build(), + context); var serviceEventSource = - new InformerEventSource<>(InformerConfiguration.from(Service.class, WebPage.class) - .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) - .build(), context); + new InformerEventSource<>( + InformerEventSourceConfiguration.from(Service.class, WebPage.class) + .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) + .build(), + context); var ingressEventSource = - new InformerEventSource<>(InformerConfiguration.from(Ingress.class, WebPage.class) - .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) - .build(), context); + new InformerEventSource<>( + InformerEventSourceConfiguration.from(Ingress.class, WebPage.class) + .withInformerConfiguration(c -> c.withLabelSelector(SELECTOR)) + .build(), + context); return List.of(configMapEventSource, deploymentEventSource, serviceEventSource, ingressEventSource); } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java index 0b8d44fe22..e7930a3658 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java @@ -4,6 +4,7 @@ import java.util.List; import io.fabric8.kubernetes.api.model.ConfigMap; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl; @@ -11,7 +12,6 @@ import io.javaoperatorsdk.operator.api.reconciler.EventSourceUtils; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow; import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowBuilder; @@ -96,7 +96,7 @@ private Workflow createDependentResourcesAndWorkflow() { // configure them with our label selector Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR) .forEach(dr -> dr.configureWith(new KubernetesDependentResourceConfigBuilder() - .withKubernetesDependentInformerConfig(InformerConfigHolder.builder() + .withKubernetesDependentInformerConfig(InformerConfiguration.builder() .withLabelSelector(SELECTOR + "=true") .buildForInformerEventSource()) .build())); diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ConfigMapDependentResource.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ConfigMapDependentResource.java index aa03aaabca..816db3688e 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ConfigMapDependentResource.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ConfigMapDependentResource.java @@ -6,9 +6,9 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.sample.customresource.WebPage; @@ -16,7 +16,7 @@ import static io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler.SELECTOR; // this annotation only activates when using managed dependents and is not otherwise needed -@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = SELECTOR)) +@KubernetesDependent(informer = @Informer(labelSelector = SELECTOR)) public class ConfigMapDependentResource extends CRUDKubernetesDependentResource { diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/DeploymentDependentResource.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/DeploymentDependentResource.java index 3aa90bf54c..b427e42d33 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/DeploymentDependentResource.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/DeploymentDependentResource.java @@ -5,9 +5,9 @@ import io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder; import io.fabric8.kubernetes.api.model.apps.Deployment; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.sample.Utils; import io.javaoperatorsdk.operator.sample.customresource.WebPage; @@ -18,7 +18,7 @@ import static io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler.SELECTOR; // this annotation only activates when using managed dependents and is not otherwise needed -@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = SELECTOR)) +@KubernetesDependent(informer = @Informer(labelSelector = SELECTOR)) public class DeploymentDependentResource extends CRUDKubernetesDependentResource { diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/IngressDependentResource.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/IngressDependentResource.java index abfe9a13f5..e680d10fcf 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/IngressDependentResource.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/IngressDependentResource.java @@ -1,9 +1,9 @@ package io.javaoperatorsdk.operator.sample.dependentresource; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler; import io.javaoperatorsdk.operator.sample.customresource.WebPage; @@ -12,7 +12,7 @@ // this annotation only activates when using managed dependents and is not otherwise needed @KubernetesDependent( - informerConfig = @InformerConfig(labelSelector = WebPageManagedDependentsReconciler.SELECTOR)) + informer = @Informer(labelSelector = WebPageManagedDependentsReconciler.SELECTOR)) public class IngressDependentResource extends CRUDKubernetesDependentResource { public IngressDependentResource() { diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ServiceDependentResource.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ServiceDependentResource.java index 2669fe5f97..ff9e7a1a52 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ServiceDependentResource.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/dependentresource/ServiceDependentResource.java @@ -4,8 +4,8 @@ import java.util.Map; import io.fabric8.kubernetes.api.model.Service; +import io.javaoperatorsdk.operator.api.config.informer.Informer; import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; import io.javaoperatorsdk.operator.sample.Utils; import io.javaoperatorsdk.operator.sample.customresource.WebPage; @@ -16,7 +16,7 @@ import static io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler.SELECTOR; // this annotation only activates when using managed dependents and is not otherwise needed -@KubernetesDependent(informerConfig = @InformerConfig(labelSelector = SELECTOR)) +@KubernetesDependent(informer = @Informer(labelSelector = SELECTOR)) public class ServiceDependentResource extends io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource { From 292bc0bbcabe2c03a1a3b54085ad432bb533d398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Thu, 15 Aug 2024 11:26:09 +0200 Subject: [PATCH 69/96] improve: replace jenvtest with kube-api-test from fabric8 client (#2497) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- operator-framework/pom.xml | 4 ++-- .../InformerRelatedBehaviorITS.java | 6 +----- pom.xml | 8 +++----- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index 0026c48dd6..172f176c73 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -85,8 +85,8 @@ test - io.javaoperatorsdk - jenvtest + io.fabric8 + kube-api-test-client-inject test diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorITS.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorITS.java index 12488af133..21079c0504 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/informerrelatedbehavior/InformerRelatedBehaviorITS.java @@ -3,9 +3,8 @@ import java.time.Duration; import org.junit.jupiter.api.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.fabric8.kubeapitest.junit.EnableKubeAPIServer; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.api.model.Namespace; @@ -18,7 +17,6 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil; -import io.javaoperatorsdk.jenvtest.junit.EnableKubeAPIServer; import io.javaoperatorsdk.operator.Operator; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.ReconcilerUtils; @@ -49,8 +47,6 @@ @EnableKubeAPIServer(apiServerFlags = {"--min-request-timeout", "1"}, updateKubeConfigFile = true) class InformerRelatedBehaviorITS { - private static final Logger log = LoggerFactory.getLogger(InformerRelatedBehaviorITS.class); - public static final String TEST_RESOURCE_NAME = "test1"; public static final String ADDITIONAL_NAMESPACE_SUFFIX = "-additional"; diff --git a/pom.xml b/pom.xml index 010a350e1d..325a64a215 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,6 @@ 1.13.3 4.12.0 3.1.8 - 0.9.6 0.9.11 2.16.1 @@ -215,10 +214,9 @@ ${caffeine.version} - io.javaoperatorsdk - jenvtest - ${jenvtest.version} - test + io.fabric8 + kube-api-test-client-inject + ${fabric8-client.version} From d6a67abaa9f3e7adc8293de927481cae7e2939a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 19 Aug 2024 08:58:21 +0200 Subject: [PATCH 70/96] feat: config option to not exit when stops leading (#2500) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: config option to not exit when stops leading Signed-off-by: Attila Mészáros * Update operator-framework-core/src/main/java/io/javaoperatorsdk/operator/LeaderElectionManager.java Co-authored-by: Chris Laprun --------- Signed-off-by: Attila Mészáros Co-authored-by: Chris Laprun --- .../operator/LeaderElectionManager.java | 14 +++++++++----- .../api/config/LeaderElectionConfiguration.java | 17 ++++++++++++----- .../LeaderElectionConfigurationBuilder.java | 8 +++++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/LeaderElectionManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/LeaderElectionManager.java index d0af5ee441..d6ee17a383 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/LeaderElectionManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/LeaderElectionManager.java @@ -102,11 +102,15 @@ private void startLeading() { } private void stopLeading() { - log.info("Stopped leading for identity: {}. Exiting.", identity); - // When leader stops leading the process ends immediately to prevent multiple reconciliations - // running parallel. - // Note that some reconciliations might run for a very long time. - System.exit(1); + if (configurationService.getLeaderElectionConfiguration().orElseThrow().isExitOnStopLeading()) { + log.info("Stopped leading for identity: {}. Exiting.", identity); + // When leader stops leading the process ends immediately to prevent multiple reconciliations + // running parallel. + // Note that some reconciliations might run for a very long time. + System.exit(1); + } else { + log.info("Stopped leading, configured not to exit"); + } } private String identity(LeaderElectionConfiguration config) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfiguration.java index 0ab72ff165..cfce453e14 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfiguration.java @@ -20,6 +20,7 @@ public class LeaderElectionConfiguration { private final Duration retryPeriod; private final LeaderCallbacks leaderCallbacks; + private final boolean exitOnStopLeading; public LeaderElectionConfiguration(String leaseName, String leaseNamespace, String identity) { this( @@ -27,7 +28,7 @@ public LeaderElectionConfiguration(String leaseName, String leaseNamespace, Stri leaseNamespace, LEASE_DURATION_DEFAULT_VALUE, RENEW_DEADLINE_DEFAULT_VALUE, - RETRY_PERIOD_DEFAULT_VALUE, identity, null); + RETRY_PERIOD_DEFAULT_VALUE, identity, null, true); } public LeaderElectionConfiguration(String leaseName, String leaseNamespace) { @@ -36,7 +37,7 @@ public LeaderElectionConfiguration(String leaseName, String leaseNamespace) { leaseNamespace, LEASE_DURATION_DEFAULT_VALUE, RENEW_DEADLINE_DEFAULT_VALUE, - RETRY_PERIOD_DEFAULT_VALUE, null, null); + RETRY_PERIOD_DEFAULT_VALUE, null, null, true); } public LeaderElectionConfiguration(String leaseName) { @@ -45,7 +46,7 @@ public LeaderElectionConfiguration(String leaseName) { null, LEASE_DURATION_DEFAULT_VALUE, RENEW_DEADLINE_DEFAULT_VALUE, - RETRY_PERIOD_DEFAULT_VALUE, null, null); + RETRY_PERIOD_DEFAULT_VALUE, null, null, true); } public LeaderElectionConfiguration( @@ -54,7 +55,7 @@ public LeaderElectionConfiguration( Duration leaseDuration, Duration renewDeadline, Duration retryPeriod) { - this(leaseName, leaseNamespace, leaseDuration, renewDeadline, retryPeriod, null, null); + this(leaseName, leaseNamespace, leaseDuration, renewDeadline, retryPeriod, null, null, true); } public LeaderElectionConfiguration( @@ -64,7 +65,8 @@ public LeaderElectionConfiguration( Duration renewDeadline, Duration retryPeriod, String identity, - LeaderCallbacks leaderCallbacks) { + LeaderCallbacks leaderCallbacks, + boolean exitOnStopLeading) { this.leaseName = leaseName; this.leaseNamespace = leaseNamespace; this.leaseDuration = leaseDuration; @@ -72,6 +74,7 @@ public LeaderElectionConfiguration( this.retryPeriod = retryPeriod; this.identity = identity; this.leaderCallbacks = leaderCallbacks; + this.exitOnStopLeading = exitOnStopLeading; } public Optional getLeaseNamespace() { @@ -101,4 +104,8 @@ public Optional getIdentity() { public Optional getLeaderCallbacks() { return Optional.ofNullable(leaderCallbacks); } + + public boolean isExitOnStopLeading() { + return exitOnStopLeading; + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfigurationBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfigurationBuilder.java index 494c9d8e66..eda262f9eb 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfigurationBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/LeaderElectionConfigurationBuilder.java @@ -16,6 +16,7 @@ public final class LeaderElectionConfigurationBuilder { private Duration renewDeadline = RENEW_DEADLINE_DEFAULT_VALUE; private Duration retryPeriod = RETRY_PERIOD_DEFAULT_VALUE; private LeaderCallbacks leaderCallbacks; + private boolean exitOnStopLeading = true; private LeaderElectionConfigurationBuilder(String leaseName) { this.leaseName = leaseName; @@ -55,8 +56,13 @@ public LeaderElectionConfigurationBuilder withLeaderCallbacks(LeaderCallbacks le return this; } + public LeaderElectionConfigurationBuilder withExitOnStopLeading(boolean exitOnStopLeading) { + this.exitOnStopLeading = exitOnStopLeading; + return this; + } + public LeaderElectionConfiguration build() { return new LeaderElectionConfiguration(leaseName, leaseNamespace, leaseDuration, renewDeadline, - retryPeriod, identity, leaderCallbacks); + retryPeriod, identity, leaderCallbacks, exitOnStopLeading); } } From f409d1c1d36cbb778b8aee15c23c8f35ce4939f6 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 19 Aug 2024 15:26:24 +0200 Subject: [PATCH 71/96] refactor: clean up ResourceConfiguration & rename to Informable (#2486) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Signed-off-by: Attila Mészáros Co-authored-by: Attila Mészáros Co-authored-by: Attila Mészáros --- .../io/javaoperatorsdk/operator/Operator.java | 5 +- .../api/config/BaseConfigurationService.java | 2 +- .../api/config/ConfigurationService.java | 6 +- .../api/config/ControllerConfiguration.java | 14 +- .../ControllerConfigurationOverrider.java | 13 +- .../config/DefaultResourceConfiguration.java | 41 ----- .../operator/api/config/Informable.java | 18 ++ .../ResolvedControllerConfiguration.java | 21 ++- .../api/config/ResourceConfiguration.java | 161 ----------------- .../api/config/informer/Informer.java | 2 +- .../informer/InformerConfiguration.java | 165 ++++++++++++++++-- .../InformerEventSourceConfiguration.java | 59 ++----- .../operator/api/reconciler/Constants.java | 1 + .../dependent/DependentResourceFactory.java | 15 +- .../KubernetesDependentConverter.java | 5 +- .../processing/event/EventSourceManager.java | 14 +- .../controller/ControllerEventSource.java | 7 +- .../source/informer/InformerEventSource.java | 9 +- .../source/informer/InformerManager.java | 26 +-- .../informer/ManagedInformerEventSource.java | 4 +- .../ControllerConfigurationOverriderTest.java | 77 ++++---- .../api/config/InformerConfigurationTest.java | 83 +++++++++ .../config/MockControllerConfiguration.java | 7 +- .../api/config/ResourceConfigurationTest.java | 79 --------- .../event/EventSourceManagerTest.java | 7 +- .../controller/ControllerEventSourceTest.java | 1 - .../informer/InformerEventSourceTest.java | 18 +- .../runtime/DefaultConfigurationService.java | 3 +- ...ultipleSecondaryEventSourceReconciler.java | 5 +- .../config/BaseConfigurationServiceTest.java | 16 +- .../WebPageDependentsWorkflowReconciler.java | 2 +- ...WebPageStandaloneDependentsReconciler.java | 2 +- 32 files changed, 417 insertions(+), 471 deletions(-) delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Informable.java delete mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java create mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/InformerConfigurationTest.java delete mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java index 1283896a42..9680bc7e8d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java @@ -213,8 +213,9 @@ public

RegisteredController

register(Reconciler

re controllerManager.add(controller); - final var watchedNS = configuration.watchAllNamespaces() ? "[all namespaces]" - : configuration.getEffectiveNamespaces(); + final var informerConfig = configuration.getInformerConfig(); + final var watchedNS = informerConfig.watchAllNamespaces() ? "[all namespaces]" + : informerConfig.getEffectiveNamespaces(configuration); log.info( "Registered reconciler: '{}' for resource: '{}' for namespace(s): {}", diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index 20beef7f90..4204cb6faf 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -280,7 +280,7 @@ private

ResolvedControllerConfiguration

controllerCon .buildForController(); return new ResolvedControllerConfiguration

( - resourceClass, name, generationAware, + name, generationAware, associatedReconcilerClass, retry, rateLimiter, ResolvedControllerConfiguration.getMaxReconciliationInterval(interval, timeUnit), valueOrDefaultFromAnnotation(annotation, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index 2fc29ca4c5..14a13bf0b6 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -367,7 +367,7 @@ default ExecutorServiceManager getExecutorServiceManager() { * SSA based create/update can be still used with the legacy matching, just overriding the match * method of Kubernetes Dependent Resource. * - * @return if SSA should be used for dependent resources + * @return {@code true} if SSA should be used for dependent resources, {@code false} otherwise * @since 4.4.0 */ default boolean ssaBasedCreateUpdateMatchForDependentResources() { @@ -455,6 +455,8 @@ default Set> defaultNonSSAResource() { * * @return if special annotation should be used for dependent resource to filter events * @since 4.5.0 + * + * @return if special annotation should be used for dependent resource to filter events */ default boolean previousAnnotationForDependentResourcesEventFiltering() { return true; @@ -471,6 +473,8 @@ default boolean previousAnnotationForDependentResourcesEventFiltering() { * * @return if resource version should be parsed (as integer) * @since 4.5.0 + * + * @return if resource version should be parsed (as integer) */ default boolean parseResourceVersionsForEventFilteringAndCaching() { return false; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java index aa74d7ea1a..e03cf5626e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java @@ -14,7 +14,7 @@ import io.javaoperatorsdk.operator.processing.retry.GenericRetry; import io.javaoperatorsdk.operator.processing.retry.Retry; -public interface ControllerConfiguration

extends ResourceConfiguration

{ +public interface ControllerConfiguration

extends Informable

{ @SuppressWarnings("rawtypes") RateLimiter DEFAULT_RATE_LIMITER = LinearRateLimiter.deactivatedRateLimiter(); @@ -74,19 +74,9 @@ default Optional maxReconciliationInterval() { ConfigurationService getConfigurationService(); - @SuppressWarnings("unchecked") - @Override - default Class

getResourceClass() { - // note that this implementation at the end not used within the boundaries of the core - // framework, should be removed in the future, (and marked as an API changed, or behavior - // change) - return (Class

) Utils.getFirstTypeArgumentFromSuperClassOrInterface(getClass(), - ControllerConfiguration.class); - } - @SuppressWarnings("unused") default Set getEffectiveNamespaces() { - return ResourceConfiguration.super.getEffectiveNamespaces(this); + return getInformerConfig().getEffectiveNamespaces(this); } /** diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java index 423867107a..3d3eef5990 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverrider.java @@ -35,15 +35,8 @@ public class ControllerConfigurationOverrider { private ControllerConfigurationOverrider(ControllerConfiguration original) { this.finalizer = original.getFinalizerName(); this.generationAware = original.isGenerationAware(); - this.config = InformerConfiguration.builder(original.getResourceClass()) - .withName(name) - .withNamespaces(original.getNamespaces()) - .withLabelSelector(original.getLabelSelector()) - .withOnAddFilter(original.onAddFilter().orElse(null)) - .withOnUpdateFilter(original.onUpdateFilter().orElse(null)) - .withGenericFilter(original.genericFilter().orElse(null)) - .withInformerListLimit(original.getInformerListLimit().orElse(null)) - .withItemStore(original.getItemStore().orElse(null)); + final var informerConfig = original.getInformerConfig(); + this.config = InformerConfiguration.builder(informerConfig); this.retry = original.getRetry(); this.reconciliationMaxInterval = original.maxReconciliationInterval().orElse(null); this.original = original; @@ -194,7 +187,7 @@ public ControllerConfigurationOverrider replacingNamedDependentResourceConfig } public ControllerConfiguration build() { - return new ResolvedControllerConfiguration<>(original.getResourceClass(), + return new ResolvedControllerConfiguration<>( name, generationAware, original.getAssociatedReconcilerClassName(), retry, rateLimiter, reconciliationMaxInterval, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java deleted file mode 100644 index c0d725f746..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultResourceConfiguration.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.javaoperatorsdk.operator.api.config; - - -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; - -public class DefaultResourceConfiguration - implements ResourceConfiguration { - - private final Class resourceClass; - private final String resourceTypeName; - private final InformerConfiguration informerConfig; - - protected DefaultResourceConfiguration(Class resourceClass, - InformerConfiguration informerConfig) { - this.resourceClass = resourceClass; - this.resourceTypeName = resourceClass.isAssignableFrom(GenericKubernetesResource.class) - // in general this is irrelevant now for secondary resources it is used just by controller - // where GenericKubernetesResource now does not apply - ? GenericKubernetesResource.class.getSimpleName() - : ReconcilerUtils.getResourceTypeName(resourceClass); - this.informerConfig = informerConfig; - } - - @Override - public String getResourceTypeName() { - return resourceTypeName; - } - - @Override - public Class getResourceClass() { - return resourceClass; - } - - @Override - public InformerConfiguration getInformerConfig() { - return informerConfig; - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Informable.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Informable.java new file mode 100644 index 0000000000..5b58836483 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Informable.java @@ -0,0 +1,18 @@ +package io.javaoperatorsdk.operator.api.config; + + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; + +public interface Informable { + + default String getResourceTypeName() { + return getInformerConfig().getResourceTypeName(); + } + + InformerConfiguration getInformerConfig(); + + default Class getResourceClass() { + return getInformerConfig().getResourceClass(); + } +} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java index 9bb7efb5cf..7e8415f584 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResolvedControllerConfiguration.java @@ -16,9 +16,9 @@ @SuppressWarnings("rawtypes") public class ResolvedControllerConfiguration

- extends DefaultResourceConfiguration

implements io.javaoperatorsdk.operator.api.config.ControllerConfiguration

{ + private final InformerConfiguration

informerConfig; private final String name; private final boolean generationAware; private final String associatedReconcilerClassName; @@ -31,8 +31,8 @@ public class ResolvedControllerConfiguration

private final String fieldManager; private WorkflowSpec workflowSpec; - public ResolvedControllerConfiguration(Class

resourceClass, ControllerConfiguration

other) { - this(resourceClass, other.getName(), other.isGenerationAware(), + public ResolvedControllerConfiguration(ControllerConfiguration

other) { + this(other.getName(), other.isGenerationAware(), other.getAssociatedReconcilerClassName(), other.getRetry(), other.getRateLimiter(), other.maxReconciliationInterval().orElse(null), other.getFinalizerName(), Collections.emptyMap(), @@ -42,7 +42,7 @@ public ResolvedControllerConfiguration(Class

resourceClass, ControllerConfigu other.getWorkflowSpec().orElse(null)); } - public ResolvedControllerConfiguration(Class

resourceClass, String name, + public ResolvedControllerConfiguration(String name, boolean generationAware, String associatedReconcilerClassName, Retry retry, RateLimiter rateLimiter, Duration maxReconciliationInterval, String finalizer, @@ -51,19 +51,19 @@ public ResolvedControllerConfiguration(Class

resourceClass, String name, ConfigurationService configurationService, InformerConfiguration

informerConfig, WorkflowSpec workflowSpec) { - this(resourceClass, name, generationAware, associatedReconcilerClassName, retry, rateLimiter, + this(name, generationAware, associatedReconcilerClassName, retry, rateLimiter, maxReconciliationInterval, finalizer, configurations, fieldManager, configurationService, informerConfig); setWorkflowSpec(workflowSpec); } - protected ResolvedControllerConfiguration(Class

resourceClass, String name, + protected ResolvedControllerConfiguration(String name, boolean generationAware, String associatedReconcilerClassName, Retry retry, RateLimiter rateLimiter, Duration maxReconciliationInterval, String finalizer, Map configurations, String fieldManager, ConfigurationService configurationService, InformerConfiguration

informerConfig) { - super(resourceClass, informerConfig); + this.informerConfig = informerConfig; this.configurationService = configurationService; this.name = ControllerConfiguration.ensureValidName(name, associatedReconcilerClassName); this.generationAware = generationAware; @@ -79,11 +79,16 @@ protected ResolvedControllerConfiguration(Class

resourceClass, String name, protected ResolvedControllerConfiguration(Class

resourceClass, String name, Class reconcilerClas, ConfigurationService configurationService) { - this(resourceClass, name, false, getAssociatedReconcilerClassName(reconcilerClas), null, null, + this(name, false, getAssociatedReconcilerClassName(reconcilerClas), null, null, null, null, null, null, configurationService, InformerConfiguration.builder(resourceClass).buildForController()); } + @Override + public InformerConfiguration

getInformerConfig() { + return informerConfig; + } + public static Duration getMaxReconciliationInterval(long interval, TimeUnit timeUnit) { return interval > 0 ? Duration.of(interval, timeUnit.toChronoUnit()) : null; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java deleted file mode 100644 index cac44c93db..0000000000 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ResourceConfiguration.java +++ /dev/null @@ -1,161 +0,0 @@ -package io.javaoperatorsdk.operator.api.config; - -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.informers.cache.ItemStore; -import io.javaoperatorsdk.operator.OperatorException; -import io.javaoperatorsdk.operator.ReconcilerUtils; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Constants; -import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; - -import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES_SET; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE_SET; - -public interface ResourceConfiguration { - - default String getResourceTypeName() { - return ReconcilerUtils.getResourceTypeName(getResourceClass()); - } - - InformerConfiguration getInformerConfig(); - - default Optional> onAddFilter() { - return Optional.ofNullable(getInformerConfig().getOnAddFilter()); - } - - default Optional> onUpdateFilter() { - return Optional.ofNullable(getInformerConfig().getOnUpdateFilter()); - } - - default Optional> genericFilter() { - return Optional.ofNullable(getInformerConfig().getGenericFilter()); - } - - /** - * Retrieves the label selector that is used to filter which resources are actually watched by the - * associated event source. See the official documentation on the - * topic - * for more details on syntax. - * - * @return the label selector filtering watched resources - */ - default String getLabelSelector() { - return getInformerConfig().getLabelSelector(); - } - - static String ensureValidLabelSelector(String labelSelector) { - // might want to implement validation here? - return labelSelector; - } - - @SuppressWarnings("unchecked") - default Class getResourceClass() { - return (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface(getClass(), - ResourceConfiguration.class); - } - - default Set getNamespaces() { - return getInformerConfig().getNamespaces(); - } - - default boolean watchAllNamespaces() { - return allNamespacesWatched(getNamespaces()); - } - - static boolean allNamespacesWatched(Set namespaces) { - failIfNotValid(namespaces); - return DEFAULT_NAMESPACES_SET.equals(namespaces); - } - - default boolean watchCurrentNamespace() { - return currentNamespaceWatched(getNamespaces()); - } - - static boolean currentNamespaceWatched(Set namespaces) { - failIfNotValid(namespaces); - return WATCH_CURRENT_NAMESPACE_SET.equals(namespaces); - } - - static void failIfNotValid(Set namespaces) { - if (namespaces != null && !namespaces.isEmpty()) { - final var present = namespaces.contains(Constants.WATCH_CURRENT_NAMESPACE) - || namespaces.contains(Constants.WATCH_ALL_NAMESPACES); - if (!present || namespaces.size() == 1) { - return; - } - } - throw new IllegalArgumentException( - "Must specify namespaces. To watch all namespaces, use only '" - + Constants.WATCH_ALL_NAMESPACES - + "'. To watch only the namespace in which the operator is deployed, use only '" - + Constants.WATCH_CURRENT_NAMESPACE + "'"); - } - - static Set ensureValidNamespaces(Collection namespaces) { - if (namespaces != null && !namespaces.isEmpty()) { - return namespaces.stream().map(String::trim).collect(Collectors.toSet()); - } else { - return Constants.DEFAULT_NAMESPACES_SET; - } - } - - /** - * Computes the effective namespaces based on the set specified by the user, in particular - * retrieves the current namespace from the client when the user specified that they wanted to - * watch the current namespace only. - * - * @return a Set of namespace names the associated controller will watch - */ - default Set getEffectiveNamespaces(ControllerConfiguration controllerConfiguration) { - var targetNamespaces = getNamespaces(); - if (watchCurrentNamespace()) { - final String namespace = - controllerConfiguration.getConfigurationService().getKubernetesClient().getConfiguration() - .getNamespace(); - if (namespace == null) { - throw new OperatorException( - "Couldn't retrieve the currently connected namespace. Make sure it's correctly set in your ~/.kube/config file, using, e.g. 'kubectl config set-context --namespace='"); - } - targetNamespaces = Collections.singleton(namespace); - } - return targetNamespaces; - } - - /** - * Replaces the item store in informer. See underlying method - * in fabric8 client informer implementation. - * - *

- * The main goal, is to be able to use limited caches or provide any custom implementation. - *

- * - *

- * See {@link BoundedItemStore} and CaffeineBoundedCache - *

- * - * @return Optional {@link ItemStore} implementation. If present this item store will be used by - * the informers. - */ - default Optional> getItemStore() { - return Optional.ofNullable(getInformerConfig().getItemStore()); - } - - /** - * The maximum amount of items to return for a single list call when starting an informer. If this - * is a not null it will result in paginating for the initial load of the informer cache. - */ - default Optional getInformerListLimit() { - return Optional.ofNullable(getInformerConfig().getInformerListLimit()); - } -} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java index 363200bea5..57da4f41a6 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java @@ -13,7 +13,7 @@ import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; -import static io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; +import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_LONG_VALUE_SET; import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java index 0cb6892ebe..8d7b232889 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java @@ -1,12 +1,19 @@ package io.javaoperatorsdk.operator.api.config.informer; +import java.util.Collection; +import java.util.Collections; import java.util.Set; +import java.util.stream.Collectors; +import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.informers.cache.ItemStore; -import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; +import io.javaoperatorsdk.operator.OperatorException; +import io.javaoperatorsdk.operator.ReconcilerUtils; +import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.api.reconciler.Constants; +import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; @@ -18,6 +25,8 @@ @SuppressWarnings("unused") public class InformerConfiguration { private final Builder builder = new Builder(); + private final Class resourceClass; + private final String resourceTypeName; private String name; private Set namespaces; private Boolean followControllerNamespacesOnChange; @@ -29,11 +38,12 @@ public class InformerConfiguration { private ItemStore itemStore; private Long informerListLimit; - public InformerConfiguration(String name, Set namespaces, + protected InformerConfiguration(Class resourceClass, String name, Set namespaces, boolean followControllerNamespacesOnChange, String labelSelector, OnAddFilter onAddFilter, OnUpdateFilter onUpdateFilter, OnDeleteFilter onDeleteFilter, GenericFilter genericFilter, ItemStore itemStore, Long informerListLimit) { + this(resourceClass); this.name = name; this.namespaces = namespaces; this.followControllerNamespacesOnChange = followControllerNamespacesOnChange; @@ -46,28 +56,80 @@ public InformerConfiguration(String name, Set namespaces, this.informerListLimit = informerListLimit; } - private InformerConfiguration() {} - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static InformerConfiguration.Builder builder() { - return new InformerConfiguration().builder; + private InformerConfiguration(Class resourceClass) { + this.resourceClass = resourceClass; + this.resourceTypeName = resourceClass.isAssignableFrom(GenericKubernetesResource.class) + // in general this is irrelevant now for secondary resources it is used just by controller + // where GenericKubernetesResource now does not apply + ? GenericKubernetesResource.class.getSimpleName() + : ReconcilerUtils.getResourceTypeName(resourceClass); } @SuppressWarnings({"rawtypes", "unchecked"}) public static InformerConfiguration.Builder builder( Class resourceClass) { - return new InformerConfiguration().builder; + return new InformerConfiguration(resourceClass).builder; } @SuppressWarnings({"rawtypes", "unchecked"}) public static InformerConfiguration.Builder builder( InformerConfiguration original) { - return new InformerConfiguration(original.name, original.namespaces, + return new InformerConfiguration(original.resourceClass, original.name, original.namespaces, original.followControllerNamespacesOnChange, original.labelSelector, original.onAddFilter, original.onUpdateFilter, original.onDeleteFilter, original.genericFilter, original.itemStore, original.informerListLimit).builder; } + public static String ensureValidLabelSelector(String labelSelector) { + // might want to implement validation here? + return labelSelector; + } + + public static boolean allNamespacesWatched(Set namespaces) { + failIfNotValid(namespaces); + return DEFAULT_NAMESPACES_SET.equals(namespaces); + } + + public static boolean currentNamespaceWatched(Set namespaces) { + failIfNotValid(namespaces); + return WATCH_CURRENT_NAMESPACE_SET.equals(namespaces); + } + + public static void failIfNotValid(Set namespaces) { + if (namespaces != null && !namespaces.isEmpty()) { + final var present = namespaces.contains(WATCH_CURRENT_NAMESPACE) + || namespaces.contains(WATCH_ALL_NAMESPACES); + if (!present || namespaces.size() == 1) { + return; + } + } + throw new IllegalArgumentException( + "Must specify namespaces. To watch all namespaces, use only '" + + WATCH_ALL_NAMESPACES + + "'. To watch only the namespace in which the operator is deployed, use only '" + + WATCH_CURRENT_NAMESPACE + "'"); + } + + public static Set ensureValidNamespaces(Collection namespaces) { + if (namespaces != null && !namespaces.isEmpty()) { + return namespaces.stream().map(String::trim).collect(Collectors.toSet()); + } else { + return Constants.DEFAULT_NAMESPACES_SET; + } + } + + public static boolean inheritsNamespacesFromController(Set namespaces) { + return SAME_AS_CONTROLLER_NAMESPACES_SET.equals(namespaces); + } + + public Class getResourceClass() { + return resourceClass; + } + + public String getResourceTypeName() { + return resourceTypeName; + } + public String getName() { return name; } @@ -76,10 +138,64 @@ public Set getNamespaces() { return namespaces; } + public boolean watchAllNamespaces() { + return InformerConfiguration.allNamespacesWatched(getNamespaces()); + } + + public boolean watchCurrentNamespace() { + return InformerConfiguration.currentNamespaceWatched(getNamespaces()); + } + + public boolean inheritsNamespacesFromController() { + return inheritsNamespacesFromController(getNamespaces()); + } + + /** + * Computes the effective namespaces based on the set specified by the user, in particular + * retrieves the current namespace from the client when the user specified that they wanted to + * watch the current namespace only. + * + * @return a Set of namespace names the associated controller will watch + */ + public Set getEffectiveNamespaces(ControllerConfiguration controllerConfiguration) { + if (inheritsNamespacesFromController()) { + return controllerConfiguration.getEffectiveNamespaces(); + } + + var targetNamespaces = getNamespaces(); + if (watchCurrentNamespace()) { + final String namespace = + controllerConfiguration.getConfigurationService().getKubernetesClient().getConfiguration() + .getNamespace(); + if (namespace == null) { + throw new OperatorException( + "Couldn't retrieve the currently connected namespace. Make sure it's correctly set in your ~/.kube/config file, using, e.g. 'kubectl config set-context --namespace='"); + } + targetNamespaces = Collections.singleton(namespace); + } + return targetNamespaces; + } + + /** + * Used in case the watched namespaces are changed dynamically, thus when operator is running (See + * {@link io.javaoperatorsdk.operator.RegisteredController}). If true, changing the target + * namespaces of a controller would result to change target namespaces for the + * InformerEventSource. + * + * @return if namespace changes should be followed + */ public boolean isFollowControllerNamespacesOnChange() { return followControllerNamespacesOnChange; } + /** + * Retrieves the label selector that is used to filter which resources are actually watched by the + * associated informer. See the official documentation on the + * topic + * for more details on syntax. + * + * @return the label selector filtering watched resources + */ public String getLabelSelector() { return labelSelector; } @@ -100,10 +216,31 @@ public GenericFilter getGenericFilter() { return genericFilter; } + /** + * Replaces the item store in informer. See underlying method + * in fabric8 client informer implementation. + * + *

+ * The main goal, is to be able to use limited caches or provide any custom implementation. + *

+ * + *

+ * See {@link BoundedItemStore} and CaffeineBoundedCache + *

+ * + * @return Optional {@link ItemStore} implementation. If present this item store will be used by + * the informers. + */ public ItemStore getItemStore() { return itemStore; } + /** + * The maximum amount of items to return for a single list call when starting an informer. If this + * is a not null it will result in paginating for the initial load of the informer cache. + */ public Long getInformerListLimit() { return informerListLimit; } @@ -116,9 +253,11 @@ public InformerConfiguration buildForController() { // if the informer config uses the default "same as controller" value, reset the namespaces to // the default set for controllers if (namespaces == null || namespaces.isEmpty() - || InformerEventSourceConfiguration.inheritsNamespacesFromController(namespaces)) { + || inheritsNamespacesFromController(namespaces)) { namespaces = Constants.DEFAULT_NAMESPACES_SET; } + // to avoid potential NPE + followControllerNamespacesOnChange = false; return InformerConfiguration.this; } @@ -128,7 +267,7 @@ public InformerConfiguration buildForInformerEventSource() { } if (followControllerNamespacesOnChange == null) { followControllerNamespacesOnChange = - InformerEventSourceConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; + DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE; } return InformerConfiguration.this; } @@ -184,7 +323,7 @@ public Builder withName(String name) { public Builder withNamespaces(Set namespaces) { InformerConfiguration.this.namespaces = - ResourceConfiguration.ensureValidNamespaces(namespaces); + ensureValidNamespaces(namespaces); return this; } @@ -239,7 +378,7 @@ public Builder withFollowControllerNamespacesOnChange(boolean followChanges) { public Builder withLabelSelector(String labelSelector) { InformerConfiguration.this.labelSelector = - ResourceConfiguration.ensureValidLabelSelector(labelSelector); + ensureValidLabelSelector(labelSelector); return this; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java index 1e5e1ce666..20e6c7f131 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java @@ -2,31 +2,18 @@ import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.function.Consumer; import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.config.DefaultResourceConfiguration; -import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; -import io.javaoperatorsdk.operator.api.config.Utils; +import io.javaoperatorsdk.operator.api.config.Informable; import io.javaoperatorsdk.operator.processing.GroupVersionKind; import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; - public interface InformerEventSourceConfiguration - extends ResourceConfiguration { - - boolean DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE = true; - - static boolean inheritsNamespacesFromController(Set namespaces) { - return SAME_AS_CONTROLLER_NAMESPACES_SET.equals(namespaces); - } + extends Informable { static Builder from( Class resourceClass, Class primaryResourceClass) { @@ -62,10 +49,6 @@ default boolean followControllerNamespaceChanges() { */ SecondaryToPrimaryMapper getSecondaryToPrimaryMapper(); - default Optional> onDeleteFilter() { - return Optional.ofNullable(getInformerConfig().getOnDeleteFilter()); - } -

PrimaryToSecondaryMapper

getPrimaryToSecondaryMapper(); Optional getGroupVersionKind(); @@ -74,39 +57,32 @@ default String name() { return getInformerConfig().getName(); } - @SuppressWarnings("unchecked") - @Override - default Class getResourceClass() { - return (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface(getClass(), - InformerEventSourceConfiguration.class); - } - - class DefaultInformerEventSourceConfiguration extends - DefaultResourceConfiguration implements InformerEventSourceConfiguration { + class DefaultInformerEventSourceConfiguration + implements InformerEventSourceConfiguration { private final PrimaryToSecondaryMapper primaryToSecondaryMapper; private final SecondaryToPrimaryMapper secondaryToPrimaryMapper; private final GroupVersionKind groupVersionKind; + private final InformerConfiguration informerConfig; protected DefaultInformerEventSourceConfiguration( - Class resourceClass, GroupVersionKind groupVersionKind, PrimaryToSecondaryMapper primaryToSecondaryMapper, SecondaryToPrimaryMapper secondaryToPrimaryMapper, InformerConfiguration informerConfig) { - super(resourceClass, informerConfig); + this.informerConfig = Objects.requireNonNull(informerConfig); this.groupVersionKind = groupVersionKind; this.primaryToSecondaryMapper = primaryToSecondaryMapper; this.secondaryToPrimaryMapper = secondaryToPrimaryMapper; } @Override - public SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { - return secondaryToPrimaryMapper; + public InformerConfiguration getInformerConfig() { + return informerConfig; } @Override - public Optional> onDeleteFilter() { - return Optional.ofNullable(getInformerConfig().getOnDeleteFilter()); + public SecondaryToPrimaryMapper getSecondaryToPrimaryMapper() { + return secondaryToPrimaryMapper; } @Override @@ -119,19 +95,6 @@ public

PrimaryToSecondaryMapper

getPrimaryToSecondary public Optional getGroupVersionKind() { return Optional.ofNullable(groupVersionKind); } - - public boolean inheritsNamespacesFromController() { - return InformerEventSourceConfiguration.inheritsNamespacesFromController(getNamespaces()); - } - - @Override - public Set getEffectiveNamespaces(ControllerConfiguration controllerConfiguration) { - if (inheritsNamespacesFromController()) { - return controllerConfiguration.getEffectiveNamespaces(); - } else { - return super.getEffectiveNamespaces(controllerConfiguration); - } - } } @@ -223,7 +186,7 @@ public InformerEventSourceConfiguration build() { "If GroupVersionKind is set the resource type must be GenericKubernetesDependentResource"); } - return new DefaultInformerEventSourceConfiguration<>(resourceClass, + return new DefaultInformerEventSourceConfiguration<>( groupVersionKind, primaryToSecondaryMapper, Objects.requireNonNullElse(secondaryToPrimaryMapper, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Constants.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Constants.java index 594fcddd09..8003d8f836 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Constants.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Constants.java @@ -25,6 +25,7 @@ public final class Constants { public static final String RESOURCE_GVK_KEY = "josdk.resource.gvk"; public static final String CONTROLLER_NAME = "controller.name"; + public static final boolean DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE = true; private Constants() {} } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceFactory.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceFactory.java index 105d2b6c75..cc9a1dd6c3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceFactory.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceFactory.java @@ -6,11 +6,11 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; @SuppressWarnings({"rawtypes", "unchecked"}) -public interface DependentResourceFactory> { +public interface DependentResourceFactory, D extends DependentResourceSpec> { DependentResourceFactory DEFAULT = new DependentResourceFactory() {}; - default DependentResource createFrom(DependentResourceSpec spec, C controllerConfiguration) { + default DependentResource createFrom(D spec, C controllerConfiguration) { final var dependentResourceClass = spec.getDependentResourceClass(); return Utils.instantiateAndConfigureIfNeeded(dependentResourceClass, DependentResource.class, @@ -18,8 +18,7 @@ default DependentResource createFrom(DependentResourceSpec spec, C controllerCon (instance) -> configure(instance, spec, controllerConfiguration)); } - default void configure(DependentResource instance, DependentResourceSpec spec, - C controllerConfiguration) { + default void configure(DependentResource instance, D spec, C controllerConfiguration) { if (instance instanceof ConfiguredDependentResource configurable) { final var config = controllerConfiguration.getConfigurationFor(spec); if (config != null) { @@ -27,4 +26,12 @@ default void configure(DependentResource instance, DependentResourceSpec spec, } } } + + default Class associatedResourceType(D spec) { + final var dependentResourceClass = spec.getDependentResourceClass(); + final var dr = Utils.instantiateAndConfigureIfNeeded(dependentResourceClass, + DependentResource.class, + null, null); + return dr != null ? dr.resourceType() : null; + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java index 36625b0689..3bfa8351d3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java @@ -43,7 +43,10 @@ private InformerConfiguration createInformerConfig( Class> dependentResourceClass = (Class>) spec.getDependentResourceClass(); - InformerConfiguration.Builder config = InformerConfiguration.builder(); + final var resourceType = controllerConfig.getConfigurationService().dependentResourceFactory() + .associatedResourceType(spec); + + InformerConfiguration.Builder config = InformerConfiguration.builder(resourceType); if (configAnnotation != null) { final var informerConfig = configAnnotation.informer(); final var context = Utils.contextFor(controllerConfig, dependentResourceClass, diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java index 2bb8c7a39a..174ffa0978 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java @@ -173,16 +173,16 @@ public void broadcastOnResourceEvent(ResourceAction action, P resource, P oldRes } public void changeNamespaces(Set namespaces) { - eventSources.controllerEventSource() - .changeNamespaces(namespaces); - executorServiceManager.boundedExecuteAndWaitForAllToComplete(eventSources + eventSources.controllerEventSource().changeNamespaces(namespaces); + final var namespaceChangeables = eventSources .additionalEventSources() .filter(NamespaceChangeable.class::isInstance) .map(NamespaceChangeable.class::cast) - .filter(NamespaceChangeable::allowsNamespaceChanges), e -> { - e.changeNamespaces(namespaces); - return null; - }, + .filter(NamespaceChangeable::allowsNamespaceChanges); + executorServiceManager.boundedExecuteAndWaitForAllToComplete(namespaceChangeables, e -> { + e.changeNamespaces(namespaces); + return null; + }, getEventSourceThreadNamer("changeNamespace")); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java index db457a4e41..07e5bd3fa2 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java @@ -43,11 +43,12 @@ public ControllerEventSource(Controller controller) { .or(onUpdateMarkedForDeletion()); // by default the on add should be processed in all cases regarding internal filters - config.onAddFilter().ifPresent(this::setOnAddFilter); - config.onUpdateFilter() + final var informerConfig = config.getInformerConfig(); + Optional.ofNullable(informerConfig.getOnAddFilter()).ifPresent(this::setOnAddFilter); + Optional.ofNullable(informerConfig.getOnUpdateFilter()) .ifPresentOrElse(filter -> setOnUpdateFilter(filter.and(internalOnUpdateFilter)), () -> setOnUpdateFilter(internalOnUpdateFilter)); - config.genericFilter().ifPresent(this::setGenericFilter); + Optional.ofNullable(informerConfig.getGenericFilter()).ifPresent(this::setGenericFilter); setControllerConfiguration(config); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java index db3b9d6601..2568683600 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java @@ -106,10 +106,11 @@ private InformerEventSource(InformerEventSourceConfiguration configuration, primaryToSecondaryIndex = NOOPPrimaryToSecondaryIndex.getInstance(); } - onAddFilter = configuration.onAddFilter().orElse(null); - onUpdateFilter = configuration.onUpdateFilter().orElse(null); - onDeleteFilter = configuration.onDeleteFilter().orElse(null); - genericFilter = configuration.genericFilter().orElse(null); + final var informerConfig = configuration.getInformerConfig(); + onAddFilter = informerConfig.getOnAddFilter(); + onUpdateFilter = informerConfig.getOnUpdateFilter(); + onDeleteFilter = informerConfig.getOnDeleteFilter(); + genericFilter = informerConfig.getGenericFilter(); } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java index 9fc4a7db19..57bbf2a8ce 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java @@ -19,7 +19,8 @@ import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.ReconcilerUtils; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; -import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; +import io.javaoperatorsdk.operator.api.config.Informable; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.health.InformerHealthIndicator; import io.javaoperatorsdk.operator.processing.LifecycleAware; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -28,7 +29,7 @@ import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_ALL_NAMESPACES; -class InformerManager> +class InformerManager> implements LifecycleAware, IndexerResourceCache { private static final Logger log = LoggerFactory.getLogger(InformerManager.class); @@ -71,8 +72,9 @@ private void initSources() { if (!sources.isEmpty()) { throw new IllegalStateException("Some sources already initialized."); } - final var targetNamespaces = configuration.getEffectiveNamespaces(controllerConfiguration); - if (ResourceConfiguration.allNamespacesWatched(targetNamespaces)) { + final var targetNamespaces = + configuration.getInformerConfig().getEffectiveNamespaces(controllerConfiguration); + if (InformerConfiguration.allNamespacesWatched(targetNamespaces)) { var source = createEventSourceForNamespace(WATCH_ALL_NAMESPACES); log.debug("Registered {} -> {} for any namespace", this, source); } else { @@ -108,13 +110,14 @@ public void changeNamespaces(Set namespaces) { private InformerWrapper createEventSourceForNamespace(String namespace) { final InformerWrapper source; + final var labelSelector = configuration.getInformerConfig().getLabelSelector(); if (namespace.equals(WATCH_ALL_NAMESPACES)) { final var filteredBySelectorClient = - client.inAnyNamespace().withLabelSelector(configuration.getLabelSelector()); + client.inAnyNamespace().withLabelSelector(labelSelector); source = createEventSource(filteredBySelectorClient, eventHandler, WATCH_ALL_NAMESPACES); } else { source = createEventSource( - client.inNamespace(namespace).withLabelSelector(configuration.getLabelSelector()), + client.inNamespace(namespace).withLabelSelector(labelSelector), eventHandler, namespace); } source.addIndexers(indexers); @@ -124,9 +127,11 @@ private InformerWrapper createEventSourceForNamespace(String namespace) { private InformerWrapper createEventSource( FilterWatchListDeletable, Resource> filteredBySelectorClient, ResourceEventHandler eventHandler, String namespaceIdentifier) { - var informer = configuration.getInformerListLimit().map(filteredBySelectorClient::withLimit) + final var informerConfig = configuration.getInformerConfig(); + var informer = Optional.ofNullable(informerConfig.getInformerListLimit()) + .map(filteredBySelectorClient::withLimit) .orElse(filteredBySelectorClient).runnableInformer(0); - configuration.getItemStore().ifPresent(informer::itemStore); + Optional.ofNullable(informerConfig.getItemStore()).ifPresent(informer::itemStore); var source = new InformerWrapper<>(informer, controllerConfiguration.getConfigurationService(), namespaceIdentifier); source.addEventHandler(eventHandler); @@ -205,11 +210,12 @@ public List byIndex(String indexName, String indexKey) { @Override public String toString() { - final var selector = configuration.getLabelSelector(); + final var informerConfig = configuration.getInformerConfig(); + final var selector = informerConfig.getLabelSelector(); return "InformerManager [" + ReconcilerUtils.getResourceTypeNameWithVersion(configuration.getResourceClass()) + "] watching: " - + configuration.getEffectiveNamespaces(controllerConfiguration) + + informerConfig.getEffectiveNamespaces(controllerConfiguration) + (selector != null ? " selector: " + selector : ""); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java index 54d60e2cdf..f5e899826d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java @@ -17,8 +17,8 @@ import io.fabric8.kubernetes.client.informers.ResourceEventHandler; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.config.Informable; import io.javaoperatorsdk.operator.api.config.NamespaceChangeable; -import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; import io.javaoperatorsdk.operator.api.reconciler.dependent.RecentOperationCacheFiller; import io.javaoperatorsdk.operator.health.InformerHealthIndicator; import io.javaoperatorsdk.operator.health.InformerWrappingEventSourceHealthIndicator; @@ -27,7 +27,7 @@ import io.javaoperatorsdk.operator.processing.event.source.*; @SuppressWarnings("rawtypes") -public abstract class ManagedInformerEventSource> +public abstract class ManagedInformerEventSource> extends AbstractEventSource implements ResourceEventHandler, Cache, IndexerResourceCache, RecentOperationCacheFiller, NamespaceChangeable, diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java index 00733b496b..46ef56e1d4 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java @@ -30,7 +30,7 @@ import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfigBuilder; import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; -import static io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration.inheritsNamespacesFromController; +import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.inheritsNamespacesFromController; import static org.junit.jupiter.api.Assertions.*; class ControllerConfigurationOverriderTest { @@ -67,7 +67,7 @@ void overridingNSShouldPreserveUntouchedDependents() { .settingNamespace(namespace) .replacingNamedDependentResourceConfig(externalDRName, stringConfig) .build(); - assertEquals(Set.of(namespace), configuration.getNamespaces()); + assertEquals(Set.of(namespace), configuration.getInformerConfig().getNamespaces()); // check that we still have the proper number of dependent configs dependentResources = configuration.getWorkflowSpec().orElseThrow().getDependentResourceSpecs(); @@ -77,12 +77,11 @@ void overridingNSShouldPreserveUntouchedDependents() { assertEquals(stringConfig, resourceConfig); } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes"}) private KubernetesDependentResourceConfig extractFirstDependentKubernetesResourceConfig( io.javaoperatorsdk.operator.api.config.ControllerConfiguration configuration) { - var conf = (KubernetesDependentResourceConfig) extractDependentKubernetesResourceConfig( + return (KubernetesDependentResourceConfig) extractDependentKubernetesResourceConfig( configuration, 0); - return conf; } private io.javaoperatorsdk.operator.api.config.ControllerConfiguration createConfiguration( @@ -93,48 +92,55 @@ private io.javaoperatorsdk.operator.api.config.ControllerConfiguration create @Test void overridingNamespacesShouldWork() { var configuration = createConfiguration(new WatchCurrentReconciler()); - assertEquals(Set.of("foo"), configuration.getNamespaces()); - assertFalse(configuration.watchAllNamespaces()); - assertFalse(configuration.watchCurrentNamespace()); + var informerConfig = configuration.getInformerConfig(); + assertEquals(Set.of("foo"), informerConfig.getNamespaces()); + assertFalse(informerConfig.watchAllNamespaces()); + assertFalse(informerConfig.watchCurrentNamespace()); configuration = ControllerConfigurationOverrider.override(configuration) .addingNamespaces("foo", "bar") .build(); - assertEquals(Set.of("foo", "bar"), configuration.getNamespaces()); - assertFalse(configuration.watchAllNamespaces()); - assertFalse(configuration.watchCurrentNamespace()); + informerConfig = configuration.getInformerConfig(); + assertEquals(Set.of("foo", "bar"), informerConfig.getNamespaces()); + assertFalse(informerConfig.watchAllNamespaces()); + assertFalse(informerConfig.watchCurrentNamespace()); configuration = ControllerConfigurationOverrider.override(configuration) .removingNamespaces("bar") .build(); - assertEquals(Set.of("foo"), configuration.getNamespaces()); - assertFalse(configuration.watchAllNamespaces()); - assertFalse(configuration.watchCurrentNamespace()); + informerConfig = configuration.getInformerConfig(); + assertEquals(Set.of("foo"), informerConfig.getNamespaces()); + assertFalse(informerConfig.watchAllNamespaces()); + assertFalse(informerConfig.watchCurrentNamespace()); configuration = ControllerConfigurationOverrider.override(configuration) .removingNamespaces("foo") .build(); - assertTrue(configuration.watchAllNamespaces()); - assertFalse(configuration.watchCurrentNamespace()); + informerConfig = configuration.getInformerConfig(); + assertTrue(informerConfig.watchAllNamespaces()); + assertFalse(informerConfig.watchCurrentNamespace()); configuration = ControllerConfigurationOverrider.override(configuration) .settingNamespace("foo") .build(); - assertFalse(configuration.watchAllNamespaces()); - assertFalse(configuration.watchCurrentNamespace()); - assertEquals(Set.of("foo"), configuration.getNamespaces()); + informerConfig = configuration.getInformerConfig(); + assertFalse(informerConfig.watchAllNamespaces()); + assertFalse(informerConfig.watchCurrentNamespace()); + assertEquals(Set.of("foo"), informerConfig.getNamespaces()); configuration = ControllerConfigurationOverrider.override(configuration) .watchingOnlyCurrentNamespace() .build(); - assertFalse(configuration.watchAllNamespaces()); - assertTrue(configuration.watchCurrentNamespace()); + informerConfig = configuration.getInformerConfig(); + assertFalse(informerConfig.watchAllNamespaces()); + assertTrue(informerConfig.watchCurrentNamespace()); configuration = ControllerConfigurationOverrider.override(configuration) .watchingAllNamespaces() .build(); - assertTrue(configuration.watchAllNamespaces()); - assertFalse(configuration.watchCurrentNamespace()); + informerConfig = configuration.getInformerConfig(); + assertTrue(informerConfig.watchAllNamespaces()); + assertFalse(informerConfig.watchCurrentNamespace()); } @Test @@ -144,23 +150,24 @@ void itemStorePreserved() { configuration = ControllerConfigurationOverrider.override(configuration) .build(); - assertNotNull(configuration.getItemStore().orElse(null)); + assertNotNull(configuration.getInformerConfig().getItemStore()); } @Test void configuredDependentShouldNotChangeOnParentOverrideEvenWhenInitialConfigIsSame() { var configuration = createConfiguration(new OverriddenNSOnDepReconciler()); // retrieve the config for the first (and unique) dependent - var config = extractFirstDependentKubernetesResourceConfig(configuration); + var kubeDependentConfig = extractFirstDependentKubernetesResourceConfig(configuration); // override the parent NS to match the dependent's configuration = ControllerConfigurationOverrider.override(configuration) .settingNamespace(OverriddenNSDependent.DEP_NS).build(); - assertEquals(Set.of(OverriddenNSDependent.DEP_NS), configuration.getNamespaces()); + assertEquals(Set.of(OverriddenNSDependent.DEP_NS), + configuration.getInformerConfig().getNamespaces()); // check that the DependentResource inherits has its own configured NS - var informerConfig = config.informerConfig(); - assertEquals(Set.of(OverriddenNSDependent.DEP_NS), informerConfig.getNamespaces()); + assertEquals(Set.of(OverriddenNSDependent.DEP_NS), + kubeDependentConfig.informerConfig().getNamespaces()); // override the parent's NS final var newNS = "bar"; @@ -168,9 +175,9 @@ void configuredDependentShouldNotChangeOnParentOverrideEvenWhenInitialConfigIsSa ControllerConfigurationOverrider.override(configuration).settingNamespace(newNS).build(); // check that dependent config is still using its own NS - config = extractFirstDependentKubernetesResourceConfig(configuration); - informerConfig = config.informerConfig(); - assertEquals(Set.of(OverriddenNSDependent.DEP_NS), informerConfig.getNamespaces()); + kubeDependentConfig = extractFirstDependentKubernetesResourceConfig(configuration); + assertEquals(Set.of(OverriddenNSDependent.DEP_NS), + kubeDependentConfig.informerConfig().getNamespaces()); } @SuppressWarnings("unchecked") @@ -182,8 +189,7 @@ void dependentShouldWatchAllNamespacesIfParentDoesAsWell() { // check that the DependentResource inherits the controller's configuration if applicable var informerConfig = config.informerConfig(); - assertTrue( - inheritsNamespacesFromController(informerConfig.getNamespaces())); + assertTrue(inheritsNamespacesFromController(informerConfig.getNamespaces())); } @@ -196,7 +202,7 @@ void shouldBePossibleToForceDependentToWatchAllNamespaces() { // check that the DependentResource inherits the controller's configuration if applicable assertTrue( - ResourceConfiguration + InformerConfiguration .allNamespacesWatched(config.informerConfig().getNamespaces())); // override the NS @@ -207,12 +213,11 @@ void shouldBePossibleToForceDependentToWatchAllNamespaces() { // check that dependent config is still configured to watch all NS config = extractFirstDependentKubernetesResourceConfig(configuration); assertTrue( - ResourceConfiguration + InformerConfiguration .allNamespacesWatched(config.informerConfig().getNamespaces())); } @Test - @SuppressWarnings("unchecked") void overridingNamespacesShouldBePropagatedToDependentsWithDefaultConfig() { var configuration = createConfiguration(new OneDepReconciler()); // retrieve the config for the first (and unique) dependent diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/InformerConfigurationTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/InformerConfigurationTest.java new file mode 100644 index 0000000000..468c67e0d7 --- /dev/null +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/InformerConfigurationTest.java @@ -0,0 +1,83 @@ +package io.javaoperatorsdk.operator.api.config; + +import java.util.Collections; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.Constants; + +import static org.junit.jupiter.api.Assertions.*; + +class InformerConfigurationTest { + + @Test + void allNamespacesWatched() { + assertThrows(IllegalArgumentException.class, + () -> InformerConfiguration.allNamespacesWatched(null)); + assertThrows(IllegalArgumentException.class, () -> InformerConfiguration.allNamespacesWatched( + Set.of(Constants.WATCH_CURRENT_NAMESPACE, Constants.WATCH_ALL_NAMESPACES, "foo"))); + assertThrows(IllegalArgumentException.class, () -> InformerConfiguration.allNamespacesWatched( + Collections.emptySet())); + assertFalse(InformerConfiguration.allNamespacesWatched(Set.of("foo", "bar"))); + assertTrue(InformerConfiguration.allNamespacesWatched(Set.of(Constants.WATCH_ALL_NAMESPACES))); + assertFalse(InformerConfiguration.allNamespacesWatched(Set.of("foo"))); + assertFalse( + InformerConfiguration.allNamespacesWatched(Set.of(Constants.WATCH_CURRENT_NAMESPACE))); + } + + @Test + void currentNamespaceWatched() { + assertThrows(IllegalArgumentException.class, + () -> InformerConfiguration.currentNamespaceWatched(null)); + assertThrows(IllegalArgumentException.class, + () -> InformerConfiguration.currentNamespaceWatched( + Set.of(Constants.WATCH_CURRENT_NAMESPACE, Constants.WATCH_ALL_NAMESPACES, "foo"))); + assertThrows(IllegalArgumentException.class, + () -> InformerConfiguration.currentNamespaceWatched(Collections.emptySet())); + assertFalse(InformerConfiguration.currentNamespaceWatched(Set.of("foo", "bar"))); + assertFalse( + InformerConfiguration.currentNamespaceWatched(Set.of(Constants.WATCH_ALL_NAMESPACES))); + assertFalse(InformerConfiguration.currentNamespaceWatched(Set.of("foo"))); + assertTrue( + InformerConfiguration.currentNamespaceWatched(Set.of(Constants.WATCH_CURRENT_NAMESPACE))); + } + + @Test + void nullLabelSelectorByDefault() { + final var informerConfig = + InformerConfiguration.builder(ConfigMap.class).buildForInformerEventSource(); + assertNull(informerConfig.getLabelSelector()); + } + + @Test + void shouldWatchAllNamespacesByDefaultForControllers() { + final var informerConfig = InformerConfiguration.builder(ConfigMap.class).buildForController(); + assertTrue(informerConfig.watchAllNamespaces()); + } + + @Test + void shouldFollowControllerNamespacesByDefaultForInformerEventSource() { + final var informerConfig = + InformerConfiguration.builder(ConfigMap.class).buildForInformerEventSource(); + assertTrue(informerConfig.isFollowControllerNamespacesOnChange()); + } + + @Test + void failIfNotValid() { + assertThrows(IllegalArgumentException.class, () -> InformerConfiguration.failIfNotValid(null)); + assertThrows(IllegalArgumentException.class, + () -> InformerConfiguration.failIfNotValid(Collections.emptySet())); + assertThrows(IllegalArgumentException.class, () -> InformerConfiguration.failIfNotValid( + Set.of(Constants.WATCH_CURRENT_NAMESPACE, Constants.WATCH_ALL_NAMESPACES, "foo"))); + assertThrows(IllegalArgumentException.class, () -> InformerConfiguration.failIfNotValid( + Set.of(Constants.WATCH_CURRENT_NAMESPACE, "foo"))); + assertThrows(IllegalArgumentException.class, () -> InformerConfiguration.failIfNotValid( + Set.of(Constants.WATCH_ALL_NAMESPACES, "foo"))); + + // should work + InformerConfiguration.failIfNotValid(Set.of("foo", "bar")); + } +} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/MockControllerConfiguration.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/MockControllerConfiguration.java index 6ae83294bb..afd01d0f90 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/MockControllerConfiguration.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/MockControllerConfiguration.java @@ -1,6 +1,7 @@ package io.javaoperatorsdk.operator.api.config; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES_SET; import static org.mockito.ArgumentMatchers.any; @@ -18,9 +19,11 @@ public static ControllerConfiguration forResource( public static ControllerConfiguration forResource( Class resourceType, ConfigurationService configurationService) { final ControllerConfiguration configuration = mock(ControllerConfiguration.class); + final InformerConfiguration informerConfiguration = mock(InformerConfiguration.class); + when(configuration.getInformerConfig()).thenReturn(informerConfiguration); when(configuration.getResourceClass()).thenReturn(resourceType); - when(configuration.getNamespaces()).thenReturn(DEFAULT_NAMESPACES_SET); - when(configuration.getEffectiveNamespaces(any())).thenCallRealMethod(); + when(informerConfiguration.getNamespaces()).thenReturn(DEFAULT_NAMESPACES_SET); + when(informerConfiguration.getEffectiveNamespaces(any())).thenCallRealMethod(); when(configuration.getName()).thenReturn(resourceType.getSimpleName()); when(configuration.getConfigurationService()).thenReturn(configurationService); return configuration; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java deleted file mode 100644 index 5cf8376ea2..0000000000 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ResourceConfigurationTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package io.javaoperatorsdk.operator.api.config; - -import java.util.Collections; -import java.util.Set; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.reconciler.Constants; - -import static org.junit.jupiter.api.Assertions.*; - -class ResourceConfigurationTest { - - public static final ResourceConfiguration DEFAULT = - () -> InformerConfiguration.builder().buildForInformerEventSource(); - - @Test - void allNamespacesWatched() { - assertThrows(IllegalArgumentException.class, - () -> ResourceConfiguration.allNamespacesWatched(null)); - assertThrows(IllegalArgumentException.class, () -> ResourceConfiguration.allNamespacesWatched( - Set.of(Constants.WATCH_CURRENT_NAMESPACE, Constants.WATCH_ALL_NAMESPACES, "foo"))); - assertThrows(IllegalArgumentException.class, () -> ResourceConfiguration.allNamespacesWatched( - Collections.emptySet())); - assertFalse(ResourceConfiguration.allNamespacesWatched(Set.of("foo", "bar"))); - assertTrue(ResourceConfiguration.allNamespacesWatched(Set.of(Constants.WATCH_ALL_NAMESPACES))); - assertFalse(ResourceConfiguration.allNamespacesWatched(Set.of("foo"))); - assertFalse( - ResourceConfiguration.allNamespacesWatched(Set.of(Constants.WATCH_CURRENT_NAMESPACE))); - } - - @Test - void currentNamespaceWatched() { - assertThrows(IllegalArgumentException.class, - () -> ResourceConfiguration.currentNamespaceWatched(null)); - assertThrows(IllegalArgumentException.class, - () -> ResourceConfiguration.currentNamespaceWatched( - Set.of(Constants.WATCH_CURRENT_NAMESPACE, Constants.WATCH_ALL_NAMESPACES, "foo"))); - assertThrows(IllegalArgumentException.class, - () -> ResourceConfiguration.currentNamespaceWatched(Collections.emptySet())); - assertFalse(ResourceConfiguration.currentNamespaceWatched(Set.of("foo", "bar"))); - assertFalse( - ResourceConfiguration.currentNamespaceWatched(Set.of(Constants.WATCH_ALL_NAMESPACES))); - assertFalse(ResourceConfiguration.currentNamespaceWatched(Set.of("foo"))); - assertTrue( - ResourceConfiguration.currentNamespaceWatched(Set.of(Constants.WATCH_CURRENT_NAMESPACE))); - } - - @Test - void nullLabelSelectorByDefault() { - assertNull(DEFAULT.getLabelSelector()); - } - - // todo: fix me - @Disabled - @Test - void shouldWatchAllNamespacesByDefault() { - assertTrue(DEFAULT.watchAllNamespaces()); - } - - @Test - void failIfNotValid() { - assertThrows(IllegalArgumentException.class, () -> ResourceConfiguration.failIfNotValid(null)); - assertThrows(IllegalArgumentException.class, - () -> ResourceConfiguration.failIfNotValid(Collections.emptySet())); - assertThrows(IllegalArgumentException.class, () -> ResourceConfiguration.failIfNotValid( - Set.of(Constants.WATCH_CURRENT_NAMESPACE, Constants.WATCH_ALL_NAMESPACES, "foo"))); - assertThrows(IllegalArgumentException.class, () -> ResourceConfiguration.failIfNotValid( - Set.of(Constants.WATCH_CURRENT_NAMESPACE, "foo"))); - assertThrows(IllegalArgumentException.class, () -> ResourceConfiguration.failIfNotValid( - Set.of(Constants.WATCH_ALL_NAMESPACES, "foo"))); - - // should work - ResourceConfiguration.failIfNotValid(Set.of("foo", "bar")); - } -} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java index e24de96dbb..a7f0dade3b 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java @@ -168,14 +168,13 @@ void changesNamespacesOnControllerAndInformerEventSources() { when(controllerResourceEventSourceMock.allowsNamespaceChanges()).thenCallRealMethod(); var manager = new EventSourceManager(controller, eventSources); - InformerEventSourceConfiguration informerConfigurationMock = + InformerEventSourceConfiguration eventSourceConfigurationMock = mock(InformerEventSourceConfiguration.class); - when(informerConfigurationMock.followControllerNamespaceChanges()).thenReturn(true); InformerEventSource informerEventSource = mock(InformerEventSource.class); when(informerEventSource.name()).thenReturn("ies"); when(informerEventSource.resourceType()).thenReturn(TestCustomResource.class); - when(informerEventSource.configuration()).thenReturn(informerConfigurationMock); - when(informerEventSource.allowsNamespaceChanges()).thenCallRealMethod(); + when(informerEventSource.configuration()).thenReturn(eventSourceConfigurationMock); + when(informerEventSource.allowsNamespaceChanges()).thenReturn(true); manager.registerEventSource(informerEventSource); manager.changeNamespaces(Set.of(newNamespaces)); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java index 5282fd2138..4ba2a5184c 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSourceTest.java @@ -191,7 +191,6 @@ public TestConfiguration(boolean generationAware, OnAddFilter onUpdateFilter, GenericFilter genericFilter) { super( - TestCustomResource.class, "test", generationAware, null, diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java index 442f53bc98..ce027846f0 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java @@ -16,6 +16,7 @@ import io.javaoperatorsdk.operator.api.config.ConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.InformerStoppedHandler; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.processing.event.EventHandler; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -44,18 +45,19 @@ class InformerEventSourceTest { private final TemporaryResourceCache temporaryResourceCacheMock = mock(TemporaryResourceCache.class); private final EventHandler eventHandlerMock = mock(EventHandler.class); - private final InformerEventSourceConfiguration informerConfiguration = + private final InformerEventSourceConfiguration informerEventSourceConfiguration = mock(InformerEventSourceConfiguration.class); @BeforeEach void setup() { - when(informerConfiguration.getEffectiveNamespaces(any())) - .thenReturn(DEFAULT_NAMESPACES_SET); - when(informerConfiguration.getSecondaryToPrimaryMapper()) + final var informerConfig = mock(InformerConfiguration.class); + when(informerEventSourceConfiguration.getInformerConfig()).thenReturn(informerConfig); + when(informerConfig.getEffectiveNamespaces(any())).thenReturn(DEFAULT_NAMESPACES_SET); + when(informerEventSourceConfiguration.getSecondaryToPrimaryMapper()) .thenReturn(mock(SecondaryToPrimaryMapper.class)); - when(informerConfiguration.getResourceClass()).thenReturn(Deployment.class); + when(informerEventSourceConfiguration.getResourceClass()).thenReturn(Deployment.class); - informerEventSource = new InformerEventSource<>(informerConfiguration, clientMock); + informerEventSource = new InformerEventSource<>(informerEventSourceConfiguration, clientMock); var mockControllerConfig = mock(ControllerConfiguration.class); when(mockControllerConfig.getConfigurationService()).thenReturn(new BaseConfigurationService()); @@ -63,7 +65,7 @@ void setup() { informerEventSource.setEventHandler(eventHandlerMock); informerEventSource.setControllerConfiguration(mockControllerConfig); SecondaryToPrimaryMapper secondaryToPrimaryMapper = mock(SecondaryToPrimaryMapper.class); - when(informerConfiguration.getSecondaryToPrimaryMapper()) + when(informerEventSourceConfiguration.getSecondaryToPrimaryMapper()) .thenReturn(secondaryToPrimaryMapper); when(secondaryToPrimaryMapper.toPrimaryResourceIDs(any())) .thenReturn(Set.of(ResourceID.fromResource(testDeployment()))); @@ -184,7 +186,7 @@ void informerStoppedHandlerShouldBeCalledWhenInformerStops() { var mockControllerConfig = mock(ControllerConfiguration.class); when(mockControllerConfig.getConfigurationService()).thenReturn(configuration); - informerEventSource = new InformerEventSource<>(informerConfiguration, + informerEventSource = new InformerEventSource<>(informerEventSourceConfiguration, MockKubernetesClient.client(Deployment.class, unused -> { throw exception; })); diff --git a/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationService.java b/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationService.java index 12573b50f7..1a1214aa78 100644 --- a/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationService.java +++ b/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationService.java @@ -11,7 +11,6 @@ public class DefaultConfigurationService extends BaseConfigurationService { @Override protected ControllerConfiguration configFor(Reconciler reconciler) { final var other = super.configFor(reconciler); - return new ResolvedControllerConfiguration<>( - RuntimeControllerMetadata.getResourceClass(reconciler), other); + return new ResolvedControllerConfiguration<>(other); } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java index bde573171d..77a3b245b0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java @@ -71,7 +71,10 @@ public List> prepareE var config = InformerEventSourceConfiguration .from(ConfigMap.class, MultipleSecondaryEventSourceCustomResource.class) .withInformerConfiguration(c -> c - .withNamespaces(context.getControllerConfiguration().getNamespaces()) + // TODO: this shouldn't be needed since this should be the default behavior (tracking + // the controller's namespaces) + .withNamespaces( + context.getControllerConfiguration().getInformerConfig().getNamespaces()) .withLabelSelector("multisecondary")) .withSecondaryToPrimaryMapper(s -> { var name = diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java index 2f89bb6892..d239122314 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java @@ -117,19 +117,21 @@ void missingAnnotationCreatesDefaultConfig() { var config = configFor(reconciler); assertThat(config.getName()).isEqualTo(ReconcilerUtils.getNameFor(reconciler)); - assertThat(config.getLabelSelector()).isNull(); assertThat(config.getRetry()).isInstanceOf(GenericRetry.class); assertThat(config.getRateLimiter()).isInstanceOf(LinearRateLimiter.class); assertThat(config.maxReconciliationInterval()).hasValue(Duration.ofHours(DEFAULT_INTERVAL)); assertThat(config.fieldManager()).isEqualTo(config.getName()); - assertThat(config.getInformerListLimit()).isEmpty(); - assertThat(config.onAddFilter()).isEmpty(); - assertThat(config.onUpdateFilter()).isEmpty(); - assertThat(config.genericFilter()).isEmpty(); - assertThat(config.getNamespaces()).isEqualTo(Constants.DEFAULT_NAMESPACES_SET); assertThat(config.getFinalizerName()) .isEqualTo(ReconcilerUtils.getDefaultFinalizerName(config.getResourceClass())); - assertThat(config.getItemStore()).isEmpty(); + + final var informerConfig = config.getInformerConfig(); + assertThat(informerConfig.getLabelSelector()).isNull(); + assertNull(informerConfig.getInformerListLimit()); + assertNull(informerConfig.getOnAddFilter()); + assertNull(informerConfig.getOnUpdateFilter()); + assertNull(informerConfig.getGenericFilter()); + assertNull(informerConfig.getItemStore()); + assertThat(informerConfig.getNamespaces()).isEqualTo(Constants.DEFAULT_NAMESPACES_SET); } @SuppressWarnings("rawtypes") diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index b38f48b912..15343793fd 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -85,7 +85,7 @@ private void initDependentResources(KubernetesClient client) { Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR) .forEach(dr -> dr.configureWith(new KubernetesDependentResourceConfigBuilder() - .withKubernetesDependentInformerConfig(InformerConfiguration.builder() + .withKubernetesDependentInformerConfig(InformerConfiguration.builder(dr.resourceType()) .withLabelSelector(DEPENDENT_RESOURCE_LABEL_SELECTOR) .buildForInformerEventSource()) .build())); diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java index e7930a3658..580d529a72 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java @@ -96,7 +96,7 @@ private Workflow createDependentResourcesAndWorkflow() { // configure them with our label selector Arrays.asList(configMapDR, deploymentDR, serviceDR, ingressDR) .forEach(dr -> dr.configureWith(new KubernetesDependentResourceConfigBuilder() - .withKubernetesDependentInformerConfig(InformerConfiguration.builder() + .withKubernetesDependentInformerConfig(InformerConfiguration.builder(dr.resourceType()) .withLabelSelector(SELECTOR + "=true") .buildForInformerEventSource()) .build())); From 1a449c403d87bd60dfb17a72d65a47028069fa5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 20 Aug 2024 13:29:11 +0200 Subject: [PATCH 72/96] feat: support to handle different cluster for InformerEventSource (#2499) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros Signed-off-by: Chris Laprun Co-authored-by: Chris Laprun --- docs/content/en/docs/features/_index.md | 19 ++++ .../InformerEventSourceConfiguration.java | 33 ++++++- .../source/informer/InformerEventSource.java | 19 ++-- .../InformerRemoteClusterCustomResource.java | 14 +++ .../InformerRemoteClusterIT.java | 88 +++++++++++++++++++ .../InformerRemoteClusterReconciler.java | 65 ++++++++++++++ .../InformerRemoteClusterStatus.java | 14 +++ .../LabelSelectorTestReconciler.java | 1 + 8 files changed, 241 insertions(+), 12 deletions(-) create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterReconciler.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterStatus.java diff --git a/docs/content/en/docs/features/_index.md b/docs/content/en/docs/features/_index.md index 6832e31438..17c385e119 100644 --- a/docs/content/en/docs/features/_index.md +++ b/docs/content/en/docs/features/_index.md @@ -608,6 +608,25 @@ parts of reconciliation logic and during the execution of the controller: For more information about MDC see this [link](https://www.baeldung.com/mdc-in-log4j-2-logback). +## InformerEventSource Multi-Cluster Support + +It is possible to handle resources for remote cluster with `InformerEventSource`. To do so, +simply set a client that connects to a remote cluster: + +```java + +InformerEventSourceConfiguration configuration = + InformerEventSourceConfiguration.from(SecondaryResource.class, PrimaryResource.class) + .withKubernetesClient(remoteClusterClient) + .withSecondaryToPrimaryMapper(Mappers.fromDefaultAnnotations()); + +``` + +You will also need to specify a `SecondaryToPrimaryMapper`, since the default one +is based on owner references and won't work across cluster instances. You could, for example, use the provided implementation that relies on annotations added to the secondary resources to identify the associated primary resource. + +See related [integration test](https://github.com/operator-framework/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster). + ## Dynamically Changing Target Namespaces A controller can be configured to watch a specific set of namespaces in addition of the diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java index 20e6c7f131..9ad6dded4c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java @@ -6,6 +6,7 @@ import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.config.Informable; import io.javaoperatorsdk.operator.processing.GroupVersionKind; import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper; @@ -57,22 +58,33 @@ default String name() { return getInformerConfig().getName(); } + /** + * Optional, specific kubernetes client, typically to connect to a different cluster than the rest + * of the operator. Note that this is solely for multi cluster support. + */ + default Optional getKubernetesClient() { + return Optional.empty(); + } + class DefaultInformerEventSourceConfiguration implements InformerEventSourceConfiguration { private final PrimaryToSecondaryMapper primaryToSecondaryMapper; private final SecondaryToPrimaryMapper secondaryToPrimaryMapper; private final GroupVersionKind groupVersionKind; private final InformerConfiguration informerConfig; + private final KubernetesClient kubernetesClient; protected DefaultInformerEventSourceConfiguration( GroupVersionKind groupVersionKind, PrimaryToSecondaryMapper primaryToSecondaryMapper, SecondaryToPrimaryMapper secondaryToPrimaryMapper, - InformerConfiguration informerConfig) { + InformerConfiguration informerConfig, + KubernetesClient kubernetesClient) { this.informerConfig = Objects.requireNonNull(informerConfig); this.groupVersionKind = groupVersionKind; this.primaryToSecondaryMapper = primaryToSecondaryMapper; this.secondaryToPrimaryMapper = secondaryToPrimaryMapper; + this.kubernetesClient = kubernetesClient; } @Override @@ -95,8 +107,12 @@ public

PrimaryToSecondaryMapper

getPrimaryToSecondary public Optional getGroupVersionKind() { return Optional.ofNullable(groupVersionKind); } - } + @Override + public Optional getKubernetesClient() { + return Optional.ofNullable(kubernetesClient); + } + } @SuppressWarnings({"unused", "UnusedReturnValue"}) class Builder { @@ -108,6 +124,7 @@ class Builder { private String name; private PrimaryToSecondaryMapper primaryToSecondaryMapper; private SecondaryToPrimaryMapper secondaryToPrimaryMapper; + private KubernetesClient kubernetesClient; private Builder(Class resourceClass, Class primaryResourceClass) { @@ -152,6 +169,16 @@ public Builder withSecondaryToPrimaryMapper( return this; } + /** + * Use this is case want to create an InformerEventSource that handles resources from different + * cluster. + */ + public Builder withKubernetesClient( + KubernetesClient kubernetesClient) { + this.kubernetesClient = kubernetesClient; + return this; + } + public String getName() { return name; } @@ -192,7 +219,7 @@ public InformerEventSourceConfiguration build() { Objects.requireNonNullElse(secondaryToPrimaryMapper, Mappers.fromOwnerReferences(HasMetadata.getApiVersion(primaryResourceClass), HasMetadata.getKind(primaryResourceClass), false)), - config.buildForInformerEventSource()); + config.buildForInformerEventSource(), kubernetesClient); } } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java index 2568683600..48534a27b3 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java @@ -1,6 +1,8 @@ package io.javaoperatorsdk.operator.processing.event.source.informer; -import java.util.*; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; import org.slf4j.Logger; @@ -67,10 +69,8 @@ public class InformerEventSource extends ManagedInformerEventSource> implements ResourceEventHandler { - public static String PREVIOUS_ANNOTATION_KEY = "javaoperatorsdk.io/previous"; - private static final Logger log = LoggerFactory.getLogger(InformerEventSource.class); - + public static final String PREVIOUS_ANNOTATION_KEY = "javaoperatorsdk.io/previous"; // we need direct control for the indexer to propagate the just update resource also to the index private final PrimaryToSecondaryIndex primaryToSecondaryIndex; private final PrimaryToSecondaryMapper

primaryToSecondaryMapper; @@ -78,7 +78,8 @@ public class InformerEventSource public InformerEventSource( InformerEventSourceConfiguration configuration, EventSourceContext

context) { - this(configuration, context.getClient(), + this(configuration, + configuration.getKubernetesClient().orElse(context.getClient()), context.getControllerConfiguration().getConfigurationService() .parseResourceVersionsForEventFilteringAndCaching()); } @@ -287,10 +288,6 @@ private boolean eventAcceptedByFilter(Operation operation, R newObject, R oldObj } } - private enum Operation { - ADD, UPDATE - } - private boolean acceptedByDeleteFilters(R resource, boolean b) { return (onDeleteFilter == null || onDeleteFilter.accept(resource, b)) && (genericFilter == null || genericFilter.accept(resource)); @@ -307,4 +304,8 @@ public R addPreviousAnnotation(String resourceVersion, R target) { id + Optional.ofNullable(resourceVersion).map(rv -> "," + rv).orElse("")); return target; } + + private enum Operation { + ADD, UPDATE + } } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterCustomResource.java new file mode 100644 index 0000000000..c7e6ee43b4 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterCustomResource.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.baseapi.informerremotecluster; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("irc") +public class InformerRemoteClusterCustomResource + extends CustomResource implements Namespaced { +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterIT.java new file mode 100644 index 0000000000..3ad274d954 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterIT.java @@ -0,0 +1,88 @@ +package io.javaoperatorsdk.operator.baseapi.informerremotecluster; + +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubeapitest.junit.EnableKubeAPIServer; +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; + +import static io.javaoperatorsdk.operator.baseapi.informerremotecluster.InformerRemoteClusterReconciler.DATA_KEY; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +@EnableKubeAPIServer +class InformerRemoteClusterIT { + + public static final String NAME = "test1"; + public static final String CONFIG_MAP_NAME = "testcm"; + public static final String INITIAL_VALUE = "initial_value"; + public static final String CHANGED_VALUE = "changed_value"; + public static final String CM_NAMESPACE = "default"; + + // injected by Kube API Test. Client for another cluster. + static KubernetesClient kubernetesClient; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(new InformerRemoteClusterReconciler(kubernetesClient)) + .build(); + + @Test + void testRemoteClusterInformer() { + var r = extension.create(testCustomResource()); + + var cm = kubernetesClient.configMaps() + .resource(remoteConfigMap(r.getMetadata().getName(), + r.getMetadata().getNamespace())) + .create(); + + // config map does not exist on the primary resource cluster + assertThat(extension.getKubernetesClient().configMaps() + .inNamespace(CM_NAMESPACE) + .withName(CONFIG_MAP_NAME).get()).isNull(); + + await().untilAsserted(() -> { + var cr = extension.get(InformerRemoteClusterCustomResource.class, NAME); + assertThat(cr.getStatus()).isNotNull(); + assertThat(cr.getStatus().getRemoteConfigMapMessage()).isEqualTo(INITIAL_VALUE); + }); + + cm.getData().put(DATA_KEY, CHANGED_VALUE); + kubernetesClient.configMaps().resource(cm).update(); + + await().untilAsserted(() -> { + var cr = extension.get(InformerRemoteClusterCustomResource.class, NAME); + assertThat(cr.getStatus().getRemoteConfigMapMessage()).isEqualTo(CHANGED_VALUE); + }); + } + + InformerRemoteClusterCustomResource testCustomResource() { + var res = new InformerRemoteClusterCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(NAME) + .build()); + return res; + } + + ConfigMap remoteConfigMap(String ownerName, String ownerNamespace) { + return new ConfigMapBuilder() + .withMetadata(new ObjectMetaBuilder() + .withName(CONFIG_MAP_NAME) + .withNamespace(CM_NAMESPACE) + .withAnnotations(Map.of( + Mappers.DEFAULT_ANNOTATION_FOR_NAME, ownerName, + Mappers.DEFAULT_ANNOTATION_FOR_NAMESPACE, ownerNamespace)) + .build()) + .withData(Map.of(DATA_KEY, INITIAL_VALUE)) + .build(); + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterReconciler.java new file mode 100644 index 0000000000..44d81f5327 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterReconciler.java @@ -0,0 +1,65 @@ +package io.javaoperatorsdk.operator.baseapi.informerremotecluster; + +import java.util.List; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; +import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.processing.event.source.EventSource; +import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; +import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers; + +@ControllerConfiguration +public class InformerRemoteClusterReconciler + implements Reconciler { + + public static final String DATA_KEY = "key"; + + private final KubernetesClient remoteClient; + + public InformerRemoteClusterReconciler(KubernetesClient remoteClient) { + this.remoteClient = remoteClient; + } + + @Override + public UpdateControl reconcile( + InformerRemoteClusterCustomResource resource, + Context context) throws Exception { + + return context.getSecondaryResource(ConfigMap.class).map(cm -> { + var r = new InformerRemoteClusterCustomResource(); + r.setMetadata(new ObjectMetaBuilder() + .withName(resource.getMetadata().getName()) + .withNamespace(resource.getMetadata().getNamespace()) + .build()); + r.setStatus(new InformerRemoteClusterStatus()); + r.getStatus().setRemoteConfigMapMessage(cm.getData().get(DATA_KEY)); + return UpdateControl.patchStatus(r); + }).orElseGet(UpdateControl::noUpdate); + } + + @Override + public List> prepareEventSources( + EventSourceContext context) { + + var es = new InformerEventSource<>(InformerEventSourceConfiguration + .from(ConfigMap.class, InformerRemoteClusterCustomResource.class) + // owner references do not work cross cluster, using + // annotations here to reference primary resource + .withSecondaryToPrimaryMapper(Mappers.fromDefaultAnnotations()) + // setting remote client for informer + .withKubernetesClient(remoteClient) + .withInformerConfiguration( + InformerConfiguration.Builder::withWatchAllNamespaces) + .build(), context); + + return List.of(es); + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterStatus.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterStatus.java new file mode 100644 index 0000000000..e49322fb10 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterStatus.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.baseapi.informerremotecluster; + +public class InformerRemoteClusterStatus { + + private String remoteConfigMapMessage; + + public String getRemoteConfigMapMessage() { + return remoteConfigMapMessage; + } + + public void setRemoteConfigMapMessage(String remoteConfigMapMessage) { + this.remoteConfigMapMessage = remoteConfigMapMessage; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java index 771effc3a1..a225f6a7be 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/labelselector/LabelSelectorTestReconciler.java @@ -22,6 +22,7 @@ public class LabelSelectorTestReconciler @Override public UpdateControl reconcile( LabelSelectorTestCustomResource resource, Context context) { + numberOfExecutions.addAndGet(1); return UpdateControl.noUpdate(); } From 146abe08240cdec82222c3309e81d2622fb89992 Mon Sep 17 00:00:00 2001 From: matteriben <159169801+matteriben@users.noreply.github.com> Date: Wed, 21 Aug 2024 12:49:59 -0500 Subject: [PATCH 73/96] chore: update comment to reflect change in interface (#2512) Signed-off-by: Matt Riben --- .../processing/dependent/BulkDependentResource.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java index a54027e4c3..957a969ecc 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java @@ -8,10 +8,9 @@ import io.javaoperatorsdk.operator.processing.dependent.Matcher.Result; /** - * Manages dynamic number of resources created for a primary resource. Since the point of a bulk - * dependent resource is to manage the number of secondary resources dynamically it implement - * {@link Creator} and {@link Deleter} interfaces out of the box. A concrete dependent resource can - * implement additionally also {@link Updater}. + * Manages dynamic number of resources created for a primary resource. A dependent resource + * implementing this interface will typically also implement one or more additional interfaces such + * as {@link Creator}, {@link Updater}, {@link Deleter}. * * @param the dependent resource type * @param

the primary resource type From c294e473b1ac65a14a87b355e13bc1d3e3520e3d Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 29 Aug 2024 22:16:42 +0200 Subject: [PATCH 74/96] fix: wrong return type Signed-off-by: Chris Laprun --- .../kubernetes/GenericKubernetesDependentResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java index 4b1396d408..c5dd08069e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/GenericKubernetesDependentResource.java @@ -27,7 +27,7 @@ protected InformerEventSourceConfiguration.Builder in } @SuppressWarnings("unused") - public GroupVersionKind getGroupVersionKind() { + public GroupVersionKindPlural getGroupVersionKind() { return groupVersionKind; } } From 585e41281416398cc405895bcaff852c44b9398c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 6 Sep 2024 16:50:23 +0200 Subject: [PATCH 75/96] improve: cleaner throws Exception (#2527) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../io/javaoperatorsdk/operator/api/reconciler/Cleaner.java | 2 +- .../java/io/javaoperatorsdk/operator/processing/Controller.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java index 1e75764f80..cd683fbc31 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java @@ -27,6 +27,6 @@ public interface Cleaner

{ * that it can be safely deleted. * @see DeleteControl#noFinalizerRemoval() */ - DeleteControl cleanup(P resource, Context

context); + DeleteControl cleanup(P resource, Context

context) throws Exception; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 40fb23def8..d62dcd7b9a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -188,7 +188,7 @@ public Map metadata() { } @Override - public DeleteControl execute() { + public DeleteControl execute() throws Exception { initContextIfNeeded(resource, context); WorkflowCleanupResult workflowCleanupResult = null; From f2311b5fcf97b227f34f60c73c823ea3a11cda15 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 19 Sep 2024 15:17:13 +0200 Subject: [PATCH 76/96] feat: explicit node configuration in WorkflowBuilder (#2511) * feat: explicit node configuration in WorkflowBuilder Fixes #2284 Signed-off-by: Chris Laprun * refactor: rename more appropriately Signed-off-by: Chris Laprun --------- Signed-off-by: Chris Laprun --- .../dependent/workflow/WorkflowBuilder.java | 115 ++++++++++----- .../workflow/WorkflowCleanupExecutorTest.java | 50 +++---- .../WorkflowReconcileExecutorTest.java | 135 +++++++++--------- .../dependent/workflow/WorkflowTest.java | 16 +-- .../WebPageDependentsWorkflowReconciler.java | 3 +- ...WebPageStandaloneDependentsReconciler.java | 2 +- 6 files changed, 181 insertions(+), 140 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java index 7bb5f75f6f..20f40c5a83 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java @@ -16,50 +16,25 @@ public class WorkflowBuilder

{ private final Map> dependentResourceNodes = new HashMap<>(); private boolean throwExceptionAutomatically = THROW_EXCEPTION_AUTOMATICALLY_DEFAULT; - private DependentResourceNode currentNode; private boolean isCleaner = false; - public WorkflowBuilder

addDependentResource(DependentResource dependentResource) { - currentNode = new DependentResourceNode<>(dependentResource); - isCleaner = isCleaner || dependentResource.isDeletable(); - final var actualName = dependentResource.name(); - dependentResourceNodes.put(actualName, currentNode); - return this; - } - - public WorkflowBuilder

dependsOn(Set dependentResources) { - for (var dependentResource : dependentResources) { - var dependsOn = getNodeByDependentResource(dependentResource); - currentNode.addDependsOnRelation(dependsOn); - } - return this; - } - - public WorkflowBuilder

dependsOn(DependentResource... dependentResources) { - if (dependentResources != null) { - return dependsOn(new HashSet<>(Arrays.asList(dependentResources))); - } - return this; + public WorkflowNodeConfigurationBuilder addDependentResourceAndConfigure( + DependentResource dependentResource) { + final var currentNode = doAddDependentResource(dependentResource); + return new WorkflowNodeConfigurationBuilder(currentNode); } - public WorkflowBuilder

withReconcilePrecondition(Condition reconcilePrecondition) { - currentNode.setReconcilePrecondition(reconcilePrecondition); - return this; - } - - public WorkflowBuilder

withReadyPostcondition(Condition readyPostcondition) { - currentNode.setReadyPostcondition(readyPostcondition); - return this; - } - - public WorkflowBuilder

withDeletePostcondition(Condition deletePostcondition) { - currentNode.setDeletePostcondition(deletePostcondition); + public WorkflowBuilder

addDependentResource(DependentResource dependentResource) { + doAddDependentResource(dependentResource); return this; } - public WorkflowBuilder

withActivationCondition(Condition activationCondition) { - currentNode.setActivationCondition(activationCondition); - return this; + private DependentResourceNode doAddDependentResource(DependentResource dependentResource) { + final var currentNode = new DependentResourceNode<>(dependentResource); + isCleaner = isCleaner || dependentResource.isDeletable(); + final var actualName = dependentResource.name(); + dependentResourceNodes.put(actualName, currentNode); + return currentNode; } DependentResourceNode getNodeByDependentResource(DependentResource dependentResource) { @@ -88,4 +63,70 @@ DefaultWorkflow

buildAsDefaultWorkflow() { return new DefaultWorkflow(new HashSet<>(dependentResourceNodes.values()), throwExceptionAutomatically, isCleaner); } + + public class WorkflowNodeConfigurationBuilder { + private final DependentResourceNode currentNode; + + private WorkflowNodeConfigurationBuilder(DependentResourceNode currentNode) { + this.currentNode = currentNode; + } + + public WorkflowBuilder

addDependentResource(DependentResource dependentResource) { + return WorkflowBuilder.this.addDependentResource(dependentResource); + } + + public WorkflowNodeConfigurationBuilder addDependentResourceAndConfigure( + DependentResource dependentResource) { + final var currentNode = WorkflowBuilder.this.doAddDependentResource(dependentResource); + return new WorkflowNodeConfigurationBuilder(currentNode); + } + + public Workflow

build() { + return WorkflowBuilder.this.build(); + } + + DefaultWorkflow

buildAsDefaultWorkflow() { + return WorkflowBuilder.this.buildAsDefaultWorkflow(); + } + + public WorkflowBuilder

withThrowExceptionFurther(boolean throwExceptionFurther) { + return WorkflowBuilder.this.withThrowExceptionFurther(throwExceptionFurther); + } + + public WorkflowNodeConfigurationBuilder toDependOn(Set dependentResources) { + for (var dependentResource : dependentResources) { + var dependsOn = getNodeByDependentResource(dependentResource); + currentNode.addDependsOnRelation(dependsOn); + } + return this; + } + + public WorkflowNodeConfigurationBuilder toDependOn(DependentResource... dependentResources) { + if (dependentResources != null) { + return toDependOn(new HashSet<>(Arrays.asList(dependentResources))); + } + return this; + } + + public WorkflowNodeConfigurationBuilder withReconcilePrecondition( + Condition reconcilePrecondition) { + currentNode.setReconcilePrecondition(reconcilePrecondition); + return this; + } + + public WorkflowNodeConfigurationBuilder withReadyPostcondition(Condition readyPostcondition) { + currentNode.setReadyPostcondition(readyPostcondition); + return this; + } + + public WorkflowNodeConfigurationBuilder withDeletePostcondition(Condition deletePostcondition) { + currentNode.setDeletePostcondition(deletePostcondition); + return this; + } + + public WorkflowNodeConfigurationBuilder withActivationCondition(Condition activationCondition) { + currentNode.setActivationCondition(activationCondition); + return this; + } + } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java index 461a043862..2d9dee6fc8 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java @@ -54,9 +54,9 @@ void setup() { void cleanUpDiamondWorkflow() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResource(dr1).dependsOn(dd1) - .addDependentResource(dd2).dependsOn(dd1) - .addDependentResource(dd3).dependsOn(dr1, dd2) + .addDependentResourceAndConfigure(dr1).toDependOn(dd1) + .addDependentResourceAndConfigure(dd2).toDependOn(dd1) + .addDependentResourceAndConfigure(dd3).toDependOn(dr1, dd2) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -73,9 +73,9 @@ void cleanUpDiamondWorkflow() { void dontDeleteIfDependentErrored() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResource(dd2).dependsOn(dd1) - .addDependentResource(dd3).dependsOn(dd2) - .addDependentResource(errorDD).dependsOn(dd2) + .addDependentResourceAndConfigure(dd2).toDependOn(dd1) + .addDependentResourceAndConfigure(dd3).toDependOn(dd2) + .addDependentResourceAndConfigure(errorDD).toDependOn(dd2) .withThrowExceptionFurther(false) .build(); @@ -95,7 +95,8 @@ void dontDeleteIfDependentErrored() { void cleanupConditionTrivialCase() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResource(dd2).dependsOn(dd1).withDeletePostcondition(notMetCondition) + .addDependentResourceAndConfigure(dd2).toDependOn(dd1) + .withDeletePostcondition(notMetCondition) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -110,7 +111,7 @@ void cleanupConditionTrivialCase() { void cleanupConditionMet() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResource(dd2).dependsOn(dd1).withDeletePostcondition(metCondition) + .addDependentResourceAndConfigure(dd2).toDependOn(dd1).withDeletePostcondition(metCondition) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -126,9 +127,10 @@ void cleanupConditionMet() { void cleanupConditionDiamondWorkflow() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResource(dd2).dependsOn(dd1) - .addDependentResource(dd3).dependsOn(dd1).withDeletePostcondition(notMetCondition) - .addDependentResource(dd4).dependsOn(dd2, dd3) + .addDependentResourceAndConfigure(dd2).toDependOn(dd1) + .addDependentResourceAndConfigure(dd3).toDependOn(dd1) + .withDeletePostcondition(notMetCondition) + .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -162,10 +164,10 @@ void dontDeleteIfGarbageCollected() { void ifDependentActiveDependentNormallyDeleted() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResource(dd2).dependsOn(dd1) - .addDependentResource(dd3).dependsOn(dd1) + .addDependentResourceAndConfigure(dd2).toDependOn(dd1) + .addDependentResourceAndConfigure(dd3).toDependOn(dd1) .withActivationCondition(metCondition) - .addDependentResource(dd4).dependsOn(dd2, dd3) + .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -182,11 +184,11 @@ void ifDependentActiveDependentNormallyDeleted() { void ifDependentActiveDeletePostConditionIsChecked() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResource(dd2).dependsOn(dd1) - .addDependentResource(dd3).dependsOn(dd1) + .addDependentResourceAndConfigure(dd2).toDependOn(dd1) + .addDependentResourceAndConfigure(dd3).toDependOn(dd1) .withDeletePostcondition(notMetCondition) .withActivationCondition(metCondition) - .addDependentResource(dd4).dependsOn(dd2, dd3) + .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -206,10 +208,10 @@ void ifDependentActiveDeletePostConditionIsChecked() { void ifDependentInactiveDeleteIsNotCalled() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResource(dd2).dependsOn(dd1) - .addDependentResource(dd3).dependsOn(dd1) + .addDependentResourceAndConfigure(dd2).toDependOn(dd1) + .addDependentResourceAndConfigure(dd3).toDependOn(dd1) .withActivationCondition(notMetCondition) - .addDependentResource(dd4).dependsOn(dd2, dd3) + .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -225,11 +227,11 @@ void ifDependentInactiveDeleteIsNotCalled() { void ifDependentInactiveDeletePostConditionNotChecked() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResource(dd2).dependsOn(dd1) - .addDependentResource(dd3).dependsOn(dd1) + .addDependentResourceAndConfigure(dd2).toDependOn(dd1) + .addDependentResourceAndConfigure(dd3).toDependOn(dd1) .withDeletePostcondition(notMetCondition) .withActivationCondition(notMetCondition) - .addDependentResource(dd4).dependsOn(dd2, dd3) + .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -243,7 +245,7 @@ void ifDependentInactiveDeletePostConditionNotChecked() { @Test void singleInactiveDependent() { var workflow = new WorkflowBuilder() - .addDependentResource(dd1) + .addDependentResourceAndConfigure(dd1) .withActivationCondition(notMetCondition) .build(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java index 996dd66e38..340f308d86 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java @@ -54,7 +54,7 @@ void reconcileTopLevelResources() { void reconciliationWithSimpleDependsOn() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -71,8 +71,8 @@ void reconciliationWithTwoTheDependsOns() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(dr2).dependsOn(dr1) - .addDependentResource(dr3).dependsOn(dr1) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr3).toDependOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -89,9 +89,9 @@ void reconciliationWithTwoTheDependsOns() { void diamondShareWorkflowReconcile() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(dr2).dependsOn(dr1) - .addDependentResource(dr3).dependsOn(dr1) - .addDependentResource(dr4).dependsOn(dr3).dependsOn(dr2) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr3).toDependOn(dr1) + .addDependentResourceAndConfigure(dr4).toDependOn(dr3).toDependOn(dr2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -129,8 +129,8 @@ void exceptionHandlingSimpleCases() { void dependentsOnErroredResourceNotReconciled() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(drError).dependsOn(dr1) - .addDependentResource(dr2).dependsOn(drError) + .addDependentResourceAndConfigure(drError).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).toDependOn(drError) .withThrowExceptionFurther(false) .build(); @@ -149,9 +149,9 @@ void oneBranchErrorsOtherCompletes() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(drError).dependsOn(dr1) - .addDependentResource(dr2).dependsOn(dr1) - .addDependentResource(dr3).dependsOn(dr2) + .addDependentResourceAndConfigure(drError).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr3).toDependOn(dr2) .withThrowExceptionFurther(false) .build(); @@ -170,7 +170,7 @@ void onlyOneDependsOnErroredResourceNotReconciled() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) .addDependentResource(drError) - .addDependentResource(dr2).dependsOn(drError, dr1) + .addDependentResourceAndConfigure(dr2).toDependOn(drError, dr1) .withThrowExceptionFurther(false) .build(); @@ -197,9 +197,9 @@ public Result detailedIsMet( }; var workflow = new WorkflowBuilder() - .addDependentResource(dr1).withReconcilePrecondition(unmetWithResult) - .addDependentResource(dr2).withReconcilePrecondition(metCondition) - .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition) + .addDependentResourceAndConfigure(dr1).withReconcilePrecondition(unmetWithResult) + .addDependentResourceAndConfigure(dr2).withReconcilePrecondition(metCondition) + .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -217,9 +217,9 @@ public Result detailedIsMet( void triangleOnceConditionNotMet() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(dr2).dependsOn(dr1) - .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition) - .dependsOn(dr1) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) + .toDependOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -236,11 +236,11 @@ void reconcileConditionTransitiveDelete() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) .withReconcilePrecondition(notMetCondition) - .addDependentResource(drDeleter).dependsOn(dr2) + .addDependentResourceAndConfigure(drDeleter).toDependOn(dr2) .withReconcilePrecondition(metCondition) - .addDependentResource(drDeleter2).dependsOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) .withReconcilePrecondition(metCondition) .build(); @@ -262,8 +262,8 @@ void reconcileConditionAlsoErrorDependsOn() { var workflow = new WorkflowBuilder() .addDependentResource(drError) - .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition) - .addDependentResource(drDeleter2).dependsOn(drError, drDeleter) + .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) + .addDependentResourceAndConfigure(drDeleter2).toDependOn(drError, drDeleter) .withReconcilePrecondition(metCondition) .withThrowExceptionFurther(false) .build(); @@ -285,8 +285,8 @@ void reconcileConditionAlsoErrorDependsOn() { void oneDependsOnConditionNotMet() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(dr2).withReconcilePrecondition(notMetCondition) - .addDependentResource(drDeleter).dependsOn(dr1, dr2) + .addDependentResourceAndConfigure(dr2).withReconcilePrecondition(notMetCondition) + .addDependentResourceAndConfigure(drDeleter).toDependOn(dr1, dr2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -304,9 +304,9 @@ void deletedIfReconcileConditionNotMet() { TestDeleterDependent drDeleter2 = new TestDeleterDependent("DR_DELETER_2"); var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(drDeleter).dependsOn(dr1) + .addDependentResourceAndConfigure(drDeleter).toDependOn(dr1) .withReconcilePrecondition(notMetCondition) - .addDependentResource(drDeleter2).dependsOn(dr1, drDeleter) + .addDependentResourceAndConfigure(drDeleter2).toDependOn(dr1, drDeleter) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -328,11 +328,11 @@ void deleteDoneInReverseOrder() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition) - .dependsOn(dr1) - .addDependentResource(drDeleter2).dependsOn(drDeleter) - .addDependentResource(drDeleter3).dependsOn(drDeleter) - .addDependentResource(drDeleter4).dependsOn(drDeleter3) + .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) + .toDependOn(dr1) + .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter4).toDependOn(drDeleter3) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -354,11 +354,11 @@ void diamondDeleteWithPostConditionInMiddle() { TestDeleterDependent drDeleter4 = new TestDeleterDependent("DR_DELETER_4"); var workflow = new WorkflowBuilder() - .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition) - .addDependentResource(drDeleter2).dependsOn(drDeleter) - .addDependentResource(drDeleter3).dependsOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) + .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter) .withDeletePostcondition(this.notMetCondition) - .addDependentResource(drDeleter4).dependsOn(drDeleter3, drDeleter2) + .addDependentResourceAndConfigure(drDeleter4).toDependOn(drDeleter3, drDeleter2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -378,10 +378,10 @@ void diamondDeleteErrorInMiddle() { TestDeleterDependent drDeleter3 = new TestDeleterDependent("DR_DELETER_3"); var workflow = new WorkflowBuilder() - .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition) - .addDependentResource(drDeleter2).dependsOn(drDeleter) - .addDependentResource(errorDD).dependsOn(drDeleter) - .addDependentResource(drDeleter3).dependsOn(errorDD, drDeleter2) + .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) + .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) + .addDependentResourceAndConfigure(errorDD).toDependOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter3).toDependOn(errorDD, drDeleter2) .withThrowExceptionFurther(false) .build(); @@ -399,8 +399,8 @@ void diamondDeleteErrorInMiddle() { @Test void readyConditionTrivialCase() { var workflow = new WorkflowBuilder() - .addDependentResource(dr1).withReadyPostcondition(metCondition) - .addDependentResource(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr1).withReadyPostcondition(metCondition) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -415,8 +415,8 @@ void readyConditionTrivialCase() { @Test void readyConditionNotMetTrivialCase() { var workflow = new WorkflowBuilder() - .addDependentResource(dr1).withReadyPostcondition(notMetCondition) - .addDependentResource(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr1).withReadyPostcondition(notMetCondition) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -433,9 +433,9 @@ void readyConditionNotMetTrivialCase() { void readyConditionNotMetInOneParent() { var workflow = new WorkflowBuilder() - .addDependentResource(dr1).withReadyPostcondition(notMetCondition) + .addDependentResourceAndConfigure(dr1).withReadyPostcondition(notMetCondition) .addDependentResource(dr2) - .addDependentResource(dr3).dependsOn(dr1, dr2) + .addDependentResourceAndConfigure(dr3).toDependOn(dr1, dr2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -450,9 +450,10 @@ void readyConditionNotMetInOneParent() { void diamondShareWithReadyCondition() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResource(dr2).dependsOn(dr1).withReadyPostcondition(notMetCondition) - .addDependentResource(dr3).dependsOn(dr1) - .addDependentResource(dr4).dependsOn(dr2, dr3) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .withReadyPostcondition(notMetCondition) + .addDependentResourceAndConfigure(dr3).toDependOn(dr1) + .addDependentResourceAndConfigure(dr4).toDependOn(dr2, dr3) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -470,7 +471,7 @@ void diamondShareWithReadyCondition() { @Test void garbageCollectedResourceIsDeletedIfReconcilePreconditionDoesNotHold() { var workflow = new WorkflowBuilder() - .addDependentResource(gcDeleter).withReconcilePrecondition(notMetCondition) + .addDependentResourceAndConfigure(gcDeleter).withReconcilePrecondition(notMetCondition) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -482,8 +483,8 @@ void garbageCollectedResourceIsDeletedIfReconcilePreconditionDoesNotHold() { @Test void garbageCollectedDeepResourceIsDeletedIfReconcilePreconditionDoesNotHold() { var workflow = new WorkflowBuilder() - .addDependentResource(dr1).withReconcilePrecondition(notMetCondition) - .addDependentResource(gcDeleter).dependsOn(dr1) + .addDependentResourceAndConfigure(dr1).withReconcilePrecondition(notMetCondition) + .addDependentResourceAndConfigure(gcDeleter).toDependOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -495,7 +496,7 @@ void garbageCollectedDeepResourceIsDeletedIfReconcilePreconditionDoesNotHold() { @Test void notReconciledIfActivationConditionNotMet() { var workflow = new WorkflowBuilder() - .addDependentResource(dr1) + .addDependentResourceAndConfigure(dr1) .withActivationCondition(notMetCondition) .addDependentResource(dr2) .build(); @@ -509,10 +510,10 @@ void notReconciledIfActivationConditionNotMet() { @Test void dependentsOnANonActiveDependentNotReconciled() { var workflow = new WorkflowBuilder() - .addDependentResource(dr1) + .addDependentResourceAndConfigure(dr1) .withActivationCondition(notMetCondition) .addDependentResource(dr2) - .addDependentResource(dr3).dependsOn(dr1) + .addDependentResourceAndConfigure(dr3).toDependOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -524,11 +525,11 @@ void dependentsOnANonActiveDependentNotReconciled() { @Test void readyConditionNotCheckedOnNonActiveDependent() { var workflow = new WorkflowBuilder() - .addDependentResource(dr1) + .addDependentResourceAndConfigure(dr1) .withActivationCondition(notMetCondition) .withReadyPostcondition(notMetCondition) .addDependentResource(dr2) - .addDependentResource(dr3).dependsOn(dr1) + .addDependentResourceAndConfigure(dr3).toDependOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -542,7 +543,7 @@ void reconcilePreconditionNotCheckedOnNonActiveDependent() { var precondition = mock(Condition.class); var workflow = new WorkflowBuilder() - .addDependentResource(dr1) + .addDependentResourceAndConfigure(dr1) .withActivationCondition(notMetCondition) .withReconcilePrecondition(precondition) .build(); @@ -558,11 +559,11 @@ void deletesDependentsOfNonActiveDependentButNotTheNonActive() { TestDeleterDependent drDeleter3 = new TestDeleterDependent("DR_DELETER_3"); var workflow = new WorkflowBuilder() - .addDependentResource(dr1).withActivationCondition(notMetCondition) - .addDependentResource(drDeleter).dependsOn(dr1) - .addDependentResource(drDeleter2).dependsOn(drDeleter) + .addDependentResourceAndConfigure(dr1).withActivationCondition(notMetCondition) + .addDependentResourceAndConfigure(drDeleter).toDependOn(dr1) + .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) .withActivationCondition(notMetCondition) - .addDependentResource(drDeleter3).dependsOn(drDeleter2) + .addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -581,8 +582,8 @@ void activationConditionOnlyCalledOnceOnDeleteDependents() { when(condition.isMet(any(), any(), any())).thenReturn(false); var workflow = new WorkflowBuilder() - .addDependentResource(drDeleter).withActivationCondition(condition) - .addDependentResource(drDeleter2).dependsOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter).withActivationCondition(condition) + .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) .build(); workflow.reconcile(new TestCustomResource(), mockContext); @@ -613,7 +614,7 @@ public boolean isSuccess() { } }; var workflow = new WorkflowBuilder() - .addDependentResource(dr1) + .addDependentResourceAndConfigure(dr1) .withReadyPostcondition(resultCondition) .build(); @@ -643,7 +644,7 @@ public boolean isSuccess() { } }; var workflow = new WorkflowBuilder() - .addDependentResource(dr1) + .addDependentResourceAndConfigure(dr1) .withReadyPostcondition(resultCondition) .build(); @@ -660,7 +661,7 @@ public boolean isSuccess() { @Test void shouldReturnEmptyIfNoConditionResultExists() { var workflow = new WorkflowBuilder() - .addDependentResource(dr1) + .addDependentResourceAndConfigure(dr1) .withReadyPostcondition(notMetCondition) .build(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java index d6e14a1645..203c1714f2 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java @@ -1,8 +1,6 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.stream.Collectors; import org.junit.jupiter.api.Test; @@ -22,8 +20,6 @@ @SuppressWarnings("rawtypes") class WorkflowTest { - ExecutorService executorService = Executors.newCachedThreadPool(); - @Test void zeroTopLevelDRShouldThrowException() { var dr1 = mockDependent("dr1"); @@ -31,10 +27,10 @@ void zeroTopLevelDRShouldThrowException() { var dr3 = mockDependent("dr3"); var cyclicWorkflowBuilderSetup = new WorkflowBuilder() - .addDependentResource(dr1).dependsOn() - .addDependentResource(dr2).dependsOn(dr1) - .addDependentResource(dr3).dependsOn(dr2) - .addDependentResource(dr1).dependsOn(dr2); + .addDependentResourceAndConfigure(dr1).toDependOn() + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr3).toDependOn(dr2) + .addDependentResourceAndConfigure(dr1).toDependOn(dr2); assertThrows(IllegalStateException.class, cyclicWorkflowBuilderSetup::build); @@ -49,7 +45,7 @@ void calculatesTopLevelResources() { var workflow = new WorkflowBuilder() .addDependentResource(independentDR) .addDependentResource(dr1) - .addDependentResource(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) .buildAsDefaultWorkflow(); Set topResources = @@ -69,7 +65,7 @@ void calculatesBottomLevelResources() { final var workflow = new WorkflowBuilder() .addDependentResource(independentDR) .addDependentResource(dr1) - .addDependentResource(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr2).toDependOn(dr1) .buildAsDefaultWorkflow(); Set bottomResources = diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java index 15343793fd..4dc75122f2 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java @@ -46,7 +46,8 @@ public WebPageDependentsWorkflowReconciler(KubernetesClient kubernetesClient) { .addDependentResource(configMapDR) .addDependentResource(deploymentDR) .addDependentResource(serviceDR) - .addDependentResource(ingressDR).withReconcilePrecondition(new ExposedIngressCondition()) + .addDependentResourceAndConfigure(ingressDR) + .withReconcilePrecondition(new ExposedIngressCondition()) .build(); } diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java index 580d529a72..d2475b983f 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java @@ -109,7 +109,7 @@ private Workflow createDependentResourcesAndWorkflow() { .addDependentResource(configMapDR) .addDependentResource(deploymentDR) .addDependentResource(serviceDR) - .addDependentResource(ingressDR) + .addDependentResourceAndConfigure(ingressDR) // prevent the Ingress from being created based on the linked condition (here: only if the // `exposed` flag is set in the primary resource), delete the Ingress if it already exists // and the condition becomes false From 2b82f81fc927771cf5a71e8422633c1eb504e785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 20 Sep 2024 09:05:30 +0200 Subject: [PATCH 77/96] fix: cleanup after rebase on main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../processing/dependent/workflow/WorkflowTest.java | 2 +- pom.xml | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java index 203c1714f2..b8d90a45ad 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java @@ -12,8 +12,8 @@ import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.*; diff --git a/pom.xml b/pom.xml index 325a64a215..d36c1e440a 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,6 @@ 4.2.0 2.7.3 1.13.3 - 4.12.0 3.1.8 0.9.11 2.16.1 @@ -198,16 +197,6 @@ operator-framework ${project.version} - - com.squareup.okhttp3 - logging-interceptor - ${okhttp.version} - - - com.squareup.okhttp3 - mockwebserver - ${okhttp.version} - com.github.ben-manes.caffeine caffeine From 76163c8d5acd663f9576f652eb476523a85519ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 23 Sep 2024 08:48:21 +0200 Subject: [PATCH 78/96] feat: context getSecondary resource is activation condition aware (#2532) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../api/reconciler/DefaultContext.java | 25 ++++++++++-- .../operator/processing/Controller.java | 6 +++ .../processing/event/EventSources.java | 3 +- .../event/NoEventSourceForClassException.java | 16 ++++++++ .../api/reconciler/DefaultContextTest.java | 37 +++++++++++++++++ .../event/EventSourceManagerTest.java | 4 +- .../ConfigMapDependentResource.java | 28 +++++++++++++ .../FalseActivationCondition.java | 17 ++++++++ .../GetNonActiveSecondaryCustomResource.java | 17 ++++++++ .../RouteDependentResource.java | 27 +++++++++++++ .../WorkflowActivationConditionIT.java | 40 +++++++++++++++++++ ...WorkflowActivationConditionReconciler.java | 40 +++++++++++++++++++ 12 files changed, 252 insertions(+), 8 deletions(-) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NoEventSourceForClassException.java create mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContextTest.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/ConfigMapDependentResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/FalseActivationCondition.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/GetNonActiveSecondaryCustomResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/RouteDependentResource.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/WorkflowActivationConditionIT.java create mode 100644 operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/WorkflowActivationConditionReconciler.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java index e8f6d475cb..45fc3705e6 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java @@ -13,6 +13,7 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedWorkflowAndDependentResourceContext; import io.javaoperatorsdk.operator.processing.Controller; import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; +import io.javaoperatorsdk.operator.processing.event.NoEventSourceForClassException; import io.javaoperatorsdk.operator.processing.event.ResourceID; public class DefaultContext

implements Context

{ @@ -62,10 +63,26 @@ public Stream getSecondaryResourcesAsStream(Class expectedType) { @Override public Optional getSecondaryResource(Class expectedType, String eventSourceName) { - return controller - .getEventSourceManager() - .getEventSourceFor(expectedType, eventSourceName) - .getSecondaryResource(primaryResource); + try { + return controller + .getEventSourceManager() + .getEventSourceFor(expectedType, eventSourceName) + .getSecondaryResource(primaryResource); + } catch (NoEventSourceForClassException e) { + /* + * If a workflow has an activation condition there can be event sources which are only + * registered if the activation condition holds, but to provide a consistent API we return an + * Optional instead of throwing an exception. + * + * Note that not only the resource which has an activation condition might not be registered + * but dependents which depend on it. + */ + if (eventSourceName == null && controller.workflowContainsDependentForType(expectedType)) { + return Optional.empty(); + } else { + throw e; + } + } } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index d62dcd7b9a..bf8b18ea53 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -473,4 +473,10 @@ public WorkflowCleanupResult cleanupManagedWorkflow(P resource, Context

conte public boolean isWorkflowExplicitInvocation() { return explicitWorkflowInvocation; } + + public boolean workflowContainsDependentForType(Class clazz) { + return managedWorkflow.getDependentResourcesByName().values().stream() + .anyMatch(d -> d.resourceType().equals(clazz)); + } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java index e790ae3c32..1a49add3cb 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java @@ -99,8 +99,7 @@ public EventSource get(Class dependentType, String name) { final var sourcesForType = sources.get(keyFor(dependentType)); if (sourcesForType == null || sourcesForType.isEmpty()) { - throw new IllegalArgumentException( - "There is no event source found for class:" + dependentType.getName()); + throw new NoEventSourceForClassException(dependentType); } final var size = sourcesForType.size(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NoEventSourceForClassException.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NoEventSourceForClassException.java new file mode 100644 index 0000000000..74c3449f87 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/NoEventSourceForClassException.java @@ -0,0 +1,16 @@ +package io.javaoperatorsdk.operator.processing.event; + +import io.javaoperatorsdk.operator.OperatorException; + +public class NoEventSourceForClassException extends OperatorException { + + private Class clazz; + + public NoEventSourceForClassException(Class clazz) { + this.clazz = clazz; + } + + public Class getClazz() { + return clazz; + } +} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContextTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContextTest.java new file mode 100644 index 0000000000..3d8fc9563e --- /dev/null +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContextTest.java @@ -0,0 +1,37 @@ +package io.javaoperatorsdk.operator.api.reconciler; + +import org.junit.jupiter.api.Test; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.Secret; +import io.javaoperatorsdk.operator.processing.Controller; +import io.javaoperatorsdk.operator.processing.event.EventSourceManager; +import io.javaoperatorsdk.operator.processing.event.NoEventSourceForClassException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class DefaultContextTest { + + Secret primary = new Secret(); + Controller mockController = mock(Controller.class); + + DefaultContext context = new DefaultContext<>(null, mockController, primary); + + @Test + void getSecondaryResourceReturnsEmptyOptionalOnNonActivatedDRType() { + var mockManager = mock(EventSourceManager.class); + when(mockController.getEventSourceManager()).thenReturn(mockManager); + when(mockController.workflowContainsDependentForType(ConfigMap.class)).thenReturn(true); + when(mockManager.getEventSourceFor(any(), any())) + .thenThrow(new NoEventSourceForClassException(ConfigMap.class)); + + var res = context.getSecondaryResource(ConfigMap.class); + + assertThat(res).isEmpty(); + } + +} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java index a7f0dade3b..6c68916e98 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java @@ -85,12 +85,12 @@ public void startCascadesToEventSources() { @Test void retrievingEventSourceForClassShouldWork() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(NoEventSourceForClassException.class) .isThrownBy(() -> eventSourceManager.getEventSourceFor(Class.class)); // manager is initialized with a controller configured to handle HasMetadata EventSourceManager manager = initManager(); - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(NoEventSourceForClassException.class) .isThrownBy(() -> manager.getEventSourceFor(HasMetadata.class, "unknown_name")); ManagedInformerEventSource eventSource = mock(ManagedInformerEventSource.class); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/ConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/ConfigMapDependentResource.java new file mode 100644 index 0000000000..0c1bdd5900 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/ConfigMapDependentResource.java @@ -0,0 +1,28 @@ +package io.javaoperatorsdk.operator.workflow.getnonactivesecondary; + + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; + +public class ConfigMapDependentResource + extends CRUDKubernetesDependentResource { + + public static final String DATA_KEY = "data"; + + public ConfigMapDependentResource() { + super(ConfigMap.class); + } + + @Override + protected ConfigMap desired(GetNonActiveSecondaryCustomResource primary, + Context context) { + ConfigMap configMap = new ConfigMap(); + configMap.setMetadata(new ObjectMetaBuilder() + .withName(primary.getMetadata().getName()) + .withNamespace(primary.getMetadata().getNamespace()) + .build()); + return configMap; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/FalseActivationCondition.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/FalseActivationCondition.java new file mode 100644 index 0000000000..fde69215bc --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/FalseActivationCondition.java @@ -0,0 +1,17 @@ +package io.javaoperatorsdk.operator.workflow.getnonactivesecondary; + +import io.fabric8.openshift.api.model.Route; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; + +public class FalseActivationCondition + implements Condition { + @Override + public boolean isMet( + DependentResource dependentResource, + GetNonActiveSecondaryCustomResource primary, + Context context) { + return false; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/GetNonActiveSecondaryCustomResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/GetNonActiveSecondaryCustomResource.java new file mode 100644 index 0000000000..fddcd9fe75 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/GetNonActiveSecondaryCustomResource.java @@ -0,0 +1,17 @@ +package io.javaoperatorsdk.operator.workflow.getnonactivesecondary; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.ShortNames; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk") +@Version("v1") +@ShortNames("gnas") +public class GetNonActiveSecondaryCustomResource + extends CustomResource + implements Namespaced { + + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/RouteDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/RouteDependentResource.java new file mode 100644 index 0000000000..c7d1b9a1b1 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/RouteDependentResource.java @@ -0,0 +1,27 @@ +package io.javaoperatorsdk.operator.workflow.getnonactivesecondary; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.openshift.api.model.Route; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; + +public class RouteDependentResource + extends CRUDKubernetesDependentResource { + + public RouteDependentResource() { + super(Route.class); + } + + @Override + protected Route desired(GetNonActiveSecondaryCustomResource primary, + Context context) { + // basically does not matter since this should not be called + Route route = new Route(); + route.setMetadata(new ObjectMetaBuilder() + .withName(primary.getMetadata().getName()) + .withNamespace(primary.getMetadata().getNamespace()) + .build()); + + return route; + } +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/WorkflowActivationConditionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/WorkflowActivationConditionIT.java new file mode 100644 index 0000000000..c2c073df88 --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/WorkflowActivationConditionIT.java @@ -0,0 +1,40 @@ +package io.javaoperatorsdk.operator.workflow.getnonactivesecondary; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class WorkflowActivationConditionIT { + + public static final String TEST_RESOURCE_NAME = "test1"; + + @RegisterExtension + LocallyRunOperatorExtension extension = + LocallyRunOperatorExtension.builder() + .withReconciler(WorkflowActivationConditionReconciler.class) + .build(); + + @Test + void reconciledOnVanillaKubernetesDespiteRouteInWorkflow() { + extension.create(testResource()); + + await().untilAsserted(() -> { + assertThat(extension.getReconcilerOfType(WorkflowActivationConditionReconciler.class) + .getNumberOfReconciliationExecution()).isEqualTo(1); + }); + } + + private GetNonActiveSecondaryCustomResource testResource() { + var res = new GetNonActiveSecondaryCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(TEST_RESOURCE_NAME) + .build()); + return res; + } + +} diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/WorkflowActivationConditionReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/WorkflowActivationConditionReconciler.java new file mode 100644 index 0000000000..2d2d39274d --- /dev/null +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/workflow/getnonactivesecondary/WorkflowActivationConditionReconciler.java @@ -0,0 +1,40 @@ +package io.javaoperatorsdk.operator.workflow.getnonactivesecondary; + +import java.util.concurrent.atomic.AtomicInteger; + +import io.fabric8.openshift.api.model.Route; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.javaoperatorsdk.operator.api.reconciler.Workflow; +import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; + +@Workflow(dependents = { + @Dependent(type = ConfigMapDependentResource.class), + @Dependent(type = RouteDependentResource.class, + activationCondition = FalseActivationCondition.class) +}) +@ControllerConfiguration +public class WorkflowActivationConditionReconciler + implements Reconciler { + + private final AtomicInteger numberOfReconciliationExecution = new AtomicInteger(0); + + @Override + public UpdateControl reconcile( + GetNonActiveSecondaryCustomResource resource, + Context context) { + + // should not throw an exception even if the condition is false + var route = context.getSecondaryResource(Route.class); + + numberOfReconciliationExecution.incrementAndGet(); + + return UpdateControl.noUpdate(); + } + + public int getNumberOfReconciliationExecution() { + return numberOfReconciliationExecution.get(); + } +} From c18de80929de753d6fc2aa96beed6e63a0085187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 23 Sep 2024 11:08:07 +0200 Subject: [PATCH 79/96] feat: e2e test to demonstrate namespace deletion problem fix (#2528) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../controller-namespace-deletion/README.md | 8 + .../k8s/operator.yaml | 62 ++++++++ .../controller-namespace-deletion/pom.xml | 87 +++++++++++ ...rollerNamespaceDeletionCustomResource.java | 14 ++ .../ControllerNamespaceDeletionOperator.java | 49 ++++++ ...ControllerNamespaceDeletionReconciler.java | 59 +++++++ .../ControllerNamespaceDeletionSpec.java | 15 ++ .../ControllerNamespaceDeletionStatus.java | 15 ++ .../src/main/resources/log4j2.xml | 13 ++ .../ControllerNamespaceDeletionE2E.java | 144 ++++++++++++++++++ .../src/test/resources/log4j2.xml | 13 ++ sample-operators/leader-election/pom.xml | 5 - sample-operators/mysql-schema/pom.xml | 5 - sample-operators/pom.xml | 1 + sample-operators/tomcat-operator/pom.xml | 5 - sample-operators/webpage/pom.xml | 5 - 16 files changed, 480 insertions(+), 20 deletions(-) create mode 100644 sample-operators/controller-namespace-deletion/README.md create mode 100644 sample-operators/controller-namespace-deletion/k8s/operator.yaml create mode 100644 sample-operators/controller-namespace-deletion/pom.xml create mode 100644 sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionCustomResource.java create mode 100644 sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionOperator.java create mode 100644 sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionReconciler.java create mode 100644 sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionSpec.java create mode 100644 sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionStatus.java create mode 100644 sample-operators/controller-namespace-deletion/src/main/resources/log4j2.xml create mode 100644 sample-operators/controller-namespace-deletion/src/test/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionE2E.java create mode 100644 sample-operators/controller-namespace-deletion/src/test/resources/log4j2.xml diff --git a/sample-operators/controller-namespace-deletion/README.md b/sample-operators/controller-namespace-deletion/README.md new file mode 100644 index 0000000000..3ea02d1d36 --- /dev/null +++ b/sample-operators/controller-namespace-deletion/README.md @@ -0,0 +1,8 @@ +This sample demonstrates the workaround for problem when a namespace +is being deleted with a running controller, that watches resources +in its own namespace. If the pod or other underlying resources (role, +role binding, service account) are deleted before the cleanup of +the custom resource the namespace deletion is stuck. + +see also: https://github.com/operator-framework/java-operator-sdk/pull/2528 + diff --git a/sample-operators/controller-namespace-deletion/k8s/operator.yaml b/sample-operators/controller-namespace-deletion/k8s/operator.yaml new file mode 100644 index 0000000000..bc9eeb84ed --- /dev/null +++ b/sample-operators/controller-namespace-deletion/k8s/operator.yaml @@ -0,0 +1,62 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: operator + finalizers: + - controller.deletion/finalizer + +--- +apiVersion: v1 +kind: Pod +metadata: + name: operator +spec: + serviceAccountName: operator + containers: + - name: operator + image: controller-namespace-deletion-operator + imagePullPolicy: Never + env: + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + terminationGracePeriodSeconds: 30 + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: operator + finalizers: + - controller.deletion/finalizer +subjects: + - kind: ServiceAccount + name: operator +roleRef: + kind: Role + name: operator + apiGroup: rbac.authorization.k8s.io + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: operator + finalizers: + - controller.deletion/finalizer +rules: + - apiGroups: + - "apiextensions.k8s.io" + resources: + - customresourcedefinitions + verbs: + - '*' + - apiGroups: + - "namespacedeletion.io" + resources: + - controllernamespacedeletioncustomresources + - controllernamespacedeletioncustomresources/status + verbs: + - '*' + diff --git a/sample-operators/controller-namespace-deletion/pom.xml b/sample-operators/controller-namespace-deletion/pom.xml new file mode 100644 index 0000000000..4979eec0d1 --- /dev/null +++ b/sample-operators/controller-namespace-deletion/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + + io.javaoperatorsdk + sample-operators + 5.0.0-SNAPSHOT + + + sample-controller-namespace-deletion + jar + Operator SDK - Samples - Controller Namespace Deletion + Deleting namespace with controller and custom resources + + + + + io.javaoperatorsdk + operator-framework-bom + ${project.version} + pom + import + + + + + + + io.javaoperatorsdk + operator-framework + + + io.fabric8 + crd-generator-apt + provided + + + org.apache.logging.log4j + log4j-slf4j2-impl + compile + + + org.apache.logging.log4j + log4j-core + compile + + + org.takes + takes + 1.24.4 + + + org.awaitility + awaitility + compile + + + io.javaoperatorsdk + operator-framework-junit-5 + test + + + org.junit.jupiter + junit-jupiter-params + test + + + + + + com.google.cloud.tools + jib-maven-plugin + ${jib-maven-plugin.version} + + + gcr.io/distroless/java17-debian11 + + + controller-namespace-deletion-operator + + + + + + + diff --git a/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionCustomResource.java b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionCustomResource.java new file mode 100644 index 0000000000..ae0f1034ee --- /dev/null +++ b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionCustomResource.java @@ -0,0 +1,14 @@ +package io.javaoperatorsdk.operator.sample; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("namespacedeletion.io") +@Version("v1") +public class ControllerNamespaceDeletionCustomResource + extends CustomResource + implements Namespaced { + +} diff --git a/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionOperator.java b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionOperator.java new file mode 100644 index 0000000000..5364852467 --- /dev/null +++ b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionOperator.java @@ -0,0 +1,49 @@ +package io.javaoperatorsdk.operator.sample; + +import java.time.LocalTime; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import io.javaoperatorsdk.operator.Operator; +import io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider; + +import static java.time.temporal.ChronoUnit.SECONDS; + +public class ControllerNamespaceDeletionOperator { + + private static final Logger log = + LoggerFactory.getLogger(ControllerNamespaceDeletionOperator.class); + + public static void main(String[] args) { + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + log.info("Shutting down..."); + boolean allResourcesDeleted = waitUntilResourcesDeleted(); + log.info("All resources within timeout: {}", allResourcesDeleted); + })); + + Operator operator = new Operator(); + operator.register(new ControllerNamespaceDeletionReconciler(), + ControllerConfigurationOverrider::watchingOnlyCurrentNamespace); + operator.start(); + } + + private static boolean waitUntilResourcesDeleted() { + try (var client = new KubernetesClientBuilder().build()) { + var startTime = LocalTime.now(); + while (startTime.until(LocalTime.now(), SECONDS) < 20) { + var items = + client.resources(ControllerNamespaceDeletionCustomResource.class) + .inNamespace(client.getConfiguration().getNamespace()) + .list().getItems(); + log.info("Custom resource in namespace: {}", items); + if (items.isEmpty()) { + return true; + } + } + return false; + } + } +} diff --git a/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionReconciler.java b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionReconciler.java new file mode 100644 index 0000000000..7261f269b4 --- /dev/null +++ b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionReconciler.java @@ -0,0 +1,59 @@ +package io.javaoperatorsdk.operator.sample; + +import java.time.Duration; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Cleaner; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; + +public class ControllerNamespaceDeletionReconciler + implements Reconciler, + Cleaner { + + private static final Logger log = + LoggerFactory.getLogger(ControllerNamespaceDeletionReconciler.class); + + public static final Duration CLEANUP_DELAY = Duration.ofSeconds(10); + + @Override + public UpdateControl reconcile( + ControllerNamespaceDeletionCustomResource resource, + Context context) { + log.info("Reconciling: {} in namespace: {}", resource.getMetadata().getName(), + resource.getMetadata().getNamespace()); + + var response = createResponseResource(resource); + response.getStatus().setValue(resource.getSpec().getValue()); + + return UpdateControl.patchStatus(response); + } + + private ControllerNamespaceDeletionCustomResource createResponseResource( + ControllerNamespaceDeletionCustomResource resource) { + var res = new ControllerNamespaceDeletionCustomResource(); + res.setMetadata(new ObjectMetaBuilder() + .withName(resource.getMetadata().getName()) + .withNamespace(resource.getMetadata().getNamespace()) + .build()); + res.setStatus(new ControllerNamespaceDeletionStatus()); + return res; + } + + @Override + public DeleteControl cleanup(ControllerNamespaceDeletionCustomResource resource, + Context context) { + log.info("Cleaning up resource"); + try { + Thread.sleep(CLEANUP_DELAY.toMillis()); + return DeleteControl.defaultDelete(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } +} diff --git a/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionSpec.java b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionSpec.java new file mode 100644 index 0000000000..dc5092e7e5 --- /dev/null +++ b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionSpec.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.sample; + + +public class ControllerNamespaceDeletionSpec { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionStatus.java b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionStatus.java new file mode 100644 index 0000000000..732fa7d626 --- /dev/null +++ b/sample-operators/controller-namespace-deletion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionStatus.java @@ -0,0 +1,15 @@ +package io.javaoperatorsdk.operator.sample; + + +public class ControllerNamespaceDeletionStatus { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/sample-operators/controller-namespace-deletion/src/main/resources/log4j2.xml b/sample-operators/controller-namespace-deletion/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..0ec69bf713 --- /dev/null +++ b/sample-operators/controller-namespace-deletion/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/sample-operators/controller-namespace-deletion/src/test/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionE2E.java b/sample-operators/controller-namespace-deletion/src/test/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionE2E.java new file mode 100644 index 0000000000..36c7f132ab --- /dev/null +++ b/sample-operators/controller-namespace-deletion/src/test/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionE2E.java @@ -0,0 +1,144 @@ +package io.javaoperatorsdk.operator.sample; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.time.Duration; +import java.util.List; +import java.util.UUID; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.NamespaceBuilder; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.api.model.rbac.RoleBinding; +import io.fabric8.kubernetes.client.ConfigBuilder; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; + +import static io.javaoperatorsdk.operator.junit.AbstractOperatorExtension.CRD_READY_WAIT; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + + +class ControllerNamespaceDeletionE2E { + + private static final Logger log = LoggerFactory.getLogger(ControllerNamespaceDeletionE2E.class); + + public static final String TEST_RESOURCE_NAME = "test1"; + public static final String INITIAL_VALUE = "initial value"; + public static final String ROLE_ROLE_BINDING_FINALIZER = "controller.deletion/finalizer"; + public static final String RESOURCE_NAME = "operator"; + + String namespace; + KubernetesClient client; + + // not for local mode by design + @EnabledIfSystemProperty(named = "test.deployment", matches = "remote") + @Test + void customResourceCleanedUpOnNamespaceDeletion() { + deployController(); + client.resource(testResource()).serverSideApply(); + + await().untilAsserted(() -> { + var res = client.resources(ControllerNamespaceDeletionCustomResource.class) + .inNamespace(namespace).withName(TEST_RESOURCE_NAME).get(); + assertThat(res.getStatus()).isNotNull(); + assertThat(res.getStatus().getValue()).isEqualTo(INITIAL_VALUE); + }); + + client.namespaces().withName(namespace).delete(); + + await().timeout(Duration.ofSeconds(20)).untilAsserted(() -> { + var ns = client.resources(ControllerNamespaceDeletionCustomResource.class) + .inNamespace(namespace).withName(TEST_RESOURCE_NAME).get(); + assertThat(ns).isNull(); + }); + + log.info("Removing finalizers from role and role bing and service account"); + removeRoleAndRoleBindingFinalizers(); + + await().timeout(Duration.ofSeconds(20)).untilAsserted(() -> { + var ns = client.namespaces().withName(namespace).get(); + assertThat(ns).isNull(); + }); + } + + private void removeRoleAndRoleBindingFinalizers() { + var rolebinding = + client.rbac().roleBindings().inNamespace(namespace).withName(RESOURCE_NAME).get(); + rolebinding.getFinalizers().clear(); + client.resource(rolebinding).update(); + + var role = client.rbac().roles().inNamespace(namespace).withName(RESOURCE_NAME).get(); + role.getFinalizers().clear(); + client.resource(role).update(); + + var sa = client.serviceAccounts().inNamespace(namespace).withName(RESOURCE_NAME).get(); + sa.getMetadata().getFinalizers().clear(); + client.resource(sa).update(); + } + + ControllerNamespaceDeletionCustomResource testResource() { + var cr = new ControllerNamespaceDeletionCustomResource(); + cr.setMetadata(new ObjectMetaBuilder() + .withName(TEST_RESOURCE_NAME) + .withNamespace(namespace) + .build()); + cr.setSpec(new ControllerNamespaceDeletionSpec()); + cr.getSpec().setValue(INITIAL_VALUE); + return cr; + } + + + @BeforeEach + void setup() { + namespace = "controller-namespace-" + UUID.randomUUID(); + client = new KubernetesClientBuilder().withConfig(new ConfigBuilder() + .withNamespace(namespace) + .build()).build(); + applyCRD(); + client.namespaces().resource(new NamespaceBuilder().withNewMetadata().withName(namespace) + .endMetadata().build()).create(); + } + + void deployController() { + try { + List resources = client.load(new FileInputStream("k8s/operator.yaml")).items(); + resources.forEach(hm -> { + hm.getMetadata().setNamespace(namespace); + if (hm.getKind().equalsIgnoreCase("rolebinding")) { + var crb = (RoleBinding) hm; + for (var subject : crb.getSubjects()) { + subject.setNamespace(namespace); + } + } + }); + client.resourceList(resources) + .inNamespace(namespace) + .createOrReplace(); + + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + + void applyCRD() { + String path = + "target/classes/META-INF/fabric8/controllernamespacedeletioncustomresources.namespacedeletion.io-v1.yml"; + try (InputStream is = new FileInputStream(path)) { + final var crd = client.load(is); + crd.serverSideApply(); + Thread.sleep(CRD_READY_WAIT); + log.debug("Applied CRD with name: {}", crd.get().get(0).getMetadata().getName()); + } catch (InterruptedException | IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/sample-operators/controller-namespace-deletion/src/test/resources/log4j2.xml b/sample-operators/controller-namespace-deletion/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..2b7fdd3479 --- /dev/null +++ b/sample-operators/controller-namespace-deletion/src/test/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample-operators/leader-election/pom.xml b/sample-operators/leader-election/pom.xml index 894b96d988..d686634ad7 100644 --- a/sample-operators/leader-election/pom.xml +++ b/sample-operators/leader-election/pom.xml @@ -76,11 +76,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - io.fabric8 diff --git a/sample-operators/mysql-schema/pom.xml b/sample-operators/mysql-schema/pom.xml index bc8207a92e..46d555966c 100644 --- a/sample-operators/mysql-schema/pom.xml +++ b/sample-operators/mysql-schema/pom.xml @@ -102,11 +102,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - diff --git a/sample-operators/pom.xml b/sample-operators/pom.xml index 6d09f9a3ad..478508f9d5 100644 --- a/sample-operators/pom.xml +++ b/sample-operators/pom.xml @@ -17,5 +17,6 @@ webpage mysql-schema leader-election + controller-namespace-deletion diff --git a/sample-operators/tomcat-operator/pom.xml b/sample-operators/tomcat-operator/pom.xml index 7af9893609..d22260c614 100644 --- a/sample-operators/tomcat-operator/pom.xml +++ b/sample-operators/tomcat-operator/pom.xml @@ -104,11 +104,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - diff --git a/sample-operators/webpage/pom.xml b/sample-operators/webpage/pom.xml index 9982da49c4..34b6846b94 100644 --- a/sample-operators/webpage/pom.xml +++ b/sample-operators/webpage/pom.xml @@ -75,11 +75,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - From 69e729d6cb1d9d22081b42df4f5259de3ddee831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 27 Sep 2024 16:26:01 +0200 Subject: [PATCH 80/96] docs: remove javadoc todos (#2541) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../javaoperatorsdk/operator/api/config/informer/Informer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java index 57da4f41a6..3a425b786b 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/Informer.java @@ -107,7 +107,6 @@ * * @return the class of the {@link ItemStore} implementation to use */ - // todo: check javadoc Class itemStore() default ItemStore.class; /** @@ -115,7 +114,6 @@ * related informers. If this is a not null it will result in paginating for the initial load of * the informer cache. */ - // todo: check javadoc long informerListLimit() default NO_LONG_VALUE_SET; } From b0522ffb2a860687244692bd97fbaaadc47fbe59 Mon Sep 17 00:00:00 2001 From: 10000-ki <10000ki6472@gmail.com> Date: Tue, 1 Oct 2024 05:57:25 +0900 Subject: [PATCH 81/96] feat: print diff resource as yaml (#2542) --- .../SSABasedGenericKubernetesResourceMatcher.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java index 24b9a8f4a4..83562cd9c7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java @@ -108,12 +108,21 @@ public boolean matches(R actual, R desired, Context context) { removeIrrelevantValues(desiredMap); if (LoggingUtils.isNotSensitiveResource(desired)) { - log.debug("Pruned actual: \n {} \n desired: \n {} ", prunedActual, desiredMap); + logDiff(prunedActual, desiredMap, objectMapper); } return prunedActual.equals(desiredMap); } + private void logDiff(Map prunedActualMap, Map desiredMap, + KubernetesSerialization serialization) { + if (log.isDebugEnabled()) { + var actualYaml = serialization.asYaml(prunedActualMap); + var desiredYaml = serialization.asYaml(desiredMap); + log.debug("Pruned actual yaml: \n {} \n desired yaml: \n {} ", actualYaml, desiredYaml); + } + } + /** * Correct for known issue with SSA */ From a37479662e3131f3c3d27f4cfa7013e44059fea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 9 Oct 2024 09:58:11 +0200 Subject: [PATCH 82/96] fix: integration test timeout issue (#2547) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../GenericKubernetesDependentTestBase.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentTestBase.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentTestBase.java index d031b1cc61..c26fcb42b4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentTestBase.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/generickubernetesresource/GenericKubernetesDependentTestBase.java @@ -9,6 +9,7 @@ import io.javaoperatorsdk.operator.dependent.generickubernetesresource.generickubernetesdependentstandalone.ConfigMapGenericKubernetesDependent; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import static io.javaoperatorsdk.operator.IntegrationTestConstants.GARBAGE_COLLECTION_TIMEOUT_SECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -38,7 +39,7 @@ void testReconciliation() { extension().delete(resource); - await().timeout(Duration.ofSeconds(30)).untilAsserted(() -> { + await().timeout(Duration.ofSeconds(GARBAGE_COLLECTION_TIMEOUT_SECONDS)).untilAsserted(() -> { var cm = extension().get(ConfigMap.class, TEST_RESOURCE_NAME); assertThat(cm).isNull(); }); From 46ae8a2e0756fb7a49b7949e55aefdd04d2444ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 9 Oct 2024 19:19:53 +0200 Subject: [PATCH 83/96] improve: naming target resource selector method (#2546) --- .../dependent/AbstractDependentResource.java | 4 ++-- .../kubernetes/KubernetesDependentResource.java | 6 +++--- .../ExternalWithStateDependentResource.java | 2 +- ...eManagedDependentNoDiscriminatorConfigMap1.java | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java index 63223a01ff..db69d8134b 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java @@ -114,7 +114,7 @@ public Optional getSecondaryResource(P primary, Context

context) { if (secondaryResources.isEmpty()) { return Optional.empty(); } else { - return selectManagedSecondaryResource(secondaryResources, primary, context); + return selectTargetSecondaryResource(secondaryResources, primary, context); } } @@ -132,7 +132,7 @@ public Optional getSecondaryResource(P primary, Context

context) { * @throws IllegalStateException if more than one candidate is found, in which case some other * mechanism might be necessary to distinguish between candidate secondary resources */ - protected Optional selectManagedSecondaryResource(Set secondaryResources, P primary, + protected Optional selectTargetSecondaryResource(Set secondaryResources, P primary, Context

context) { R desired = desired(primary, context); var targetResources = secondaryResources.stream().filter(r -> r.equals(desired)).toList(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 35b959c1ec..048b2b8f03 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -222,9 +222,9 @@ protected void addSecondaryToPrimaryMapperAnnotations(R desired, P primary, Stri } @Override - protected Optional selectManagedSecondaryResource(Set secondaryResources, P primary, + protected Optional selectTargetSecondaryResource(Set secondaryResources, P primary, Context

context) { - ResourceID managedResourceID = managedSecondaryResourceID(primary, context); + ResourceID managedResourceID = targetSecondaryResourceID(primary, context); return secondaryResources.stream() .filter(r -> r.getMetadata().getName().equals(managedResourceID.getName()) && Objects.equals(r.getMetadata().getNamespace(), @@ -240,7 +240,7 @@ protected Optional selectManagedSecondaryResource(Set secondaryResources, * @param context of current reconciliation * @return id of the target managed resource */ - protected ResourceID managedSecondaryResourceID(P primary, Context

context) { + protected ResourceID targetSecondaryResourceID(P primary, Context

context) { return ResourceID.fromResource(desired(primary, context)); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalWithStateDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalWithStateDependentResource.java index 9bdeea93cd..47d6a25144 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalWithStateDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/externalstate/ExternalWithStateDependentResource.java @@ -40,7 +40,7 @@ public Set fetchResources( } @Override - protected Optional selectManagedSecondaryResource( + protected Optional selectTargetSecondaryResource( Set secondaryResources, ExternalStateCustomResource primary, Context context) { var id = getResourceID(primary); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java index 750f8489b7..6b83593173 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/multipledrsametypenodiscriminator/MultipleManagedDependentNoDiscriminatorConfigMap1.java @@ -8,6 +8,7 @@ import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; +import io.javaoperatorsdk.operator.processing.event.ResourceID; @KubernetesDependent public class MultipleManagedDependentNoDiscriminatorConfigMap1 @@ -20,6 +21,19 @@ public MultipleManagedDependentNoDiscriminatorConfigMap1() { super(ConfigMap.class); } + /* + * Showcases optimization to avoid computing the whole desired state by providing the ResourceID + * of the target resource. In this particular case this would not be necessary, since desired + * state creation is pretty lightweight. However, this might make sense in situation where the + * desired state is more costly + */ + protected ResourceID targetSecondaryResourceID( + MultipleManagedDependentNoDiscriminatorCustomResource primary, + Context context) { + return new ResourceID(primary.getMetadata().getName() + NAME_SUFFIX, + primary.getMetadata().getNamespace()); + } + @Override protected ConfigMap desired(MultipleManagedDependentNoDiscriminatorCustomResource primary, Context context) { From a9b977fe6a4812d351b9c059c281820e02739881 Mon Sep 17 00:00:00 2001 From: bachmanity1 <81428651+bachmanity1@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:17:02 +0900 Subject: [PATCH 84/96] feat: improve diff logging (#2544) * imporve diff logging Signed-off-by: bachmanity1 * compute diff only when actual doesn't match desired Signed-off-by: bachmanity1 * slight improvements Signed-off-by: bachmanity1 * increase context size Signed-off-by: bachmanity1 * fix style Signed-off-by: bachmanity1 * calculate diff only if debug is enabled Signed-off-by: bachmanity1 * print actual resources when trace is enabled Signed-off-by: bachmanity1 * use java-diff-utils Signed-off-by: bachmanity1 * add unit tests --------- Signed-off-by: bachmanity1 --- operator-framework-core/pom.xml | 4 ++ ...BasedGenericKubernetesResourceMatcher.java | 66 ++++++++++++++++--- ...dGenericKubernetesResourceMatcherTest.java | 47 +++++++++++++ pom.xml | 6 ++ 4 files changed, 115 insertions(+), 8 deletions(-) diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index 7f015c87f6..76a6169a3f 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -14,6 +14,10 @@ Core framework for implementing Kubernetes operators + + io.github.java-diff-utils + java-diff-utils + io.fabric8 kubernetes-client diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java index 83562cd9c7..a314b22723 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -33,6 +34,9 @@ import static io.javaoperatorsdk.operator.processing.dependent.kubernetes.ResourceRequirementsSanitizer.sanitizeResourceRequirements; +import com.github.difflib.DiffUtils; +import com.github.difflib.UnifiedDiffUtils; + /** * Matches the actual state on the server vs the desired state. Based on the managedFields of SSA. *

@@ -107,20 +111,66 @@ public boolean matches(R actual, R desired, Context context) { removeIrrelevantValues(desiredMap); - if (LoggingUtils.isNotSensitiveResource(desired)) { - logDiff(prunedActual, desiredMap, objectMapper); + var matches = prunedActual.equals(desiredMap); + + if (!matches && log.isDebugEnabled() && LoggingUtils.isNotSensitiveResource(desired)) { + var diff = getDiff(prunedActual, desiredMap, objectMapper); + log.debug( + "Diff between actual and desired state for resource: {} with name: {} in namespace: {} is: \n{}", + actual.getKind(), actual.getMetadata().getName(), actual.getMetadata().getNamespace(), + diff); } - return prunedActual.equals(desiredMap); + return matches; } - private void logDiff(Map prunedActualMap, Map desiredMap, + private String getDiff(Map prunedActualMap, Map desiredMap, KubernetesSerialization serialization) { - if (log.isDebugEnabled()) { - var actualYaml = serialization.asYaml(prunedActualMap); - var desiredYaml = serialization.asYaml(desiredMap); - log.debug("Pruned actual yaml: \n {} \n desired yaml: \n {} ", actualYaml, desiredYaml); + var actualYaml = serialization.asYaml(sortMap(prunedActualMap)); + var desiredYaml = serialization.asYaml(sortMap(desiredMap)); + if (log.isTraceEnabled()) { + log.trace("Pruned actual resource: \n {} \ndesired resource: \n {} ", actualYaml, + desiredYaml); + } + + var patch = DiffUtils.diff(actualYaml.lines().toList(), desiredYaml.lines().toList()); + List unifiedDiff = + UnifiedDiffUtils.generateUnifiedDiff("", "", actualYaml.lines().toList(), patch, 1); + return String.join("\n", unifiedDiff); + } + + @SuppressWarnings("unchecked") + Map sortMap(Map map) { + List sortedKeys = new ArrayList<>(map.keySet()); + Collections.sort(sortedKeys); + + Map sortedMap = new LinkedHashMap<>(); + for (String key : sortedKeys) { + Object value = map.get(key); + if (value instanceof Map) { + sortedMap.put(key, sortMap((Map) value)); + } else if (value instanceof List) { + sortedMap.put(key, sortListItems((List) value)); + } else { + sortedMap.put(key, value); + } + } + return sortedMap; + } + + @SuppressWarnings("unchecked") + List sortListItems(List list) { + List sortedList = new ArrayList<>(); + for (Object item : list) { + if (item instanceof Map) { + sortedList.add(sortMap((Map) item)); + } else if (item instanceof List) { + sortedList.add(sortListItems((List) item)); + } else { + sortedList.add(item); + } } + return sortedList; } /** diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcherTest.java index bfbd7eacbb..4939724698 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcherTest.java @@ -1,5 +1,8 @@ package io.javaoperatorsdk.operator.processing.dependent.kubernetes; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; @@ -206,4 +209,48 @@ private static R loadResource(String fileName, Class clazz) { return ReconcilerUtils.loadYaml(clazz, SSABasedGenericKubernetesResourceMatcherTest.class, fileName); } + + @Test + @SuppressWarnings("unchecked") + void sortListItemsTest() { + Map nestedMap1 = new HashMap<>(); + nestedMap1.put("z", 26); + nestedMap1.put("y", 25); + + Map nestedMap2 = new HashMap<>(); + nestedMap2.put("b", 26); + nestedMap2.put("c", 25); + nestedMap2.put("a", 24); + + List unsortedListItems = Arrays.asList(1, nestedMap1, nestedMap2); + List sortedListItems = matcher.sortListItems(unsortedListItems); + + assertThat(sortedListItems).element(0).isEqualTo(1); + + Map sortedNestedMap1 = (Map) sortedListItems.get(1); + assertThat(sortedNestedMap1.keySet()).containsExactly("y", "z"); + + Map sortedNestedMap2 = (Map) sortedListItems.get(2); + assertThat(sortedNestedMap2.keySet()).containsExactly("a", "b", "c"); + } + + @Test + @SuppressWarnings("unchecked") + void testSortMapWithNestedMap() { + Map nestedMap = new HashMap<>(); + nestedMap.put("z", 26); + nestedMap.put("y", 25); + + Map unsortedMap = new HashMap<>(); + unsortedMap.put("b", nestedMap); + unsortedMap.put("a", 1); + unsortedMap.put("c", 2); + + Map sortedMap = matcher.sortMap(unsortedMap); + + assertThat(sortedMap.keySet()).containsExactly("a", "b", "c"); + + Map sortedNestedMap = (Map) sortedMap.get("b"); + assertThat(sortedNestedMap.keySet()).containsExactly("y", "z"); + } } diff --git a/pom.xml b/pom.xml index d36c1e440a..a89059e155 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,7 @@ 3.1.8 0.9.11 2.16.1 + 4.12 2.11 3.12.1 @@ -161,6 +162,11 @@ ${mokito.version} + + io.github.java-diff-utils + java-diff-utils + ${java.diff.version} + org.slf4j slf4j-api From 7a7cffdfebb2d6dd812997419ddd98a5f03da390 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 10 Oct 2024 16:33:53 +0200 Subject: [PATCH 85/96] fix: race condition in workflow reconciler (#2549) Signed-off-by: Chris Laprun --- .../workflow/AbstractWorkflowExecutor.java | 21 +++++++++++-------- .../workflow/WorkflowReconcileExecutor.java | 4 ++-- .../dependent/workflow/WorkflowResult.java | 4 ++-- .../WorkflowReconcileExecutorTest.java | 3 ++- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java index 32c0bddbc0..eb0f3f7e83 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.processing.dependent.workflow; +import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -36,7 +37,7 @@ protected AbstractWorkflowExecutor(DefaultWorkflow

workflow, P primary, Conte this.context = context; this.primaryID = ResourceID.fromResource(primary); executorService = context.getWorkflowExecutorService(); - results = new ConcurrentHashMap<>(workflow.getDependentResourcesByName().size()); + results = new HashMap<>(workflow.getDependentResourcesByName().size()); } protected abstract Logger logger(); @@ -84,13 +85,13 @@ protected boolean isMarkedForDelete(DependentResourceNode drn) { return getResultFlagFor(drn, WorkflowResult.DetailBuilder::isMarkedForDelete); } - protected WorkflowResult.DetailBuilder createOrGetResultFor( + protected synchronized WorkflowResult.DetailBuilder createOrGetResultFor( DependentResourceNode dependentResourceNode) { return results.computeIfAbsent(dependentResourceNode, unused -> new WorkflowResult.DetailBuilder()); } - protected Optional> getResultFor( + protected synchronized Optional> getResultFor( DependentResourceNode dependentResourceNode) { return Optional.ofNullable(results.get(dependentResourceNode)); } @@ -115,8 +116,8 @@ protected synchronized void handleExceptionInExecutor( createOrGetResultFor(dependentResourceNode).withError(e); } - protected boolean isNotReady(DependentResourceNode dependentResourceNode) { - return getResultFlagFor(dependentResourceNode, WorkflowResult.DetailBuilder::isNotReady); + protected boolean isReady(DependentResourceNode dependentResourceNode) { + return getResultFlagFor(dependentResourceNode, WorkflowResult.DetailBuilder::isReady); } protected boolean isInError(DependentResourceNode dependentResourceNode) { @@ -132,15 +133,17 @@ protected synchronized void handleNodeExecutionFinish( } } - @SuppressWarnings("unchecked") + @SuppressWarnings({"unchecked", "OptionalUsedAsFieldOrParameterType"}) protected boolean isConditionMet( Optional> condition, DependentResourceNode dependentResource) { final var dr = dependentResource.getDependentResource(); return condition.map(c -> { final DetailedCondition.Result r = c.detailedIsMet(dr, primary, context); - results.computeIfAbsent(dependentResource, unused -> new WorkflowResult.DetailBuilder()) - .withResultForCondition(c, r); + synchronized (this) { + results.computeIfAbsent(dependentResource, unused -> new WorkflowResult.DetailBuilder()) + .withResultForCondition(c, r); + } return r; }).orElse(DetailedCondition.Result.metWithoutResult).isSuccess(); } @@ -170,7 +173,7 @@ protected void registerOrDeregisterEventSourceBasedOnActivation( } } - protected Map> asDetails() { + protected synchronized Map> asDetails() { return results.entrySet().stream() .collect( Collectors.toMap(e -> e.getKey().getDependentResource(), e -> e.getValue().build())); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java index b130e8fd5f..962d01c8e5 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java @@ -120,7 +120,7 @@ private synchronized void handleDelete(DependentResourceNode dependentResourceNo private boolean allDependentsDeletedAlready(DependentResourceNode dependentResourceNode) { var dependents = dependentResourceNode.getParents(); - return dependents.stream().allMatch(d -> alreadyVisited(d) && !isNotReady(d) + return dependents.stream().allMatch(d -> alreadyVisited(d) && isReady(d) && !isInError(d) && !postDeleteConditionNotMet(d)); } @@ -231,7 +231,7 @@ private void markDependentsForDelete(DependentResourceNode dependentResour private boolean allParentsReconciledAndReady(DependentResourceNode dependentResourceNode) { return dependentResourceNode.getDependsOn().isEmpty() || dependentResourceNode.getDependsOn().stream() - .allMatch(d -> alreadyVisited(d) && !isNotReady(d)); + .allMatch(d -> alreadyVisited(d) && isReady(d)); } private boolean hasErroredParent(DependentResourceNode dependentResourceNode) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java index 900022444d..1b278fed77 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java @@ -178,8 +178,8 @@ public boolean hasPostDeleteConditionNotMet() { return deletePostconditionResult != null && !deletePostconditionResult.isSuccess(); } - public boolean isNotReady() { - return readyPostconditionResult != null && !readyPostconditionResult.isSuccess(); + public boolean isReady() { + return readyPostconditionResult == null || readyPostconditionResult.isSuccess(); } DetailBuilder markAsVisited() { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java index 340f308d86..826451c697 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java @@ -450,7 +450,8 @@ void readyConditionNotMetInOneParent() { void diamondShareWithReadyCondition() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2) + .toDependOn(dr1) .withReadyPostcondition(notMetCondition) .addDependentResourceAndConfigure(dr3).toDependOn(dr1) .addDependentResourceAndConfigure(dr4).toDependOn(dr2, dr3) From a0b10e64a960627f161403c610080345a7ab9f1d Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 17 Oct 2024 09:49:20 +0200 Subject: [PATCH 86/96] feat(ci): split integration tests execution by category (#2548) * feat(build): split ITs by category, parallel CRD generation Also avoid generating CRDs when not needed by default, summarizes test results. * chore(deps): bump actions-setup-minikube to 2.13.0 * feat: default to use vertx client * chore(ci): reduce tested combinations, only run client tests on baseapi * fix: increase deletion timeout --------- Signed-off-by: Chris Laprun --- .github/workflows/build.yml | 49 ++++++++ .../fabric8-next-version-schedule.yml | 42 +------ .github/workflows/integration-tests.yml | 22 +++- .github/workflows/pr.yml | 40 +----- .../WorkflowReconcileExecutorTest.java | 8 +- operator-framework/pom.xml | 10 +- .../ClusterScopedResourceIT.java | 3 +- pom.xml | 116 +++++++++++++++++- 8 files changed, 194 insertions(+), 96 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..67ab977ac3 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,49 @@ +name: Build + +env: + MAVEN_ARGS: -V -ntp -e + +on: + workflow_call: + +jobs: + integration_tests: + strategy: + matrix: + java: [ 17, 21 ] + kubernetes: [ 'v1.28.14', 'v1.29.9','1.30.5', '1.31.1' ] + it-category: [ 'baseapi', 'dependent', 'workflow' ] + uses: ./.github/workflows/integration-tests.yml + with: + java-version: ${{ matrix.java }} + kube-version: ${{ matrix.kubernetes }} + it-category: ${{ matrix.it-category }} + + http_client_tests: + strategy: + matrix: + java: [ 17, 21 ] + kubernetes: [ 'v1.28.14', 'v1.29.9','1.30.5', '1.31.1' ] + it-category: [ 'baseapi' ] + httpclient: [ 'vertx', 'jdk', 'jetty' ] + uses: ./.github/workflows/integration-tests.yml + with: + java-version: ${{ matrix.java }} + kube-version: ${{ matrix.kubernetes }} + it-category: ${{ matrix.it-category }} + http-client: ${{ matrix.httpclient }} + + special_integration_tests: + runs-on: ubuntu-latest + strategy: + matrix: + java: [ 17, 21 ] + steps: + - uses: actions/checkout@v4 + - name: Set up Java and Maven + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: ${{ matrix.java }} + - name: Run Special Integration Tests + run: ./mvnw ${MAVEN_ARGS} -B package -P minimal-watch-timeout-dependent-it --file pom.xml \ No newline at end of file diff --git a/.github/workflows/fabric8-next-version-schedule.yml b/.github/workflows/fabric8-next-version-schedule.yml index b0bc57ea75..64d2042135 100644 --- a/.github/workflows/fabric8-next-version-schedule.yml +++ b/.github/workflows/fabric8-next-version-schedule.yml @@ -23,46 +23,8 @@ jobs: with: distribution: temurin java-version: 17 - cache: 'maven' - name: Run unit tests run: ./mvnw ${MAVEN_ARGS} clean install --file pom.xml - integration_tests: - strategy: - matrix: - java: [ 11, 17 ] - kubernetes: ['v1.28.12', 'v1.29.7','1.30.3', '1.31.0'] - uses: ./.github/workflows/integration-tests.yml - with: - java-version: ${{ matrix.java }} - kube-version: ${{ matrix.kubernetes }} - - httpclient-tests: - strategy: - matrix: - httpclient: [ 'vertx', 'jdk', 'jetty' ] - uses: ./.github/workflows/integration-tests.yml - with: - java-version: 17 - kube-version: 'v1.29.1' - http-client: ${{ matrix.httpclient }} - experimental: true - checkout-ref: 'fabric8-next-version' - - special_integration_tests: - runs-on: ubuntu-latest - strategy: - matrix: - java: [ 11, 17 ] - steps: - - uses: actions/checkout@v4 - with: - ref: 'fabric8-next-version' - - name: Set up Java and Maven - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: ${{ matrix.java }} - cache: 'maven' - - name: Run Special Integration Tests - run: ./mvnw ${MAVEN_ARGS} -B package -P minimal-watch-timeout-dependent-it --file pom.xml \ No newline at end of file + build: + uses: ./.github/workflows/build.yml \ No newline at end of file diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 63a4b1c47b..e36add39c2 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -12,7 +12,7 @@ on: http-client: type: string required: false - default: 'jdk' + default: 'vertx' experimental: type: boolean required: false @@ -21,6 +21,10 @@ on: type: string required: false default: '' + it-category: + type: string + required: false + default: '' jobs: integration_tests: @@ -42,9 +46,17 @@ jobs: - name: Set up Minikube uses: manusa/actions-setup-minikube@v2.13.0 with: - minikube version: v1.33.0 - kubernetes version: ${{ inputs.kube-version }} + minikube version: 'v1.33.0' + kubernetes version: '${{ inputs.kube-version }}' driver: 'docker' github token: ${{ secrets.GITHUB_TOKEN }} - - name: Run integration tests - run: ./mvnw ${MAVEN_ARGS} -B package -P no-unit-tests -Dfabric8-httpclient-impl.name=${{inputs.http-client}} --file pom.xml \ No newline at end of file + - name: "${{inputs.it-category}} integration tests (kube: ${{ inputs.kube-version }} / java: ${{ inputs.java-version }} / client: ${{ inputs.http-client }})" + run: | + if [ -z "${{inputs.it-category}}" ]; then + it_profile="integration-tests" + else + it_profile="integration-tests-${{inputs.it-category}}" + fi + echo "Using profile: ${it_profile}" + ./mvnw ${MAVEN_ARGS} -T1C -B install -DskipTests -Pno-apt --file pom.xml + ./mvnw ${MAVEN_ARGS} -T1C -B package -P${it_profile} -Dfabric8-httpclient-impl.name=${{inputs.http-client}} --file pom.xml \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 471cea503e..facd6be13a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -28,41 +28,7 @@ jobs: run: | ./mvnw ${MAVEN_ARGS} spotless:check --file pom.xml - name: Run unit tests - run: ./mvnw ${MAVEN_ARGS} clean install --file pom.xml + run: ./mvnw ${MAVEN_ARGS} clean install -Pno-apt --file pom.xml - integration_tests: - strategy: - matrix: - java: [ 17, 21 ] - kubernetes: [ 'v1.28.12', 'v1.29.7','1.30.3', '1.31.0' ] - uses: ./.github/workflows/integration-tests.yml - with: - java-version: ${{ matrix.java }} - kube-version: ${{ matrix.kubernetes }} - - httpclient-tests: - strategy: - matrix: - httpclient: [ 'vertx', 'jdk', 'jetty' ] - uses: ./.github/workflows/integration-tests.yml - with: - java-version: 17 - kube-version: 'v1.29.1' - http-client: ${{ matrix.httpclient }} - experimental: true - - special_integration_tests: - runs-on: ubuntu-latest - strategy: - matrix: - java: [ 17, 21 ] - steps: - - uses: actions/checkout@v4 - - name: Set up Java and Maven - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: ${{ matrix.java }} - cache: 'maven' - - name: Run Special Integration Tests - run: ./mvnw ${MAVEN_ARGS} -B package -P minimal-watch-timeout-dependent-it --file pom.xml \ No newline at end of file + build: + uses: ./.github/workflows/build.yml \ No newline at end of file diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java index 826451c697..a21e8a6f14 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java @@ -6,6 +6,9 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.HasMetadata; @@ -20,6 +23,7 @@ import static org.mockito.Mockito.*; class WorkflowReconcileExecutorTest extends AbstractWorkflowExecutorTest { + private static final Logger log = LoggerFactory.getLogger(WorkflowReconcileExecutorTest.class); @SuppressWarnings("unchecked") Context mockContext = spy(Context.class); @@ -30,8 +34,8 @@ class WorkflowReconcileExecutorTest extends AbstractWorkflowExecutorTest { @BeforeEach @SuppressWarnings("unchecked") - void setup() { - when(mockContext.managedDependentResourceContext()).thenReturn(mock(ManagedDependentResourceContext.class)); + void setup(TestInfo testInfo) { + log.debug("==> Starting test {}", testInfo.getDisplayName()); when(mockContext.getWorkflowExecutorService()).thenReturn(executorService); when(mockContext.eventSourceRetriever()).thenReturn(mock(EventSourceRetriever.class)); } diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index 172f176c73..455b1268fd 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -57,11 +57,6 @@ compile-testing test - - io.fabric8 - crd-generator-apt - test - io.fabric8 @@ -113,7 +108,10 @@ + + org.apache.maven.plugins + maven-surefire-plugin + - diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedResourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedResourceIT.java index c17cf632c2..e923084425 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedResourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/clusterscopedresource/ClusterScopedResourceIT.java @@ -9,6 +9,7 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; +import static io.javaoperatorsdk.operator.IntegrationTestConstants.GARBAGE_COLLECTION_TIMEOUT_SECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -46,7 +47,7 @@ void crudOperationOnClusterScopedCustomResource() { }); operator.delete(resource); - await().atMost(Duration.ofSeconds(30)) + await().atMost(Duration.ofSeconds(GARBAGE_COLLECTION_TIMEOUT_SECONDS)) .untilAsserted(() -> assertThat(operator.get(ConfigMap.class, TEST_NAME)).isNull()); } diff --git a/pom.xml b/pom.xml index a89059e155..8d63726674 100644 --- a/pom.xml +++ b/pom.xml @@ -255,6 +255,11 @@ org.apache.maven.plugins maven-compiler-plugin ${maven-compiler-plugin.version} + + + -Aio.fabric8.crd.generator.parallel=true + + org.apache.maven.plugins @@ -275,6 +280,23 @@ org.apache.maven.plugins maven-surefire-plugin ${maven-surefire-plugin.version} + + + plain + + true + + + UNICODE + + + + + me.fabriciorby + maven-surefire-junit5-tree-reporter + 1.3.0 + + org.apache.maven.plugins @@ -349,7 +371,14 @@ - all-tests + integration-tests + + + io.fabric8 + crd-generator-apt + test + + @@ -357,17 +386,26 @@ maven-surefire-plugin - **/*Test.java **/*IT.java - **/*E2E.java + + **/*Test.java + **/*E2E.java + - no-unit-tests + integration-tests-baseapi + + + io.fabric8 + crd-generator-apt + test + + @@ -375,7 +413,61 @@ maven-surefire-plugin - **/*IT.java + io/javaoperatorsdk/operator/baseapi/**/*IT.java + + + **/*Test.java + **/*E2E.java + + + + + + + + integration-tests-dependent + + + io.fabric8 + crd-generator-apt + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + io/javaoperatorsdk/operator/dependent/**/*IT.java + + + **/*Test.java + **/*E2E.java + + + + + + + + integration-tests-workflow + + + io.fabric8 + crd-generator-apt + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + io/javaoperatorsdk/operator/workflow/**/*IT.java **/*Test.java @@ -389,6 +481,13 @@ minimal-watch-timeout-dependent-it + + + io.fabric8 + crd-generator-apt + test + + @@ -410,6 +509,13 @@ end-to-end-tests + + + io.fabric8 + crd-generator-apt + test + + From f2ccea9a8a5b9c366a7ab60cd4ebb8d222f64289 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 17 Oct 2024 10:23:20 +0200 Subject: [PATCH 87/96] refactor: rename method more appropriately (#2554) Signed-off-by: Chris Laprun --- .../processing/dependent/workflow/DefaultWorkflow.java | 2 +- .../processing/dependent/workflow/WorkflowCleanupExecutor.java | 3 ++- .../operator/processing/dependent/workflow/WorkflowTest.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java index 782f8a61ec..bff83b175a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java @@ -117,7 +117,7 @@ public Set getTopLevelDependentResources() { return topLevelResources; } - public Set getBottomLevelResource() { + public Set getBottomLevelDependentResources() { return bottomLevelResource; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutor.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutor.java index da518be6ce..73633adb82 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutor.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutor.java @@ -21,7 +21,8 @@ class WorkflowCleanupExecutor

extends AbstractWorkflowExe } public synchronized WorkflowCleanupResult cleanup() { - for (DependentResourceNode dependentResourceNode : workflow.getBottomLevelResource()) { + for (DependentResourceNode dependentResourceNode : workflow + .getBottomLevelDependentResources()) { handleCleanup(dependentResourceNode); } waitForScheduledExecutionsToRun(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java index b8d90a45ad..415218b587 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java @@ -69,7 +69,7 @@ void calculatesBottomLevelResources() { .buildAsDefaultWorkflow(); Set bottomResources = - workflow.getBottomLevelResource().stream() + workflow.getBottomLevelDependentResources().stream() .map(DependentResourceNode::getDependentResource) .collect(Collectors.toSet()); From 85c7cb2268c664f0b65b651dc82d33f792378fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sat, 26 Oct 2024 13:21:00 +0200 Subject: [PATCH 88/96] improve: workflow builder naming (#2559) --- .../dependent/workflow/WorkflowBuilder.java | 6 +- .../workflow/WorkflowCleanupExecutorTest.java | 46 +++++----- .../WorkflowReconcileExecutorTest.java | 88 +++++++++---------- .../dependent/workflow/WorkflowTest.java | 12 +-- 4 files changed, 76 insertions(+), 76 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java index 20f40c5a83..7493058723 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowBuilder.java @@ -93,7 +93,7 @@ public WorkflowBuilder

withThrowExceptionFurther(boolean throwExceptionFurthe return WorkflowBuilder.this.withThrowExceptionFurther(throwExceptionFurther); } - public WorkflowNodeConfigurationBuilder toDependOn(Set dependentResources) { + public WorkflowNodeConfigurationBuilder dependsOn(Set dependentResources) { for (var dependentResource : dependentResources) { var dependsOn = getNodeByDependentResource(dependentResource); currentNode.addDependsOnRelation(dependsOn); @@ -101,9 +101,9 @@ public WorkflowNodeConfigurationBuilder toDependOn(Set depend return this; } - public WorkflowNodeConfigurationBuilder toDependOn(DependentResource... dependentResources) { + public WorkflowNodeConfigurationBuilder dependsOn(DependentResource... dependentResources) { if (dependentResources != null) { - return toDependOn(new HashSet<>(Arrays.asList(dependentResources))); + return dependsOn(new HashSet<>(Arrays.asList(dependentResources))); } return this; } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java index 2d9dee6fc8..8c624405da 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java @@ -54,9 +54,9 @@ void setup() { void cleanUpDiamondWorkflow() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResourceAndConfigure(dr1).toDependOn(dd1) - .addDependentResourceAndConfigure(dd2).toDependOn(dd1) - .addDependentResourceAndConfigure(dd3).toDependOn(dr1, dd2) + .addDependentResourceAndConfigure(dr1).dependsOn(dd1) + .addDependentResourceAndConfigure(dd2).dependsOn(dd1) + .addDependentResourceAndConfigure(dd3).dependsOn(dr1, dd2) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -73,9 +73,9 @@ void cleanUpDiamondWorkflow() { void dontDeleteIfDependentErrored() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResourceAndConfigure(dd2).toDependOn(dd1) - .addDependentResourceAndConfigure(dd3).toDependOn(dd2) - .addDependentResourceAndConfigure(errorDD).toDependOn(dd2) + .addDependentResourceAndConfigure(dd2).dependsOn(dd1) + .addDependentResourceAndConfigure(dd3).dependsOn(dd2) + .addDependentResourceAndConfigure(errorDD).dependsOn(dd2) .withThrowExceptionFurther(false) .build(); @@ -95,7 +95,7 @@ void dontDeleteIfDependentErrored() { void cleanupConditionTrivialCase() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResourceAndConfigure(dd2).toDependOn(dd1) + .addDependentResourceAndConfigure(dd2).dependsOn(dd1) .withDeletePostcondition(notMetCondition) .build(); @@ -111,7 +111,7 @@ void cleanupConditionTrivialCase() { void cleanupConditionMet() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResourceAndConfigure(dd2).toDependOn(dd1).withDeletePostcondition(metCondition) + .addDependentResourceAndConfigure(dd2).dependsOn(dd1).withDeletePostcondition(metCondition) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -127,10 +127,10 @@ void cleanupConditionMet() { void cleanupConditionDiamondWorkflow() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResourceAndConfigure(dd2).toDependOn(dd1) - .addDependentResourceAndConfigure(dd3).toDependOn(dd1) + .addDependentResourceAndConfigure(dd2).dependsOn(dd1) + .addDependentResourceAndConfigure(dd3).dependsOn(dd1) .withDeletePostcondition(notMetCondition) - .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) + .addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -164,10 +164,10 @@ void dontDeleteIfGarbageCollected() { void ifDependentActiveDependentNormallyDeleted() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResourceAndConfigure(dd2).toDependOn(dd1) - .addDependentResourceAndConfigure(dd3).toDependOn(dd1) + .addDependentResourceAndConfigure(dd2).dependsOn(dd1) + .addDependentResourceAndConfigure(dd3).dependsOn(dd1) .withActivationCondition(metCondition) - .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) + .addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -184,11 +184,11 @@ void ifDependentActiveDependentNormallyDeleted() { void ifDependentActiveDeletePostConditionIsChecked() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResourceAndConfigure(dd2).toDependOn(dd1) - .addDependentResourceAndConfigure(dd3).toDependOn(dd1) + .addDependentResourceAndConfigure(dd2).dependsOn(dd1) + .addDependentResourceAndConfigure(dd3).dependsOn(dd1) .withDeletePostcondition(notMetCondition) .withActivationCondition(metCondition) - .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) + .addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -208,10 +208,10 @@ void ifDependentActiveDeletePostConditionIsChecked() { void ifDependentInactiveDeleteIsNotCalled() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResourceAndConfigure(dd2).toDependOn(dd1) - .addDependentResourceAndConfigure(dd3).toDependOn(dd1) + .addDependentResourceAndConfigure(dd2).dependsOn(dd1) + .addDependentResourceAndConfigure(dd3).dependsOn(dd1) .withActivationCondition(notMetCondition) - .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) + .addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); @@ -227,11 +227,11 @@ void ifDependentInactiveDeleteIsNotCalled() { void ifDependentInactiveDeletePostConditionNotChecked() { var workflow = new WorkflowBuilder() .addDependentResource(dd1) - .addDependentResourceAndConfigure(dd2).toDependOn(dd1) - .addDependentResourceAndConfigure(dd3).toDependOn(dd1) + .addDependentResourceAndConfigure(dd2).dependsOn(dd1) + .addDependentResourceAndConfigure(dd3).dependsOn(dd1) .withDeletePostcondition(notMetCondition) .withActivationCondition(notMetCondition) - .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3) + .addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3) .build(); var res = workflow.cleanup(new TestCustomResource(), mockContext); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java index a21e8a6f14..7b62926ff5 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java @@ -58,7 +58,7 @@ void reconcileTopLevelResources() { void reconciliationWithSimpleDependsOn() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -75,8 +75,8 @@ void reconciliationWithTwoTheDependsOns() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) - .addDependentResourceAndConfigure(dr3).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr3).dependsOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -93,9 +93,9 @@ void reconciliationWithTwoTheDependsOns() { void diamondShareWorkflowReconcile() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) - .addDependentResourceAndConfigure(dr3).toDependOn(dr1) - .addDependentResourceAndConfigure(dr4).toDependOn(dr3).toDependOn(dr2) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr3).dependsOn(dr1) + .addDependentResourceAndConfigure(dr4).dependsOn(dr3).dependsOn(dr2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -133,8 +133,8 @@ void exceptionHandlingSimpleCases() { void dependentsOnErroredResourceNotReconciled() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResourceAndConfigure(drError).toDependOn(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(drError) + .addDependentResourceAndConfigure(drError).dependsOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(drError) .withThrowExceptionFurther(false) .build(); @@ -153,9 +153,9 @@ void oneBranchErrorsOtherCompletes() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResourceAndConfigure(drError).toDependOn(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) - .addDependentResourceAndConfigure(dr3).toDependOn(dr2) + .addDependentResourceAndConfigure(drError).dependsOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr3).dependsOn(dr2) .withThrowExceptionFurther(false) .build(); @@ -174,7 +174,7 @@ void onlyOneDependsOnErroredResourceNotReconciled() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) .addDependentResource(drError) - .addDependentResourceAndConfigure(dr2).toDependOn(drError, dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(drError, dr1) .withThrowExceptionFurther(false) .build(); @@ -221,9 +221,9 @@ public Result detailedIsMet( void triangleOnceConditionNotMet() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) - .toDependOn(dr1) + .dependsOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -240,11 +240,11 @@ void reconcileConditionTransitiveDelete() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) .withReconcilePrecondition(notMetCondition) - .addDependentResourceAndConfigure(drDeleter).toDependOn(dr2) + .addDependentResourceAndConfigure(drDeleter).dependsOn(dr2) .withReconcilePrecondition(metCondition) - .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter) .withReconcilePrecondition(metCondition) .build(); @@ -267,7 +267,7 @@ void reconcileConditionAlsoErrorDependsOn() { var workflow = new WorkflowBuilder() .addDependentResource(drError) .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) - .addDependentResourceAndConfigure(drDeleter2).toDependOn(drError, drDeleter) + .addDependentResourceAndConfigure(drDeleter2).dependsOn(drError, drDeleter) .withReconcilePrecondition(metCondition) .withThrowExceptionFurther(false) .build(); @@ -290,7 +290,7 @@ void oneDependsOnConditionNotMet() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) .addDependentResourceAndConfigure(dr2).withReconcilePrecondition(notMetCondition) - .addDependentResourceAndConfigure(drDeleter).toDependOn(dr1, dr2) + .addDependentResourceAndConfigure(drDeleter).dependsOn(dr1, dr2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -308,9 +308,9 @@ void deletedIfReconcileConditionNotMet() { TestDeleterDependent drDeleter2 = new TestDeleterDependent("DR_DELETER_2"); var workflow = new WorkflowBuilder() .addDependentResource(dr1) - .addDependentResourceAndConfigure(drDeleter).toDependOn(dr1) + .addDependentResourceAndConfigure(drDeleter).dependsOn(dr1) .withReconcilePrecondition(notMetCondition) - .addDependentResourceAndConfigure(drDeleter2).toDependOn(dr1, drDeleter) + .addDependentResourceAndConfigure(drDeleter2).dependsOn(dr1, drDeleter) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -333,10 +333,10 @@ void deleteDoneInReverseOrder() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) - .toDependOn(dr1) - .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) - .addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter) - .addDependentResourceAndConfigure(drDeleter4).toDependOn(drDeleter3) + .dependsOn(dr1) + .addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter3).dependsOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter4).dependsOn(drDeleter3) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -359,10 +359,10 @@ void diamondDeleteWithPostConditionInMiddle() { var workflow = new WorkflowBuilder() .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) - .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) - .addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter3).dependsOn(drDeleter) .withDeletePostcondition(this.notMetCondition) - .addDependentResourceAndConfigure(drDeleter4).toDependOn(drDeleter3, drDeleter2) + .addDependentResourceAndConfigure(drDeleter4).dependsOn(drDeleter3, drDeleter2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -383,9 +383,9 @@ void diamondDeleteErrorInMiddle() { var workflow = new WorkflowBuilder() .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition) - .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) - .addDependentResourceAndConfigure(errorDD).toDependOn(drDeleter) - .addDependentResourceAndConfigure(drDeleter3).toDependOn(errorDD, drDeleter2) + .addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter) + .addDependentResourceAndConfigure(errorDD).dependsOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter3).dependsOn(errorDD, drDeleter2) .withThrowExceptionFurther(false) .build(); @@ -404,7 +404,7 @@ void diamondDeleteErrorInMiddle() { void readyConditionTrivialCase() { var workflow = new WorkflowBuilder() .addDependentResourceAndConfigure(dr1).withReadyPostcondition(metCondition) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -420,7 +420,7 @@ void readyConditionTrivialCase() { void readyConditionNotMetTrivialCase() { var workflow = new WorkflowBuilder() .addDependentResourceAndConfigure(dr1).withReadyPostcondition(notMetCondition) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -439,7 +439,7 @@ void readyConditionNotMetInOneParent() { var workflow = new WorkflowBuilder() .addDependentResourceAndConfigure(dr1).withReadyPostcondition(notMetCondition) .addDependentResource(dr2) - .addDependentResourceAndConfigure(dr3).toDependOn(dr1, dr2) + .addDependentResourceAndConfigure(dr3).dependsOn(dr1, dr2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -455,10 +455,10 @@ void diamondShareWithReadyCondition() { var workflow = new WorkflowBuilder() .addDependentResource(dr1) .addDependentResourceAndConfigure(dr2) - .toDependOn(dr1) + .dependsOn(dr1) .withReadyPostcondition(notMetCondition) - .addDependentResourceAndConfigure(dr3).toDependOn(dr1) - .addDependentResourceAndConfigure(dr4).toDependOn(dr2, dr3) + .addDependentResourceAndConfigure(dr3).dependsOn(dr1) + .addDependentResourceAndConfigure(dr4).dependsOn(dr2, dr3) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -489,7 +489,7 @@ void garbageCollectedResourceIsDeletedIfReconcilePreconditionDoesNotHold() { void garbageCollectedDeepResourceIsDeletedIfReconcilePreconditionDoesNotHold() { var workflow = new WorkflowBuilder() .addDependentResourceAndConfigure(dr1).withReconcilePrecondition(notMetCondition) - .addDependentResourceAndConfigure(gcDeleter).toDependOn(dr1) + .addDependentResourceAndConfigure(gcDeleter).dependsOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -518,7 +518,7 @@ void dependentsOnANonActiveDependentNotReconciled() { .addDependentResourceAndConfigure(dr1) .withActivationCondition(notMetCondition) .addDependentResource(dr2) - .addDependentResourceAndConfigure(dr3).toDependOn(dr1) + .addDependentResourceAndConfigure(dr3).dependsOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -534,7 +534,7 @@ void readyConditionNotCheckedOnNonActiveDependent() { .withActivationCondition(notMetCondition) .withReadyPostcondition(notMetCondition) .addDependentResource(dr2) - .addDependentResourceAndConfigure(dr3).toDependOn(dr1) + .addDependentResourceAndConfigure(dr3).dependsOn(dr1) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -565,10 +565,10 @@ void deletesDependentsOfNonActiveDependentButNotTheNonActive() { var workflow = new WorkflowBuilder() .addDependentResourceAndConfigure(dr1).withActivationCondition(notMetCondition) - .addDependentResourceAndConfigure(drDeleter).toDependOn(dr1) - .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter).dependsOn(dr1) + .addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter) .withActivationCondition(notMetCondition) - .addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter2) + .addDependentResourceAndConfigure(drDeleter3).dependsOn(drDeleter2) .build(); var res = workflow.reconcile(new TestCustomResource(), mockContext); @@ -588,7 +588,7 @@ void activationConditionOnlyCalledOnceOnDeleteDependents() { var workflow = new WorkflowBuilder() .addDependentResourceAndConfigure(drDeleter).withActivationCondition(condition) - .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter) + .addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter) .build(); workflow.reconcile(new TestCustomResource(), mockContext); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java index 415218b587..6d268082f5 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java @@ -27,10 +27,10 @@ void zeroTopLevelDRShouldThrowException() { var dr3 = mockDependent("dr3"); var cyclicWorkflowBuilderSetup = new WorkflowBuilder() - .addDependentResourceAndConfigure(dr1).toDependOn() - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) - .addDependentResourceAndConfigure(dr3).toDependOn(dr2) - .addDependentResourceAndConfigure(dr1).toDependOn(dr2); + .addDependentResourceAndConfigure(dr1).dependsOn() + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) + .addDependentResourceAndConfigure(dr3).dependsOn(dr2) + .addDependentResourceAndConfigure(dr1).dependsOn(dr2); assertThrows(IllegalStateException.class, cyclicWorkflowBuilderSetup::build); @@ -45,7 +45,7 @@ void calculatesTopLevelResources() { var workflow = new WorkflowBuilder() .addDependentResource(independentDR) .addDependentResource(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) .buildAsDefaultWorkflow(); Set topResources = @@ -65,7 +65,7 @@ void calculatesBottomLevelResources() { final var workflow = new WorkflowBuilder() .addDependentResource(independentDR) .addDependentResource(dr1) - .addDependentResourceAndConfigure(dr2).toDependOn(dr1) + .addDependentResourceAndConfigure(dr2).dependsOn(dr1) .buildAsDefaultWorkflow(); Set bottomResources = From 7dce3265e232c68f7f296dc48b3de4caa108544a Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Tue, 5 Nov 2024 20:01:58 +0100 Subject: [PATCH 89/96] chore: adapt after rebase Signed-off-by: Chris Laprun --- ...edWorkflowAndDependentResourceContext.java | 14 +++++----- .../operator/processing/Controller.java | 27 +++++++------------ .../dependent/workflow/DefaultWorkflow.java | 10 +++---- .../workflow/WorkflowCleanupExecutorTest.java | 6 ++--- .../WorkflowReconcileExecutorTest.java | 3 +++ 5 files changed, 27 insertions(+), 33 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java index ee2987983d..161c38210f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedWorkflowAndDependentResourceContext.java @@ -11,10 +11,10 @@ @SuppressWarnings("rawtypes") public class DefaultManagedWorkflowAndDependentResourceContext

- implements ManagedWorkflowAndDependentResourceContext { + implements ManagedWorkflowAndDependentResourceContext { - public static final Object RECONCILE_RESULT_KEY = new Object(); - public static final Object CLEANUP_RESULT_KEY = new Object(); + public static final Object RECONCILE_RESULT_KEY = new Object(); + public static final Object CLEANUP_RESULT_KEY = new Object(); private final ConcurrentHashMap attributes = new ConcurrentHashMap(); private final Controller

controller; private final P primaryResource; @@ -53,13 +53,13 @@ public T getMandatory(Object key, Class expectedType) { } @Override - public Optional getWorkflowReconcileResult() { - return get(RECONCILE_RESULT_KEY, WorkflowReconcileResult.class); + public WorkflowReconcileResult getWorkflowReconcileResult() { + return getMandatory(RECONCILE_RESULT_KEY, WorkflowReconcileResult.class); } @Override - public Optional getWorkflowCleanupResult() { - return get(CLEANUP_RESULT_KEY, WorkflowCleanupResult.class); + public WorkflowCleanupResult getWorkflowCleanupResult() { + return getMandatory(CLEANUP_RESULT_KEY, WorkflowCleanupResult.class); } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index bf8b18ea53..76c8401249 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -149,7 +149,7 @@ public UpdateControl

execute() throws Exception { initContextIfNeeded(resource, context); configuration.getWorkflowSpec().ifPresent(ws -> { if (!managedWorkflow.isEmpty() && !explicitWorkflowInvocation) { - managedWorkflow.reconcile(resource, context); + managedWorkflow.reconcile(resource, context); } }); return reconciler.reconcile(resource, context); @@ -177,9 +177,9 @@ public String successTypeName(DeleteControl deleteControl) { return deleteControl.isRemoveFinalizer() ? DELETE : FINALIZER_NOT_REMOVED; } - @Override - public ResourceID resourceID() { - return ResourceID.fromResource(resource); + @Override + public ResourceID resourceID() { + return ResourceID.fromResource(resource); } @Override @@ -192,7 +192,8 @@ public DeleteControl execute() throws Exception { initContextIfNeeded(resource, context); WorkflowCleanupResult workflowCleanupResult = null; - // The cleanup is called also when explicit invocation is true, but the cleaner is not implemented + // The cleanup is called also when explicit invocation is true, but the cleaner is not + // implemented if (managedWorkflow.hasCleaner() || !explicitWorkflowInvocation) { workflowCleanupResult = managedWorkflow.cleanup(resource, context); } @@ -450,23 +451,13 @@ public EventSourceContext

eventSourceContext() { public void reconcileManagedWorkflow(P primary, Context

context) { if (!managedWorkflow.isEmpty()) { - var res = managedWorkflow.reconcile(primary, context); - ((DefaultManagedWorkflowAndDependentResourceContext) context - .managedWorkflowAndDependentResourceContext()) - .setWorkflowExecutionResult(res); + managedWorkflow.reconcile(primary, context); } } - public WorkflowCleanupResult cleanupManagedWorkflow(P resource, Context

context) { + public void cleanupManagedWorkflow(P resource, Context

context) { if (managedWorkflow.hasCleaner()) { - var workflowCleanupResult = managedWorkflow.cleanup(resource, context); - ((DefaultManagedWorkflowAndDependentResourceContext) context - .managedWorkflowAndDependentResourceContext()) - .setWorkflowCleanupResult(workflowCleanupResult); - - return workflowCleanupResult; - } else { - return null; + managedWorkflow.cleanup(resource, context); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java index bff83b175a..3b928ad78a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java @@ -12,9 +12,11 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedDependentResourceContext; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; +import static io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedWorkflowAndDependentResourceContext.CLEANUP_RESULT_KEY; +import static io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedWorkflowAndDependentResourceContext.RECONCILE_RESULT_KEY; + /** * Dependents definition: so if B depends on A, the B is dependent of A. * @@ -92,8 +94,7 @@ public WorkflowReconcileResult reconcile(P primary, Context

context) { WorkflowReconcileExecutor

workflowReconcileExecutor = new WorkflowReconcileExecutor<>(this, primary, context); var result = workflowReconcileExecutor.reconcile(); - context.managedDependentResourceContext() - .put(DefaultManagedDependentResourceContext.RECONCILE_RESULT_KEY, result); + context.managedWorkflowAndDependentResourceContext().put(RECONCILE_RESULT_KEY, result); if (throwExceptionAutomatically) { result.throwAggregateExceptionIfErrorsPresent(); } @@ -105,8 +106,7 @@ public WorkflowCleanupResult cleanup(P primary, Context

context) { WorkflowCleanupExecutor

workflowCleanupExecutor = new WorkflowCleanupExecutor<>(this, primary, context); var result = workflowCleanupExecutor.cleanup(); - context.managedDependentResourceContext() - .put(DefaultManagedDependentResourceContext.CLEANUP_RESULT_KEY, result); + context.managedWorkflowAndDependentResourceContext().put(CLEANUP_RESULT_KEY, result); if (throwExceptionAutomatically) { result.throwAggregateExceptionIfErrorsPresent(); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java index 8c624405da..878cec419c 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java @@ -14,7 +14,7 @@ import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedDependentResourceContext; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedWorkflowAndDependentResourceContext; import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; @@ -44,8 +44,8 @@ void setup() { when(eventSourceContextMock.getControllerConfiguration()).thenReturn(mockControllerConfig); when(mockControllerConfig.getConfigurationService()) .thenReturn(mock(ConfigurationService.class)); - when(mockContext.managedDependentResourceContext()) - .thenReturn(mock(ManagedDependentResourceContext.class)); + when(mockContext.managedWorkflowAndDependentResourceContext()) + .thenReturn(mock(ManagedWorkflowAndDependentResourceContext.class)); when(mockContext.getWorkflowExecutorService()).thenReturn(executorService); when(mockContext.eventSourceRetriever()).thenReturn(eventSourceRetrieverMock); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java index 7b62926ff5..0aa93fb0f9 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java @@ -15,6 +15,7 @@ import io.javaoperatorsdk.operator.AggregatedOperatorException; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedWorkflowAndDependentResourceContext; import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever; import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; @@ -36,6 +37,8 @@ class WorkflowReconcileExecutorTest extends AbstractWorkflowExecutorTest { @SuppressWarnings("unchecked") void setup(TestInfo testInfo) { log.debug("==> Starting test {}", testInfo.getDisplayName()); + when(mockContext.managedWorkflowAndDependentResourceContext()) + .thenReturn(mock(ManagedWorkflowAndDependentResourceContext.class)); when(mockContext.getWorkflowExecutorService()).thenReturn(executorService); when(mockContext.eventSourceRetriever()).thenReturn(mock(EventSourceRetriever.class)); } From 5f71aaa7c25bfbca89e879b4b2110a11bc2ea86d Mon Sep 17 00:00:00 2001 From: Donnerbart Date: Wed, 6 Nov 2024 08:11:31 +0000 Subject: [PATCH 90/96] fix: infinite resource updates due to canonical format conversion of resource requirements (#2565) * refactor: clean up SSABasedGenericKubernetesResourceMatcher Signed-off-by: David Sondermann * test: add missing tests for StatefulSet with VolumeClaimTemplates for SSABasedGenericKubernetesResourceMatcher Signed-off-by: David Sondermann * fix: Fix infinite resource updates due to canonical format conversion of resource requirements Signed-off-by: David Sondermann * test: Add test cases with init containers to ResourceRequirementsSanitizerTest Signed-off-by: David Sondermann --------- Signed-off-by: David Sondermann Signed-off-by: Chris Laprun --- ...BasedGenericKubernetesResourceMatcher.java | 59 ++++++------- ...dGenericKubernetesResourceMatcherTest.java | 87 +++++++++---------- 2 files changed, 70 insertions(+), 76 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java index a314b22723..261ab6c825 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java @@ -12,10 +12,6 @@ import java.util.Optional; import java.util.Set; import java.util.TreeMap; -import java.util.Optional; -import java.util.Set; -import java.util.SortedMap; -import java.util.TreeMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,11 +28,11 @@ import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.LoggingUtils; -import static io.javaoperatorsdk.operator.processing.dependent.kubernetes.ResourceRequirementsSanitizer.sanitizeResourceRequirements; - import com.github.difflib.DiffUtils; import com.github.difflib.UnifiedDiffUtils; +import static io.javaoperatorsdk.operator.processing.dependent.kubernetes.ResourceRequirementsSanitizer.sanitizeResourceRequirements; + /** * Matches the actual state on the server vs the desired state. Based on the managedFields of SSA. *

@@ -112,15 +108,13 @@ public boolean matches(R actual, R desired, Context context) { removeIrrelevantValues(desiredMap); var matches = prunedActual.equals(desiredMap); - if (!matches && log.isDebugEnabled() && LoggingUtils.isNotSensitiveResource(desired)) { var diff = getDiff(prunedActual, desiredMap, objectMapper); log.debug( - "Diff between actual and desired state for resource: {} with name: {} in namespace: {} is: \n{}", + "Diff between actual and desired state for resource: {} with name: {} in namespace: {} is:\n{}", actual.getKind(), actual.getMetadata().getName(), actual.getMetadata().getNamespace(), diff); } - return matches; } @@ -129,24 +123,23 @@ private String getDiff(Map prunedActualMap, Map var actualYaml = serialization.asYaml(sortMap(prunedActualMap)); var desiredYaml = serialization.asYaml(sortMap(desiredMap)); if (log.isTraceEnabled()) { - log.trace("Pruned actual resource: \n {} \ndesired resource: \n {} ", actualYaml, - desiredYaml); + log.trace("Pruned actual resource:\n {} \ndesired resource:\n {} ", actualYaml, desiredYaml); } var patch = DiffUtils.diff(actualYaml.lines().toList(), desiredYaml.lines().toList()); - List unifiedDiff = + var unifiedDiff = UnifiedDiffUtils.generateUnifiedDiff("", "", actualYaml.lines().toList(), patch, 1); return String.join("\n", unifiedDiff); } @SuppressWarnings("unchecked") Map sortMap(Map map) { - List sortedKeys = new ArrayList<>(map.keySet()); + var sortedKeys = new ArrayList<>(map.keySet()); Collections.sort(sortedKeys); - Map sortedMap = new LinkedHashMap<>(); - for (String key : sortedKeys) { - Object value = map.get(key); + var sortedMap = new LinkedHashMap(); + for (var key : sortedKeys) { + var value = map.get(key); if (value instanceof Map) { sortedMap.put(key, sortMap((Map) value)); } else if (value instanceof List) { @@ -160,8 +153,8 @@ Map sortMap(Map map) { @SuppressWarnings("unchecked") List sortListItems(List list) { - List sortedList = new ArrayList<>(); - for (Object item : list) { + var sortedList = new ArrayList<>(); + for (var item : list) { if (item instanceof Map) { sortedList.add(sortMap((Map) item)); } else if (item instanceof List) { @@ -177,9 +170,10 @@ List sortListItems(List list) { * Correct for known issue with SSA */ private void sanitizeState(R actual, R desired, Map actualMap) { - if (actual instanceof StatefulSet) { - var actualSpec = (((StatefulSet) actual)).getSpec(); - var desiredSpec = (((StatefulSet) desired)).getSpec(); + if (actual instanceof StatefulSet actualStatefulSet + && desired instanceof StatefulSet desiredStatefulSet) { + var actualSpec = actualStatefulSet.getSpec(); + var desiredSpec = desiredStatefulSet.getSpec(); int claims = desiredSpec.getVolumeClaimTemplates().size(); if (claims == actualSpec.getVolumeClaimTemplates().size()) { for (int i = 0; i < claims; i++) { @@ -197,18 +191,21 @@ private void sanitizeState(R actual, R desired, Map actualMap) { } } sanitizeResourceRequirements(actualMap, actualSpec.getTemplate(), desiredSpec.getTemplate()); - } else if (actual instanceof Deployment) { + } else if (actual instanceof Deployment actualDeployment + && desired instanceof Deployment desiredDeployment) { sanitizeResourceRequirements(actualMap, - ((Deployment) actual).getSpec().getTemplate(), - ((Deployment) desired).getSpec().getTemplate()); - } else if (actual instanceof ReplicaSet) { + actualDeployment.getSpec().getTemplate(), + desiredDeployment.getSpec().getTemplate()); + } else if (actual instanceof ReplicaSet actualReplicaSet + && desired instanceof ReplicaSet desiredReplicaSet) { sanitizeResourceRequirements(actualMap, - ((ReplicaSet) actual).getSpec().getTemplate(), - ((ReplicaSet) desired).getSpec().getTemplate()); - } else if (actual instanceof DaemonSet) { + actualReplicaSet.getSpec().getTemplate(), + desiredReplicaSet.getSpec().getTemplate()); + } else if (actual instanceof DaemonSet actualDaemonSet + && desired instanceof DaemonSet desiredDaemonSet) { sanitizeResourceRequirements(actualMap, - ((DaemonSet) actual).getSpec().getTemplate(), - ((DaemonSet) desired).getSpec().getTemplate()); + actualDaemonSet.getSpec().getTemplate(), + desiredDaemonSet.getSpec().getTemplate()); } } @@ -393,7 +390,7 @@ private static Map.Entry> selectListEntryBasedOnKey } } if (possibleTargets.isEmpty()) { - throw new IllegalStateException("Cannot find list element for key: " + key + ", in map: " + throw new IllegalStateException("Cannot find list element for key: " + key + " in map: " + values.stream().map(Map::keySet).toList()); } if (possibleTargets.size() > 1) { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcherTest.java index 4939724698..f30b6949fa 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcherTest.java @@ -1,6 +1,5 @@ package io.javaoperatorsdk.operator.processing.dependent.kubernetes; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -123,6 +122,48 @@ void addedLabelInDesiredMakesMatchFail() { assertThat(matcher.matches(actualConfigMap, desiredConfigMap, mockedContext)).isFalse(); } + @Test + @SuppressWarnings("unchecked") + void sortListItemsTest() { + var nestedMap1 = new HashMap(); + nestedMap1.put("z", 26); + nestedMap1.put("y", 25); + + var nestedMap2 = new HashMap(); + nestedMap2.put("b", 26); + nestedMap2.put("c", 25); + nestedMap2.put("a", 24); + + var unsortedListItems = List.of(1, nestedMap1, nestedMap2); + var sortedListItems = matcher.sortListItems(unsortedListItems); + assertThat(sortedListItems).element(0).isEqualTo(1); + + var sortedNestedMap1 = (Map) sortedListItems.get(1); + assertThat(sortedNestedMap1.keySet()).containsExactly("y", "z"); + + var sortedNestedMap2 = (Map) sortedListItems.get(2); + assertThat(sortedNestedMap2.keySet()).containsExactly("a", "b", "c"); + } + + @Test + @SuppressWarnings("unchecked") + void testSortMapWithNestedMap() { + var nestedMap = new HashMap(); + nestedMap.put("z", 26); + nestedMap.put("y", 25); + + var unsortedMap = new HashMap(); + unsortedMap.put("b", nestedMap); + unsortedMap.put("a", 1); + unsortedMap.put("c", 2); + + var sortedMap = matcher.sortMap(unsortedMap); + assertThat(sortedMap.keySet()).containsExactly("a", "b", "c"); + + var sortedNestedMap = (Map) sortedMap.get("b"); + assertThat(sortedNestedMap.keySet()).containsExactly("y", "z"); + } + @ParameterizedTest @ValueSource(strings = {"sample-sts-volumeclaimtemplates-desired.yaml", "sample-sts-volumeclaimtemplates-desired-with-status.yaml", @@ -209,48 +250,4 @@ private static R loadResource(String fileName, Class clazz) { return ReconcilerUtils.loadYaml(clazz, SSABasedGenericKubernetesResourceMatcherTest.class, fileName); } - - @Test - @SuppressWarnings("unchecked") - void sortListItemsTest() { - Map nestedMap1 = new HashMap<>(); - nestedMap1.put("z", 26); - nestedMap1.put("y", 25); - - Map nestedMap2 = new HashMap<>(); - nestedMap2.put("b", 26); - nestedMap2.put("c", 25); - nestedMap2.put("a", 24); - - List unsortedListItems = Arrays.asList(1, nestedMap1, nestedMap2); - List sortedListItems = matcher.sortListItems(unsortedListItems); - - assertThat(sortedListItems).element(0).isEqualTo(1); - - Map sortedNestedMap1 = (Map) sortedListItems.get(1); - assertThat(sortedNestedMap1.keySet()).containsExactly("y", "z"); - - Map sortedNestedMap2 = (Map) sortedListItems.get(2); - assertThat(sortedNestedMap2.keySet()).containsExactly("a", "b", "c"); - } - - @Test - @SuppressWarnings("unchecked") - void testSortMapWithNestedMap() { - Map nestedMap = new HashMap<>(); - nestedMap.put("z", 26); - nestedMap.put("y", 25); - - Map unsortedMap = new HashMap<>(); - unsortedMap.put("b", nestedMap); - unsortedMap.put("a", 1); - unsortedMap.put("c", 2); - - Map sortedMap = matcher.sortMap(unsortedMap); - - assertThat(sortedMap.keySet()).containsExactly("a", "b", "c"); - - Map sortedNestedMap = (Map) sortedMap.get("b"); - assertThat(sortedNestedMap.keySet()).containsExactly("y", "z"); - } } From 6157e2be347413f4c02d654059d1619957b3def8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 13 Nov 2024 16:41:00 +0100 Subject: [PATCH 91/96] fix: concurrent modification when getting event sources (v5) (#2572) --- .../processing/event/EventSources.java | 6 ++- .../event/EventSourceManagerTest.java | 2 + .../processing/event/EventSourcesTest.java | 43 ++++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java index 1a49add3cb..c21509f41c 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSources.java @@ -1,10 +1,12 @@ package io.javaoperatorsdk.operator.processing.event; + import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.stream.Stream; @@ -33,7 +35,8 @@ public void add(EventSource eventSource) { + " is already registered with name: " + name); } sourceByName.put(name, eventSource); - sources.computeIfAbsent(keyFor(eventSource), k -> new HashMap<>()).put(name, eventSource); + sources.computeIfAbsent(keyFor(eventSource), k -> new ConcurrentHashMap<>()).put(name, + eventSource); } public EventSource remove(String name) { @@ -144,7 +147,6 @@ public List> getEventSources(Class dependentType) { if (sourcesForType == null) { return Collections.emptyList(); } - return sourcesForType.values().stream() .map(es -> (EventSource) es).toList(); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java index 6c68916e98..9ddb877f07 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourceManagerTest.java @@ -36,6 +36,7 @@ class EventSourceManagerTest { public void registersEventSource() { EventSource eventSource = mock(EventSource.class); when(eventSource.resourceType()).thenReturn(EventSource.class); + when(eventSource.name()).thenReturn("name1"); eventSourceManager.registerEventSource(eventSource); @@ -95,6 +96,7 @@ void retrievingEventSourceForClassShouldWork() { ManagedInformerEventSource eventSource = mock(ManagedInformerEventSource.class); when(eventSource.resourceType()).thenReturn(String.class); + when(eventSource.name()).thenReturn("name1"); manager.registerEventSource(eventSource); var source = manager.getEventSourceFor(String.class); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java index 3d0d92da4f..12f0cc7331 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventSourcesTest.java @@ -1,5 +1,10 @@ package io.javaoperatorsdk.operator.processing.event; +import java.util.ConcurrentModificationException; +import java.util.concurrent.Phaser; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.IntStream; + import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -177,7 +182,43 @@ void getEventSourcesShouldWork() { assertThat(eventSources.getEventSources(Service.class)).isEmpty(); } - + @Test + void testConcurrentAddRemoveAndGet() throws InterruptedException { + + final var concurrentExceptionFound = new AtomicBoolean(false); + + for (int i = 0; i < 1000 && !concurrentExceptionFound.get(); i++) { + final var eventSources = new EventSources(); + var eventSourceList = + IntStream.range(1, 20).mapToObj(n -> eventSourceMockWithName(EventSource.class, + "name" + n, HasMetadata.class)).toList(); + + IntStream.range(1, 10).forEach(n -> eventSources.add(eventSourceList.get(n - 1))); + + var phaser = new Phaser(2); + + var t1 = new Thread(() -> { + phaser.arriveAndAwaitAdvance(); + IntStream.range(11, 20).forEach(n -> eventSources.add(eventSourceList.get(n - 1))); + }); + var t2 = new Thread(() -> { + phaser.arriveAndAwaitAdvance(); + try { + eventSources.getEventSources(eventSourceList.get(0).resourceType()); + } catch (ConcurrentModificationException e) { + concurrentExceptionFound.set(true); + } + }); + t1.start(); + t2.start(); + t1.join(); + t2.join(); + } + + assertThat(concurrentExceptionFound) + .withFailMessage("ConcurrentModificationException thrown") + .isFalse(); + } EventSource eventSourceMockWithName(Class clazz, String name, Class resourceType) { From 45759ff9350d7702f80e44c6acbb77dad0125ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 13 Nov 2024 20:15:02 +0100 Subject: [PATCH 92/96] fix: issue after rebase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/junit/LocallyRunOperatorExtension.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java index 6b8ef3f622..5d5055ac4a 100644 --- a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java +++ b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java @@ -74,14 +74,11 @@ private LocallyRunOperatorExtension( this.portForwards = portForwards; this.localPortForwards = new ArrayList<>(portForwards.size()); this.additionalCustomResourceDefinitions = additionalCustomResourceDefinitions; - configurationServiceOverrider = configurationServiceOverrider != null - ? configurationServiceOverrider - .andThen(overrider -> overrider.withKubernetesClient(kubernetesClient)) - : overrider -> overrider.withKubernetesClient(kubernetesClient); - this.operator = new Operator( - configurationServiceOverrider == null ? o -> o.withKubernetesClient(getKubernetesClient()) - : configurationServiceOverrider - .andThen(o -> o.withKubernetesClient(getKubernetesClient()))); + configurationServiceOverrider = configurationServiceOverrider != null + ? configurationServiceOverrider + .andThen(overrider -> overrider.withKubernetesClient(kubernetesClient)) + : overrider -> overrider.withKubernetesClient(kubernetesClient); + this.operator = new Operator(configurationServiceOverrider); this.registeredControllers = new HashMap<>(); this.crdMappings = crdMappings; } From 0d6226545566d2df9ffce300c8fb1b238a97cbfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 15 Nov 2024 22:19:07 +0100 Subject: [PATCH 93/96] fix: formatting issue after rebase (#2582) --- .../operator/junit/LocallyRunOperatorExtension.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java index 5d5055ac4a..442e398d83 100644 --- a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java +++ b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java @@ -75,9 +75,9 @@ private LocallyRunOperatorExtension( this.localPortForwards = new ArrayList<>(portForwards.size()); this.additionalCustomResourceDefinitions = additionalCustomResourceDefinitions; configurationServiceOverrider = configurationServiceOverrider != null - ? configurationServiceOverrider + ? configurationServiceOverrider .andThen(overrider -> overrider.withKubernetesClient(kubernetesClient)) - : overrider -> overrider.withKubernetesClient(kubernetesClient); + : overrider -> overrider.withKubernetesClient(kubernetesClient); this.operator = new Operator(configurationServiceOverrider); this.registeredControllers = new HashMap<>(); this.crdMappings = crdMappings; From c62734a4350829aa523bfdd4cfd51ed5bc89bdec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sat, 16 Nov 2024 09:01:58 +0100 Subject: [PATCH 94/96] fix: docs double header in migration docs (#2584) --- docs/content/en/docs/migration/v2-migration.md | 3 --- docs/content/en/docs/migration/v3-1-migration.md | 3 --- docs/content/en/docs/migration/v3-migration.md | 3 --- docs/content/en/docs/migration/v4-3-migration.md | 3 --- docs/content/en/docs/migration/v4-4-migration.md | 3 --- docs/content/en/docs/migration/v4-5-migration.md | 3 --- 6 files changed, 18 deletions(-) diff --git a/docs/content/en/docs/migration/v2-migration.md b/docs/content/en/docs/migration/v2-migration.md index 4500672308..5b0ef31c45 100644 --- a/docs/content/en/docs/migration/v2-migration.md +++ b/docs/content/en/docs/migration/v2-migration.md @@ -1,12 +1,9 @@ --- title: Migrating from v1 to v2 -description: Migrating from v1 to v2 layout: docs permalink: /docs/v2-migration --- -# Migrating from v1 to v2 - Version 2 of the framework introduces improvements, features and breaking changes for the APIs both internal and user facing ones. The migration should be however trivial in most of the cases. For detailed overview of all major issues until the release of diff --git a/docs/content/en/docs/migration/v3-1-migration.md b/docs/content/en/docs/migration/v3-1-migration.md index 9a7d9f7a9f..e42c4a206a 100644 --- a/docs/content/en/docs/migration/v3-1-migration.md +++ b/docs/content/en/docs/migration/v3-1-migration.md @@ -1,12 +1,9 @@ --- title: Migrating from v3 to v3.1 -description: Migrating from v3 to v3.1 layout: docs permalink: /docs/v3-1-migration --- -# Migrating from v3 to v3.1 - ## ReconciliationMaxInterval Annotation has been renamed to MaxReconciliationInterval Associated methods on both the `ControllerConfiguration` class and annotation have also been diff --git a/docs/content/en/docs/migration/v3-migration.md b/docs/content/en/docs/migration/v3-migration.md index 97e844904e..462ab26f9f 100644 --- a/docs/content/en/docs/migration/v3-migration.md +++ b/docs/content/en/docs/migration/v3-migration.md @@ -1,12 +1,9 @@ --- title: Migrating from v2 to v3 -description: Migrating from v2 to v3 layout: docs permalink: /docs/v3-migration --- -# Migrating from v2 to v3 - Version 3 introduces some breaking changes to APIs, however the migration to these changes should be trivial. ## Reconciler diff --git a/docs/content/en/docs/migration/v4-3-migration.md b/docs/content/en/docs/migration/v4-3-migration.md index 17d3be70b4..e9fd58c5f8 100644 --- a/docs/content/en/docs/migration/v4-3-migration.md +++ b/docs/content/en/docs/migration/v4-3-migration.md @@ -1,12 +1,9 @@ --- title: Migrating from v4.2 to v4.3 -description: Migrating from v4.2 to v4.3 layout: docs permalink: /docs/v4-3-migration --- -# Migrating from v4.2 to v4.3 - ## Condition API Change In Workflows the target of the condition was the managed resource itself, not the target dependent resource. diff --git a/docs/content/en/docs/migration/v4-4-migration.md b/docs/content/en/docs/migration/v4-4-migration.md index c198871f3f..998e6ddf9a 100644 --- a/docs/content/en/docs/migration/v4-4-migration.md +++ b/docs/content/en/docs/migration/v4-4-migration.md @@ -1,12 +1,9 @@ --- title: Migrating from v4.3 to v4.4 -description: Migrating from v4.3 to v4.4 layout: docs permalink: /docs/v4-4-migration --- -# Migrating from v4.3 to v4.4 - ## API changes ### ConfigurationService diff --git a/docs/content/en/docs/migration/v4-5-migration.md b/docs/content/en/docs/migration/v4-5-migration.md index 0ff08eef13..eff1581d87 100644 --- a/docs/content/en/docs/migration/v4-5-migration.md +++ b/docs/content/en/docs/migration/v4-5-migration.md @@ -1,12 +1,9 @@ --- title: Migrating from v4.4 to v4.5 -description: Migrating from v4.4 to v4.5 layout: docs permalink: /docs/v4-5-migration --- -# Migrating from v4.4 to v4.5 - Version 4.5 introduces improvements related to event handling for Dependent Resources, more precisely the [caching and event handling](https://javaoperatorsdk.io/docs/dependent-resources#caching-and-event-handling-in-kubernetesdependentresource) features. As a result the Kubernetes resources managed using From aebf018bdcb1d77b568cd4ba0cf85e5826a0d5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 17 Nov 2024 03:26:03 +0100 Subject: [PATCH 95/96] improve: mapping from annotation depends on type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/processing/GroupVersionKind.java | 13 +++++ .../KubernetesDependentResource.java | 8 +-- .../event/source/informer/Mappers.java | 52 ++++++++++++++----- .../processing/GroupVersionKindTest.java | 9 ++++ 4 files changed, 67 insertions(+), 15 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java index 4b0a607182..68c2a7988f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/GroupVersionKind.java @@ -68,6 +68,19 @@ public static GroupVersionKind fromString(String gvk) { } } + /** + * Reverse to {@link #fromString(String)}. + * + * @return gvk encoded in simple string. + */ + public String toSimpleString() { + var res = ""; + if (group != null) { + res += group + "/"; + } + return res + version + "/" + kind; + } + public String getGroup() { return group; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index 048b2b8f03..dc401f654d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -19,6 +19,7 @@ import io.javaoperatorsdk.operator.api.reconciler.Ignore; import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ConfiguredDependentResource; +import io.javaoperatorsdk.operator.processing.GroupVersionKind; import io.javaoperatorsdk.operator.processing.dependent.AbstractEventSourceHolderDependentResource; import io.javaoperatorsdk.operator.processing.dependent.Matcher.Result; import io.javaoperatorsdk.operator.processing.event.ResourceID; @@ -208,17 +209,18 @@ private boolean useNonOwnerRefBasedSecondaryToPrimaryMapping() { protected void addSecondaryToPrimaryMapperAnnotations(R desired, P primary) { addSecondaryToPrimaryMapperAnnotations(desired, primary, Mappers.DEFAULT_ANNOTATION_FOR_NAME, - Mappers.DEFAULT_ANNOTATION_FOR_NAMESPACE); + Mappers.DEFAULT_ANNOTATION_FOR_NAMESPACE, Mappers.DEFAULT_ANNOTATION_FOR_PRIMARY_TYPE); } protected void addSecondaryToPrimaryMapperAnnotations(R desired, P primary, String nameKey, - String namespaceKey) { + String namespaceKey, String typeKey) { var annotations = desired.getMetadata().getAnnotations(); annotations.put(nameKey, primary.getMetadata().getName()); var primaryNamespaces = primary.getMetadata().getNamespace(); if (primaryNamespaces != null) { annotations.put(namespaceKey, primary.getMetadata().getNamespace()); } + annotations.put(typeKey, GroupVersionKind.gvkFor(primary.getClass()).toSimpleString()); } @Override @@ -274,7 +276,7 @@ protected Optional> getSecondaryToPrimaryMapper( return Optional .of(Mappers.fromOwnerReferences(context.getPrimaryResourceClass(), clustered)); } else if (isCreatable()) { - return Optional.of(Mappers.fromDefaultAnnotations()); + return Optional.of(Mappers.fromDefaultAnnotations(context.getPrimaryResourceClass())); } } return Optional.empty(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java index 97ab1ef402..bc83730592 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java @@ -5,6 +5,7 @@ import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.javaoperatorsdk.operator.processing.GroupVersionKind; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper; @@ -13,33 +14,42 @@ public class Mappers { public static final String DEFAULT_ANNOTATION_FOR_NAME = "io.javaoperatorsdk/primary-name"; public static final String DEFAULT_ANNOTATION_FOR_NAMESPACE = "io.javaoperatorsdk/primary-namespace"; + public static final String DEFAULT_ANNOTATION_FOR_PRIMARY_TYPE = + "io.javaoperatorsdk/primary-type"; private Mappers() {} public static SecondaryToPrimaryMapper fromAnnotation( - String nameKey) { - return fromMetadata(nameKey, null, false); + String nameKey, String typeKey, Class primaryResourceType) { + return fromMetadata(nameKey, null, typeKey, primaryResourceType, false); } @SuppressWarnings("unused") public static SecondaryToPrimaryMapper fromAnnotation( - String nameKey, String namespaceKey) { - return fromMetadata(nameKey, namespaceKey, false); + String nameKey, String namespaceKey, String typeKey, + Class primaryResourceType) { + return fromMetadata(nameKey, namespaceKey, typeKey, primaryResourceType, false); } @SuppressWarnings("unused") - public static SecondaryToPrimaryMapper fromLabel(String nameKey) { - return fromMetadata(nameKey, null, true); + public static SecondaryToPrimaryMapper fromLabel(String nameKey, + String typeKey, + Class primaryResourceType) { + return fromMetadata(nameKey, null, typeKey, primaryResourceType, true); } - public static SecondaryToPrimaryMapper fromDefaultAnnotations() { - return fromMetadata(DEFAULT_ANNOTATION_FOR_NAME, DEFAULT_ANNOTATION_FOR_NAMESPACE, false); + public static SecondaryToPrimaryMapper fromDefaultAnnotations( + Class primaryResourceType) { + return fromMetadata(DEFAULT_ANNOTATION_FOR_NAME, DEFAULT_ANNOTATION_FOR_NAMESPACE, + DEFAULT_ANNOTATION_FOR_PRIMARY_TYPE, + primaryResourceType, false); } @SuppressWarnings("unused") public static SecondaryToPrimaryMapper fromLabel( - String nameKey, String namespaceKey) { - return fromMetadata(nameKey, namespaceKey, true); + String nameKey, String namespaceKey, String typeKey, + Class primaryResourceType) { + return fromMetadata(nameKey, namespaceKey, typeKey, primaryResourceType, true); } public static SecondaryToPrimaryMapper fromOwnerReferences( @@ -78,7 +88,8 @@ public static SecondaryToPrimaryMapper fromOwnerRefer } private static SecondaryToPrimaryMapper fromMetadata( - String nameKey, String namespaceKey, boolean isLabel) { + String nameKey, String namespaceKey, String typeKey, + Class primaryResourceType, boolean isLabel) { return resource -> { final var metadata = resource.getMetadata(); if (metadata == null) { @@ -94,6 +105,15 @@ private static SecondaryToPrimaryMapper fromMetadata( } var namespace = namespaceKey == null ? resource.getMetadata().getNamespace() : map.get(namespaceKey); + + String gvkSimple = map.get(typeKey); + + if (gvkSimple != null && + !GroupVersionKind.fromString(gvkSimple) + .equals(GroupVersionKind.gvkFor(primaryResourceType))) { + return Set.of(); + } + return Set.of(new ResourceID(name, namespace)); } }; @@ -139,9 +159,17 @@ public static SecondaryToPrim public static class SecondaryToPrimaryFromDefaultAnnotation implements SecondaryToPrimaryMapper { + + private Class primaryResourceType; + + public SecondaryToPrimaryFromDefaultAnnotation( + Class primaryResourceType) { + this.primaryResourceType = primaryResourceType; + } + @Override public Set toPrimaryResourceIDs(HasMetadata resource) { - return Mappers.fromDefaultAnnotations().toPrimaryResourceIDs(resource); + return Mappers.fromDefaultAnnotations(primaryResourceType).toPrimaryResourceIDs(resource); } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/GroupVersionKindTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/GroupVersionKindTest.java index aefbaf6d49..2b73107610 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/GroupVersionKindTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/GroupVersionKindTest.java @@ -75,4 +75,13 @@ void pluralShouldOverrideDefaultComputedVersionIfProvided() { "MyPlural"); assertThat(gvk.getPlural()).hasValue("MyPlural"); } + + @Test + void encodesGVKToSimpleString() { + var gvk = GroupVersionKind.fromString("apps/v1/Deployment"); + assertThat(gvk.toSimpleString()).isEqualTo("apps/v1/Deployment"); + + gvk = GroupVersionKind.fromString("v1/ConfigMap"); + assertThat(gvk.toSimpleString()).isEqualTo("v1/ConfigMap"); + } } From 7785994e246d746936c387e283998810e020822d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 19 Nov 2024 17:56:50 +0100 Subject: [PATCH 96/96] compiles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../InformerEventSourceTestCustomReconciler.java | 5 ++++- .../InformerRemoteClusterReconciler.java | 3 ++- .../CustomMappingConfigMapDependentResource.java | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java index 59430fd581..5028d6a0f4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informereventsource/InformerEventSourceTestCustomReconciler.java @@ -26,6 +26,7 @@ public class InformerEventSourceTestCustomReconciler LoggerFactory.getLogger(InformerEventSourceTestCustomReconciler.class); public static final String RELATED_RESOURCE_NAME = "relatedResourceName"; + public static final String RELATED_RESOURCE_TYPE = "relatedResourceType"; public static final String TARGET_CONFIG_MAP_KEY = "targetStatus"; public static final String MISSING_CONFIG_MAP = "Missing Config Map"; @@ -38,7 +39,9 @@ public List> prepareEventS InformerEventSourceConfiguration config = InformerEventSourceConfiguration .from(ConfigMap.class, InformerEventSourceTestCustomResource.class) - .withSecondaryToPrimaryMapper(Mappers.fromAnnotation(RELATED_RESOURCE_NAME)) + .withSecondaryToPrimaryMapper( + Mappers.fromAnnotation(RELATED_RESOURCE_NAME, RELATED_RESOURCE_TYPE, + InformerEventSourceTestCustomResource.class)) .build(); return List.of(new InformerEventSource<>(config, context)); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterReconciler.java index 44d81f5327..9246e0bbd5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/informerremotecluster/InformerRemoteClusterReconciler.java @@ -53,7 +53,8 @@ public List> prepareEventSou .from(ConfigMap.class, InformerRemoteClusterCustomResource.class) // owner references do not work cross cluster, using // annotations here to reference primary resource - .withSecondaryToPrimaryMapper(Mappers.fromDefaultAnnotations()) + .withSecondaryToPrimaryMapper( + Mappers.fromDefaultAnnotations(InformerRemoteClusterCustomResource.class)) // setting remote client for informer .withKubernetesClient(remoteClient) .withInformerConfiguration( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java index 1f05ebfeca..ad8639f6cf 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/dependent/dependentcustommappingannotation/CustomMappingConfigMapDependentResource.java @@ -20,10 +20,12 @@ public class CustomMappingConfigMapDependentResource public static final String CUSTOM_NAME_KEY = "customNameKey"; public static final String CUSTOM_NAMESPACE_KEY = "customNamespaceKey"; + public static final String CUSTOM_TYPE_KEY = "customTypeKey"; public static final String KEY = "key"; private static final SecondaryToPrimaryMapper mapper = - Mappers.fromAnnotation(CUSTOM_NAME_KEY, CUSTOM_NAMESPACE_KEY); + Mappers.fromAnnotation(CUSTOM_NAME_KEY, CUSTOM_NAMESPACE_KEY, CUSTOM_TYPE_KEY, + DependentCustomMappingCustomResource.class); public CustomMappingConfigMapDependentResource() { super(ConfigMap.class); @@ -44,7 +46,8 @@ protected ConfigMap desired(DependentCustomMappingCustomResource primary, @Override protected void addSecondaryToPrimaryMapperAnnotations(ConfigMap desired, DependentCustomMappingCustomResource primary) { - addSecondaryToPrimaryMapperAnnotations(desired, primary, CUSTOM_NAME_KEY, CUSTOM_NAMESPACE_KEY); + addSecondaryToPrimaryMapperAnnotations(desired, primary, CUSTOM_NAME_KEY, CUSTOM_NAMESPACE_KEY, + CUSTOM_TYPE_KEY); }

InformerConfigurationBuilder withWatchCurrentNamespace() { - this.namespaces = WATCH_CURRENT_NAMESPACE_SET; - return this; - } - - /** - * Whether the associated informer should track changes made to the parent - * {@link io.javaoperatorsdk.operator.processing.Controller}'s namespaces configuration. - * - * @param followChanges {@code true} to reconfigure the associated informer when the parent - * controller's namespaces are reconfigured, {@code false} otherwise - * @return the builder instance so that calls can be chained fluently - */ - public InformerConfigurationBuilder followControllerNamespacesOnChange( - boolean followChanges) { - this.followControllerNamespacesOnChange = followChanges; - return this; - } - - public InformerConfigurationBuilder withLabelSelector(String labelSelector) { - this.labelSelector = labelSelector; - return this; - } - - public InformerConfigurationBuilder withOnAddFilter(OnAddFilter onAddFilter) { - this.onAddFilter = onAddFilter; - return this; - } - - public InformerConfigurationBuilder withOnUpdateFilter( - OnUpdateFilter onUpdateFilter) { - this.onUpdateFilter = onUpdateFilter; - return this; - } - - public InformerConfigurationBuilder withOnDeleteFilter( - OnDeleteFilter onDeleteFilter) { - this.onDeleteFilter = onDeleteFilter; - return this; - } - - public InformerConfigurationBuilder withGenericFilter( - GenericFilter genericFilter) { - this.genericFilter = genericFilter; - return this; - } - - public InformerConfigurationBuilder withItemStore(ItemStore itemStore) { - this.itemStore = itemStore; - return this; - } - - /** - * Sets a max page size limit when starting the informer. This will result in pagination while - * populating the cache. This means that longer lists will take multiple requests to fetch. See - * {@link io.fabric8.kubernetes.client.dsl.Informable#withLimit(Long)} for more details. - * - * @param informerListLimit null (the default) results in no pagination - */ - public InformerConfigurationBuilder withInformerListLimit(Long informerListLimit) { - this.informerListLimit = informerListLimit; - return this; - } - public String getName() { return name; } @@ -318,32 +205,13 @@ public InformerConfiguration build() { "If GroupVersionKind is set the resource type must be GenericKubernetesDependentResource"); } - return new DefaultInformerConfiguration<>(name, labelSelector, resourceClass, + return new DefaultInformerConfiguration<>(resourceClass, groupVersionKind, primaryToSecondaryMapper, Objects.requireNonNullElse(secondaryToPrimaryMapper, Mappers.fromOwnerReferences(HasMetadata.getApiVersion(primaryResourceClass), HasMetadata.getKind(primaryResourceClass), false)), - namespaces, followControllerNamespacesOnChange, onAddFilter, onUpdateFilter, - onDeleteFilter, genericFilter, itemStore, informerListLimit); + config.buildForInformerEventSource()); } } - - static InformerConfigurationBuilder from( - Class resourceClass, Class primaryResourceClass) { - return new InformerConfigurationBuilder<>(resourceClass, primaryResourceClass); - } - - - static InformerConfigurationBuilder from( - GroupVersionKind groupVersionKind, Class primaryResourceClass) { - return new InformerConfigurationBuilder<>(groupVersionKind, primaryResourceClass); - } - - @SuppressWarnings("unchecked") - @Override - default Class getResourceClass() { - return (Class) Utils.getFirstTypeArgumentFromSuperClassOrInterface(getClass(), - InformerConfiguration.class); - } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java index 49cf56c1aa..a5232700c0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java @@ -6,18 +6,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import io.fabric8.kubernetes.client.informers.cache.ItemStore; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfig; import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter; import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter; -import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; -import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; -import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; import io.javaoperatorsdk.operator.processing.retry.Retry; import static io.javaoperatorsdk.operator.api.config.ControllerConfiguration.CONTROLLER_NAME_AS_FIELD_MANAGER; -import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_LONG_VALUE_SET; @Inherited @Retention(RetentionPolicy.RUNTIME) @@ -26,6 +21,8 @@ String name() default Constants.NO_VALUE_SET; + InformerConfig informerConfig() default @InformerConfig; + /** * Optional finalizer name, if it is not provided, one will be automatically generated. Note that * finalizers are only added when Reconciler implement {@link Cleaner} interface and/or at least @@ -45,44 +42,6 @@ */ boolean generationAwareEventProcessing() default true; - /** - * Specified which namespaces this Controller monitors for custom resources events. If no - * namespace is specified then the controller will monitor all namespaces by default. - * - * @return the array of namespaces this controller monitors - */ - String[] namespaces() default Constants.WATCH_ALL_NAMESPACES; - - /** - * Optional label selector used to identify the set of custom resources the controller will acc - * upon. The label selector can be made of multiple comma separated requirements that acts as a - * logical AND operator. - * - * @return the label selector - */ - String labelSelector() default Constants.NO_VALUE_SET; - - /** - * Filter of onAdd events of resources. - * - * @return on-add filter - **/ - Class onAddFilter() default OnAddFilter.class; - - /** - * Filter of onUpdate events of resources. - * - * @return on-update filter - */ - Class onUpdateFilter() default OnUpdateFilter.class; - - /** - * Filter applied to all operations (add, update, delete). Used to ignore some resources. - * - * @return generic filter - **/ - Class genericFilter() default GenericFilter.class; - /** * Optional configuration of the maximal interval the SDK will wait for a reconciliation request * to happen before one will be automatically triggered. @@ -108,25 +67,6 @@ MaxReconciliationInterval maxReconciliationInterval() default @MaxReconciliation */ Class rateLimiter() default LinearRateLimiter.class; - /** - * Replaces the item store used by the informer for the associated primary resource controller. - * See underlying - * method in fabric8 client informer implementation. - * - *