Search in sources :

Example 6 with StatusDiff

use of io.strimzi.operator.cluster.model.StatusDiff in project strimzi-kafka-operator by strimzi.

the class AbstractOperator method updateStatus.

/**
 * Updates the Status field of the Kafka CR. It diffs the desired status against the current status and calls
 * the update only when there is any difference in non-timestamp fields.
 *
 * @param reconciliation the reconciliation identified
 * @param desiredStatus The KafkaStatus which should be set
 *
 * @return
 */
Future<Void> updateStatus(Reconciliation reconciliation, S desiredStatus) {
    if (desiredStatus == null) {
        LOGGER.debugCr(reconciliation, "Desired status is null - status will not be updated");
        return Future.succeededFuture();
    }
    String namespace = reconciliation.namespace();
    String name = reconciliation.name();
    return resourceOperator.getAsync(namespace, name).compose(res -> {
        if (res != null) {
            S currentStatus = res.getStatus();
            StatusDiff sDiff = new StatusDiff(currentStatus, desiredStatus);
            if (!sDiff.isEmpty()) {
                res.setStatus(desiredStatus);
                return resourceOperator.updateStatusAsync(reconciliation, res).compose(notUsed -> {
                    LOGGER.debugCr(reconciliation, "Completed status update");
                    return Future.succeededFuture();
                }, error -> {
                    LOGGER.errorCr(reconciliation, "Failed to update status", error);
                    return Future.failedFuture(error);
                });
            } else {
                LOGGER.debugCr(reconciliation, "Status did not change");
                return Future.succeededFuture();
            }
        } else {
            LOGGER.errorCr(reconciliation, "Current {} resource not found", reconciliation.kind());
            return Future.failedFuture("Current " + reconciliation.kind() + " resource with name " + name + " not found");
        }
    }, error -> {
        LOGGER.errorCr(reconciliation, "Failed to get the current {} resource and its status", reconciliation.kind(), error);
        return Future.failedFuture(error);
    });
}
Also used : StatusDiff(io.strimzi.operator.cluster.model.StatusDiff)

Example 7 with StatusDiff

use of io.strimzi.operator.cluster.model.StatusDiff in project strimzi by strimzi.

the class AbstractConnectOperator method updateStatus.

public static void updateStatus(Reconciliation reconciliation, Throwable error, KafkaConnector kafkaConnector2, CrdOperator<?, KafkaConnector, ?> connectorOperations) {
    KafkaConnectorStatus status = new KafkaConnectorStatus();
    StatusUtils.setStatusConditionAndObservedGeneration(kafkaConnector2, status, error);
    StatusDiff diff = new StatusDiff(kafkaConnector2.getStatus(), status);
    if (!diff.isEmpty()) {
        KafkaConnector copy = new KafkaConnectorBuilder(kafkaConnector2).build();
        copy.setStatus(status);
        connectorOperations.updateStatusAsync(reconciliation, copy);
    }
}
Also used : StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus)

Example 8 with StatusDiff

use of io.strimzi.operator.cluster.model.StatusDiff in project strimzi by strimzi.

the class AbstractConnectOperator method maybeUpdateStatusCommon.

/**
 * Updates the Status field of the KafkaConnect or KafkaConnector CR. It diffs the desired status against the current status and calls
 * the update only when there is any difference in non-timestamp fields.
 *
 * @param resource The CR of KafkaConnect or KafkaConnector
 * @param reconciliation Reconciliation information
 * @param desiredStatus The KafkaConnectStatus or KafkaConnectorStatus which should be set
 *
 * @return
 */
protected <T extends CustomResource<?, S>, S extends Status, L extends CustomResourceList<T>> Future<Void> maybeUpdateStatusCommon(CrdOperator<KubernetesClient, T, L> resourceOperator, T resource, Reconciliation reconciliation, S desiredStatus, BiFunction<T, S, T> copyWithStatus) {
    Promise<Void> updateStatusPromise = Promise.promise();
    resourceOperator.getAsync(resource.getMetadata().getNamespace(), resource.getMetadata().getName()).onComplete(getRes -> {
        if (getRes.succeeded()) {
            T fetchedResource = getRes.result();
            if (fetchedResource != null) {
                if ((!(fetchedResource instanceof KafkaConnector)) && (!(fetchedResource instanceof KafkaMirrorMaker2))) {
                    LOGGER.warnCr(reconciliation, "{} {} needs to be upgraded from version {} to 'v1beta1' to use the status field", fetchedResource.getKind(), fetchedResource.getMetadata().getName(), fetchedResource.getApiVersion());
                    updateStatusPromise.complete();
                } else {
                    S currentStatus = fetchedResource.getStatus();
                    StatusDiff ksDiff = new StatusDiff(currentStatus, desiredStatus);
                    if (!ksDiff.isEmpty()) {
                        T resourceWithNewStatus = copyWithStatus.apply(fetchedResource, desiredStatus);
                        resourceOperator.updateStatusAsync(reconciliation, resourceWithNewStatus).onComplete(updateRes -> {
                            if (updateRes.succeeded()) {
                                LOGGER.debugCr(reconciliation, "Completed status update");
                                updateStatusPromise.complete();
                            } else {
                                LOGGER.errorCr(reconciliation, "Failed to update status", updateRes.cause());
                                updateStatusPromise.fail(updateRes.cause());
                            }
                        });
                    } else {
                        LOGGER.debugCr(reconciliation, "Status did not change");
                        updateStatusPromise.complete();
                    }
                }
            } else {
                LOGGER.errorCr(reconciliation, "Current {} resource not found", resource.getKind());
                updateStatusPromise.fail("Current " + resource.getKind() + " resource not found");
            }
        } else {
            LOGGER.errorCr(reconciliation, "Failed to get the current {} resource and its status", resource.getKind(), getRes.cause());
            updateStatusPromise.fail(getRes.cause());
        }
    });
    return updateStatusPromise.future();
}
Also used : ANNO_STRIMZI_IO_RESTART(io.strimzi.operator.common.Annotations.ANNO_STRIMZI_IO_RESTART) StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2)

Example 9 with StatusDiff

use of io.strimzi.operator.cluster.model.StatusDiff in project strimzi by strimzi.

the class AbstractOperator method updateStatus.

/**
 * Updates the Status field of the Kafka CR. It diffs the desired status against the current status and calls
 * the update only when there is any difference in non-timestamp fields.
 *
 * @param reconciliation the reconciliation identified
 * @param desiredStatus The KafkaStatus which should be set
 *
 * @return
 */
Future<Void> updateStatus(Reconciliation reconciliation, S desiredStatus) {
    if (desiredStatus == null) {
        LOGGER.debugCr(reconciliation, "Desired status is null - status will not be updated");
        return Future.succeededFuture();
    }
    String namespace = reconciliation.namespace();
    String name = reconciliation.name();
    return resourceOperator.getAsync(namespace, name).compose(res -> {
        if (res != null) {
            S currentStatus = res.getStatus();
            StatusDiff sDiff = new StatusDiff(currentStatus, desiredStatus);
            if (!sDiff.isEmpty()) {
                res.setStatus(desiredStatus);
                return resourceOperator.updateStatusAsync(reconciliation, res).compose(notUsed -> {
                    LOGGER.debugCr(reconciliation, "Completed status update");
                    return Future.succeededFuture();
                }, error -> {
                    LOGGER.errorCr(reconciliation, "Failed to update status", error);
                    return Future.failedFuture(error);
                });
            } else {
                LOGGER.debugCr(reconciliation, "Status did not change");
                return Future.succeededFuture();
            }
        } else {
            LOGGER.errorCr(reconciliation, "Current {} resource not found", reconciliation.kind());
            return Future.failedFuture("Current " + reconciliation.kind() + " resource with name " + name + " not found");
        }
    }, error -> {
        LOGGER.errorCr(reconciliation, "Failed to get the current {} resource and its status", reconciliation.kind(), error);
        return Future.failedFuture(error);
    });
}
Also used : StatusDiff(io.strimzi.operator.cluster.model.StatusDiff)

Example 10 with StatusDiff

use of io.strimzi.operator.cluster.model.StatusDiff in project strimzi-kafka-operator by strimzi.

the class KafkaRebalanceAssemblyOperator method updateStatus.

private Future<KafkaRebalance> updateStatus(Reconciliation reconciliation, KafkaRebalance kafkaRebalance, KafkaRebalanceStatus desiredStatus, Throwable e) {
    // Leave the current status when the desired state is null
    if (desiredStatus != null) {
        Condition cond = rebalanceStateCondition(desiredStatus);
        List<Condition> previous = Collections.emptyList();
        if (desiredStatus.getConditions() != null) {
            previous = desiredStatus.getConditions().stream().filter(condition -> condition != cond).collect(Collectors.toList());
        }
        // If a throwable is supplied, it is set in the status with priority
        if (e != null) {
            StatusUtils.setStatusConditionAndObservedGeneration(kafkaRebalance, desiredStatus, KafkaRebalanceState.NotReady.toString(), e);
            desiredStatus.setConditions(Stream.concat(desiredStatus.getConditions().stream(), previous.stream()).collect(Collectors.toList()));
        } else if (cond != null) {
            StatusUtils.setStatusConditionAndObservedGeneration(kafkaRebalance, desiredStatus, cond);
            desiredStatus.setConditions(Stream.concat(desiredStatus.getConditions().stream(), previous.stream()).collect(Collectors.toList()));
        } else {
            throw new IllegalArgumentException("Status related exception and the Status condition's type cannot both be null");
        }
        StatusDiff diff = new StatusDiff(kafkaRebalance.getStatus(), desiredStatus);
        if (!diff.isEmpty()) {
            return kafkaRebalanceOperator.updateStatusAsync(reconciliation, new KafkaRebalanceBuilder(kafkaRebalance).withStatus(desiredStatus).build());
        }
    }
    return Future.succeededFuture(kafkaRebalance);
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder)

Aggregations

StatusDiff (io.strimzi.operator.cluster.model.StatusDiff)10 KafkaConnector (io.strimzi.api.kafka.model.KafkaConnector)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 KafkaConnectorBuilder (io.strimzi.api.kafka.model.KafkaConnectorBuilder)2 KafkaMirrorMaker2 (io.strimzi.api.kafka.model.KafkaMirrorMaker2)2 KafkaRebalanceBuilder (io.strimzi.api.kafka.model.KafkaRebalanceBuilder)2 StrimziPodSet (io.strimzi.api.kafka.model.StrimziPodSet)2 StrimziPodSetBuilder (io.strimzi.api.kafka.model.StrimziPodSetBuilder)2 Condition (io.strimzi.api.kafka.model.status.Condition)2 KafkaConnectorStatus (io.strimzi.api.kafka.model.status.KafkaConnectorStatus)2 ANNO_STRIMZI_IO_RESTART (io.strimzi.operator.common.Annotations.ANNO_STRIMZI_IO_RESTART)2