use of org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConditionUtilsTest method testFindManagedKafkaCondition.
@Test
void testFindManagedKafkaCondition() {
ManagedKafka mk = new ManagedKafkaBuilder().withMetadata(new ObjectMetaBuilder().withNamespace("test").withName("my-managed-kafka").build()).withSpec(new ManagedKafkaSpecBuilder().withNewVersions().withKafka("2.6.0").withStrimzi("0.21.1").endVersions().build()).withStatus(new ManagedKafkaStatusBuilder().addNewCondition().withStatus(Status.True.name()).withType(ManagedKafkaCondition.Type.Ready.name()).endCondition().build()).build();
assertNotNull(ConditionUtils.findManagedKafkaCondition(mk.getStatus().getConditions(), ManagedKafkaCondition.Type.Ready).get());
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ControlPlaneTest method testManagedKafkaStatusComparison.
@Test
public void testManagedKafkaStatusComparison() {
ManagedKafkaStatus status = null;
assertFalse(ControlPlane.statusChanged(status, status));
status = new ManagedKafkaStatus();
assertFalse(ControlPlane.statusChanged(status, null));
assertFalse(ControlPlane.statusChanged(status, status));
assertTrue(ControlPlane.statusChanged(null, status));
ManagedKafkaStatus newStatus = new ManagedKafkaStatusBuilder().withUpdatedTimestamp("2020-01-01").build();
assertTrue(ControlPlane.statusChanged(status, newStatus));
assertTrue(ControlPlane.statusChanged(newStatus, status));
status.setConditions(new ArrayList<>());
status.setUpdatedTimestamp("2021-01-01");
assertTrue(ControlPlane.statusChanged(newStatus, status));
newStatus.setUpdatedTimestamp("2022-01-01");
assertTrue(ControlPlane.statusChanged(status, newStatus));
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ManagedKafkaController method updateManagedKafkaStatus.
/**
* Extract from the current KafkaInstance overall status (Kafka, Canary and AdminServer)
* a corresponding list of ManagedKafkaCondition(s) to set on the ManagedKafka status
*
* @param managedKafka ManagedKafka instance
*/
private void updateManagedKafkaStatus(ManagedKafka managedKafka) {
// add status if not already available on the ManagedKafka resource
ManagedKafkaStatus status = Objects.requireNonNullElse(managedKafka.getStatus(), new ManagedKafkaStatusBuilder().build());
status.setUpdatedTimestamp(ConditionUtils.iso8601Now());
managedKafka.setStatus(status);
// add conditions if not already available
List<ManagedKafkaCondition> managedKafkaConditions = managedKafka.getStatus().getConditions();
if (managedKafkaConditions == null) {
managedKafkaConditions = new ArrayList<>();
status.setConditions(managedKafkaConditions);
}
Optional<ManagedKafkaCondition> optReady = ConditionUtils.findManagedKafkaCondition(managedKafkaConditions, ManagedKafkaCondition.Type.Ready);
ManagedKafkaCondition ready = null;
if (optReady.isPresent()) {
ready = optReady.get();
} else {
ready = ConditionUtils.buildCondition(ManagedKafkaCondition.Type.Ready, Status.Unknown);
managedKafkaConditions.add(ready);
}
// a not valid ManagedKafka skips the handling of it, so the status will report an error condition
OperandReadiness readiness = this.validity(managedKafka).orElse(kafkaInstance.getReadiness(managedKafka));
ConditionUtils.updateConditionStatus(ready, readiness.getStatus(), readiness.getReason(), readiness.getMessage());
// routes should always be set on the CR status, even if it's just an empty list
status.setRoutes(List.of());
int replicas = kafkaCluster.getReplicas(managedKafka);
if (ingressControllerManagerInstance.isResolvable()) {
IngressControllerManager ingressControllerManager = ingressControllerManagerInstance.get();
List<ManagedKafkaRoute> routes = ingressControllerManager.getManagedKafkaRoutesFor(managedKafka);
// expect route for each broker + 1 for bootstrap URL + 1 for Admin API server
int expectedNumRoutes = replicas + NUM_NON_BROKER_ROUTES;
if (routes.size() >= expectedNumRoutes && routes.stream().noneMatch(r -> "".equals(r.getRouter()))) {
status.setRoutes(routes);
}
}
if (Status.True.equals(readiness.getStatus())) {
status.setCapacity(new ManagedKafkaCapacityBuilder(managedKafka.getSpec().getCapacity()).withMaxDataRetentionSize(kafkaInstance.getKafkaCluster().calculateRetentionSize(managedKafka)).build());
// the versions in the status are updated incrementally copying the spec only when each stage ends
VersionsBuilder versionsBuilder = status.getVersions() != null ? new VersionsBuilder(status.getVersions()) : new VersionsBuilder(managedKafka.getSpec().getVersions());
if (!Reason.StrimziUpdating.equals(readiness.getReason()) && !this.strimziManager.hasStrimziChanged(managedKafka)) {
versionsBuilder.withStrimzi(managedKafka.getSpec().getVersions().getStrimzi());
}
if (!Reason.KafkaUpdating.equals(readiness.getReason()) && !this.kafkaManager.hasKafkaVersionChanged(managedKafka)) {
versionsBuilder.withKafka(managedKafka.getSpec().getVersions().getKafka());
}
if (!Reason.KafkaIbpUpdating.equals(readiness.getReason()) && !this.kafkaManager.hasKafkaIbpVersionChanged(managedKafka)) {
String kafkaIbp = managedKafka.getSpec().getVersions().getKafkaIbp() != null ? managedKafka.getSpec().getVersions().getKafkaIbp() : AbstractKafkaCluster.getKafkaIbpVersion(managedKafka.getSpec().getVersions().getKafka());
versionsBuilder.withKafkaIbp(kafkaIbp);
}
status.setVersions(versionsBuilder.build());
status.setAdminServerURI(kafkaInstance.getAdminServer().uri(managedKafka));
status.setServiceAccounts(managedKafka.getSpec().getServiceAccounts());
}
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class UpdateTest method testControlPlaneUpdates.
@Test
public void testControlPlaneUpdates() {
ManagedKafka managedKafka = PollerTest.exampleManagedKafka();
managedKafka.getMetadata().setNamespace(managedKafka.getId());
managedKafka.setStatus(new ManagedKafkaStatusBuilder().addNewCondition().withStatus("Installed").endCondition().build());
managedKafkaClient.create(managedKafka);
controlPlane.updateKafkaClusterStatus(PollerTest.exampleManagedKafka(), managedKafka);
assertEquals("Installed", getUpdates().getValue().get(PollerTest.ID).getConditions().get(0).getStatus());
// simulate a resync
// for now we're just looking for equality
Mockito.clearInvocations(controlPlaneRestClient);
controlPlane.updateKafkaClusterStatus(managedKafka, managedKafka);
// should not be sent
Mockito.verifyNoInteractions(controlPlaneRestClient);
// send everything
controlPlane.sendResync();
ArgumentCaptor<Map<String, ManagedKafkaStatus>> statusCaptor = getUpdates();
assertEquals("Installed", statusCaptor.getValue().get(PollerTest.ID).getConditions().get(0).getStatus());
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class StrimziManagerTest method testStrimziVersionChange.
@Test
public void testStrimziVersionChange() {
ManagedKafka mk = ManagedKafka.getDummyInstance(1);
mk.getSpec().getVersions().setStrimzi("strimzi-cluster-operator.v1");
Kafka kafka = this.kafkaCluster.kafkaFrom(mk, null);
kafkaClient.create(kafka);
// Kafka reconcile not paused and current label version as the ManagedKafka one
assertFalse(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_RECONCILE_ANNOTATION));
assertEquals(kafka.getMetadata().getLabels().get(this.strimziManager.getVersionLabel()), mk.getSpec().getVersions().getStrimzi());
// ManagedKafka and Kafka updated their status information
mk.setStatus(new ManagedKafkaStatusBuilder().withVersions(new VersionsBuilder().withStrimzi("strimzi-cluster-operator.v1").build()).build());
kafka.setStatus(new KafkaStatusBuilder().withConditions(new ConditionBuilder().withType("Ready").withStatus("True").build()).build());
kafkaClient.replaceStatus(kafka);
// ask for a Strimzi version change on ManagedKafka
mk.getSpec().getVersions().setStrimzi("strimzi-cluster-operator.v2");
kafka = this.kafkaCluster.kafkaFrom(mk, kafka);
// Kafka reconcile paused but label is still the current version
assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_RECONCILE_ANNOTATION));
assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION));
assertEquals(kafka.getMetadata().getLabels().get(this.strimziManager.getVersionLabel()), mk.getStatus().getVersions().getStrimzi());
// nothing should change after an intermediate reconcile
kafka = this.kafkaCluster.kafkaFrom(mk, kafka);
assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION));
// Kafka moves to be paused
kafka.setStatus(new KafkaStatusBuilder().withConditions(new ConditionBuilder().withType("ReconciliationPaused").withStatus("True").build()).build());
kafkaClient.replaceStatus(kafka);
kafka = this.kafkaCluster.kafkaFrom(mk, kafka);
// Kafka reconcile not paused and Kafka label updated to requested Strimzi version
assertFalse(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_RECONCILE_ANNOTATION));
// the pause reason should stay until strimzi updates to ready
assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION));
assertEquals(kafka.getMetadata().getLabels().get(this.strimziManager.getVersionLabel()), "strimzi-cluster-operator.v2");
}
Aggregations