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] fixing unnecessary error logs when cleaning resources #9667

Merged
merged 2 commits into from
Feb 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -101,7 +101,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.NodeSelectorRequirement;
Expand Down Expand Up @@ -321,8 +320,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