From 5431289871baaf221745cbf7e522b70f7e69c9e2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Oct 2021 08:19:50 +0200 Subject: [PATCH 01/19] chore(deps): bump micrometer-core from 1.7.4 to 1.7.5 (#606) Bumps [micrometer-core](https://github.com/micrometer-metrics/micrometer) from 1.7.4 to 1.7.5. - [Release notes](https://github.com/micrometer-metrics/micrometer/releases) - [Commits](https://github.com/micrometer-metrics/micrometer/compare/v1.7.4...v1.7.5) --- updated-dependencies: - dependency-name: io.micrometer:micrometer-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ac2324c699..401ba48b11 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ 3.21.0 4.1.0 2.5.5 - 1.7.4 + 1.7.5 2.11 3.8.1 From 30dcf72ed347f560f656d869d5441282266ebf9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 20 Oct 2021 12:39:31 +0200 Subject: [PATCH 02/19] fix: re-schedule generics (#614) --- .../java/io/javaoperatorsdk/operator/api/UpdateControl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/UpdateControl.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/UpdateControl.java index d9e14a6c5a..4d89b69f95 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/UpdateControl.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/UpdateControl.java @@ -47,11 +47,11 @@ public static UpdateControl noUpdate() { return new UpdateControl<>(null, false, false); } - public UpdateControl withReSchedule(long delay, TimeUnit timeUnit) { + public UpdateControl withReSchedule(long delay, TimeUnit timeUnit) { return withReSchedule(timeUnit.toMillis(delay)); } - public UpdateControl withReSchedule(long delay) { + public UpdateControl withReSchedule(long delay) { this.reScheduleDelay = delay; return this; } From f9ee9b2aa8c44aa91598b4cd10a3e020923595bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Oct 2021 09:13:50 +0200 Subject: [PATCH 03/19] chore(deps): bump spring-boot.version from 2.5.5 to 2.5.6 (#617) Bumps `spring-boot.version` from 2.5.5 to 2.5.6. Updates `spring-boot-dependencies` from 2.5.5 to 2.5.6 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v2.5.5...v2.5.6) Updates `spring-boot-maven-plugin` from 2.5.5 to 2.5.6 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v2.5.5...v2.5.6) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-dependencies dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.springframework.boot:spring-boot-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 401ba48b11..74d9ed70d6 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ 1.13.0 3.21.0 4.1.0 - 2.5.5 + 2.5.6 1.7.5 2.11 From fb15a1ef59fd76796a2225c941dd7067681d787a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Oct 2021 03:11:08 +0000 Subject: [PATCH 04/19] chore(deps): bump awaitility from 4.1.0 to 4.1.1 Bumps [awaitility](https://github.com/awaitility/awaitility) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/awaitility/awaitility/releases) - [Changelog](https://github.com/awaitility/awaitility/blob/master/changelog.txt) - [Commits](https://github.com/awaitility/awaitility/compare/awaitility-4.1.0...awaitility-4.1.1) --- updated-dependencies: - dependency-name: org.awaitility:awaitility dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- operator-framework-junit5/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/operator-framework-junit5/pom.xml b/operator-framework-junit5/pom.xml index 6256cc7de3..45b4f86c89 100644 --- a/operator-framework-junit5/pom.xml +++ b/operator-framework-junit5/pom.xml @@ -39,7 +39,7 @@ org.awaitility awaitility - 4.1.0 + 4.1.1 diff --git a/pom.xml b/pom.xml index 74d9ed70d6..acf9da1fc2 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ 0.19 1.13.0 3.21.0 - 4.1.0 + 4.1.1 2.5.6 1.7.5 From f18847357988fe11d7833c6c4df4828a77196ec0 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Tue, 26 Oct 2021 19:19:39 +0200 Subject: [PATCH 05/19] fix: prevent double registration of same CR with different controllers Fixes #626 --- .../io/javaoperatorsdk/operator/Operator.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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 31bf1a80ec..5b23e3817a 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 @@ -3,9 +3,10 @@ import java.io.Closeable; import java.io.IOException; import java.net.ConnectException; -import java.util.Collections; -import java.util.LinkedList; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +51,7 @@ public ConfigurationService getConfigurationService() { } public List getControllers() { - return Collections.unmodifiableList(controllers.controllers); + return new ArrayList<>(controllers.controllers.values()); } /** @@ -159,7 +160,7 @@ public void register( } private static class ControllerManager implements Closeable { - private final List controllers = new LinkedList<>(); + private final Map controllers = new HashMap<>(); private boolean started = false; @@ -173,7 +174,7 @@ public synchronized void shouldStart() { } public synchronized void start() { - controllers.parallelStream().forEach(ConfiguredController::start); + controllers.values().parallelStream().forEach(ConfiguredController::start); started = true; } @@ -183,7 +184,7 @@ public synchronized void close() { return; } - this.controllers.parallelStream().forEach(closeable -> { + this.controllers.values().parallelStream().forEach(closeable -> { try { log.debug("closing {}", closeable); closeable.close(); @@ -196,7 +197,15 @@ public synchronized void close() { } public synchronized void add(ConfiguredController configuredController) { - this.controllers.add(configuredController); + final var configuration = configuredController.getConfiguration(); + final var crdName = configuration.getCRDName(); + final var existing = controllers.get(crdName); + if (existing != null) { + throw new OperatorException("Cannot register controller " + configuration.getName() + + ": another controller (" + existing.getConfiguration().getName() + + ") is already registered for CRD " + crdName); + } + this.controllers.put(crdName, configuredController); if (started) { configuredController.start(); } From 7c0a6307237543f2fc4d8d57c7847a91d0645320 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 27 Oct 2021 10:37:50 +0000 Subject: [PATCH 06/19] Set new SNAPSHOT version into pom files. --- micrometer-support/pom.xml | 2 +- operator-framework-core/pom.xml | 2 +- operator-framework-junit5/pom.xml | 2 +- operator-framework/pom.xml | 2 +- pom.xml | 2 +- samples/common/pom.xml | 2 +- samples/pom.xml | 2 +- samples/pure-java/pom.xml | 2 +- samples/spring-boot-plain/pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/micrometer-support/pom.xml b/micrometer-support/pom.xml index a12c83738b..8f74d3f30e 100644 --- a/micrometer-support/pom.xml +++ b/micrometer-support/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 1.9.9-SNAPSHOT + 1.9.10-SNAPSHOT 4.0.0 diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index e578810de5..87db534cbb 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk - 1.9.9-SNAPSHOT + 1.9.10-SNAPSHOT ../pom.xml diff --git a/operator-framework-junit5/pom.xml b/operator-framework-junit5/pom.xml index 45b4f86c89..527a4ac30f 100644 --- a/operator-framework-junit5/pom.xml +++ b/operator-framework-junit5/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 1.9.9-SNAPSHOT + 1.9.10-SNAPSHOT 4.0.0 diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index 996c29bcae..43cf5fedc6 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 1.9.9-SNAPSHOT + 1.9.10-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index acf9da1fc2..943ebfd242 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.javaoperatorsdk java-operator-sdk - 1.9.9-SNAPSHOT + 1.9.10-SNAPSHOT Operator SDK for Java Java SDK for implementing Kubernetes operators pom diff --git a/samples/common/pom.xml b/samples/common/pom.xml index 066f5007b3..e1023bf55f 100644 --- a/samples/common/pom.xml +++ b/samples/common/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk-samples - 1.9.9-SNAPSHOT + 1.9.10-SNAPSHOT operator-framework-samples-common diff --git a/samples/pom.xml b/samples/pom.xml index 73528a4b20..55e6706c24 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk - 1.9.9-SNAPSHOT + 1.9.10-SNAPSHOT java-operator-sdk-samples diff --git a/samples/pure-java/pom.xml b/samples/pure-java/pom.xml index c53735c45b..6d75734f85 100644 --- a/samples/pure-java/pom.xml +++ b/samples/pure-java/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk-samples - 1.9.9-SNAPSHOT + 1.9.10-SNAPSHOT operator-framework-samples-pure-java diff --git a/samples/spring-boot-plain/pom.xml b/samples/spring-boot-plain/pom.xml index e361ca1cfc..a68cb86e10 100644 --- a/samples/spring-boot-plain/pom.xml +++ b/samples/spring-boot-plain/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk-samples - 1.9.9-SNAPSHOT + 1.9.10-SNAPSHOT operator-framework-samples-spring-boot-plain From 0cc051237f1639b9a419f9b0beaf3d1c8cb0e31d Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 28 Oct 2021 13:04:59 +0200 Subject: [PATCH 07/19] fix: restart event handler (#632) Properly start event handler when starting the event source. Minor clean-ups. Fixes #630 Co-authored-by: csviri --- .../api/config/ExecutorServiceManager.java | 2 +- .../processing/DefaultEventHandler.java | 15 +++++- .../processing/event/EventHandler.java | 2 + .../internal/CustomResourceEventSource.java | 2 + .../processing/DefaultEventHandlerTest.java | 1 - .../CustomResourceEventSourceTest.java | 52 +++++++++++++++++++ 6 files changed, 71 insertions(+), 3 deletions(-) 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 682b004c3d..f593b3c755 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 @@ -46,7 +46,7 @@ public static void close() { public static ExecutorServiceManager instance() { if (instance == null) { throw new IllegalStateException( - "ExecutorServiceManager hasn't been started. Call start method before using!"); + "ExecutorServiceManager hasn't been started. Call init method before using!"); } return instance; } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java index 27843a669a..bcaf395136 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java @@ -60,11 +60,15 @@ public DefaultEventHandler(ConfiguredController controller) { controller.getConfiguration().getConfigurationService().getMetrics().getEventMonitor()); } - DefaultEventHandler(EventDispatcher eventDispatcher, String relatedControllerName, + public DefaultEventHandler(EventDispatcher eventDispatcher, String relatedControllerName, Retry retry) { this(null, relatedControllerName, eventDispatcher, retry, null); } + public boolean isRunning() { + return running; + } + private DefaultEventHandler(ExecutorService executor, String relatedControllerName, EventDispatcher eventDispatcher, Retry retry, EventMonitor monitor) { this.running = true; @@ -142,6 +146,15 @@ public void handleEvent(Event event) { } } + public void start() { + try { + lock.lock(); + this.running = true; + } finally { + lock.unlock(); + } + } + @Override public void close() { try { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventHandler.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventHandler.java index e0a657e1d1..3bab14c2e0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventHandler.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventHandler.java @@ -9,4 +9,6 @@ public interface EventHandler extends Closeable { @Override default void close() throws IOException {} + + default void start() {} } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSource.java index c7a959061b..360f57bdca 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSource.java @@ -48,6 +48,8 @@ public CustomResourceEventSource(ConfiguredController controller) { @Override public void start() { + eventHandler.start(); + final var configuration = controller.getConfiguration(); final var targetNamespaces = configuration.getEffectiveNamespaces(); final var client = controller.getCRClient(); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/DefaultEventHandlerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/DefaultEventHandlerTest.java index a03f4bd8a1..36269ddd57 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/DefaultEventHandlerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/DefaultEventHandlerTest.java @@ -63,7 +63,6 @@ public void setup() { // todo: remove when(defaultEventSourceManagerMock.getCache()).thenReturn(customResourceCache); doCallRealMethod().when(defaultEventSourceManagerMock).getLatestResource(any()); - doCallRealMethod().when(defaultEventSourceManagerMock).getLatestResource(any()); doCallRealMethod().when(defaultEventSourceManagerMock).getLatestResources(any()); doCallRealMethod().when(defaultEventSourceManagerMock).getLatestResourceUids(any()); doCallRealMethod().when(defaultEventSourceManagerMock).cacheResource(any(), any()); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSourceTest.java index 727caf3be1..cefa720833 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSourceTest.java @@ -1,5 +1,6 @@ package io.javaoperatorsdk.operator.processing.event.internal; +import java.io.IOException; import java.time.LocalDateTime; import java.util.List; @@ -7,7 +8,10 @@ import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.KubernetesResourceList; +import io.fabric8.kubernetes.api.model.ListOptions; +import io.fabric8.kubernetes.client.Watch; import io.fabric8.kubernetes.client.Watcher; +import io.fabric8.kubernetes.client.dsl.FilterWatchListMultiDeletable; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; import io.javaoperatorsdk.operator.Metrics; @@ -15,11 +19,19 @@ import io.javaoperatorsdk.operator.api.config.ConfigurationService; import io.javaoperatorsdk.operator.api.config.DefaultControllerConfiguration; import io.javaoperatorsdk.operator.processing.ConfiguredController; +import io.javaoperatorsdk.operator.processing.CustomResourceCache; +import io.javaoperatorsdk.operator.processing.DefaultEventHandler; +import io.javaoperatorsdk.operator.processing.EventDispatcher; +import io.javaoperatorsdk.operator.processing.event.DefaultEventSourceManager; import io.javaoperatorsdk.operator.processing.event.EventHandler; import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.any; +import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -102,6 +114,46 @@ public void eventNotMarkedForLastGenerationIfNoFinalizer() { verify(eventHandler, times(2)).handleEvent(any()); } + @Test + public void restartingShouldResumeEventHandling() throws IOException { + final var cr = TestUtils.testCustomResource(); + + CustomResourceCache customResourceCache = new CustomResourceCache(); + customResourceCache.cacheResource(cr); + DefaultEventSourceManager defaultEventSourceManagerMock = + mock(DefaultEventSourceManager.class); + EventDispatcher eventDispatcherMock = mock(EventDispatcher.class); + DefaultEventHandler local = new DefaultEventHandler(eventDispatcherMock, "Test", + null); + local.setEventSourceManager(defaultEventSourceManagerMock); + when(defaultEventSourceManagerMock.getCache()).thenReturn(customResourceCache); + doCallRealMethod().when(defaultEventSourceManagerMock).getLatestResource(any()); + doCallRealMethod().when(defaultEventSourceManagerMock).getLatestResources(any()); + doCallRealMethod().when(defaultEventSourceManagerMock).getLatestResourceUids(any()); + doCallRealMethod().when(defaultEventSourceManagerMock).cacheResource(any(), any()); + + final var mock = mock(FilterWatchListMultiDeletable.class); + when(mock.watch((ListOptions) any(), any())).thenReturn(mock(Watch.class)); + when(client.inAnyNamespace()).thenReturn(mock); + + customResourceEventSource.setEventHandler(local); + + customResourceEventSource.eventReceived(Watcher.Action.MODIFIED, cr); + verify(eventDispatcherMock, timeout(50).times(1)).handleExecution(any()); + + customResourceEventSource.close(); + assertFalse(local.isRunning()); + customResourceEventSource.eventReceived(Watcher.Action.MODIFIED, cr); + // mockito times method is not reset and keeps increasing so here we stay at 1 call + verify(eventDispatcherMock, timeout(50).times(1)).handleExecution(any()); + + customResourceEventSource.start(); + assertTrue(local.isRunning()); + customResourceEventSource.eventReceived(Watcher.Action.MODIFIED, cr); + // we're expecting another call to the dispatcher, so total number of calls should now be 2 + verify(eventDispatcherMock, timeout(50).times(2)).handleExecution(any()); + } + private static class TestConfiguredController extends ConfiguredController { public TestConfiguredController(boolean generationAware) { From 24ac6ed2acc901c23de0c3fac37ed3cdcc11a162 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 28 Oct 2021 11:08:18 +0000 Subject: [PATCH 08/19] Set new SNAPSHOT version into pom files. --- micrometer-support/pom.xml | 2 +- operator-framework-core/pom.xml | 2 +- operator-framework-junit5/pom.xml | 2 +- operator-framework/pom.xml | 2 +- pom.xml | 2 +- samples/common/pom.xml | 2 +- samples/pom.xml | 2 +- samples/pure-java/pom.xml | 2 +- samples/spring-boot-plain/pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/micrometer-support/pom.xml b/micrometer-support/pom.xml index 8f74d3f30e..5e54be30f5 100644 --- a/micrometer-support/pom.xml +++ b/micrometer-support/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 1.9.10-SNAPSHOT + 1.9.11-SNAPSHOT 4.0.0 diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index 87db534cbb..5cc9bf1d4b 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk - 1.9.10-SNAPSHOT + 1.9.11-SNAPSHOT ../pom.xml diff --git a/operator-framework-junit5/pom.xml b/operator-framework-junit5/pom.xml index 527a4ac30f..70570a7d15 100644 --- a/operator-framework-junit5/pom.xml +++ b/operator-framework-junit5/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 1.9.10-SNAPSHOT + 1.9.11-SNAPSHOT 4.0.0 diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index 43cf5fedc6..8f76543592 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 1.9.10-SNAPSHOT + 1.9.11-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 943ebfd242..50d8460675 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.javaoperatorsdk java-operator-sdk - 1.9.10-SNAPSHOT + 1.9.11-SNAPSHOT Operator SDK for Java Java SDK for implementing Kubernetes operators pom diff --git a/samples/common/pom.xml b/samples/common/pom.xml index e1023bf55f..939ad59404 100644 --- a/samples/common/pom.xml +++ b/samples/common/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk-samples - 1.9.10-SNAPSHOT + 1.9.11-SNAPSHOT operator-framework-samples-common diff --git a/samples/pom.xml b/samples/pom.xml index 55e6706c24..a1e72542a1 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk - 1.9.10-SNAPSHOT + 1.9.11-SNAPSHOT java-operator-sdk-samples diff --git a/samples/pure-java/pom.xml b/samples/pure-java/pom.xml index 6d75734f85..2a2d4315c4 100644 --- a/samples/pure-java/pom.xml +++ b/samples/pure-java/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk-samples - 1.9.10-SNAPSHOT + 1.9.11-SNAPSHOT operator-framework-samples-pure-java diff --git a/samples/spring-boot-plain/pom.xml b/samples/spring-boot-plain/pom.xml index a68cb86e10..e5691cd78b 100644 --- a/samples/spring-boot-plain/pom.xml +++ b/samples/spring-boot-plain/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk-samples - 1.9.10-SNAPSHOT + 1.9.11-SNAPSHOT operator-framework-samples-spring-boot-plain From 3f9c9cef2c4c6b2fe1249187d2eeedeb38434e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 29 Oct 2021 10:12:39 +0200 Subject: [PATCH 09/19] docs: webpage docs skeleton (#631) --- README.md | 1 + docs/Gemfile.lock | 4 ++- docs/_data/sidebar.yml | 11 ++++++-- docs/documentation/faq.md | 7 +++++ docs/documentation/features.md | 39 +++++++++++++++++++++++++++ docs/documentation/intro-operators.md | 12 +++++++++ 6 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 docs/documentation/faq.md create mode 100644 docs/documentation/features.md create mode 100644 docs/documentation/intro-operators.md diff --git a/README.md b/README.md index 2988e55408..d42c45b7a0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Build Kubernetes Operators in Java without hassle. Inspired by [operator-sdk](https://github.com/operator-framework/operator-sdk). +Our webpage with documentation is getting better every day: https://javaoperatorsdk.io/ Table of Contents ========== diff --git a/docs/Gemfile.lock b/docs/Gemfile.lock index e8ee3a5427..605cd1d411 100644 --- a/docs/Gemfile.lock +++ b/docs/Gemfile.lock @@ -74,11 +74,13 @@ GEM unicode-display_width (1.7.0) PLATFORMS + ruby universal-darwin-20 + x86_64-linux DEPENDENCIES jekyll (~> 4.2) jekyll-github-metadata BUNDLED WITH - 2.2.22 + 2.2.30 diff --git a/docs/_data/sidebar.yml b/docs/_data/sidebar.yml index 96266dd842..7d88cde491 100644 --- a/docs/_data/sidebar.yml +++ b/docs/_data/sidebar.yml @@ -1,7 +1,14 @@ # Navbar menu navigation links + - title: Intro to Operators + url: /docs/intro-operators - title: Getting Started url: /docs/getting-started - - title: Contributing - url: /docs/contributing - title: How to use Samples url: /docs/using-samples + - title: Features + url: /docs/features + - title: FAQ + url: /docs/faq + - title: Contributing + url: /docs/contributing + diff --git a/docs/documentation/faq.md b/docs/documentation/faq.md new file mode 100644 index 0000000000..f4127b39fe --- /dev/null +++ b/docs/documentation/faq.md @@ -0,0 +1,7 @@ +--- +title: FAQ +description: Frequently asked questions +layout: docs +permalink: /docs/faq +--- + diff --git a/docs/documentation/features.md b/docs/documentation/features.md new file mode 100644 index 0000000000..7f77bcbbde --- /dev/null +++ b/docs/documentation/features.md @@ -0,0 +1,39 @@ +--- +title: Features +description: Features of the SDK +layout: docs +permalink: /docs/features +--- + +# Features + +## Controller Registration + +## Configurations + +## Finalizers + +### When not to Use Finalizers + +## Automatic Retries on Error + +### Correctness and automatic retry + +## Re-Scheduling Execution + +## Retry and Re-Scheduling Common Behavior + +## Handling Related Events with Event Sources + +### Caching and Event Sources + +### The CustomResourceEventSource + +### Built-in Event Sources + +## Monitoring with Micrometer + + + + + diff --git a/docs/documentation/intro-operators.md b/docs/documentation/intro-operators.md new file mode 100644 index 0000000000..13a9812df1 --- /dev/null +++ b/docs/documentation/intro-operators.md @@ -0,0 +1,12 @@ +--- +title: Introduction to Operators +description: Introduction to Operators +layout: docs +permalink: /docs/intro-operators +--- + +# Introduction To Operators + +On this page we selected a collection of resources to introduce you to the concepts of Kubernetes Operators. + + From f0ca4cac77db1ec7bfed56f722e8b94701c64198 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 28 Oct 2021 20:30:49 +0200 Subject: [PATCH 10/19] fix: replace jandex plugin by Quarkus detection of beans.xml files This allows to not run into compatibility between index versions. --- .../src/main/resources/META-INF/beans.xml | 0 pom.xml | 18 ------------------ 2 files changed, 18 deletions(-) create mode 100644 operator-framework-core/src/main/resources/META-INF/beans.xml diff --git a/operator-framework-core/src/main/resources/META-INF/beans.xml b/operator-framework-core/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pom.xml b/pom.xml index 50d8460675..008918a945 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,6 @@ 2.8.2 2.5.2 5.0.0 - 1.2.1 2.16.0 1.0 1.6.2 @@ -224,11 +223,6 @@ maven-install-plugin ${maven-install-plugin.version} - - org.jboss.jandex - jandex-maven-plugin - ${jandex-maven-plugin.version} - net.revelc.code.formatter formatter-maven-plugin @@ -269,18 +263,6 @@ - - org.jboss.jandex - jandex-maven-plugin - - - make-index - - jandex - - - - org.apache.maven.plugins maven-surefire-plugin From 0287c0c1c6217145beca3f2f6c0066fb562c024e Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 28 Oct 2021 21:02:03 +0200 Subject: [PATCH 11/19] fix: improve duplicated controller detection, add tests While we originally planned to make it possible to register controllers with the same CR but with different version (see #637), that behavior should actually be forbidden since only one CR version can be served, see #94 for more details. --- .../io/javaoperatorsdk/operator/Operator.java | 9 +-- .../operator/ControllerManagerTest.java | 76 +++++++++++++++++++ .../sample/simple/DuplicateCRController.java | 16 ++++ .../TestCustomResourceControllerV2.java | 16 ++++ .../sample/simple/TestCustomResourceV2.java | 12 +++ 5 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/ControllerManagerTest.java create mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/DuplicateCRController.java create mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceControllerV2.java create mode 100644 operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceV2.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 5b23e3817a..7350bafce4 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 @@ -159,11 +159,10 @@ public void register( } } - private static class ControllerManager implements Closeable { + static class ControllerManager implements Closeable { private final Map controllers = new HashMap<>(); private boolean started = false; - public synchronized void shouldStart() { if (started) { return; @@ -201,9 +200,9 @@ public synchronized void add(ConfiguredController configuredController) { final var crdName = configuration.getCRDName(); final var existing = controllers.get(crdName); if (existing != null) { - throw new OperatorException("Cannot register controller " + configuration.getName() - + ": another controller (" + existing.getConfiguration().getName() - + ") is already registered for CRD " + crdName); + throw new OperatorException("Cannot register controller '" + configuration.getName() + + "': another controller named '" + existing.getConfiguration().getName() + + "' is already registered for CRD '" + crdName + "'"); } this.controllers.put(crdName, configuredController); if (started) { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/ControllerManagerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/ControllerManagerTest.java new file mode 100644 index 0000000000..d25378499e --- /dev/null +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/ControllerManagerTest.java @@ -0,0 +1,76 @@ +package io.javaoperatorsdk.operator; + +import org.junit.Test; + +import io.fabric8.kubernetes.client.CustomResource; +import io.javaoperatorsdk.operator.Operator.ControllerManager; +import io.javaoperatorsdk.operator.api.ResourceController; +import io.javaoperatorsdk.operator.api.config.DefaultControllerConfiguration; +import io.javaoperatorsdk.operator.processing.ConfiguredController; +import io.javaoperatorsdk.operator.sample.simple.DuplicateCRController; +import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; +import io.javaoperatorsdk.operator.sample.simple.TestCustomResourceController; +import io.javaoperatorsdk.operator.sample.simple.TestCustomResourceControllerV2; +import io.javaoperatorsdk.operator.sample.simple.TestCustomResourceV2; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ControllerManagerTest { + + @Test + public void shouldNotAddMultipleControllersForSameCustomResource() { + final var registered = new TestControllerConfiguration<>(new TestCustomResourceController(null), + TestCustomResource.class); + final var duplicated = + new TestControllerConfiguration<>(new DuplicateCRController(), TestCustomResource.class); + + checkException(registered, duplicated); + } + + @Test + public void addingMultipleControllersForCustomResourcesWithDifferentVersionsShouldNotWork() { + final var registered = new TestControllerConfiguration<>(new TestCustomResourceController(null), + TestCustomResource.class); + final var duplicated = new TestControllerConfiguration<>(new TestCustomResourceControllerV2(), + TestCustomResourceV2.class); + + checkException(registered, duplicated); + + } + + private , U extends CustomResource> void checkException( + TestControllerConfiguration registered, + TestControllerConfiguration duplicated) { + final var exception = assertThrows(OperatorException.class, () -> { + final var controllerManager = new ControllerManager(); + controllerManager.add(new ConfiguredController<>(registered.controller, registered, null)); + controllerManager.add(new ConfiguredController<>(duplicated.controller, duplicated, null)); + }); + final var msg = exception.getMessage(); + assertTrue( + msg.contains("Cannot register controller '" + duplicated.getControllerName() + "'") + && msg.contains(registered.getControllerName()) + && msg.contains(registered.getCRDName())); + } + + private static class TestControllerConfiguration> + extends DefaultControllerConfiguration { + private final ResourceController controller; + + public TestControllerConfiguration(ResourceController controller, Class crClass) { + super(null, getControllerName(controller), + CustomResource.getCRDName(crClass), null, false, null, null, null, null, crClass, null); + this.controller = controller; + } + + static > String getControllerName( + ResourceController controller) { + return controller.getClass().getSimpleName() + "Controller"; + } + + private String getControllerName() { + return getControllerName(controller); + } + } +} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/DuplicateCRController.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/DuplicateCRController.java new file mode 100644 index 0000000000..e61909fafe --- /dev/null +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/DuplicateCRController.java @@ -0,0 +1,16 @@ +package io.javaoperatorsdk.operator.sample.simple; + +import io.javaoperatorsdk.operator.api.Context; +import io.javaoperatorsdk.operator.api.Controller; +import io.javaoperatorsdk.operator.api.ResourceController; +import io.javaoperatorsdk.operator.api.UpdateControl; + +@Controller +public class DuplicateCRController implements ResourceController { + + @Override + public UpdateControl createOrUpdateResource(TestCustomResource resource, + Context context) { + return UpdateControl.noUpdate(); + } +} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceControllerV2.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceControllerV2.java new file mode 100644 index 0000000000..a5a3d2c935 --- /dev/null +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceControllerV2.java @@ -0,0 +1,16 @@ +package io.javaoperatorsdk.operator.sample.simple; + +import io.javaoperatorsdk.operator.api.Context; +import io.javaoperatorsdk.operator.api.Controller; +import io.javaoperatorsdk.operator.api.ResourceController; +import io.javaoperatorsdk.operator.api.UpdateControl; + +@Controller +public class TestCustomResourceControllerV2 implements ResourceController { + + @Override + public UpdateControl createOrUpdateResource(TestCustomResourceV2 resource, + Context context) { + return UpdateControl.noUpdate(); + } +} diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceV2.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceV2.java new file mode 100644 index 0000000000..e02e359bcc --- /dev/null +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/sample/simple/TestCustomResourceV2.java @@ -0,0 +1,12 @@ +package io.javaoperatorsdk.operator.sample.simple; + +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.javaoperatorsdk.io") +@Version("v2") +public class TestCustomResourceV2 + extends CustomResource { + +} From 0d9e4fefda1df115081b4377278f070079fb92d5 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 29 Oct 2021 16:12:42 +0000 Subject: [PATCH 12/19] Set new SNAPSHOT version into pom files. --- micrometer-support/pom.xml | 2 +- operator-framework-core/pom.xml | 2 +- operator-framework-junit5/pom.xml | 2 +- operator-framework/pom.xml | 2 +- pom.xml | 2 +- samples/common/pom.xml | 2 +- samples/pom.xml | 2 +- samples/pure-java/pom.xml | 2 +- samples/spring-boot-plain/pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/micrometer-support/pom.xml b/micrometer-support/pom.xml index 5e54be30f5..779bed3369 100644 --- a/micrometer-support/pom.xml +++ b/micrometer-support/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 1.9.11-SNAPSHOT + 1.9.12-SNAPSHOT 4.0.0 diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index 5cc9bf1d4b..e20cac3aef 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk - 1.9.11-SNAPSHOT + 1.9.12-SNAPSHOT ../pom.xml diff --git a/operator-framework-junit5/pom.xml b/operator-framework-junit5/pom.xml index 70570a7d15..1c05135126 100644 --- a/operator-framework-junit5/pom.xml +++ b/operator-framework-junit5/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 1.9.11-SNAPSHOT + 1.9.12-SNAPSHOT 4.0.0 diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index 8f76543592..f5010675b5 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -5,7 +5,7 @@ java-operator-sdk io.javaoperatorsdk - 1.9.11-SNAPSHOT + 1.9.12-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 008918a945..2e1251c44d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.javaoperatorsdk java-operator-sdk - 1.9.11-SNAPSHOT + 1.9.12-SNAPSHOT Operator SDK for Java Java SDK for implementing Kubernetes operators pom diff --git a/samples/common/pom.xml b/samples/common/pom.xml index 939ad59404..781073b774 100644 --- a/samples/common/pom.xml +++ b/samples/common/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk-samples - 1.9.11-SNAPSHOT + 1.9.12-SNAPSHOT operator-framework-samples-common diff --git a/samples/pom.xml b/samples/pom.xml index a1e72542a1..f24d4ff71a 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk - 1.9.11-SNAPSHOT + 1.9.12-SNAPSHOT java-operator-sdk-samples diff --git a/samples/pure-java/pom.xml b/samples/pure-java/pom.xml index 2a2d4315c4..86b88f1d06 100644 --- a/samples/pure-java/pom.xml +++ b/samples/pure-java/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk-samples - 1.9.11-SNAPSHOT + 1.9.12-SNAPSHOT operator-framework-samples-pure-java diff --git a/samples/spring-boot-plain/pom.xml b/samples/spring-boot-plain/pom.xml index e5691cd78b..3f4d241312 100644 --- a/samples/spring-boot-plain/pom.xml +++ b/samples/spring-boot-plain/pom.xml @@ -6,7 +6,7 @@ io.javaoperatorsdk java-operator-sdk-samples - 1.9.11-SNAPSHOT + 1.9.12-SNAPSHOT operator-framework-samples-spring-boot-plain From d7b63b32a70401fa8c167050dba9eef0565d2e92 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 08:04:31 +0100 Subject: [PATCH 13/19] chore(deps): bump formatter-maven-plugin from 2.16.0 to 2.17.0 (#644) Bumps [formatter-maven-plugin](https://github.com/revelc/formatter-maven-plugin) from 2.16.0 to 2.17.0. - [Release notes](https://github.com/revelc/formatter-maven-plugin/releases) - [Changelog](https://github.com/revelc/formatter-maven-plugin/blob/main/CHANGELOG.md) - [Commits](https://github.com/revelc/formatter-maven-plugin/compare/formatter-maven-plugin-2.16.0...formatter-maven-plugin-2.17.0) --- updated-dependencies: - dependency-name: net.revelc.code.formatter:formatter-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2e1251c44d..a70e5e36bf 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ 2.8.2 2.5.2 5.0.0 - 2.16.0 + 2.17.0 1.0 1.6.2 From 5891cedbade4bfc895ab7808dc710e8bdf79c900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 1 Nov 2021 08:54:52 +0100 Subject: [PATCH 14/19] docs: link for basic operato articles (#643) --- docs/documentation/intro-operators.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/documentation/intro-operators.md b/docs/documentation/intro-operators.md index 13a9812df1..f69cb2895a 100644 --- a/docs/documentation/intro-operators.md +++ b/docs/documentation/intro-operators.md @@ -7,6 +7,12 @@ permalink: /docs/intro-operators # Introduction To Operators -On this page we selected a collection of resources to introduce you to the concepts of Kubernetes Operators. +This page provides a selection of articles that gives an introduction to Kubernetes operators. +## Operators in General + - [Introduction of the concept of Kubernetes Operators](https://blog.container-solutions.com/kubernetes-operators-explained) + - [Operator pattern explained in Kubernetes documentation](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/) + - [An explanation why Java Operators makes sense](https://blog.container-solutions.com/cloud-native-java-infrastructure-automation-with-kubernetes-operators) + - [What are the problems an operator framework is solving](https://csviri.medium.com/deep-dive-building-a-kubernetes-operator-sdk-for-java-developers-5008218822cb) + From 767858dafdbbf92e53c88a3c85ad4ad813d3c26b Mon Sep 17 00:00:00 2001 From: Bobae Kim Date: Tue, 2 Nov 2021 18:57:03 +0900 Subject: [PATCH 15/19] fix: use `close` as destroyMethod of Bean (#645) --- .../main/java/io/javaoperatorsdk/operator/sample/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/spring-boot-plain/src/main/java/io/javaoperatorsdk/operator/sample/Config.java b/samples/spring-boot-plain/src/main/java/io/javaoperatorsdk/operator/sample/Config.java index 40c5ecefb9..b6713e9ed4 100644 --- a/samples/spring-boot-plain/src/main/java/io/javaoperatorsdk/operator/sample/Config.java +++ b/samples/spring-boot-plain/src/main/java/io/javaoperatorsdk/operator/sample/Config.java @@ -18,7 +18,7 @@ public CustomServiceController customServiceController() { } // Register all controller beans - @Bean(initMethod = "start", destroyMethod = "stop") + @Bean(initMethod = "start", destroyMethod = "close") public Operator operator(List controllers) { Operator operator = new Operator(DefaultConfigurationService.instance()); controllers.forEach(operator::register); From ebc3539d775c2e0edd87f3b7a422c1ccbaf27432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 3 Nov 2021 13:28:45 +0100 Subject: [PATCH 16/19] docs: finalizers and best braticies page (#647) --- docs/_data/sidebar.yml | 2 + docs/documentation/features.md | 64 +++++++++++++++++-- docs/documentation/patterns-best-practices.md | 28 ++++++++ 3 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 docs/documentation/patterns-best-practices.md diff --git a/docs/_data/sidebar.yml b/docs/_data/sidebar.yml index 7d88cde491..a9a43907a2 100644 --- a/docs/_data/sidebar.yml +++ b/docs/_data/sidebar.yml @@ -7,6 +7,8 @@ url: /docs/using-samples - title: Features url: /docs/features + - title: Patterns and Best Practices + url: /docs/patterns-best-practices - title: FAQ url: /docs/faq - title: Contributing diff --git a/docs/documentation/features.md b/docs/documentation/features.md index 7f77bcbbde..b0b639ebbb 100644 --- a/docs/documentation/features.md +++ b/docs/documentation/features.md @@ -5,15 +5,69 @@ layout: docs permalink: /docs/features --- -# Features +# Features -## Controller Registration +Java Operator SDK is a high level framework and related tooling in order to facilitate implementation of Kubernetes +operators. The features are by default following the best practices in an opinionated way. However, feature flags and +other configuration options are provided to fine tune or turn off these features. -## Configurations +## Controller Execution in a Nutshell -## Finalizers +Controller execution is always triggered by an event. Events typically come from the custom resource +(i.e. custom resource is created, updated or deleted) that the controller is watching, but also from different sources +(see event sources). When an event is received reconciliation is executed, unless there is already a reconciliation +happening for a particular custom resource. In other words it is guaranteed by the framework that no concurrent +reconciliation happens for a custom resource. -### When not to Use Finalizers +After a reconciliation ( +i.e. [ResourceController](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ResourceController.java) +called), a post-processing phase follows, where typically framework checks if: + +- an exception was thrown during execution, if yes schedules a retry. +- there are new events received during the controller execution, if yes schedule the execution again. +- there is an instruction to re-schedule the execution for the future, if yes schedule a timer event with the specified + delay. +- if none above, the reconciliation is finished. + +Briefly, in the hearth of the execution is an eventing system, where events are the triggers of the reconciliation +execution. + +## Finalizer Support + +[Kubernetes finalizers](https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/) +make sure that a reconciliation happens when a custom resource is instructed to be deleted. Typical case when it's +useful, when an operator is down (pod not running). Without a finalizer the reconciliation - thus the cleanup +i.e. [`ResourceController.deleteResource(...)`](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ResourceController.java) + +- would not happen if a custom resource is deleted. + +Finalizers are automatically added by the framework as the first step, thus when a custom resource is created, but +before the first reconciliation, the custom resource is updated via a Kubernetes API call. As a result of this update, the +finalizer will be present. The subsequent event will be received, which will trigger the first reconciliation. + +The finalizer that is automatically added will be also removed after the `deleteResource` is executed on the controller. +However, the removal behavior can be further customized, and can be instructed to "not remove yet" - this is useful just +in some specific corner cases, when there would be a long waiting period for some dependent resource cleanup. + +The name of the finalizers can be specified, in case it is not, a name will be generated. + +This behavior can be turned off, so when configured no finalizer will be added or removed. +See [`@Controller`](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/Controller.java) +annotation for more details. + +### When not to Use Finalizers? + +Typically, automated finalizer handling should be turned off, when **all** the cleanup of the dependent resources is +handled by Kubernetes itself. This is handled by +Kubernetes [garbage collection](https://kubernetes.io/docs/concepts/architecture/garbage-collection/#owners-dependents). +Setting the owner reference and related fields are not in the scope of the SDK for now, it's up to the user to have them +configured properly when creating the objects. + +When automatic finalizer handling is turned off, the `ResourceController.deleteResource(...)` method is not called, in +case of a delete event received. So it does not make sense to implement this method and turn off finalizer at the same +time. + +## Separating `createOrUpdate` from `delete` ## Automatic Retries on Error diff --git a/docs/documentation/patterns-best-practices.md b/docs/documentation/patterns-best-practices.md new file mode 100644 index 0000000000..c5103de3ff --- /dev/null +++ b/docs/documentation/patterns-best-practices.md @@ -0,0 +1,28 @@ +--- +title: Patterns and Best Practices +description: Patterns and Best Practices Implementing a Controller +layout: docs +permalink: /docs/patterns-best-practices +--- + +# Patterns and Best Practices + +This document describes patters and best practices, to build and run operators, and how to implement them in terms +of Java Operator SDK. + +## Implementing a Controller + +### Sync of Async Way of Resource Handling + +### Idempotency + +## Why to Have Automated Retries? + +## Managing State + +## Dependent Resources + +### EventSources and Caching + +### Why are Events Irrelevant? + From 7e6e170337f289d7fb3a733db632fa8d0edfb39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 3 Nov 2021 13:44:08 +0100 Subject: [PATCH 17/19] fix: typo in docs (#649) --- docs/documentation/features.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/documentation/features.md b/docs/documentation/features.md index b0b639ebbb..6040ac39bd 100644 --- a/docs/documentation/features.md +++ b/docs/documentation/features.md @@ -21,7 +21,7 @@ reconciliation happens for a custom resource. After a reconciliation ( i.e. [ResourceController](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ResourceController.java) -called), a post-processing phase follows, where typically framework checks if: +called, a post-processing phase follows, where typically framework checks if: - an exception was thrown during execution, if yes schedules a retry. - there are new events received during the controller execution, if yes schedule the execution again. From 6d4018b4e3ac4b06a9eeb5d5930da9da6480d410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 3 Nov 2021 13:48:45 +0100 Subject: [PATCH 18/19] fix: jekyll build warning with highliting (#650) --- docs/_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_config.yml b/docs/_config.yml index 0e349390ae..a2b8fba679 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -13,7 +13,7 @@ images: /assets/images/ # Rouge highlighter markdown: kramdown -highlighter: none +highlighter: rouge kramdown: parse_block_html: true From b137794362556bd1c20a7109eedbdb3a3d2ff460 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 Nov 2021 08:57:43 +0100 Subject: [PATCH 19/19] chore(deps): bump auto-service from 1.0 to 1.0.1 (#652) Bumps [auto-service](https://github.com/google/auto) from 1.0 to 1.0.1. - [Release notes](https://github.com/google/auto/releases) - [Commits](https://github.com/google/auto/compare/auto-value-1.0...auto-common-1.0.1) --- updated-dependencies: - dependency-name: com.google.auto.service:auto-service dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a70e5e36bf..f7aaaa90ec 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ 2.14.1 4.0.0 3.12.0 - 1.0 + 1.0.1 0.19 1.13.0 3.21.0