use of io.strimzi.operator.cluster.model.StatusDiff in project strimzi by strimzi.
the class StrimziPodSetController method maybeUpdateStatus.
/**
* Updates the status of the StrimziPodSet. The status will be updated only when it changed since last time.
*
* @param reconciliation Reconciliation in which this is executed
* @param podSet Original pod set with the current status
* @param desiredStatus The desired status which should be set if it differs
*/
private void maybeUpdateStatus(Reconciliation reconciliation, StrimziPodSet podSet, StrimziPodSetStatus desiredStatus) {
if (!new StatusDiff(podSet.getStatus(), desiredStatus).isEmpty()) {
try {
LOGGER.debugCr(reconciliation, "Updating status of StrimziPodSet {} in namespace {}", reconciliation.name(), reconciliation.namespace());
StrimziPodSet updatedPodSet = new StrimziPodSetBuilder(strimziPodSetLister.namespace(reconciliation.namespace()).get(reconciliation.name())).withStatus(desiredStatus).build();
strimziPodSetOperator.client().inNamespace(reconciliation.namespace()).patchStatus(updatedPodSet);
} catch (KubernetesClientException e) {
if (e.getCode() == 409) {
LOGGER.debugCr(reconciliation, "StrimziPodSet {} in namespace {} changed while trying to update status", reconciliation.name(), reconciliation.namespace(), e);
} else {
LOGGER.errorCr(reconciliation, "Failed to update status of StrimziPodSet {} in namespace {}", reconciliation.name(), reconciliation.namespace(), e);
}
}
}
}
use of io.strimzi.operator.cluster.model.StatusDiff in project strimzi 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());
}
String rebalanceType = rebalanceStateConditionType(desiredStatus);
// 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 (rebalanceType != null) {
StatusUtils.setStatusConditionAndObservedGeneration(kafkaRebalance, desiredStatus, rebalanceType);
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);
}
use of io.strimzi.operator.cluster.model.StatusDiff in project strimzi-kafka-operator 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-kafka-operator 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-kafka-operator by strimzi.
the class StrimziPodSetController method maybeUpdateStatus.
/**
* Updates the status of the StrimziPodSet. The status will be updated only when it changed since last time.
*
* @param reconciliation Reconciliation in which this is executed
* @param podSet Original pod set with the current status
* @param desiredStatus The desired status which should be set if it differs
*/
private void maybeUpdateStatus(Reconciliation reconciliation, StrimziPodSet podSet, StrimziPodSetStatus desiredStatus) {
if (!new StatusDiff(podSet.getStatus(), desiredStatus).isEmpty()) {
try {
LOGGER.debugCr(reconciliation, "Updating status of StrimziPodSet {} in namespace {}", reconciliation.name(), reconciliation.namespace());
StrimziPodSet updatedPodSet = new StrimziPodSetBuilder(strimziPodSetLister.namespace(reconciliation.namespace()).get(reconciliation.name())).withStatus(desiredStatus).build();
strimziPodSetOperator.client().inNamespace(reconciliation.namespace()).patchStatus(updatedPodSet);
} catch (KubernetesClientException e) {
if (e.getCode() == 409) {
LOGGER.debugCr(reconciliation, "StrimziPodSet {} in namespace {} changed while trying to update status", reconciliation.name(), reconciliation.namespace(), e);
} else {
LOGGER.errorCr(reconciliation, "Failed to update status of StrimziPodSet {} in namespace {}", reconciliation.name(), reconciliation.namespace(), e);
}
}
}
}
Aggregations