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);
});
}
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);
}
}
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();
}
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);
});
}
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);
}
Aggregations