Search in sources :

Example 21 with Condition

use of io.fabric8.kubernetes.api.model.Condition in project strimzi-kafka-operator by strimzi.

the class OperatorMetricsTest method successfulReconcile.

public void successfulReconcile(VertxTestContext context, Labels selectorLabels) {
    MetricsProvider metrics = createCleanMetricsProvider();
    AbstractWatchableStatusedResourceOperator resourceOperator = resourceOperatorWithExistingResourceWithSelectorLabel(selectorLabels);
    AbstractOperator operator = new AbstractOperator(vertx, "TestResource", resourceOperator, metrics, selectorLabels) {

        @Override
        protected Future createOrUpdate(Reconciliation reconciliation, CustomResource resource) {
            return Future.succeededFuture();
        }

        @Override
        public Set<Condition> validate(Reconciliation reconciliation, CustomResource resource) {
            return emptySet();
        }

        @Override
        protected Future<Boolean> delete(Reconciliation reconciliation) {
            return null;
        }

        @Override
        protected Status createStatus() {
            return new Status() {
            };
        }
    };
    Checkpoint async = context.checkpoint();
    operator.reconcile(new Reconciliation("test", "TestResource", "my-namespace", "my-resource")).onComplete(context.succeeding(v -> context.verify(() -> {
        MeterRegistry registry = metrics.meterRegistry();
        Tag selectorTag = Tag.of("selector", selectorLabels != null ? selectorLabels.toSelectorString() : "");
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().count(), is(1L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resource.state").tag("kind", "TestResource").tag("name", "my-resource").tag("resource-namespace", "my-namespace").gauge().value(), is(1.0));
        async.flag();
    })));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) Status(io.strimzi.api.kafka.model.status.Status) VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Status(io.strimzi.api.kafka.model.status.Status) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Version(io.fabric8.kubernetes.model.annotation.Version) Tag(io.micrometer.core.instrument.Tag) Collections.emptyMap(java.util.Collections.emptyMap) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) VertxExtension(io.vertx.junit5.VertxExtension) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Spec(io.strimzi.api.kafka.model.Spec) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) Labels(io.strimzi.operator.common.model.Labels) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Group(io.fabric8.kubernetes.model.annotation.Group) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Condition(io.strimzi.api.kafka.model.status.Condition) Collections(java.util.Collections) CustomResource(io.fabric8.kubernetes.client.CustomResource) CustomResource(io.fabric8.kubernetes.client.CustomResource) Checkpoint(io.vertx.junit5.Checkpoint) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Tag(io.micrometer.core.instrument.Tag) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 22 with Condition

use of io.fabric8.kubernetes.api.model.Condition in project strimzi-kafka-operator by strimzi.

the class ResourceSupport method selfClosingWatch.

/**
 * Watches the given {@code watchable} using the given
 * {@code watchFn},
 * returning a Future which completes when {@code watchFn} returns non-null
 * to some event on the watchable, or after a timeout.
 *
 * The given {@code watchFn} will be invoked on a worker thread when the
 * Kubernetes resources changes, so may block.
 * When the {@code watchFn} returns non-null the watch will be closed and then
 * the future returned from this method will be completed on the context thread.
 *
 * In some cases such as resource deletion, it might happen that the resource is deleted already before the watch is
 * started and as a result the watch never completes. The {@code preCheckFn} will be invoked on a worker thread
 * after the watch has been created. It is expected to double check if we still need to wait for the watch to fire.
 * When the {@code preCheckFn} returns non-null the watch will be closed and the future returned from this method
 * will be completed with the result of the {@code preCheckFn} on the context thread. In the deletion example
 * described above, the {@code preCheckFn} can check if the resource still exists and close the watch in case it was
 * already deleted.
 *
 * @param reconciliation Reconciliation marker used for logging
 * @param watchable The watchable - used to watch the resource.
 * @param gettable The Gettable - used to get the resource in the pre-check.
 * @param operationTimeoutMs The timeout in ms.
 * @param watchFnDescription A description of what {@code watchFn} is watching for.
 *                           E.g. "observe ${condition} of ${kind} ${namespace}/${name}".
 * @param watchFn The function to determine if the event occured
 * @param preCheckFn Pre-check function to avoid situation when the watch is never fired because ot was started too late.
 * @param <T> The type of watched resource.
 * @param <U> The result type of the {@code watchFn}.
 *
 * @return A Futures which completes when the {@code watchFn} returns non-null
 * in response to some Kubenetes even on the watched resource(s).
 */
<T, U> Future<U> selfClosingWatch(Reconciliation reconciliation, Watchable<Watcher<T>> watchable, Gettable<T> gettable, long operationTimeoutMs, String watchFnDescription, BiFunction<Watcher.Action, T, U> watchFn, Function<T, U> preCheckFn) {
    return new Watcher<T>() {

        private final Promise<Watch> watchPromise;

        private final Promise<U> donePromise;

        private final Promise<U> resultPromise;

        private final long timerId;

        /* init */
        {
            this.watchPromise = Promise.promise();
            this.donePromise = Promise.promise();
            this.resultPromise = Promise.promise();
            this.timerId = vertx.setTimer(operationTimeoutMs, ignored -> donePromise.tryFail(new TimeoutException("\"" + watchFnDescription + "\" timed out after " + operationTimeoutMs + "ms")));
            CompositeFuture.join(watchPromise.future(), donePromise.future()).onComplete(joinResult -> {
                Future<Void> closeFuture;
                if (watchPromise.future().succeeded()) {
                    closeFuture = closeOnWorkerThread(watchPromise.future().result());
                } else {
                    closeFuture = Future.succeededFuture();
                }
                closeFuture.onComplete(closeResult -> vertx.runOnContext(ignored2 -> {
                    LOGGER.debugCr(reconciliation, "Completing watch future");
                    if (joinResult.succeeded() && closeResult.succeeded()) {
                        resultPromise.complete(joinResult.result().resultAt(1));
                    } else {
                        resultPromise.fail(collectCauses(joinResult, closeResult));
                    }
                }));
            });
            try {
                Watch watch = watchable.watch(this);
                LOGGER.debugCr(reconciliation, "Opened watch {} for evaluation of {}", watch, watchFnDescription);
                // Pre-check is done after the watch is open to make sure we did not missed the event. In the worst
                // case, both pre-check and watch complete the future. But at least one should always complete it.
                U apply = preCheckFn.apply(gettable.get());
                if (apply != null) {
                    LOGGER.debugCr(reconciliation, "Pre-check is already complete, no need to wait for the watch: {}", watchFnDescription);
                    donePromise.tryComplete(apply);
                    vertx.cancelTimer(timerId);
                } else {
                    LOGGER.debugCr(reconciliation, "Pre-check is not complete yet, let's wait for the watch: {}", watchFnDescription);
                }
                watchPromise.complete(watch);
            } catch (Throwable t) {
                watchPromise.fail(t);
            }
        }

        @Override
        public void eventReceived(Action action, T resource) {
            vertx.executeBlocking(f -> {
                try {
                    U apply = watchFn.apply(action, resource);
                    if (apply != null) {
                        LOGGER.debugCr(reconciliation, "Satisfied: {}", watchFnDescription);
                        f.tryComplete(apply);
                        vertx.cancelTimer(timerId);
                    } else {
                        LOGGER.debugCr(reconciliation, "Not yet satisfied: {}", watchFnDescription);
                    }
                } catch (Throwable t) {
                    if (!f.tryFail(t)) {
                        LOGGER.debugCr(reconciliation, "Ignoring exception thrown while " + "evaluating watch {} because the future was already completed", watchFnDescription, t);
                    }
                }
            }, true, donePromise);
        }

        @Override
        public void onClose(WatcherException cause) {
        }
    }.resultPromise.future();
}
Also used : ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) Promise(io.vertx.core.Promise) BiFunction(java.util.function.BiFunction) Vertx(io.vertx.core.Vertx) Watcher(io.fabric8.kubernetes.client.Watcher) Watch(io.fabric8.kubernetes.client.Watch) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Future(io.vertx.core.Future) Function(java.util.function.Function) WatcherException(io.fabric8.kubernetes.client.WatcherException) Reconciliation(io.strimzi.operator.common.Reconciliation) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) Gettable(io.fabric8.kubernetes.client.dsl.Gettable) Closeable(java.io.Closeable) Listable(io.fabric8.kubernetes.client.dsl.Listable) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Deletable(io.fabric8.kubernetes.client.dsl.Deletable) Watchable(io.fabric8.kubernetes.client.dsl.Watchable) Promise(io.vertx.core.Promise) Watch(io.fabric8.kubernetes.client.Watch) Watcher(io.fabric8.kubernetes.client.Watcher) WatcherException(io.fabric8.kubernetes.client.WatcherException)

Example 23 with Condition

use of io.fabric8.kubernetes.api.model.Condition in project strimzi-kafka-operator by strimzi.

the class AllNamespaceIsolatedST method testUserInDifferentNamespace.

@IsolatedTest
void testUserInDifferentNamespace(ExtensionContext extensionContext) {
    String startingNamespace = cluster.setNamespace(SECOND_NAMESPACE);
    KafkaUser user = KafkaUserTemplates.tlsUser(MAIN_NAMESPACE_CLUSTER_NAME, USER_NAME).build();
    resourceManager.createResource(extensionContext, user);
    Condition kafkaCondition = KafkaUserResource.kafkaUserClient().inNamespace(SECOND_NAMESPACE).withName(USER_NAME).get().getStatus().getConditions().get(0);
    LOGGER.info("KafkaUser condition status: {}", kafkaCondition.getStatus());
    LOGGER.info("KafkaUser condition type: {}", kafkaCondition.getType());
    assertThat(kafkaCondition.getType(), is(Ready.toString()));
    List<Secret> secretsOfSecondNamespace = kubeClient(SECOND_NAMESPACE).listSecrets();
    cluster.setNamespace(THIRD_NAMESPACE);
    for (Secret s : secretsOfSecondNamespace) {
        if (s.getMetadata().getName().equals(USER_NAME)) {
            LOGGER.info("Copying secret {} from namespace {} to namespace {}", s, SECOND_NAMESPACE, THIRD_NAMESPACE);
            copySecret(s, THIRD_NAMESPACE, USER_NAME);
        }
    }
    resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(true, MAIN_NAMESPACE_CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS, user).build());
    final String defaultKafkaClientsPodName = ResourceManager.kubeClient().listPodsByPrefixInName(MAIN_NAMESPACE_CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS).get(0).getMetadata().getName();
    InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder().withUsingPodName(defaultKafkaClientsPodName).withTopicName(TOPIC_NAME).withNamespaceName(THIRD_NAMESPACE).withClusterName(MAIN_NAMESPACE_CLUSTER_NAME).withMessageCount(MESSAGE_COUNT).withKafkaUsername(USER_NAME).withListenerName(Constants.TLS_LISTENER_DEFAULT_NAME).build();
    LOGGER.info("Checking produced and consumed messages to pod:{}", defaultKafkaClientsPodName);
    int sent = internalKafkaClient.sendMessagesTls();
    assertThat(sent, is(MESSAGE_COUNT));
    int received = internalKafkaClient.receiveMessagesTls();
    assertThat(received, is(MESSAGE_COUNT));
    cluster.setNamespace(startingNamespace);
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) KafkaUser(io.strimzi.api.kafka.model.KafkaUser) IsolatedTest(io.strimzi.systemtest.annotations.IsolatedTest)

Example 24 with Condition

use of io.fabric8.kubernetes.api.model.Condition in project strimzi-kafka-operator by strimzi.

the class ConnectIsolatedST method testScaleConnectWithConnectorToZero.

@ParallelNamespaceTest
@Tag(SCALABILITY)
@Tag(CONNECTOR_OPERATOR)
void testScaleConnectWithConnectorToZero(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
    final String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).build());
    resourceManager.createResource(extensionContext, KafkaConnectTemplates.kafkaConnect(extensionContext, clusterName, 2).editMetadata().addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().build());
    resourceManager.createResource(extensionContext, KafkaConnectorTemplates.kafkaConnector(clusterName).editSpec().withClassName("org.apache.kafka.connect.file.FileStreamSinkConnector").addToConfig("file", Constants.DEFAULT_SINK_FILE_PATH).addToConfig("key.converter", "org.apache.kafka.connect.storage.StringConverter").addToConfig("value.converter", "org.apache.kafka.connect.storage.StringConverter").addToConfig("topics", topicName).endSpec().build());
    String connectDeploymentName = KafkaConnectResources.deploymentName(clusterName);
    List<Pod> connectPods = kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, KafkaConnectResources.deploymentName(clusterName));
    assertThat(connectPods.size(), is(2));
    // scale down
    LOGGER.info("Scaling KafkaConnect down to zero");
    KafkaConnectResource.replaceKafkaConnectResourceInSpecificNamespace(clusterName, kafkaConnect -> kafkaConnect.getSpec().setReplicas(0), namespaceName);
    KafkaConnectUtils.waitForConnectReady(namespaceName, clusterName);
    PodUtils.waitForPodsReady(namespaceName, kubeClient(namespaceName).getDeploymentSelectors(namespaceName, connectDeploymentName), 0, true);
    connectPods = kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, connectDeploymentName);
    KafkaConnectStatus connectStatus = KafkaConnectResource.kafkaConnectClient().inNamespace(namespaceName).withName(clusterName).get().getStatus();
    KafkaConnectorStatus connectorStatus = KafkaConnectorResource.kafkaConnectorClient().inNamespace(namespaceName).withName(clusterName).get().getStatus();
    assertThat(connectPods.size(), is(0));
    assertThat(connectStatus.getConditions().get(0).getType(), is(Ready.toString()));
    assertThat(connectorStatus.getConditions().stream().anyMatch(condition -> condition.getType().equals(NotReady.toString())), is(true));
    assertThat(connectorStatus.getConditions().stream().anyMatch(condition -> condition.getMessage().contains("has 0 replicas")), is(true));
}
Also used : KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) Quantity(io.fabric8.kubernetes.api.model.Quantity) SMOKE(io.strimzi.systemtest.Constants.SMOKE) ConfigMapVolumeSourceBuilder(io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder) KubeClusterResource.cmdKubeClient(io.strimzi.test.k8s.KubeClusterResource.cmdKubeClient) Matchers.not(org.hamcrest.Matchers.not) Annotations(io.strimzi.operator.common.Annotations) INFRA_NAMESPACE(io.strimzi.systemtest.Constants.INFRA_NAMESPACE) KafkaUser(io.strimzi.api.kafka.model.KafkaUser) KafkaConnectResource(io.strimzi.systemtest.resources.crd.KafkaConnectResource) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) KafkaListenerAuthenticationTls(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationTls) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) KafkaConnectUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaConnectUtils) KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) Tag(org.junit.jupiter.api.Tag) StUtils(io.strimzi.systemtest.utils.StUtils) SecretVolumeSourceBuilder(io.fabric8.kubernetes.api.model.SecretVolumeSourceBuilder) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ACCEPTANCE(io.strimzi.systemtest.Constants.ACCEPTANCE) IsolatedSuite(io.strimzi.systemtest.annotations.IsolatedSuite) INTERNAL_CLIENTS_USED(io.strimzi.systemtest.Constants.INTERNAL_CLIENTS_USED) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Base64(java.util.Base64) List(java.util.List) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) Logger(org.apache.logging.log4j.Logger) KafkaTopicTemplates(io.strimzi.systemtest.templates.crd.KafkaTopicTemplates) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus) KafkaConnectorTemplates(io.strimzi.systemtest.templates.crd.KafkaConnectorTemplates) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PasswordSecretSourceBuilder(io.strimzi.api.kafka.model.PasswordSecretSourceBuilder) Secret(io.fabric8.kubernetes.api.model.Secret) Matchers.is(org.hamcrest.Matchers.is) SCALABILITY(io.strimzi.systemtest.Constants.SCALABILITY) Matchers.containsString(org.hamcrest.Matchers.containsString) AbstractST(io.strimzi.systemtest.AbstractST) Environment(io.strimzi.systemtest.Environment) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) KafkaClientsTemplates(io.strimzi.systemtest.templates.crd.KafkaClientsTemplates) KafkaConnectTemplates(io.strimzi.systemtest.templates.crd.KafkaConnectTemplates) CONNECT(io.strimzi.systemtest.Constants.CONNECT) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) HashMap(java.util.HashMap) Crds(io.strimzi.api.kafka.Crds) ExternalKafkaClient(io.strimzi.systemtest.kafkaclients.externalClients.ExternalKafkaClient) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) LinkedHashMap(java.util.LinkedHashMap) KafkaConnectorResource(io.strimzi.systemtest.resources.crd.KafkaConnectorResource) PodUtils(io.strimzi.systemtest.utils.kubeUtils.objects.PodUtils) JsonPathMatchers.hasJsonPath(org.valid4j.matchers.jsonpath.JsonPathMatchers.hasJsonPath) DeploymentStrategy(io.strimzi.api.kafka.model.template.DeploymentStrategy) NotReady(io.strimzi.systemtest.enums.CustomResourceStatus.NotReady) TestUtils(io.strimzi.test.TestUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KafkaListenerAuthenticationScramSha512(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationScramSha512) NODEPORT_SUPPORTED(io.strimzi.systemtest.Constants.NODEPORT_SUPPORTED) KafkaTemplates(io.strimzi.systemtest.templates.crd.KafkaTemplates) Ready(io.strimzi.systemtest.enums.CustomResourceStatus.Ready) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) Constants(io.strimzi.systemtest.Constants) Pod(io.fabric8.kubernetes.api.model.Pod) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) EXTERNAL_CLIENTS_USED(io.strimzi.systemtest.Constants.EXTERNAL_CLIENTS_USED) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KubeClusterResource.kubeClient(io.strimzi.test.k8s.KubeClusterResource.kubeClient) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) SecretKeySelectorBuilder(io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder) KafkaConnectorUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaConnectorUtils) DeploymentUtils(io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils) Matchers.hasItem(org.hamcrest.Matchers.hasItem) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) KafkaUserTemplates(io.strimzi.systemtest.templates.crd.KafkaUserTemplates) CONNECTOR_OPERATOR(io.strimzi.systemtest.Constants.CONNECTOR_OPERATOR) CONNECT_COMPONENTS(io.strimzi.systemtest.Constants.CONNECT_COMPONENTS) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) REGRESSION(io.strimzi.systemtest.Constants.REGRESSION) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) Pod(io.fabric8.kubernetes.api.model.Pod) Matchers.containsString(org.hamcrest.Matchers.containsString) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 25 with Condition

use of io.fabric8.kubernetes.api.model.Condition in project strimzi-kafka-operator by strimzi.

the class ConnectBuilderIsolatedST method testBuildFailsWithWrongChecksumOfArtifact.

@ParallelTest
void testBuildFailsWithWrongChecksumOfArtifact(ExtensionContext extensionContext) {
    String connectClusterName = mapWithClusterNames.get(extensionContext.getDisplayName()) + "-connect";
    String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    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, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
    String kafkaClientsPodName = kubeClient(INFRA_NAMESPACE).listPodsByPrefixInName(kafkaClientsName).get(0).getMetadata().getName();
    resourceManager.createResource(extensionContext, false, KafkaConnectTemplates.kafkaConnect(extensionContext, connectClusterName, INFRA_NAMESPACE, INFRA_NAMESPACE, 1).editMetadata().addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().editOrNewSpec().withNewBuild().withPlugins(pluginWithWrongChecksum).withNewDockerOutput().withImage(imageName).endDockerOutput().endBuild().endSpec().build());
    KafkaConnectUtils.waitForConnectNotReady(connectClusterName);
    KafkaConnectUtils.waitUntilKafkaConnectStatusConditionContainsMessage(connectClusterName, INFRA_NAMESPACE, "The Kafka Connect build failed(.*)?");
    LOGGER.info("Checking if KafkaConnect status condition contains message about build failure");
    KafkaConnect kafkaConnect = KafkaConnectResource.kafkaConnectClient().inNamespace(INFRA_NAMESPACE).withName(connectClusterName).get();
    LOGGER.info("Deploying network policies for KafkaConnect");
    NetworkPolicyResource.deployNetworkPolicyForResource(extensionContext, kafkaConnect, KafkaConnectResources.deploymentName(connectClusterName));
    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(connectClusterName, 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(connectClusterName);
    LOGGER.info("Checking if KafkaConnect API contains EchoSink connector");
    String plugins = cmdKubeClient().execInPod(kafkaClientsPodName, "curl", "-X", "GET", "http://" + KafkaConnectResources.serviceName(connectClusterName) + ":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(INFRA_NAMESPACE).withName(connectClusterName).get();
    assertTrue(kafkaConnect.getStatus().getConnectorPlugins().stream().anyMatch(connectorPlugin -> connectorPlugin.getConnectorClass().contains(ECHO_SINK_CLASS_NAME)));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest) KubeClusterResource.cmdKubeClient(io.strimzi.test.k8s.KubeClusterResource.cmdKubeClient) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Annotations(io.strimzi.operator.common.Annotations) Random(java.util.Random) KafkaTopicUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaTopicUtils) INFRA_NAMESPACE(io.strimzi.systemtest.Constants.INFRA_NAMESPACE) KafkaConnectResource(io.strimzi.systemtest.resources.crd.KafkaConnectResource) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) OtherArtifactBuilder(io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder) KafkaConnectUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaConnectUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) IsolatedSuite(io.strimzi.systemtest.annotations.IsolatedSuite) KafkaClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients) Collectors(java.util.stream.Collectors) ClientUtils(io.strimzi.systemtest.utils.ClientUtils) Labels(io.strimzi.operator.common.model.Labels) Logger(org.apache.logging.log4j.Logger) Plugin(io.strimzi.api.kafka.model.connect.build.Plugin) KafkaTopicTemplates(io.strimzi.systemtest.templates.crd.KafkaTopicTemplates) KafkaConnectorTemplates(io.strimzi.systemtest.templates.crd.KafkaConnectorTemplates) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Matchers.is(org.hamcrest.Matchers.is) Condition(io.strimzi.api.kafka.model.status.Condition) AbstractST(io.strimzi.systemtest.AbstractST) KafkaClientsTemplates(io.strimzi.systemtest.templates.crd.KafkaClientsTemplates) KafkaConnectTemplates(io.strimzi.systemtest.templates.crd.KafkaConnectTemplates) NetworkPolicyResource(io.strimzi.systemtest.resources.kubernetes.NetworkPolicyResource) CONNECT(io.strimzi.systemtest.Constants.CONNECT) OpenShiftOnly(io.strimzi.systemtest.annotations.OpenShiftOnly) HashMap(java.util.HashMap) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ZipArtifactBuilder(io.strimzi.api.kafka.model.connect.build.ZipArtifactBuilder) KafkaConnectorResource(io.strimzi.systemtest.resources.crd.KafkaConnectorResource) PodUtils(io.strimzi.systemtest.utils.kubeUtils.objects.PodUtils) NotReady(io.strimzi.systemtest.enums.CustomResourceStatus.NotReady) Service(io.fabric8.kubernetes.api.model.Service) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TgzArtifactBuilder(io.strimzi.api.kafka.model.connect.build.TgzArtifactBuilder) ImageStream(io.fabric8.openshift.api.model.ImageStream) KafkaTemplates(io.strimzi.systemtest.templates.crd.KafkaTemplates) Ready(io.strimzi.systemtest.enums.CustomResourceStatus.Ready) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) Constants(io.strimzi.systemtest.Constants) KafkaClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) JarArtifactBuilder(io.strimzi.api.kafka.model.connect.build.JarArtifactBuilder) KubeClusterResource.kubeClient(io.strimzi.test.k8s.KubeClusterResource.kubeClient) Util(io.strimzi.operator.common.Util) DeploymentUtils(io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils) CONNECT_COMPONENTS(io.strimzi.systemtest.Constants.CONNECT_COMPONENTS) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) MavenArtifactBuilder(io.strimzi.api.kafka.model.connect.build.MavenArtifactBuilder) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) REGRESSION(io.strimzi.systemtest.Constants.REGRESSION) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) Plugin(io.strimzi.api.kafka.model.connect.build.Plugin) JarArtifactBuilder(io.strimzi.api.kafka.model.connect.build.JarArtifactBuilder) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Aggregations

Condition (io.strimzi.api.kafka.model.status.Condition)46 Collections (java.util.Collections)36 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)32 Vertx (io.vertx.core.Vertx)30 Labels (io.strimzi.operator.common.model.Labels)28 Future (io.vertx.core.Future)28 BeforeAll (org.junit.jupiter.api.BeforeAll)28 Map (java.util.Map)27 Test (org.junit.jupiter.api.Test)25 Promise (io.vertx.core.Promise)22 List (java.util.List)21 Checkpoint (io.vertx.junit5.Checkpoint)20 VertxExtension (io.vertx.junit5.VertxExtension)20 VertxTestContext (io.vertx.junit5.VertxTestContext)20 CoreMatchers.is (org.hamcrest.CoreMatchers.is)20 AfterAll (org.junit.jupiter.api.AfterAll)20 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)20 Annotations (io.strimzi.operator.common.Annotations)18 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)16 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)16