use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class ResourceManager method logCurrentResourceStatus.
/**
* Log actual status of custom resource with pods.
* @param customResource - Kafka, KafkaConnect etc. - every resource that HasMetadata and HasStatus (Strimzi status)
*/
public static <T extends CustomResource<? extends Spec, ? extends Status>> void logCurrentResourceStatus(T customResource) {
if (customResource != null) {
List<String> printWholeCR = Arrays.asList(KafkaConnector.RESOURCE_KIND, KafkaTopic.RESOURCE_KIND, KafkaUser.RESOURCE_KIND);
String kind = customResource.getKind();
String name = customResource.getMetadata().getName();
if (printWholeCR.contains(kind)) {
LOGGER.info(customResource);
} else {
List<String> log = new ArrayList<>(asList(kind, " status:\n", "\nConditions:\n"));
if (customResource.getStatus() != null) {
List<Condition> conditions = customResource.getStatus().getConditions();
if (conditions != null) {
for (Condition condition : customResource.getStatus().getConditions()) {
if (condition.getMessage() != null) {
log.add("\tType: " + condition.getType() + "\n");
log.add("\tMessage: " + condition.getMessage() + "\n");
}
}
}
log.add("\nPods with conditions and messages:\n\n");
for (Pod pod : kubeClient().namespace(customResource.getMetadata().getNamespace()).listPodsByPrefixInName(name)) {
log.add(pod.getMetadata().getName() + ":");
for (PodCondition podCondition : pod.getStatus().getConditions()) {
if (podCondition.getMessage() != null) {
log.add("\n\tType: " + podCondition.getType() + "\n");
log.add("\tMessage: " + podCondition.getMessage() + "\n");
} else {
log.add("\n\tType: <EMPTY>\n");
log.add("\tMessage: <EMPTY>\n");
}
}
log.add("\n\n");
}
LOGGER.info("{}", String.join("", log).strip());
}
}
}
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class ConnectBuilderIsolatedST method testBuildFailsWithWrongChecksumOfArtifact.
@ParallelTest
void testBuildFailsWithWrongChecksumOfArtifact(ExtensionContext extensionContext) {
TestStorage storage = new TestStorage(extensionContext, clusterOperator.getDeploymentNamespace());
final String imageName = getImageNameForTestCase();
Plugin pluginWithWrongChecksum = new PluginBuilder().withName("connector-with-wrong-checksum").withArtifacts(new JarArtifactBuilder().withUrl(ECHO_SINK_JAR_URL).withSha512sum(ECHO_SINK_JAR_WRONG_CHECKSUM).build()).build();
resourceManager.createResource(extensionContext, ScraperTemplates.scraperPod(storage.getNamespaceName(), storage.getScraperName()).build());
resourceManager.createResource(extensionContext, false, KafkaConnectTemplates.kafkaConnect(storage.getClusterName(), storage.getNamespaceName(), storage.getNamespaceName(), 1).editMetadata().addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().editOrNewSpec().withNewBuild().withPlugins(pluginWithWrongChecksum).withNewDockerOutput().withImage(imageName).endDockerOutput().endBuild().endSpec().build());
KafkaConnectUtils.waitForConnectNotReady(storage.getClusterName());
KafkaConnectUtils.waitUntilKafkaConnectStatusConditionContainsMessage(storage.getClusterName(), storage.getNamespaceName(), "The Kafka Connect build failed(.*)?");
LOGGER.info("Checking if KafkaConnect status condition contains message about build failure");
KafkaConnect kafkaConnect = KafkaConnectResource.kafkaConnectClient().inNamespace(storage.getNamespaceName()).withName(storage.getClusterName()).get();
LOGGER.info("Deploying network policies for KafkaConnect");
NetworkPolicyResource.deployNetworkPolicyForResource(extensionContext, kafkaConnect, KafkaConnectResources.deploymentName(storage.getClusterName()));
Condition connectCondition = kafkaConnect.getStatus().getConditions().stream().findFirst().orElseThrow();
assertTrue(connectCondition.getMessage().matches("The Kafka Connect build failed(.*)?"));
assertThat(connectCondition.getType(), is(NotReady.toString()));
LOGGER.info("Replacing plugin's checksum with right one");
KafkaConnectResource.replaceKafkaConnectResource(storage.getClusterName(), kC -> {
Plugin pluginWithRightChecksum = new PluginBuilder().withName("connector-with-right-checksum").withArtifacts(new JarArtifactBuilder().withUrl(ECHO_SINK_JAR_URL).withSha512sum(ECHO_SINK_JAR_CHECKSUM).build()).build();
kC.getSpec().getBuild().getPlugins().remove(0);
kC.getSpec().getBuild().getPlugins().add(pluginWithRightChecksum);
});
KafkaConnectUtils.waitForConnectReady(storage.getClusterName());
String scraperPodName = kubeClient(storage.getNamespaceName()).listPodsByPrefixInName(storage.getScraperName()).get(0).getMetadata().getName();
LOGGER.info("Checking if KafkaConnect API contains EchoSink connector");
String plugins = cmdKubeClient().execInPod(scraperPodName, "curl", "-X", "GET", "http://" + KafkaConnectResources.serviceName(storage.getClusterName()) + ":8083/connector-plugins").out();
assertTrue(plugins.contains(ECHO_SINK_CLASS_NAME));
LOGGER.info("Checking if KafkaConnect resource contains EchoSink connector in status");
kafkaConnect = KafkaConnectResource.kafkaConnectClient().inNamespace(storage.getNamespaceName()).withName(storage.getClusterName()).get();
assertTrue(kafkaConnect.getStatus().getConnectorPlugins().stream().anyMatch(connectorPlugin -> connectorPlugin.getConnectorClass().contains(ECHO_SINK_CLASS_NAME)));
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class UserST method alterBigAmountOfUsers.
synchronized void alterBigAmountOfUsers(ExtensionContext extensionContext, String userName, String typeOfUser, int numberOfUsers, int producerRate, int consumerRate, int requestsPercentage, double mutationRate) {
KafkaUserQuotas kuq = new KafkaUserQuotas();
kuq.setConsumerByteRate(consumerRate);
kuq.setProducerByteRate(producerRate);
kuq.setRequestPercentage(requestsPercentage);
kuq.setControllerMutationRate(mutationRate);
LOGGER.info("Updating of existing KafkaUsers");
for (int i = 0; i < numberOfUsers; i++) {
String userNameWithSuffix = userName + "-" + i;
if (typeOfUser.equals("TLS")) {
resourceManager.createResource(extensionContext, KafkaUserTemplates.tlsUser(userClusterName, userNameWithSuffix).editMetadata().withNamespace(namespace).endMetadata().editSpec().withQuotas(kuq).endSpec().build());
} else {
resourceManager.createResource(extensionContext, KafkaUserTemplates.scramShaUser(userClusterName, userNameWithSuffix).editMetadata().withNamespace(namespace).endMetadata().editSpec().withQuotas(kuq).endSpec().build());
}
LOGGER.info("[After update] Checking status of KafkaUser {}", userNameWithSuffix);
Condition kafkaCondition = KafkaUserResource.kafkaUserClient().inNamespace(namespace).withName(userNameWithSuffix).get().getStatus().getConditions().get(0);
LOGGER.debug("KafkaUser condition status: {}", kafkaCondition.getStatus());
LOGGER.debug("KafkaUser condition type: {}", kafkaCondition.getType());
assertThat(kafkaCondition.getType(), is(Ready.toString()));
LOGGER.debug("KafkaUser {} is in desired state: {}", userNameWithSuffix, kafkaCondition.getType());
KafkaUserQuotas kuqAfter = KafkaUserResource.kafkaUserClient().inNamespace(namespace).withName(userNameWithSuffix).get().getSpec().getQuotas();
LOGGER.debug("Check altered KafkaUser {} new quotas.", userNameWithSuffix);
assertThat(kuqAfter.getRequestPercentage(), is(requestsPercentage));
assertThat(kuqAfter.getConsumerByteRate(), is(consumerRate));
assertThat(kuqAfter.getProducerByteRate(), is(producerRate));
assertThat(kuqAfter.getControllerMutationRate(), is(mutationRate));
}
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class UserST method createBigAmountOfUsers.
synchronized void createBigAmountOfUsers(ExtensionContext extensionContext, String userName, String typeOfUser, int numberOfUsers) {
LOGGER.info("Creating {} KafkaUsers", numberOfUsers);
for (int i = 0; i < numberOfUsers; i++) {
String userNameWithSuffix = userName + "-" + i;
if (typeOfUser.equals("TLS")) {
resourceManager.createResource(extensionContext, KafkaUserTemplates.tlsUser(userClusterName, userNameWithSuffix).editMetadata().withNamespace(namespace).endMetadata().build());
} else {
resourceManager.createResource(extensionContext, KafkaUserTemplates.scramShaUser(userClusterName, userNameWithSuffix).editMetadata().withNamespace(namespace).endMetadata().build());
}
LOGGER.debug("Checking status of KafkaUser {}", userNameWithSuffix);
Condition kafkaCondition = KafkaUserResource.kafkaUserClient().inNamespace(namespace).withName(userNameWithSuffix).get().getStatus().getConditions().get(0);
LOGGER.debug("KafkaUser condition status: {}", kafkaCondition.getStatus());
LOGGER.debug("KafkaUser condition type: {}", kafkaCondition.getType());
assertThat(kafkaCondition.getType(), is(Ready.toString()));
LOGGER.debug("KafkaUser {} is in desired state: {}", userNameWithSuffix, kafkaCondition.getType());
}
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class CustomResourceStatusIsolatedST method testKafkaUserStatusNotReady.
@ParallelTest
@KRaftNotSupported("UserOperator is not supported by KRaft mode and is used in this test case")
void testKafkaUserStatusNotReady(ExtensionContext extensionContext) {
// Simulate NotReady state with userName longer than 64 characters
String userName = "sasl-use-rabcdefghijklmnopqrstuvxyzabcdefghijklmnopqrstuvxyzabcdef";
resourceManager.createResource(extensionContext, false, KafkaUserTemplates.defaultUser(CUSTOM_RESOURCE_STATUS_CLUSTER_NAME, userName).build());
KafkaUserUtils.waitForKafkaUserNotReady(clusterOperator.getDeploymentNamespace(), userName);
LOGGER.info("Checking status of deployed KafkaUser {}", userName);
Condition kafkaCondition = KafkaUserResource.kafkaUserClient().inNamespace(clusterOperator.getDeploymentNamespace()).withName(userName).get().getStatus().getConditions().get(0);
LOGGER.info("KafkaUser Status: {}", kafkaCondition.getStatus());
LOGGER.info("KafkaUser Type: {}", kafkaCondition.getType());
LOGGER.info("KafkaUser Message: {}", kafkaCondition.getMessage());
LOGGER.info("KafkaUser Reason: {}", kafkaCondition.getReason());
assertThat("KafkaUser is in wrong state!", kafkaCondition.getType(), is(NotReady.toString()));
LOGGER.info("KafkaUser {} is in desired state: {}", userName, kafkaCondition.getType());
KafkaUserResource.kafkaUserClient().inNamespace(clusterOperator.getDeploymentNamespace()).withName(userName).delete();
KafkaUserUtils.waitForKafkaUserDeletion(clusterOperator.getDeploymentNamespace(), userName);
}
Aggregations