From 1283e971634aa659a64fec884df65868b3cb0eec Mon Sep 17 00:00:00 2001 From: csviri Date: Tue, 28 Mar 2023 12:13:32 +0200 Subject: [PATCH 1/5] fix: special IT failing test case --- .../io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java | 1 + 1 file changed, 1 insertion(+) 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 26f544bd90..a7326356dd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -151,6 +151,7 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator) assertThat(configMapHealthIndicator.isWatching()).isFalse(); } + @Test void resilientForLoosingPermissionForCustomResource() { setFullResourcesAccess(); From 926cad421cd742440ce7aecd9ab0ca1b653f3e1a Mon Sep 17 00:00:00 2001 From: csviri Date: Tue, 28 Mar 2023 12:15:50 +0200 Subject: [PATCH 2/5] wip --- .../io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a7326356dd..9c16331847 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -151,7 +151,7 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator) assertThat(configMapHealthIndicator.isWatching()).isFalse(); } - + @Test void resilientForLoosingPermissionForCustomResource() { setFullResourcesAccess(); From 11bae95f7e1c64297457b649453e7e85ab57ea1a Mon Sep 17 00:00:00 2001 From: csviri Date: Tue, 28 Mar 2023 12:36:40 +0200 Subject: [PATCH 3/5] wip --- .../io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9c16331847..dc94e7d3e0 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -72,8 +72,8 @@ void beforeEach(TestInfo testInfo) { @AfterEach void cleanup() { - adminClient.resource(testCustomResource()).delete(); adminClient.resource(dependentConfigMap()).delete(); + adminClient.resource(testCustomResource()).delete(); } @Test From fb9407622fb8caf4e6f543adec6a1ac746dbcfef Mon Sep 17 00:00:00 2001 From: csviri Date: Tue, 28 Mar 2023 13:05:53 +0200 Subject: [PATCH 4/5] lower min timeout --- .../operator/InformerRelatedBehaviorITS.java | 24 ++++++++++++------- ...InformerRelatedBehaviorTestReconciler.java | 6 +++++ 2 files changed, 22 insertions(+), 8 deletions(-) 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 dc94e7d3e0..5b040ec8c2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -24,6 +24,8 @@ import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.ConfigMapDependentResource; import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestCustomResource; import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestReconciler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; 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; @@ -34,7 +36,7 @@ /** * The test relies on a special api server configuration: "min-request-timeout" to have a very low * value (in case want to try with minikube use: "minikube start - * --extra-config=apiserver.min-request-timeout=3") + * --extra-config=apiserver.min-request-timeout=1") * *

* This is important when tests are affected by permission changes, since the watch permissions are @@ -45,9 +47,11 @@ * The test ends with "ITS" (Special) since it needs to run separately from other ITs *

*/ -@EnableKubeAPIServer(apiServerFlags = {"--min-request-timeout", "3"}) +@EnableKubeAPIServer(apiServerFlags = {"--min-request-timeout", "1"}) 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"; @@ -55,6 +59,7 @@ class InformerRelatedBehaviorITS { InformerRelatedBehaviorTestReconciler reconciler; String actualNamespace; String additionalNamespace; + Operator operator; volatile boolean replacementStopHandlerCalled = false; @BeforeEach @@ -72,6 +77,9 @@ void beforeEach(TestInfo testInfo) { @AfterEach void cleanup() { + if (operator != null) { + operator.stop(Duration.ofSeconds(1)); + } adminClient.resource(dependentConfigMap()).delete(); adminClient.resource(testCustomResource()).delete(); } @@ -90,7 +98,7 @@ void startsUpWhenNoPermissionToCustomResource() { adminClient.resource(testCustomResource()).createOrReplace(); setNoCustomResourceAccess(); - var operator = startOperator(false); + operator = startOperator(false); assertNotReconciled(); assertRuntimeInfoNoCRPermission(operator); @@ -106,7 +114,7 @@ void startsUpWhenNoPermissionToSecondaryResource() { adminClient.resource(testCustomResource()).createOrReplace(); setNoConfigMapAccess(); - var operator = startOperator(false); + operator = startOperator(false); assertNotReconciled(); assertRuntimeInfoForSecondaryPermission(operator); @@ -120,7 +128,7 @@ void startsUpIfNoPermissionToOneOfTwoNamespaces() { adminClient.resource(namespace(additionalNamespace)).createOrReplace(); addRoleBindingsToTestNamespaces(); - var operator = startOperator(false, false, actualNamespace, additionalNamespace); + operator = startOperator(false, false, actualNamespace, additionalNamespace); assertInformerNotWatchingForAdditionalNamespace(operator); adminClient.resource(testCustomResource()).createOrReplace(); @@ -155,14 +163,14 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator) @Test void resilientForLoosingPermissionForCustomResource() { setFullResourcesAccess(); - startOperator(true); + operator = startOperator(true); setNoCustomResourceAccess(); waitForWatchReconnect(); + adminClient.resource(testCustomResource()).createOrReplace(); assertNotReconciled(); - setFullResourcesAccess(); assertReconciled(); } @@ -211,7 +219,7 @@ void notExitingWithDefaultStopHandlerIfErrorHappensOnStartup() { private static void waitForWatchReconnect() { try { - Thread.sleep(6000); + Thread.sleep(5000); } catch (InterruptedException e) { throw new IllegalStateException(e); } 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 13057d547a..c131149ba3 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 @@ -8,7 +8,10 @@ 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.event.ResourceID; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @ControllerConfiguration( name = InformerRelatedBehaviorTestReconciler.INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER, @@ -18,6 +21,8 @@ public class InformerRelatedBehaviorTestReconciler implements Reconciler, TestExecutionInfoProvider { + private static final Logger log = LoggerFactory.getLogger(InformerRelatedBehaviorTestReconciler.class); + public static final String INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER = "InformerRelatedBehaviorTestReconciler"; public static final String CONFIG_MAP_DEPENDENT_RESOURCE = "ConfigMapDependentResource"; @@ -30,6 +35,7 @@ public UpdateControl reconcile( InformerRelatedBehaviorTestCustomResource resource, Context context) { numberOfExecutions.addAndGet(1); + log.info("Reconciled for: {}", ResourceID.fromResource(resource)); return UpdateControl.noUpdate(); } From c48f9d0264462f54201ad279187c8d4d0597a353 Mon Sep 17 00:00:00 2001 From: csviri Date: Tue, 28 Mar 2023 13:06:34 +0200 Subject: [PATCH 5/5] format --- .../operator/InformerRelatedBehaviorITS.java | 4 ++-- .../InformerRelatedBehaviorTestReconciler.java | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) 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 5b040ec8c2..3f19c27e53 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java @@ -3,6 +3,8 @@ import java.time.Duration; import org.junit.jupiter.api.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; @@ -24,8 +26,6 @@ import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.ConfigMapDependentResource; import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestCustomResource; import io.javaoperatorsdk.operator.sample.informerrelatedbehavior.InformerRelatedBehaviorTestReconciler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; 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; 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 c131149ba3..f71f243c79 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 @@ -2,6 +2,9 @@ import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; @@ -10,8 +13,6 @@ import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @ControllerConfiguration( name = InformerRelatedBehaviorTestReconciler.INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER, @@ -21,7 +22,8 @@ public class InformerRelatedBehaviorTestReconciler implements Reconciler, TestExecutionInfoProvider { - private static final Logger log = LoggerFactory.getLogger(InformerRelatedBehaviorTestReconciler.class); + private static final Logger log = + LoggerFactory.getLogger(InformerRelatedBehaviorTestReconciler.class); public static final String INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER = "InformerRelatedBehaviorTestReconciler";