From 609100e970853dbf1028ce89c8ba0b0cb0858428 Mon Sep 17 00:00:00 2001 From: hzrncik Date: Mon, 19 Aug 2024 14:16:56 +0200 Subject: [PATCH 1/2] removal of resources from co-namespace adnd put them to test suite namespace Signed-off-by: hzrncik --- .../listeners/ExecutionListener.java | 17 +++--- .../cruisecontrol/CruiseControlST.java | 52 +++++++++---------- .../systemtest/migration/MigrationST.java | 14 ++--- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/systemtest/src/main/java/io/strimzi/systemtest/listeners/ExecutionListener.java b/systemtest/src/main/java/io/strimzi/systemtest/listeners/ExecutionListener.java index 6321e42e05b..2b98ce844c4 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/listeners/ExecutionListener.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/listeners/ExecutionListener.java @@ -60,15 +60,18 @@ private void printSelectedTestClasses(TestPlan plan) { public static boolean hasSuiteParallelOrIsolatedTest(final ExtensionContext extensionContext) { Set testCases = testPlan.getChildren(extensionContext.getUniqueId()); + final Set relevantTags = Set.of( + TestConstants.PARALLEL_TEST, + TestConstants.ISOLATED_TEST, + TestConstants.DYNAMIC_CONFIGURATION, // Dynamic configuration also because in DynamicConfSharedST we use @TestFactory + TestConstants.TRACING, // Tracing, because we deploy Jaeger operator inside additional namespace + TestConstants.KAFKA_SMOKE, // KafkaVersionsST, MigrationST because here we use @ParameterizedTest + TestConstants.MIGRATION + ); + for (TestIdentifier testIdentifier : testCases) { for (TestTag testTag : testIdentifier.getTags()) { - if (testTag.getName().equals(TestConstants.PARALLEL_TEST) || testTag.getName().equals(TestConstants.ISOLATED_TEST) || - // Dynamic configuration also because in DynamicConfSharedST we use @TestFactory - testTag.getName().equals(TestConstants.DYNAMIC_CONFIGURATION) || - // Tracing, because we deploy Jaeger operator inside additional namespace - testTag.getName().equals(TestConstants.TRACING) || - // KafkaVersionsST, because here we use @ParameterizedTest - testTag.getName().equals(TestConstants.KAFKA_SMOKE)) { + if (relevantTags.contains(testTag.getName())) { return true; } } diff --git a/systemtest/src/test/java/io/strimzi/systemtest/cruisecontrol/CruiseControlST.java b/systemtest/src/test/java/io/strimzi/systemtest/cruisecontrol/CruiseControlST.java index 5ce6fe7031e..499ea823f50 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/cruisecontrol/CruiseControlST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/cruisecontrol/CruiseControlST.java @@ -90,7 +90,7 @@ void testAutoCreationOfCruiseControlTopicsWithResources() { KafkaNodePoolTemplates.controllerPool(testStorage.getNamespaceName(), testStorage.getControllerPoolName(), testStorage.getClusterName(), defaultBrokerReplicaCount).build() ) ); - resourceManager.createResourceWithWait(KafkaTemplates.kafkaWithCruiseControl(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName(), defaultBrokerReplicaCount, defaultBrokerReplicaCount) + resourceManager.createResourceWithWait(KafkaTemplates.kafkaWithCruiseControl(testStorage.getNamespaceName(), testStorage.getClusterName(), defaultBrokerReplicaCount, defaultBrokerReplicaCount) .editOrNewSpec() .editKafka() .addToConfig(Map.of("default.replication.factor", defaultBrokerReplicaCount)) @@ -110,11 +110,11 @@ void testAutoCreationOfCruiseControlTopicsWithResources() { .endSpec() .build()); - String ccPodName = kubeClient().listPodsByPrefixInName(Environment.TEST_SUITE_NAMESPACE, CruiseControlResources.componentName(testStorage.getClusterName())).get(0).getMetadata().getName(); - Container container = (Container) KubeClusterResource.kubeClient(Environment.TEST_SUITE_NAMESPACE).getPod(Environment.TEST_SUITE_NAMESPACE, ccPodName).getSpec().getContainers().stream().filter(c -> c.getName().equals("cruise-control")).findFirst().get(); + String ccPodName = kubeClient().listPodsByPrefixInName(testStorage.getNamespaceName(), CruiseControlResources.componentName(testStorage.getClusterName())).get(0).getMetadata().getName(); + Container container = (Container) KubeClusterResource.kubeClient().getPod(testStorage.getNamespaceName(), ccPodName).getSpec().getContainers().stream().filter(c -> c.getName().equals("cruise-control")).findFirst().get(); assertThat(container.getResources().getLimits().get("memory"), is(new Quantity("300Mi"))); assertThat(container.getResources().getRequests().get("memory"), is(new Quantity("300Mi"))); - VerificationUtils.assertJvmOptions(Environment.TEST_SUITE_NAMESPACE, ccPodName, "cruise-control", + VerificationUtils.assertJvmOptions(testStorage.getNamespaceName(), ccPodName, "cruise-control", "-Xmx200M", "-Xms128M", "-XX:+UseG1GC"); resourceManager.createResourceWithWait(KafkaTopicTemplates.topic(testStorage).build()); @@ -139,7 +139,7 @@ void testCruiseControlWithApiSecurityDisabled() { KafkaNodePoolTemplates.controllerPool(testStorage.getNamespaceName(), testStorage.getControllerPoolName(), testStorage.getClusterName(), 3).build() ) ); - resourceManager.createResourceWithWait(KafkaTemplates.kafkaWithCruiseControl(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName(), 3, 3) + resourceManager.createResourceWithWait(KafkaTemplates.kafkaWithCruiseControl(testStorage.getNamespaceName(), testStorage.getClusterName(), 3, 3) .editOrNewSpec() .editCruiseControl() .addToConfig("webserver.security.enable", "false") @@ -147,9 +147,9 @@ void testCruiseControlWithApiSecurityDisabled() { .endCruiseControl() .endSpec() .build()); - resourceManager.createResourceWithWait(KafkaRebalanceTemplates.kafkaRebalance(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName()).build()); + resourceManager.createResourceWithWait(KafkaRebalanceTemplates.kafkaRebalance(testStorage.getNamespaceName(), testStorage.getClusterName()).build()); - KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName(), KafkaRebalanceState.ProposalReady); + KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(testStorage.getNamespaceName(), testStorage.getClusterName(), KafkaRebalanceState.ProposalReady); } @IsolatedTest("Using more tha one Kafka cluster in one namespace") @@ -164,31 +164,31 @@ void testCruiseControlWithRebalanceResourceAndRefreshAnnotation() { KafkaNodePoolTemplates.controllerPool(testStorage.getNamespaceName(), testStorage.getControllerPoolName(), testStorage.getClusterName(), 3).build() ) ); - resourceManager.createResourceWithWait(KafkaTemplates.kafkaEphemeral(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName(), 3, 3).build()); - resourceManager.createResourceWithoutWait(KafkaRebalanceTemplates.kafkaRebalance(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName()).build()); + resourceManager.createResourceWithWait(KafkaTemplates.kafkaEphemeral(testStorage.getNamespaceName(), testStorage.getClusterName(), 3, 3).build()); + resourceManager.createResourceWithoutWait(KafkaRebalanceTemplates.kafkaRebalance(testStorage.getNamespaceName(), testStorage.getClusterName()).build()); - KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName(), KafkaRebalanceState.NotReady); + KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(testStorage.getNamespaceName(), testStorage.getClusterName(), KafkaRebalanceState.NotReady); - Map brokerPods = PodUtils.podSnapshot(Environment.TEST_SUITE_NAMESPACE, testStorage.getBrokerSelector()); + Map brokerPods = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getBrokerSelector()); // CruiseControl spec is now enabled KafkaResource.replaceKafkaResourceInSpecificNamespace(testStorage.getClusterName(), kafka -> { // Get default CC spec with tune options and set it to existing Kafka - Kafka kafkaUpdated = KafkaTemplates.kafkaWithCruiseControlTunedForFastModelGeneration(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName(), 3, 3).build(); + Kafka kafkaUpdated = KafkaTemplates.kafkaWithCruiseControlTunedForFastModelGeneration(testStorage.getNamespaceName(), testStorage.getClusterName(), 3, 3).build(); kafka.getSpec().setCruiseControl(kafkaUpdated.getSpec().getCruiseControl()); kafka.getSpec().setKafka(kafkaUpdated.getSpec().getKafka()); - }, Environment.TEST_SUITE_NAMESPACE); + }, testStorage.getNamespaceName()); - RollingUpdateUtils.waitTillComponentHasRolled(Environment.TEST_SUITE_NAMESPACE, testStorage.getBrokerSelector(), 3, brokerPods); + RollingUpdateUtils.waitTillComponentHasRolled(testStorage.getNamespaceName(), testStorage.getBrokerSelector(), 3, brokerPods); - KafkaRebalanceUtils.doRebalancingProcess(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName()); + KafkaRebalanceUtils.doRebalancingProcess(testStorage.getNamespaceName(), testStorage.getClusterName()); LOGGER.info("Annotating KafkaRebalance: {} with 'refresh' anno", testStorage.getClusterName()); - KafkaRebalanceUtils.annotateKafkaRebalanceResource(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName(), KafkaRebalanceAnnotation.refresh); - KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName(), KafkaRebalanceState.ProposalReady); + KafkaRebalanceUtils.annotateKafkaRebalanceResource(testStorage.getNamespaceName(), testStorage.getClusterName(), KafkaRebalanceAnnotation.refresh); + KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(testStorage.getNamespaceName(), testStorage.getClusterName(), KafkaRebalanceState.ProposalReady); LOGGER.info("Trying rebalancing process again"); - KafkaRebalanceUtils.doRebalancingProcess(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName()); + KafkaRebalanceUtils.doRebalancingProcess(testStorage.getNamespaceName(), testStorage.getClusterName()); } @IsolatedTest @@ -197,24 +197,24 @@ void testCruiseControlChangesFromRebalancingtoProposalReadyWhenSpecUpdated() { resourceManager.createResourceWithWait( NodePoolsConverter.convertNodePoolsIfNeeded( - KafkaNodePoolTemplates.brokerPool(clusterOperator.getDeploymentNamespace(), testStorage.getBrokerPoolName(), testStorage.getClusterName(), 3).build(), - KafkaNodePoolTemplates.controllerPool(clusterOperator.getDeploymentNamespace(), testStorage.getControllerPoolName(), testStorage.getClusterName(), 1).build() + KafkaNodePoolTemplates.brokerPool(testStorage.getNamespaceName(), testStorage.getBrokerPoolName(), testStorage.getClusterName(), 3).build(), + KafkaNodePoolTemplates.controllerPool(testStorage.getNamespaceName(), testStorage.getControllerPoolName(), testStorage.getClusterName(), 1).build() ) ); - resourceManager.createResourceWithWait(KafkaTemplates.kafkaWithCruiseControl(clusterOperator.getDeploymentNamespace(), testStorage.getClusterName(), 3, 1).build()); + resourceManager.createResourceWithWait(KafkaTemplates.kafkaWithCruiseControl(testStorage.getNamespaceName(), testStorage.getClusterName(), 3, 1).build()); - resourceManager.createResourceWithWait(KafkaRebalanceTemplates.kafkaRebalance(clusterOperator.getDeploymentNamespace(), testStorage.getClusterName()).build()); + resourceManager.createResourceWithWait(KafkaRebalanceTemplates.kafkaRebalance(testStorage.getNamespaceName(), testStorage.getClusterName()).build()); - KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(clusterOperator.getDeploymentNamespace(), testStorage.getClusterName(), KafkaRebalanceState.ProposalReady); + KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(testStorage.getNamespaceName(), testStorage.getClusterName(), KafkaRebalanceState.ProposalReady); LOGGER.info("Annotating KafkaRebalance: {} with 'approve' anno", testStorage.getClusterName()); - KafkaRebalanceUtils.annotateKafkaRebalanceResource(clusterOperator.getDeploymentNamespace(), testStorage.getClusterName(), KafkaRebalanceAnnotation.approve); + KafkaRebalanceUtils.annotateKafkaRebalanceResource(testStorage.getNamespaceName(), testStorage.getClusterName(), KafkaRebalanceAnnotation.approve); // updating the KafkaRebalance resource by configuring replication throttle - KafkaRebalanceResource.replaceKafkaRebalanceResourceInSpecificNamespace(testStorage.getClusterName(), kafkaRebalance -> kafkaRebalance.getSpec().setReplicationThrottle(100000), clusterOperator.getDeploymentNamespace()); + KafkaRebalanceResource.replaceKafkaRebalanceResourceInSpecificNamespace(testStorage.getClusterName(), kafkaRebalance -> kafkaRebalance.getSpec().setReplicationThrottle(100000), testStorage.getNamespaceName()); // the resource moved to `ProposalReady` state - KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(clusterOperator.getDeploymentNamespace(), testStorage.getClusterName(), KafkaRebalanceState.ProposalReady); + KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(testStorage.getNamespaceName(), testStorage.getClusterName(), KafkaRebalanceState.ProposalReady); } @ParallelNamespaceTest diff --git a/systemtest/src/test/java/io/strimzi/systemtest/migration/MigrationST.java b/systemtest/src/test/java/io/strimzi/systemtest/migration/MigrationST.java index 6a4fc411af7..028a515bc6d 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/migration/MigrationST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/migration/MigrationST.java @@ -143,7 +143,7 @@ public class MigrationST extends AbstractST { @ParameterizedTest(name = "with: ZK delete claim - {0}, CO deletion during process - {1}, JBOD storage - {2}") @MethodSource("getArgumentsForMigrationParametrizedTests") void testMigration(Boolean zkDeleteClaim, Boolean deleteCoDuringProcess, Boolean withJbodStorage) { - TestStorage testStorage = new TestStorage(ResourceManager.getTestContext(), TestConstants.CO_NAMESPACE); + final TestStorage testStorage = new TestStorage(ResourceManager.getTestContext()); setupMigrationTestCase(testStorage, zkDeleteClaim, withJbodStorage); doFirstPartOfMigration(testStorage, deleteCoDuringProcess, withJbodStorage); @@ -210,7 +210,7 @@ void testMigration(Boolean zkDeleteClaim, Boolean deleteCoDuringProcess, Boolean @ParameterizedTest(name = "with: CO deletion during process - {0}, JBOD storage - {1}") @MethodSource("getArgumentsForRollbackParametrizedTests") void testRollback(Boolean deleteCoDuringProcess, Boolean withJbodStorage) { - TestStorage testStorage = new TestStorage(ResourceManager.getTestContext(), TestConstants.CO_NAMESPACE); + final TestStorage testStorage = new TestStorage(ResourceManager.getTestContext()); setupMigrationTestCase(testStorage, true, withJbodStorage); doFirstPartOfMigration(testStorage, deleteCoDuringProcess, withJbodStorage); @@ -265,10 +265,10 @@ void testRollback(Boolean deleteCoDuringProcess, Boolean withJbodStorage) { */ @IsolatedTest void testMigrationWithRollback() { - TestStorage testStorage = new TestStorage(ResourceManager.getTestContext(), TestConstants.CO_NAMESPACE); - boolean zkDeleteClaim = true; - boolean deleteCoDuringProcess = false; - boolean withJbodStorage = false; + final TestStorage testStorage = new TestStorage(ResourceManager.getTestContext()); + final boolean zkDeleteClaim = true; + final boolean deleteCoDuringProcess = false; + final boolean withJbodStorage = false; setupMigrationTestCase(testStorage, zkDeleteClaim, withJbodStorage); doFirstPartOfMigration(testStorage, deleteCoDuringProcess, withJbodStorage); @@ -305,6 +305,7 @@ private void setupMigrationTestCase(TestStorage testStorage, boolean zkDeleteCla String clientsAdditionConfiguration = "delivery.timeout.ms=40000\nrequest.timeout.ms=5000\nacks=all\n"; immediateClients = new KafkaClientsBuilder() + .withNamespaceName(testStorage.getNamespaceName()) .withProducerName(testStorage.getProducerName()) .withConsumerName(testStorage.getConsumerName()) .withBootstrapAddress(KafkaResources.tlsBootstrapAddress(testStorage.getClusterName())) @@ -315,6 +316,7 @@ private void setupMigrationTestCase(TestStorage testStorage, boolean zkDeleteCla .build(); continuousClients = new KafkaClientsBuilder() + .withNamespaceName(testStorage.getNamespaceName()) .withProducerName(continuousProducerName) .withConsumerName(continuousConsumerName) .withBootstrapAddress(KafkaResources.plainBootstrapAddress(testStorage.getClusterName())) From a58ff285b074ef41f8deeb7c58546b43f49a8116 Mon Sep 17 00:00:00 2001 From: hzrncik Date: Tue, 27 Aug 2024 12:10:42 +0200 Subject: [PATCH 2/2] renaming to requiresSharedNamespace Signed-off-by: hzrncik --- .../strimzi/systemtest/listeners/ExecutionListener.java | 9 +++++---- .../systemtest/parallel/TestSuiteNamespaceManager.java | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/systemtest/src/main/java/io/strimzi/systemtest/listeners/ExecutionListener.java b/systemtest/src/main/java/io/strimzi/systemtest/listeners/ExecutionListener.java index 2b98ce844c4..b0a9e601906 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/listeners/ExecutionListener.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/listeners/ExecutionListener.java @@ -52,15 +52,16 @@ private void printSelectedTestClasses(TestPlan plan) { /** * Checks if test suite has test case, which is labeled as {@link io.strimzi.systemtest.annotations.ParallelTest} or - * {@link io.strimzi.systemtest.annotations.IsolatedTest}. + * {@link io.strimzi.systemtest.annotations.IsolatedTest} or is suite with explicit need of creating shared namespace. * * @param extensionContext ExtensionContext of the test case * @return true if test suite contains Parallel or Isolated test case. Otherwise, false. */ - public static boolean hasSuiteParallelOrIsolatedTest(final ExtensionContext extensionContext) { + public static boolean requiresSharedNamespace(final ExtensionContext extensionContext) { Set testCases = testPlan.getChildren(extensionContext.getUniqueId()); - final Set relevantTags = Set.of( + // name of suites or tags which indicates need of creation of shared namespace test-suite-namespace + final Set identifiersRequiringSharedNamespace = Set.of( TestConstants.PARALLEL_TEST, TestConstants.ISOLATED_TEST, TestConstants.DYNAMIC_CONFIGURATION, // Dynamic configuration also because in DynamicConfSharedST we use @TestFactory @@ -71,7 +72,7 @@ public static boolean hasSuiteParallelOrIsolatedTest(final ExtensionContext exte for (TestIdentifier testIdentifier : testCases) { for (TestTag testTag : testIdentifier.getTags()) { - if (relevantTags.contains(testTag.getName())) { + if (identifiersRequiringSharedNamespace.contains(testTag.getName())) { return true; } } diff --git a/systemtest/src/main/java/io/strimzi/systemtest/parallel/TestSuiteNamespaceManager.java b/systemtest/src/main/java/io/strimzi/systemtest/parallel/TestSuiteNamespaceManager.java index 06e924b8cb0..18ab3acb067 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/parallel/TestSuiteNamespaceManager.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/parallel/TestSuiteNamespaceManager.java @@ -47,7 +47,7 @@ public synchronized static TestSuiteNamespaceManager getInstance() { public void createTestSuiteNamespace() { final String testSuiteName = ResourceManager.getTestContext().getRequiredTestClass().getName(); - if (ExecutionListener.hasSuiteParallelOrIsolatedTest(ResourceManager.getTestContext())) { + if (ExecutionListener.requiresSharedNamespace(ResourceManager.getTestContext())) { // if RBAC is enabled we don't run tests in parallel mode and with that said we don't create another namespaces if (!Environment.isNamespaceRbacScope()) { NamespaceManager.getInstance().createNamespaceAndPrepare(Environment.TEST_SUITE_NAMESPACE, CollectorElement.createCollectorElement(testSuiteName)); @@ -63,7 +63,7 @@ public void createTestSuiteNamespace() { * */ public void deleteTestSuiteNamespace() { - if (ExecutionListener.hasSuiteParallelOrIsolatedTest(ResourceManager.getTestContext())) { + if (ExecutionListener.requiresSharedNamespace(ResourceManager.getTestContext())) { // if RBAC is enabled we don't run tests in parallel mode and with that said we don't create another namespaces if (!Environment.isNamespaceRbacScope()) { final String testSuiteName = ResourceManager.getTestContext().getRequiredTestClass().getName();