From 3e7e30d70adaafc8e53bbefada2e9a4c2a85c0cd Mon Sep 17 00:00:00 2001 From: henryZrncik <40673682+henryZrncik@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:19:05 +0100 Subject: [PATCH] [ST] fixing unnecessary error logs when cleaning resources (#9667) Signed-off-by: hzrncik --- .../resources/crd/KafkaResource.java | 28 ++++++++++++------- .../operator/SetupClusterOperator.java | 3 +- .../io/strimzi/systemtest/kafka/KafkaST.java | 8 ++---- .../kafka/listeners/ListenersST.java | 6 ---- .../rollingupdate/KafkaRollerST.java | 3 -- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/systemtest/src/main/java/io/strimzi/systemtest/resources/crd/KafkaResource.java b/systemtest/src/main/java/io/strimzi/systemtest/resources/crd/KafkaResource.java index e5a2b39ac08..c37ce8c1649 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/resources/crd/KafkaResource.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/resources/crd/KafkaResource.java @@ -76,18 +76,26 @@ public void delete(Kafka resource) { .allMatch(result -> true); } - // load current Kafka's annotations to obtain information, if KafkaNodePools are used for this Kafka - Map annotations = kafkaClient().inNamespace(namespaceName) - .withName(resource.getMetadata().getName()).get().getMetadata().getAnnotations(); + // get current Kafka + Kafka kafka = kafkaClient().inNamespace(namespaceName) + .withName(resource.getMetadata().getName()).get(); + + // proceed only if kafka is still present as Kafka is purposefully deleted in some test cases + if (kafka != null) { + // load current Kafka's annotations to obtain information, if KafkaNodePools are used for this Kafka + Map annotations = kafka.getMetadata().getAnnotations(); + + kafkaClient().inNamespace(namespaceName).withName( + resource.getMetadata().getName()).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete(); + + if (annotations.get(Annotations.ANNO_STRIMZI_IO_NODE_POOLS) == null + || annotations.get(Annotations.ANNO_STRIMZI_IO_NODE_POOLS).equals("disabled")) { + // additional deletion of pvcs with specification deleteClaim set to false which were not deleted prior this method + PersistentVolumeClaimUtils.deletePvcsByPrefixWithWait(namespaceName, clusterName); + } + } - kafkaClient().inNamespace(namespaceName).withName( - resource.getMetadata().getName()).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete(); - if (annotations.get(Annotations.ANNO_STRIMZI_IO_NODE_POOLS) == null - || annotations.get(Annotations.ANNO_STRIMZI_IO_NODE_POOLS).equals("disabled")) { - // additional deletion of pvcs with specification deleteClaim set to false which were not deleted prior this method - PersistentVolumeClaimUtils.deletePvcsByPrefixWithWait(namespaceName, clusterName); - } } @Override diff --git a/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java b/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java index 6dacb55e6ff..fe9beecc37e 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java @@ -100,7 +100,8 @@ public class SetupClusterOperator { private int replicas = 1; private String testClassName; - private String testMethodName; + // by default, we expect at least empty method name in order to collect logs correctly + private String testMethodName = ""; private List roleBindings; private List roles; private List clusterRoles; diff --git a/systemtest/src/test/java/io/strimzi/systemtest/kafka/KafkaST.java b/systemtest/src/test/java/io/strimzi/systemtest/kafka/KafkaST.java index 456450ecba1..cdd24b8f007 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/kafka/KafkaST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/kafka/KafkaST.java @@ -390,7 +390,8 @@ void testKafkaJBODDeleteClaimsTrueFalse(ExtensionContext extensionContext) { JbodStorage jbodStorage = new JbodStorageBuilder().withVolumes(idZeroVolumeOriginal, idOneVolumeOriginal).build(); - resourceManager.createResourceWithWait(extensionContext, KafkaTemplates.kafkaJBOD(testStorage.getClusterName(), kafkaReplicas, jbodStorage).build()); + Kafka kafka = KafkaTemplates.kafkaJBOD(testStorage.getClusterName(), kafkaReplicas, jbodStorage).build(); + resourceManager.createResourceWithWait(extensionContext, kafka); // kafka cluster already deployed verifyVolumeNamesAndLabels(testStorage.getNamespaceName(), testStorage.getClusterName(), testStorage.getKafkaStatefulSetName(), kafkaReplicas, 2, diskSizeGi); @@ -420,8 +421,7 @@ void testKafkaJBODDeleteClaimsTrueFalse(ExtensionContext extensionContext) { final int volumesCount = kubeClient().listPersistentVolumeClaims(testStorage.getNamespaceName(), testStorage.getClusterName()).size(); LOGGER.info("Deleting Kafka: {}/{} cluster", testStorage.getNamespaceName(), testStorage.getClusterName()); - resourceManager.deleteResource(); - cmdKubeClient(testStorage.getNamespaceName()).deleteByName("kafka", testStorage.getClusterName()); + resourceManager.deleteResource(kafka); if (Environment.isKafkaNodePoolsEnabled()) { cmdKubeClient(testStorage.getNamespaceName()).deleteByName("kafkanodepool", testStorage.getKafkaNodePoolName()); } @@ -1000,8 +1000,6 @@ void testDeployUnsupportedKafka(ExtensionContext extensionContext) { KafkaUtils.waitForKafkaNotReady(testStorage.getNamespaceName(), testStorage.getClusterName()); KafkaUtils.waitUntilKafkaStatusConditionContainsMessage(testStorage.getClusterName(), testStorage.getNamespaceName(), nonExistingVersionMessage); - - KafkaResource.kafkaClient().inNamespace(testStorage.getNamespaceName()).withName(testStorage.getClusterName()).delete(); } void verifyVolumeNamesAndLabels(String namespaceName, String clusterName, String podSetName, int kafkaReplicas, int diskCountPerReplica, String diskSizeGi) { diff --git a/systemtest/src/test/java/io/strimzi/systemtest/kafka/listeners/ListenersST.java b/systemtest/src/test/java/io/strimzi/systemtest/kafka/listeners/ListenersST.java index e794fa96d83..d04e473e82a 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/kafka/listeners/ListenersST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/kafka/listeners/ListenersST.java @@ -2085,8 +2085,6 @@ void testNonExistingCustomCertificate(ExtensionContext extensionContext) { } KafkaUtils.waitUntilKafkaStatusConditionContainsMessage(testStorage.getClusterName(), testStorage.getNamespaceName(), ".*Secret " + nonExistingCertName + " with custom TLS certificate does not exist.*"); - - KafkaResource.kafkaClient().inNamespace(testStorage.getNamespaceName()).withName(testStorage.getClusterName()).delete(); } @ParallelNamespaceTest @@ -2123,8 +2121,6 @@ void testCertificateWithNonExistingDataCrt(ExtensionContext extensionContext) { KafkaUtils.waitUntilKafkaStatusConditionContainsMessage(testStorage.getClusterName(), testStorage.getNamespaceName(), ".*Secret " + clusterCustomCertServer1 + " does not contain certificate under the key " + nonExistingCertName + ".*"); - - KafkaResource.kafkaClient().inNamespace(testStorage.getNamespaceName()).withName(testStorage.getClusterName()).delete(); } @ParallelNamespaceTest @@ -2161,8 +2157,6 @@ void testCertificateWithNonExistingDataKey(ExtensionContext extensionContext) { KafkaUtils.waitUntilKafkaStatusConditionContainsMessage(testStorage.getClusterName(), testStorage.getNamespaceName(), ".*Secret " + clusterCustomCertServer1 + " does not contain custom certificate private key under the key " + nonExistingCertKey + ".*"); - - KafkaResource.kafkaClient().inNamespace(testStorage.getNamespaceName()).withName(testStorage.getClusterName()).delete(); } @ParallelNamespaceTest diff --git a/systemtest/src/test/java/io/strimzi/systemtest/rollingupdate/KafkaRollerST.java b/systemtest/src/test/java/io/strimzi/systemtest/rollingupdate/KafkaRollerST.java index 5a65add7192..bb47d76c395 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/rollingupdate/KafkaRollerST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/rollingupdate/KafkaRollerST.java @@ -6,7 +6,6 @@ import io.fabric8.kubernetes.api.model.Affinity; import io.fabric8.kubernetes.api.model.AffinityBuilder; -import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.api.model.Event; import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.LabelSelectorBuilder; @@ -323,8 +322,6 @@ void testKafkaPodPendingDueToRack(ExtensionContext extensionContext) { // kafka should get back ready in some reasonable time frame KafkaUtils.waitForKafkaReady(testStorage.getNamespaceName(), testStorage.getClusterName()); - KafkaResource.kafkaClient().inNamespace(testStorage.getNamespaceName()).withName(testStorage.getClusterName()).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete(); - KafkaUtils.waitForKafkaDeletion(testStorage.getNamespaceName(), testStorage.getClusterName()); } /**