use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class AbstractKafkaCluster method getReadiness.
@Override
public OperandReadiness getReadiness(ManagedKafka managedKafka) {
Kafka kafka = cachedKafka(managedKafka);
if (kafka == null) {
return new OperandReadiness(Status.False, Reason.Installing, String.format("Kafka %s does not exist", kafkaClusterName(managedKafka)));
}
Optional<Condition> notReady = kafkaCondition(kafka, c -> "NotReady".equals(c.getType()));
if (notReady.filter(c -> "True".equals(c.getStatus())).isPresent()) {
Condition c = notReady.get();
return new OperandReadiness(Status.False, "Creating".equals(c.getReason()) ? Reason.Installing : Reason.Error, c.getMessage());
}
if (isStrimziUpdating(managedKafka)) {
// the status here is actually unknown
return new OperandReadiness(Status.True, Reason.StrimziUpdating, null);
}
if (isKafkaUpdating(managedKafka) || isKafkaUpgradeStabilityChecking(managedKafka)) {
return new OperandReadiness(Status.True, Reason.KafkaUpdating, null);
}
if (isKafkaIbpUpdating(managedKafka)) {
return new OperandReadiness(Status.True, Reason.KafkaIbpUpdating, null);
}
Optional<Condition> ready = kafkaCondition(kafka, c -> "Ready".equals(c.getType()));
if (ready.filter(c -> "True".equals(c.getStatus())).isPresent()) {
return new OperandReadiness(Status.True, null, null);
}
if (isReconciliationPaused(managedKafka)) {
// strimzi may in the future report the status even when paused, but for now we don't know
return new OperandReadiness(Status.Unknown, Reason.Paused, String.format("Kafka %s is paused for an unknown reason", kafkaClusterName(managedKafka)));
}
return new OperandReadiness(Status.False, Reason.Installing, String.format("Kafka %s is not providing status", kafkaClusterName(managedKafka)));
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class KafkaCluster method calculateRetentionSize.
/**
* Get the current sum of storage as reported by the pvcs.
* This may not match the requested amount ephemerally, or due to rounding
*/
@Override
public Quantity calculateRetentionSize(ManagedKafka managedKafka) {
Kafka current = cachedKafka(managedKafka);
long storageInGbs = informerManager.getPvcsInNamespace(managedKafka.getMetadata().getNamespace()).stream().map(pvc -> {
if (pvc.getStatus() == null) {
return 0L;
}
PersistentVolumeClaimStatus status = pvc.getStatus();
Quantity q = OperandUtils.getOrDefault(status.getCapacity(), "storage", (Quantity) null);
if (q == null) {
return 0L;
}
long value = Quantity.getAmountInBytes(q).longValue();
// round down to the nearest GB - the PVC request is automatically rounded up
return (long) Math.floor(((double) unpadBrokerStorage(managedKafka, current, value)) / (1L << 30));
}).collect(Collectors.summingLong(Long::longValue));
Quantity capacity = managedKafka.getSpec().getCapacity().getMaxDataRetentionSize();
// try to correct for the overall rounding
if (storageInGbs > 0 && (capacity == null || ("Gi".equals(capacity.getFormat()) && (Quantity.getAmountInBytes(capacity).longValue() / (1L << 30)) % getBrokerReplicas(managedKafka, current) != 0))) {
storageInGbs++;
}
return Quantity.parse(String.format("%sGi", storageInGbs));
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class KafkaInstance method getReadiness.
@Override
public OperandReadiness getReadiness(ManagedKafka managedKafka) {
if (managedKafka.getSpec().isDeleted()) {
// TODO: it may be a good idea to offer a message here as well
return new OperandReadiness(isDeleted(managedKafka) ? Status.False : Status.Unknown, Reason.Deleted, null);
}
List<OperandReadiness> readiness = operands.stream().map(o -> o.getReadiness(managedKafka)).filter(Objects::nonNull).collect(Collectors.toList());
// default to the first reason, with can come from the kafka by the order of the operands
Reason reason = readiness.stream().map(OperandReadiness::getReason).filter(Objects::nonNull).findFirst().orElse(null);
// default the status to false or unknown if any are unknown
Status status = readiness.stream().anyMatch(r -> Status.Unknown.equals(r.getStatus())) ? Status.Unknown : Status.False;
// combine all the messages
String message = readiness.stream().map(OperandReadiness::getMessage).filter(Objects::nonNull).collect(Collectors.joining("; "));
// override in particular scenarios
if (readiness.stream().allMatch(r -> Status.True.equals(r.getStatus()))) {
status = Status.True;
} else if (readiness.stream().anyMatch(r -> Reason.Installing.equals(r.getReason()))) {
// may mask other error states
reason = Reason.Installing;
} else if (readiness.stream().anyMatch(r -> Reason.Error.equals(r.getReason()))) {
reason = Reason.Error;
}
return new OperandReadiness(status, reason, message);
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ManagedKafkaControllerTest method shouldCreateStatus.
@Test
void shouldCreateStatus() throws InterruptedException {
ManagedKafka mk = ManagedKafka.getDummyInstance(1);
mk.getMetadata().setUid(UUID.randomUUID().toString());
mk.getMetadata().setGeneration(1l);
mk.getMetadata().setResourceVersion("1");
// create
Context<ManagedKafka> context = Mockito.mock(Context.class);
Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new CustomResourceEvent(Action.ADDED, mk, null))));
StrimziManager strimziManager = Mockito.mock(StrimziManager.class);
Mockito.when(strimziManager.getStrimziVersion("strimzi-cluster-operator.v0.23.0")).thenReturn(new StrimziVersionStatusBuilder().withVersion(mk.getSpec().getVersions().getStrimzi()).withKafkaVersions(mk.getSpec().getVersions().getKafka()).build());
Mockito.when(strimziManager.getVersionLabel()).thenReturn("managedkafka.bf2.org/strimziVersion");
QuarkusMock.installMockForType(strimziManager, StrimziManager.class);
mkController.createOrUpdateResource(mk, context);
ManagedKafkaCondition condition = mk.getStatus().getConditions().get(0);
assertEquals(ManagedKafkaCondition.Reason.Installing.name(), condition.getReason());
mk.getSpec().setDeleted(true);
// this simulates, but not exactly an issue seen with older logic
// essentially there "last event" of the delete is something other than a deployment or a kafka
// it should still trigger the update of the status
Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new ResourceEvent<>(new ServiceBuilder().withNewMetadata().withOwnerReferences(new OwnerReferenceBuilder().withUid(mk.getMetadata().getUid()).build()).endMetadata().build(), null, Watcher.Action.DELETED))));
mkController.createOrUpdateResource(mk, context);
// should now be deleted
condition = mk.getStatus().getConditions().get(0);
assertEquals(ManagedKafkaCondition.Reason.Deleted.name(), condition.getReason());
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class StrimziBundleManager method updateStatus.
/**
* Update status of ManagedKafkaAgent resource about approval of Strimzi bundle installation
* NOTE: it creates a condition if Strimzi bundle installation was not approved. The condition is taken out if approved.
*
* @param approval the status of the approval
*/
private void updateStatus(Approval approval) {
ManagedKafkaAgent resource = this.agentClient.getByName(this.agentClient.getNamespace(), ManagedKafkaAgentResourceClient.RESOURCE_NAME);
if (resource != null && resource.getStatus() != null) {
List<ManagedKafkaCondition> conditions = resource.getStatus().getConditions();
ManagedKafkaCondition bundleReadyCondition = ConditionUtils.findManagedKafkaCondition(conditions, ManagedKafkaCondition.Type.StrimziBundleReady).orElse(null);
ManagedKafkaCondition.Reason reason = ManagedKafkaCondition.Reason.OrphanedKafkas;
ManagedKafkaCondition.Status status = ManagedKafkaCondition.Status.False;
if (approval != Approval.ORPHANED) {
if (bundleReadyCondition == null) {
return;
}
conditions.remove(bundleReadyCondition);
} else {
if (bundleReadyCondition == null) {
bundleReadyCondition = ConditionUtils.buildCondition(ManagedKafkaCondition.Type.StrimziBundleReady, status);
bundleReadyCondition.reason(reason);
conditions.add(bundleReadyCondition);
} else {
ConditionUtils.updateConditionStatus(bundleReadyCondition, status, reason, null);
}
}
this.agentClient.replaceStatus(resource);
}
}
Aggregations