Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ST] removal of resources from co-namespace across ST (except for upgrade downgrade STs) #10501

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,27 @@ 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<TestIdentifier> testCases = testPlan.getChildren(extensionContext.getUniqueId());

// name of suites or tags which indicates need of creation of shared namespace test-suite-namespace
final Set<String> identifiersRequiringSharedNamespace = 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 (identifiersRequiringSharedNamespace.contains(testTag.getName())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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());
Expand All @@ -139,17 +139,17 @@ 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")
.addToConfig("webserver.ssl.enable", "false")
.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")
Expand All @@ -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<String, String> brokerPods = PodUtils.podSnapshot(Environment.TEST_SUITE_NAMESPACE, testStorage.getBrokerSelector());
Map<String, String> 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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()))
Expand All @@ -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()))
Expand Down
Loading