diff --git a/src/main/java/io/csviri/operator/glue/reconciler/glue/GlueReconciler.java b/src/main/java/io/csviri/operator/glue/reconciler/glue/GlueReconciler.java index c37d56c..2cbf30e 100644 --- a/src/main/java/io/csviri/operator/glue/reconciler/glue/GlueReconciler.java +++ b/src/main/java/io/csviri/operator/glue/reconciler/glue/GlueReconciler.java @@ -18,6 +18,7 @@ import io.csviri.operator.glue.dependent.GenericDependentResource; import io.csviri.operator.glue.dependent.GenericResourceDiscriminator; import io.csviri.operator.glue.reconciler.ValidationAndErrorHandler; +import io.csviri.operator.glue.reconciler.operator.GlueOperatorReconciler; import io.csviri.operator.glue.templating.GenericTemplateHandler; import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; @@ -30,6 +31,7 @@ import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowBuilder; import static io.csviri.operator.glue.Utils.getResourceForSSAFrom; +import static io.csviri.operator.glue.reconciler.operator.GlueOperatorReconciler.FOR_GLUE_OPERATOR_LABEL_VALUE; import static io.csviri.operator.glue.reconciler.operator.GlueOperatorReconciler.PARENT_RELATED_RESOURCE_NAME; @ControllerConfiguration(name = GlueReconciler.GLUE_RECONCILER_NAME) @@ -222,6 +224,9 @@ private Condition toCondition(ConditionSpec condition) { } private void addFinalizersToParentResource(Glue primary, Context context) { + if (!isGlueOfAGlueOperator(primary)) { + return; + } var parent = getParentRelatedResource(primary, context); parent.ifPresent(p -> { @@ -237,6 +242,9 @@ private void addFinalizersToParentResource(Glue primary, Context context) } private void removeFinalizerForParent(Glue primary, Context context) { + if (!isGlueOfAGlueOperator(primary)) { + return; + } var parent = getParentRelatedResource(primary, context); parent.ifPresentOrElse(p -> { log.debug("Removing finalizer from parent. Glue name: {} namespace: {}", @@ -295,4 +303,12 @@ public ErrorStatusUpdateControl updateErrorStatus(Glue resource, Context prepareEventSources( EventSourceContext eventSourceContext) { glueEventSource = new InformerEventSource<>( InformerConfiguration.from(Glue.class, eventSourceContext) - .withLabelSelector(GLUE_LABEL_KEY + "=" + GLUE_LABEL_VALUE) + .withLabelSelector(FOR_GLUE_OPERATOR_LABEL_KEY + "=" + FOR_GLUE_OPERATOR_LABEL_VALUE) .build(), eventSourceContext); return EventSourceInitializer.nameEventSources(glueEventSource); diff --git a/src/test/java/io/csviri/operator/glue/GlueLabelSelectorTest.java b/src/test/java/io/csviri/operator/glue/GlueLabelSelectorTest.java index 27728f1..2545111 100644 --- a/src/test/java/io/csviri/operator/glue/GlueLabelSelectorTest.java +++ b/src/test/java/io/csviri/operator/glue/GlueLabelSelectorTest.java @@ -27,7 +27,7 @@ public class GlueLabelSelectorTest extends TestBase { @Test void testLabelSelectorHandling() { Glue glue = - TestUtils.loadResoureFlow("/glue/SimpleGlue.yaml"); + TestUtils.loadGlue("/glue/SimpleGlue.yaml"); glue = create(glue); await().pollDelay(INITIAL_RECONCILE_WAIT_TIMEOUT).untilAsserted(() -> { diff --git a/src/test/java/io/csviri/operator/glue/GlueOperatorComplexLabelSelectorTest.java b/src/test/java/io/csviri/operator/glue/GlueOperatorComplexLabelSelectorTest.java index ce9c8cc..267377a 100644 --- a/src/test/java/io/csviri/operator/glue/GlueOperatorComplexLabelSelectorTest.java +++ b/src/test/java/io/csviri/operator/glue/GlueOperatorComplexLabelSelectorTest.java @@ -33,8 +33,8 @@ void applyCRD() { @Test void testGlueOperatorLabelSelector() { - var go = create(TestUtils - .loadResourceFlowOperator("/glueoperator/SimpleGlueOperator.yaml")); + create(TestUtils + .loadGlueOperator("/glueoperator/SimpleGlueOperator.yaml")); var testCR = create(TestData.testCustomResource()); @@ -49,7 +49,7 @@ void testGlueOperatorLabelSelector() { }); delete(testCR); - await().untilAsserted(() -> { + await().timeout(TestUtils.GC_WAIT_TIMEOUT).untilAsserted(() -> { var glue = get(Glue.class, GlueOperatorReconciler.glueName(testCR.getMetadata().getName(), testCR.getKind())); assertThat(glue).isNull(); diff --git a/src/test/java/io/csviri/operator/glue/GlueOperatorLabelSelectorTest.java b/src/test/java/io/csviri/operator/glue/GlueOperatorLabelSelectorTest.java index 64e6216..7b5ee22 100644 --- a/src/test/java/io/csviri/operator/glue/GlueOperatorLabelSelectorTest.java +++ b/src/test/java/io/csviri/operator/glue/GlueOperatorLabelSelectorTest.java @@ -36,7 +36,7 @@ void applyCRD() { @Test void testGlueOperatorLabelSelector() { var go = create(TestUtils - .loadResourceFlowOperator("/glueoperator/SimpleGlueOperator.yaml")); + .loadGlueOperator("/glueoperator/SimpleGlueOperator.yaml")); var testCR = create(TestData.testCustomResource()); diff --git a/src/test/java/io/csviri/operator/glue/GlueOperatorTest.java b/src/test/java/io/csviri/operator/glue/GlueOperatorTest.java index 40b8216..a8ac01e 100644 --- a/src/test/java/io/csviri/operator/glue/GlueOperatorTest.java +++ b/src/test/java/io/csviri/operator/glue/GlueOperatorTest.java @@ -19,7 +19,7 @@ import io.quarkus.test.junit.QuarkusTest; import static io.csviri.operator.glue.TestData.*; -import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT_SECOND; +import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT; import static io.csviri.operator.glue.customresource.TestCustomResource.CR_GROUP; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -55,7 +55,7 @@ void smokeTest() { @Test void templating() { create(TestUtils - .loadResourceFlowOperator("/glueoperator/SimpleGlueOperator.yaml")); + .loadGlueOperator("/glueoperator/SimpleGlueOperator.yaml")); var cr = create(testCustomResource()); String initialValue = cr.getSpec().getValue(); @@ -78,7 +78,7 @@ void templating() { delete(cr); - await().timeout(Duration.ofMinutes(5)).untilAsserted(() -> { + await().timeout(GC_WAIT_TIMEOUT).untilAsserted(() -> { var cm1 = get(ConfigMap.class, name); var actualCR = get(TestCustomResource.class, name); assertThat(cm1).isNull(); @@ -91,7 +91,7 @@ void templating() { void simpleConcurrencyTest() { int num = 10; create(TestUtils - .loadResourceFlowOperator("/glueoperator/Concurrency.yaml")); + .loadGlueOperator("/glueoperator/Concurrency.yaml")); var resources = IntStream.range(0, num).mapToObj(n -> create(testCustomResource(n))).toList(); @@ -115,9 +115,9 @@ void simpleConcurrencyTest() { void simpleConcurrencyForMultipleOperatorTest() { int num = 10; create(TestUtils - .loadResourceFlowOperator("/glueoperator/Concurrency.yaml")); + .loadGlueOperator("/glueoperator/Concurrency.yaml")); create(TestUtils - .loadResourceFlowOperator("/glueoperator/Concurrency2.yaml")); + .loadGlueOperator("/glueoperator/Concurrency2.yaml")); var crs = IntStream.range(0, num).mapToObj(n -> create(testCustomResource(n))).toList(); @@ -137,7 +137,7 @@ void simpleConcurrencyForMultipleOperatorTest() { crs.forEach(this::delete); cr2s.forEach(this::delete); - await().timeout(GC_WAIT_TIMEOUT_SECOND) + await().timeout(GC_WAIT_TIMEOUT) .untilAsserted(() -> IntStream.range(0, num).forEach(n -> { var cm = get(ConfigMap.class, TEST_RESOURCE_PREFIX + n); assertThat(cm).isNull(); @@ -149,7 +149,7 @@ void simpleConcurrencyForMultipleOperatorTest() { @Test void nonUniqueNameTest() { var go = create(TestUtils - .loadResourceFlowOperator("/glueoperator/NonUniqueName.yaml")); + .loadGlueOperator("/glueoperator/NonUniqueName.yaml")); await().untilAsserted(() -> { var actual = get(GlueOperator.class, go.getMetadata().getName()); @@ -163,7 +163,7 @@ void nonUniqueNameTest() { @Test void parentWithLabelSelector() { create(TestUtils - .loadResourceFlowOperator("/glueoperator/ParentLabelSelector.yaml")); + .loadGlueOperator("/glueoperator/ParentLabelSelector.yaml")); var cr = create(testCustomResource()); String name = cr.getMetadata().getName(); diff --git a/src/test/java/io/csviri/operator/glue/GlueRelatedResourcesTest.java b/src/test/java/io/csviri/operator/glue/GlueRelatedResourcesTest.java index 7ffa7e5..f7ee7de 100644 --- a/src/test/java/io/csviri/operator/glue/GlueRelatedResourcesTest.java +++ b/src/test/java/io/csviri/operator/glue/GlueRelatedResourcesTest.java @@ -34,7 +34,7 @@ void applyCRD() { void simpleRelatedResourceUsage() { create(secret()); Glue glue = - TestUtils.loadResoureFlow("/glue/RelatedResourceSimpleWithCondition.yaml"); + TestUtils.loadGlue("/glue/RelatedResourceSimpleWithCondition.yaml"); create(glue); @@ -64,7 +64,7 @@ void multipleResourceNamesInRelated() { create(secret("test-secret2", BASE64_VALUE_2)); Glue glue = - create(TestUtils.loadResoureFlow("/glue/MultiNameRelatedResource.yaml")); + create(TestUtils.loadGlue("/glue/MultiNameRelatedResource.yaml")); await().untilAsserted(() -> { var cm1 = get(ConfigMap.class, "cm1"); @@ -85,7 +85,7 @@ void multipleResourceNamesInRelated() { void managedAndRelatedResourceOfSameTypeAndTriggering() { var relatedConfigMap = create(configMap()); Glue glue = - create(TestUtils.loadResoureFlow("/glue/RelatesResourceSameType.yaml")); + create(TestUtils.loadGlue("/glue/RelatesResourceSameType.yaml")); await().untilAsserted(() -> { var cm1 = get(ConfigMap.class, "cm1"); diff --git a/src/test/java/io/csviri/operator/glue/GlueResourceLabelSelectorTest.java b/src/test/java/io/csviri/operator/glue/GlueResourceLabelSelectorTest.java index e1527c3..2fb79a8 100644 --- a/src/test/java/io/csviri/operator/glue/GlueResourceLabelSelectorTest.java +++ b/src/test/java/io/csviri/operator/glue/GlueResourceLabelSelectorTest.java @@ -18,7 +18,7 @@ public class GlueResourceLabelSelectorTest extends TestBase { @Test void showCreatingResourceWithLabelSelectorAndLabel() { - var glue = create(TestUtils.loadResoureFlow("/glue/SimpleGlueWithLabeledResource.yaml")); + var glue = create(TestUtils.loadGlue("/glue/SimpleGlueWithLabeledResource.yaml")); // this serves more like a sample, hard to test here if the label selector is on informer await().untilAsserted(() -> { diff --git a/src/test/java/io/csviri/operator/glue/GlueTest.java b/src/test/java/io/csviri/operator/glue/GlueTest.java index e94a2a6..44b1b0b 100644 --- a/src/test/java/io/csviri/operator/glue/GlueTest.java +++ b/src/test/java/io/csviri/operator/glue/GlueTest.java @@ -27,7 +27,7 @@ class GlueTest extends TestBase { @Test void simpleTemplating() { Glue glue = - TestUtils.loadResoureFlow("/glue/Templating.yaml"); + TestUtils.loadGlue("/glue/Templating.yaml"); glue = create(glue); await().untilAsserted(() -> { @@ -64,7 +64,7 @@ void simpleTemplating() { @Test void crossReferenceResource() { Glue glue = - TestUtils.loadResoureFlow("/glue/CrossReferenceResource.yaml"); + TestUtils.loadGlue("/glue/CrossReferenceResource.yaml"); glue = create(glue); await().untilAsserted(() -> { @@ -103,7 +103,7 @@ void crossReferenceResource() { @Test void javaScriptCondition() { Glue glue = - TestUtils.loadResoureFlow("/glue/TwoResourcesAndCondition.yaml"); + TestUtils.loadGlue("/glue/TwoResourcesAndCondition.yaml"); create(glue); await().pollDelay(Duration.ofMillis(150)).untilAsserted(() -> { @@ -138,7 +138,7 @@ void javaScriptCondition() { @Test void stringTemplate() { - Glue glue = create(TestUtils.loadResoureFlow("/glue/ResourceTemplate.yaml")); + Glue glue = create(TestUtils.loadGlue("/glue/ResourceTemplate.yaml")); await().timeout(Duration.ofSeconds(120)).untilAsserted(() -> { var cm1 = get(ConfigMap.class, "templconfigmap1"); @@ -188,7 +188,7 @@ void simpleConcurrencyTest() { @Test void changingWorkflow() { - Glue glue = create(TestUtils.loadResoureFlow("/glue/ChanginResources.yaml")); + Glue glue = create(TestUtils.loadGlue("/glue/ChanginResources.yaml")); await().untilAsserted(() -> { var cm1 = get(ConfigMap.class, "configmap1"); @@ -226,7 +226,7 @@ void changingWorkflow() { @Test void nonUniqueNameResultsInErrorMessageOnStatus() { - Glue glue = create(TestUtils.loadResoureFlow("/glue/NonUniqueName.yaml")); + Glue glue = create(TestUtils.loadGlue("/glue/NonUniqueName.yaml")); await().untilAsserted(() -> { var actualGlue = get(Glue.class, glue.getMetadata().getName()); @@ -271,7 +271,7 @@ private List testWorkflowList(int num) { List res = new ArrayList<>(); IntStream.range(0, num).forEach(index -> { Glue w = - TestUtils.loadResoureFlow("/glue/TemplateForConcurrency.yaml"); + TestUtils.loadGlue("/glue/TemplateForConcurrency.yaml"); w.getMetadata().setName(w.getMetadata().getName() + index); res.add(w); }); diff --git a/src/test/java/io/csviri/operator/glue/TestUtils.java b/src/test/java/io/csviri/operator/glue/TestUtils.java index 3c2d9ed..f5efe86 100644 --- a/src/test/java/io/csviri/operator/glue/TestUtils.java +++ b/src/test/java/io/csviri/operator/glue/TestUtils.java @@ -24,7 +24,7 @@ public class TestUtils { - public static final Duration GC_WAIT_TIMEOUT_SECOND = Duration.ofSeconds(45); + public static final Duration GC_WAIT_TIMEOUT = Duration.ofSeconds(90); public static final Duration INITIAL_RECONCILE_WAIT_TIMEOUT = Duration.ofMillis(150); public static final int CRD_READY_WAIT = 1000; @@ -32,7 +32,7 @@ public class TestUtils { private static final Logger log = LoggerFactory.getLogger(TestUtils.class); - public static Glue loadResoureFlow(String path) { + public static Glue loadGlue(String path) { try (InputStream is = TestUtils.class.getResourceAsStream(path)) { return Serialization.unmarshal(is, Glue.class); } catch (IOException e) { @@ -40,7 +40,7 @@ public static Glue loadResoureFlow(String path) { } } - public static GlueOperator loadResourceFlowOperator(String path) { + public static GlueOperator loadGlueOperator(String path) { try (InputStream is = TestUtils.class.getResourceAsStream(path)) { return Serialization.unmarshal(is, GlueOperator.class); } catch (IOException e) { diff --git a/src/test/java/io/csviri/operator/glue/sample/mutation/MutationWebhookDeploymentE2E.java b/src/test/java/io/csviri/operator/glue/sample/mutation/MutationWebhookDeploymentE2E.java index ba0dc38..d104509 100644 --- a/src/test/java/io/csviri/operator/glue/sample/mutation/MutationWebhookDeploymentE2E.java +++ b/src/test/java/io/csviri/operator/glue/sample/mutation/MutationWebhookDeploymentE2E.java @@ -16,7 +16,7 @@ import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.dsl.NonDeletingOperation; -import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT_SECOND; +import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -55,7 +55,7 @@ void testMutationHookDeployment() { client.resource(glue).delete(); - await().timeout(GC_WAIT_TIMEOUT_SECOND).untilAsserted(() -> { + await().timeout(GC_WAIT_TIMEOUT).untilAsserted(() -> { var deployment = client.apps().deployments().withName("pod-mutating-hook").get(); assertThat(deployment).isNull(); }); diff --git a/src/test/java/io/csviri/operator/glue/sample/webpage/WebPageE2E.java b/src/test/java/io/csviri/operator/glue/sample/webpage/WebPageE2E.java index 804e8b5..c042d26 100644 --- a/src/test/java/io/csviri/operator/glue/sample/webpage/WebPageE2E.java +++ b/src/test/java/io/csviri/operator/glue/sample/webpage/WebPageE2E.java @@ -15,7 +15,7 @@ import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.dsl.NonDeletingOperation; -import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT_SECOND; +import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -62,7 +62,7 @@ void testWebPageCRUDOperations() { client.resource(createdWebPage).delete(); - await().timeout(GC_WAIT_TIMEOUT_SECOND).untilAsserted(() -> { + await().timeout(GC_WAIT_TIMEOUT).untilAsserted(() -> { var deployment = client.resources(Deployment.class).withName(webPage.getMetadata().getName()).get(); var configMap = diff --git a/src/test/java/io/csviri/operator/glue/sample/webpage/WebPageSampleTest.java b/src/test/java/io/csviri/operator/glue/sample/webpage/WebPageSampleTest.java index 4f5a81e..50f0365 100644 --- a/src/test/java/io/csviri/operator/glue/sample/webpage/WebPageSampleTest.java +++ b/src/test/java/io/csviri/operator/glue/sample/webpage/WebPageSampleTest.java @@ -60,7 +60,7 @@ void webPageCRUD() { delete(webPage); - await().timeout(TestUtils.GC_WAIT_TIMEOUT_SECOND).untilAsserted(() -> { + await().timeout(TestUtils.GC_WAIT_TIMEOUT).untilAsserted(() -> { var deployment = get(Deployment.class, webPage.getMetadata().getName()); assertThat(deployment).isNull(); });