Skip to content

Commit 354f3be

Browse files
authored
[ST] Fix upgrade/downgrade tests after merge of v1 API (strimzi#12056)
Signed-off-by: Lukas Kral <[email protected]>
1 parent 351ad80 commit 354f3be

File tree

7 files changed

+103
-53
lines changed

7 files changed

+103
-53
lines changed

pom.xml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
<testcontainer.version>1.21.3</testcontainer.version>
117117
<docker-java.version>3.4.0</docker-java.version>
118118
<junit4.version>4.13.2</junit4.version>
119-
<skodjob.test-frame.version>1.2.0</skodjob.test-frame.version>
120119
<skodjob-doc.version>0.6.0</skodjob-doc.version>
121120
<helm-client.version>0.0.15</helm-client.version>
122121
<access-operator.version>0.2.0</access-operator.version>
@@ -630,33 +629,6 @@
630629
<artifactId>snakeyaml</artifactId>
631630
<version>${snakeyaml.version}</version>
632631
</dependency>
633-
<!-- The skodjob dependency is required at compile time, not solely in the test scope, due to the creation of custom metrics components. -->
634-
<dependency>
635-
<groupId>io.skodjob</groupId>
636-
<artifactId>test-frame-metrics-collector</artifactId>
637-
<version>${skodjob.test-frame.version}</version>
638-
</dependency>
639-
<dependency>
640-
<groupId>io.skodjob</groupId>
641-
<artifactId>test-frame-log-collector</artifactId>
642-
<version>${skodjob.test-frame.version}</version>
643-
</dependency>
644-
<dependency>
645-
<groupId>io.skodjob</groupId>
646-
<artifactId>test-frame-common</artifactId>
647-
<version>${skodjob.test-frame.version}</version>
648-
</dependency>
649-
<dependency>
650-
<groupId>io.skodjob</groupId>
651-
<artifactId>test-frame-kubernetes</artifactId>
652-
<version>${skodjob.test-frame.version}</version>
653-
</dependency>
654-
<dependency>
655-
<groupId>io.skodjob</groupId>
656-
<artifactId>test-frame-openshift</artifactId>
657-
<version>${skodjob.test-frame.version}</version>
658-
<scope>test</scope>
659-
</dependency>
660632
<!-- Test dependencies -->
661633
<dependency>
662634
<groupId>io.strimzi</groupId>

systemtest/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,25 @@
1717

1818
<!-- Points to the root directory of the Strimzi project directory and can be used for fixed location to configuration files -->
1919
<strimziRootDirectory>${basedir}${file.separator}..</strimziRootDirectory>
20+
21+
<!-- Once new version of Test-Frame is released, we need to remove all the deps from here and return it back to the main pom.xml -->
22+
<skodjob.test-frame.version>1.3.0-SNAPSHOT</skodjob.test-frame.version>
2023
</properties>
2124

25+
<repositories>
26+
<repository>
27+
<name>Central Portal Snapshots</name>
28+
<id>central-portal-snapshots</id>
29+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
30+
<releases>
31+
<enabled>false</enabled>
32+
</releases>
33+
<snapshots>
34+
<enabled>true</enabled>
35+
</snapshots>
36+
</repository>
37+
</repositories>
38+
2239
<dependencies>
2340
<dependency>
2441
<groupId>io.strimzi</groupId>
@@ -232,25 +249,32 @@
232249
<groupId>io.fabric8</groupId>
233250
<artifactId>openshift-model-operatorhub</artifactId>
234251
</dependency>
252+
<!-- The skodjob dependency is required at compile time, not solely in the test scope, due to the creation of custom metrics components. -->
235253
<dependency>
236254
<groupId>io.skodjob</groupId>
237255
<artifactId>test-frame-metrics-collector</artifactId>
256+
<version>${skodjob.test-frame.version}</version>
238257
</dependency>
239258
<dependency>
240259
<groupId>io.skodjob</groupId>
241260
<artifactId>test-frame-log-collector</artifactId>
261+
<version>${skodjob.test-frame.version}</version>
242262
</dependency>
243263
<dependency>
244264
<groupId>io.skodjob</groupId>
245265
<artifactId>test-frame-common</artifactId>
266+
<version>${skodjob.test-frame.version}</version>
246267
</dependency>
247268
<dependency>
248269
<groupId>io.skodjob</groupId>
249270
<artifactId>test-frame-kubernetes</artifactId>
271+
<version>${skodjob.test-frame.version}</version>
250272
</dependency>
251273
<dependency>
252274
<groupId>io.skodjob</groupId>
253275
<artifactId>test-frame-openshift</artifactId>
276+
<version>${skodjob.test-frame.version}</version>
277+
<scope>test</scope>
254278
</dependency>
255279
<dependency>
256280
<groupId>io.skodjob</groupId>

systemtest/src/main/java/io/strimzi/systemtest/TestConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,9 @@ public interface TestConstants {
351351
* Label for Kubernetes worker nodes
352352
*/
353353
String WORKER_NODE_LABEL = "node-role.kubernetes.io/worker";
354+
355+
/**
356+
* API version
357+
*/
358+
String V1_BETA_2_API_VERSION = "kafka.strimzi.io/v1beta2";
354359
}

systemtest/src/main/java/io/strimzi/systemtest/resources/CrdClients.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package io.strimzi.systemtest.resources;
66

7+
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
8+
import io.fabric8.kubernetes.api.model.GenericKubernetesResourceList;
79
import io.fabric8.kubernetes.client.dsl.MixedOperation;
810
import io.fabric8.kubernetes.client.dsl.Resource;
911
import io.skodjob.testframe.resources.KubeResourceManager;
@@ -28,6 +30,7 @@
2830
import io.strimzi.api.kafka.model.topic.KafkaTopicList;
2931
import io.strimzi.api.kafka.model.user.KafkaUser;
3032
import io.strimzi.api.kafka.model.user.KafkaUserList;
33+
import io.strimzi.systemtest.TestConstants;
3134

3235
/**
3336
* Class containing encapsulations of clients for Strimzi's CRs.
@@ -103,6 +106,15 @@ public static MixedOperation<KafkaTopic, KafkaTopicList, Resource<KafkaTopic>> k
103106
return Crds.topicOperation(KubeResourceManager.get().kubeClient().getClient());
104107
}
105108

109+
/**
110+
* Encapsulation for {@link KafkaTopic} client for v1beta2 API version.
111+
*
112+
* @return {@link KafkaTopic} client for v1beta2 API version.
113+
*/
114+
public static MixedOperation<GenericKubernetesResource, GenericKubernetesResourceList, Resource<GenericKubernetesResource>> kafkaTopicV1Beta2Client() {
115+
return KubeResourceManager.get().kubeClient().getClient().genericKubernetesResources(TestConstants.V1_BETA_2_API_VERSION, KafkaTopic.RESOURCE_KIND);
116+
}
117+
106118
/**
107119
* Encapsulation for {@link KafkaUser} client.
108120
*

systemtest/src/main/java/io/strimzi/systemtest/utils/kafkaUtils/KafkaTopicUtils.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
*/
55
package io.strimzi.systemtest.utils.kafkaUtils;
66

7+
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
78
import io.skodjob.testframe.executor.ExecResult;
89
import io.skodjob.testframe.resources.KubeResourceManager;
10+
import io.skodjob.testframe.utils.ResourceUtils;
11+
import io.strimzi.api.kafka.model.common.Constants;
912
import io.strimzi.api.kafka.model.kafka.KafkaResources;
1013
import io.strimzi.api.kafka.model.rebalance.BrokerAndVolumeIds;
1114
import io.strimzi.api.kafka.model.topic.KafkaTopic;
@@ -42,6 +45,7 @@
4245

4346
import static io.strimzi.systemtest.enums.CustomResourceStatus.Ready;
4447
import static io.strimzi.systemtest.resources.CrdClients.kafkaTopicClient;
48+
import static io.strimzi.systemtest.resources.CrdClients.kafkaTopicV1Beta2Client;
4549
import static org.hamcrest.MatcherAssert.assertThat;
4650
import static org.hamcrest.Matchers.hasItems;
4751
import static org.hamcrest.Matchers.is;
@@ -123,6 +127,30 @@ public static void waitForKafkaTopicDeletion(String namespaceName, String topicN
123127
);
124128
}
125129

130+
public static void waitForKafkaTopicDeletionWithV1Beta2(String namespaceName, String topicName) {
131+
LOGGER.info("Waiting for KafkaTopic: {}/{} deletion", namespaceName, topicName);
132+
TestUtils.waitFor("deletion of KafkaTopic: " + namespaceName + "/" + topicName, TestConstants.POLL_INTERVAL_FOR_RESOURCE_READINESS, DELETION_TIMEOUT,
133+
() -> {
134+
if (kafkaTopicV1Beta2Client().inNamespace(namespaceName).withName(topicName).get() == null) {
135+
return true;
136+
} else {
137+
LOGGER.warn("KafkaTopic: {}/{} is not deleted yet! Triggering force delete by cmd client!", namespaceName, topicName);
138+
KubeResourceManager.get().kubeCmdClient().inNamespace(namespaceName).deleteByName(KafkaTopic.RESOURCE_PLURAL + "." + Constants.V1BETA2 + "." + Constants.RESOURCE_GROUP_NAME, topicName);
139+
return false;
140+
}
141+
},
142+
() -> LOGGER.info(kafkaTopicV1Beta2Client().inNamespace(namespaceName).withName(topicName).get())
143+
);
144+
}
145+
146+
public static void deleteAllKafkaTopicsWithV1Beta2(String namespaceName) {
147+
List<GenericKubernetesResource> kafkaTopics = kafkaTopicV1Beta2Client().inNamespace(namespaceName).list().getItems();
148+
kafkaTopics.forEach(kafkaTopic -> {
149+
kafkaTopicV1Beta2Client().inNamespace(namespaceName).resource(kafkaTopic).delete();
150+
waitForKafkaTopicDeletionWithV1Beta2(namespaceName, kafkaTopic.getMetadata().getName());
151+
});
152+
}
153+
126154
public static void waitForKafkaTopicPartitionChange(String namespaceName, String topicName, int partitions) {
127155
LOGGER.info("Waiting for KafkaTopic: {}/{} to change", namespaceName, topicName);
128156
TestUtils.waitFor("change of KafkaTopic: " + namespaceName + "/" + topicName, TestConstants.POLL_INTERVAL_FOR_RESOURCE_READINESS, TestConstants.GLOBAL_TIMEOUT,
@@ -162,6 +190,16 @@ public static void waitForKafkaTopicNotReady(final String namespaceName, String
162190
waitForKafkaTopicStatus(namespaceName, topicName, Ready, ConditionStatus.False);
163191
}
164192

193+
public static void waitForKafkaTopicReadyForV1Beta2(String namespaceName, String topicName) {
194+
KafkaTopic kafkaTopic = ResourceUtils.getGenericResourceReturnSpecific(namespaceName, topicName, TestConstants.V1_BETA_2_API_VERSION, KafkaTopic.RESOURCE_KIND, KafkaTopic.class);
195+
KubeResourceManager.get().waitResourceCondition(
196+
kafkaTopic,
197+
ResourceConditions.resourceHasDesiredState(Ready),
198+
ResourceOperation.getTimeoutForResourceReadiness(kafkaTopic.getKind()),
199+
() -> ResourceUtils.getGenericResourceReturnSpecific(namespaceName, topicName, TestConstants.V1_BETA_2_API_VERSION, KafkaTopic.RESOURCE_KIND, KafkaTopic.class)
200+
);
201+
}
202+
165203
public static void waitForTopicConfigContains(String namespaceName, String topicName, Map<String, Object> config) {
166204
LOGGER.info("Waiting for KafkaTopic: {}/{} to contain correct config", namespaceName, topicName);
167205
TestUtils.waitFor("KafkaTopic: " + namespaceName + "/" + topicName + " to contain correct config",
@@ -293,12 +331,19 @@ public static void verifyUnchangedTopicAbsence(String namespaceName, String quer
293331
}
294332

295333
public static void setFinalizersInAllTopicsToNull(String namespaceName) {
296-
LOGGER.info("Setting finalizers in all KafkaTopics in Namespace: {} to null", namespaceName);
334+
LOGGER.info("Removing finalizers from all KafkaTopics in Namespace: {}", namespaceName);
297335
kafkaTopicClient().inNamespace(namespaceName).list().getItems().forEach(kafkaTopic ->
298336
KafkaTopicUtils.replace(namespaceName, kafkaTopic.getMetadata().getName(), kt -> kt.getMetadata().setFinalizers(null))
299337
);
300338
}
301339

340+
public static void setFinalizersInAllV1Beta2TopicsToNull(String namespaceName) {
341+
LOGGER.info("Removing finalizers from all KafkaTopics in Namespace: {}", namespaceName);
342+
kafkaTopicV1Beta2Client().inNamespace(namespaceName).list().getItems().forEach(kafkaTopic ->
343+
KubeResourceManager.get().replaceResourceWithRetries(kafkaTopic, kt -> kt.getMetadata().setFinalizers(null))
344+
);
345+
}
346+
302347
public static void waitForTopicStatusMessage(String namespaceName, String topicName, String message) {
303348
LOGGER.info("Waiting for KafkaTopic: {}/{} to contain message: {} in its status", namespaceName, topicName, message);
304349

systemtest/src/main/java/io/strimzi/systemtest/utils/kafkaUtils/KafkaUserUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.fabric8.kubernetes.api.model.Secret;
1111
import io.fabric8.kubernetes.api.model.SecretBuilder;
1212
import io.skodjob.testframe.resources.KubeResourceManager;
13+
import io.skodjob.testframe.utils.ResourceUtils;
1314
import io.strimzi.api.kafka.model.common.PasswordBuilder;
1415
import io.strimzi.api.kafka.model.user.KafkaUser;
1516
import io.strimzi.api.kafka.model.user.KafkaUserScramSha512ClientAuthenticationBuilder;
@@ -125,6 +126,16 @@ public static void waitForKafkaUserReady(String namespaceName, String userName)
125126
waitForKafkaUserStatus(namespaceName, userName, Ready);
126127
}
127128

129+
public static void waitForKafkaUserReadyForV1Beta2(String namespaceName, String userName) {
130+
KafkaUser kafkaUser = ResourceUtils.getGenericResourceReturnSpecific(namespaceName, userName, TestConstants.V1_BETA_2_API_VERSION, KafkaUser.RESOURCE_KIND, KafkaUser.class);
131+
KubeResourceManager.get().waitResourceCondition(
132+
kafkaUser,
133+
ResourceConditions.resourceHasDesiredState(Ready),
134+
ResourceOperation.getTimeoutForResourceReadiness(kafkaUser.getKind()),
135+
() -> ResourceUtils.getGenericResourceReturnSpecific(namespaceName, userName, TestConstants.V1_BETA_2_API_VERSION, KafkaUser.RESOURCE_KIND, KafkaUser.class)
136+
);
137+
}
138+
128139
public static String removeKafkaUserPart(File kafkaUserFile, String partName) {
129140
YAMLMapper mapper = new YAMLMapper();
130141
try {

systemtest/src/test/java/io/strimzi/systemtest/upgrade/AbstractKRaftUpgradeST.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ protected void setupEnvAndUpgradeClusterOperator(String clusterOperatorNamespace
276276
.replace("replicas: 1", "replicas: 3") +
277277
" min.insync.replicas: 2");
278278

279-
KafkaTopicUtils.waitForKafkaTopicReady(testStorage.getNamespaceName(), testStorage.getTopicName());
279+
KafkaTopicUtils.waitForKafkaTopicReadyForV1Beta2(testStorage.getNamespaceName(), testStorage.getTopicName());
280280
}
281281

282282
// 40s is used within TF environment to make upgrade/downgrade more stable on slow env
@@ -362,7 +362,7 @@ protected void deployKafkaUserWithWaitForReadiness(final String componentsNamesp
362362
kafkaUserYaml = new File(dir, upgradeData.getFromExamples() + "/examples/user/kafka-user.yaml");
363363
LOGGER.info("Deploying KafkaUser from: {}", kafkaUserYaml.getPath());
364364
KubeResourceManager.get().kubeCmdClient().inNamespace(componentsNamespaceName).applyContent(KafkaUserUtils.removeKafkaUserPart(kafkaUserYaml, "authorization"));
365-
KafkaUserUtils.waitForKafkaUserReady(componentsNamespaceName, USER_NAME);
365+
KafkaUserUtils.waitForKafkaUserReadyForV1Beta2(componentsNamespaceName, USER_NAME);
366366
}
367367
}
368368
}
@@ -378,7 +378,7 @@ protected void deployKafkaTopicWithWaitForReadiness(final String componentsNames
378378
}
379379
LOGGER.info("Deploying KafkaTopic from: {}", kafkaTopicYaml.getPath());
380380
KubeResourceManager.get().kubeCmdClient().inNamespace(componentsNamespaceName).create(kafkaTopicYaml);
381-
KafkaTopicUtils.waitForKafkaTopicReady(componentsNamespaceName, TOPIC_NAME);
381+
KafkaTopicUtils.waitForKafkaTopicReadyForV1Beta2(componentsNamespaceName, TOPIC_NAME);
382382
}
383383
}
384384

@@ -722,24 +722,6 @@ protected void verifyProcedure(String componentsNamespaceNames, BundleVersionMod
722722
}
723723
}
724724

725-
/**
726-
* Based on {@param isUTOUsed} and {@param wasUTOUsedBefore} it returns the expected count of KafkaTopics.
727-
* In case that UTO was used before and after, the expected number of KafkaTopics is {@link #UPGRADE_TOPIC_COUNT}.
728-
* In other cases - BTO was used before or after the upgrade/downgrade - the expected number of KafkaTopics is {@link #UPGRADE_TOPIC_COUNT}
729-
* with {@link #BTO_KAFKA_TOPICS_ONLY_COUNT}.
730-
* @param isUTOUsed boolean value determining if UTO is used after upgrade/downgrade of the CO
731-
* @param wasUTOUsedBefore boolean value determining if UTO was used before upgrade/downgrade of the CO
732-
* @return expected number of KafkaTopics
733-
*/
734-
protected int getExpectedTopicCount(boolean isUTOUsed, boolean wasUTOUsedBefore) {
735-
if (isUTOUsed && wasUTOUsedBefore) {
736-
// topics that are just present in Kafka itself are not created as CRs in UTO, thus -3 topics in comparison to regular upgrade
737-
return UPGRADE_TOPIC_COUNT;
738-
}
739-
740-
return UPGRADE_TOPIC_COUNT + BTO_KAFKA_TOPICS_ONLY_COUNT;
741-
}
742-
743725
protected String getResourceApiVersion(String resourcePlural) {
744726
return resourcePlural + "." + Constants.V1BETA2 + "." + Constants.RESOURCE_GROUP_NAME;
745727
}
@@ -775,8 +757,7 @@ protected void cleanUpStrimziUpgradeTestNamespaces() {
775757
protected void cleanUpKafkaTopics(String componentsNamespaceName) {
776758
if (CrdUtils.isCrdPresent(KafkaTopic.RESOURCE_PLURAL, KafkaTopic.RESOURCE_GROUP)) {
777759
// delete all topics created in test
778-
List<KafkaTopic> kafkaTopics = CrdClients.kafkaTopicClient().inNamespace(componentsNamespaceName).list().getItems();
779-
KubeResourceManager.get().deleteResourceWithWait(kafkaTopics.toArray(new KafkaTopic[0]));
760+
KafkaTopicUtils.deleteAllKafkaTopicsWithV1Beta2(componentsNamespaceName);
780761
} else {
781762
LOGGER.info("Kafka Topic CustomResource Definition does not exist, no KafkaTopic is being deleted");
782763
}
@@ -789,7 +770,7 @@ protected void deleteInstalledYamls(String clusterOperatorNamespaceName, String
789770
}
790771
if (kafkaTopicYaml != null) {
791772
LOGGER.info("Deleting KafkaTopic configuration files");
792-
KafkaTopicUtils.setFinalizersInAllTopicsToNull(componentsNamespaceName);
773+
KafkaTopicUtils.setFinalizersInAllV1Beta2TopicsToNull(componentsNamespaceName);
793774
KubeResourceManager.get().kubeCmdClient().inNamespace(componentsNamespaceName).delete(kafkaTopicYaml);
794775
}
795776
if (kafkaYaml != null) {

0 commit comments

Comments
 (0)