Skip to content

Commit

Permalink
[ST] fixing unnecessary error logs when cleaning resources (#9667)
Browse files Browse the repository at this point in the history
Signed-off-by: hzrncik <hzrncik@redhat.com>
  • Loading branch information
henryZrncik committed Feb 13, 2024
1 parent 80117b4 commit 3e7e30d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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<String, String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoleBinding> roleBindings;
private List<Role> roles;
private List<ClusterRole> clusterRoles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 3e7e30d

Please sign in to comment.