Search in sources :

Example 31 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class KafkaInstanceTest method statusInstallingTrumpsError.

@Test
void statusInstallingTrumpsError() {
    ManagedKafka managedKafka = DUMMY_MANAGED_KAFKA;
    when(kafkaCluster.getReadiness(managedKafka)).thenReturn(new OperandReadiness(Status.True, Reason.StrimziUpdating, null));
    when(canary.getReadiness(managedKafka)).thenReturn(new OperandReadiness(Status.False, Reason.Error, "I'm not well"));
    when(adminServer.getReadiness(managedKafka)).thenReturn(new OperandReadiness(Status.False, Reason.Installing, "I'm installing"));
    OperandReadiness readiness = kafkaInstance.getReadiness(managedKafka);
    assertEquals(Status.False, readiness.getStatus());
    assertEquals(Reason.Installing, readiness.getReason());
    assertEquals("I'm not well; I'm installing", readiness.getMessage());
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 32 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class InstanceProfiler method deployIfNeeded.

private void deployIfNeeded(String name) throws Exception {
    ManagedKafka mk = null;
    Resource<ManagedKafka> mkResource = kafkaCluster.kubeClient().client().resources(ManagedKafka.class).inNamespace(Constants.KAFKA_NAMESPACE).withName(name);
    try {
        mk = mkResource.get();
    } catch (KubernetesClientException e) {
    }
    ManagedKafkaDeployment kd = null;
    if (mk == null) {
        if (!installedProvisioner) {
            // TODO: come up with a better resume logic here - it currently has to recreate everything
            installedProvisioner = true;
            kafkaProvisioner.install();
        }
        kafkaProvisioner.removeClusters(true);
        kd = kafkaProvisioner.deployCluster(name, profilingResult.capacity, profilingResult.config);
    } else {
        // TODO validate config / capacity
        kd = new ManagedKafkaDeployment(mk, kafkaCluster);
        kd.start();
    }
    instanceBootstrap = kd.waitUntilReady();
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 33 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaSync method reconcile.

/**
 * Final sync processing of the remote vs. local state
 */
void reconcile(String remoteId, String localMetaNamespaceKey) {
    ManagedKafka local = null;
    if (localMetaNamespaceKey != null) {
        // refresh the local
        local = lookup.getLocalManagedKafka(localMetaNamespaceKey);
    }
    ManagedKafka remote = null;
    if (remoteId != null) {
        // refresh the remote
        remote = controlPlane.getDesiredState(remoteId);
    }
    if (local == null && remote == null) {
        // nothing to do
        return;
    }
    String id = null;
    if (local != null) {
        id = local.getId();
    } else {
        id = remote.getId();
    }
    if (id != null) {
        NDC.push(ManagedKafkaResourceClient.ID_LOG_KEY + "=" + id);
    }
    try {
        if (local == null) {
            if (!remote.getSpec().isDeleted()) {
                create(remote);
            }
        } else if (remote == null) {
            if (deleteAllowed(local)) {
                delete(local);
            }
        } else {
            if (!Objects.equals(local.getPlacementId(), remote.getPlacementId())) {
                log.debugf("Waiting for existing ManagedKafka %s to disappear before attempting next placement", local.getPlacementId());
                return;
            }
            if (specChanged(remote.getSpec(), local)) {
                log.debugf("Updating ManagedKafka Spec for %s", Cache.metaNamespaceKeyFunc(local));
                ManagedKafkaSpec spec = remote.getSpec();
                client.edit(local.getMetadata().getNamespace(), local.getMetadata().getName(), mk -> {
                    mk.setSpec(spec);
                    return mk;
                });
            // the operator will handle it from here
            }
        }
    } finally {
        if (id != null) {
            NDC.pop();
        }
    }
}
Also used : ManagedKafkaResourceClient(org.bf2.common.ManagedKafkaResourceClient) HttpURLConnection(java.net.HttpURLConnection) Status(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status) Timed(io.micrometer.core.annotation.Timed) Logger(org.jboss.logging.Logger) Cache(io.fabric8.kubernetes.client.informers.cache.Cache) HashMap(java.util.HashMap) Inject(javax.inject.Inject) ControlPlane(org.bf2.sync.controlplane.ControlPlane) Map(java.util.Map) ExecutorService(java.util.concurrent.ExecutorService) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) LocalLookup(org.bf2.sync.informer.LocalLookup) Type(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Type) Scheduled(io.quarkus.scheduler.Scheduled) OperandUtils(org.bf2.common.OperandUtils) NDC(org.jboss.logging.NDC) ManagedKafkaStatusBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder) ConditionUtils(org.bf2.common.ConditionUtils) Reason(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason) Objects(java.util.Objects) Counted(io.micrometer.core.annotation.Counted) Namespace(io.fabric8.kubernetes.api.model.Namespace) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ManagedExecutor(org.eclipse.microprofile.context.ManagedExecutor) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ManagedKafkaSpec(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpec) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ConcurrentExecution(io.quarkus.scheduler.Scheduled.ConcurrentExecution) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaSpec(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpec)

Example 34 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ControlPlane method getKafkaClusters.

/**
 * Get the current list of ManagedKafka clusters from the control plane
 * as a blocking call.
 * Also updates the cache of desired state ManagedKafka instances.  May include
 * entries that have not yet been created locally.
 *
 * @see {@link #getDesiredStates()} to get the full cache, rather than making a
 * remote call
 */
public List<ManagedKafka> getKafkaClusters() {
    ManagedKafkaList result = controlPlaneClient.getKafkaClusters(id);
    result.getItems().forEach((mk) -> addDesiredState(mk));
    return result.getItems();
}
Also used : ManagedKafkaList(org.bf2.operator.resources.v1alpha1.ManagedKafkaList)

Example 35 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class PollerTest method exampleManagedKafka.

static ManagedKafka exampleManagedKafka() {
    ManagedKafka mk = ManagedKafka.getDummyInstance(1);
    mk.setId(ID);
    return mk;
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka)

Aggregations

ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)67 Kafka (io.strimzi.api.kafka.model.Kafka)30 Test (org.junit.jupiter.api.Test)24 QuarkusTest (io.quarkus.test.junit.QuarkusTest)23 List (java.util.List)16 Map (java.util.Map)15 Inject (javax.inject.Inject)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Objects (java.util.Objects)14 Quantity (io.fabric8.kubernetes.api.model.Quantity)11 Optional (java.util.Optional)11 Collectors (java.util.stream.Collectors)10 ApplicationScoped (javax.enterprise.context.ApplicationScoped)9 StrimziManager (org.bf2.operator.managers.StrimziManager)9 Logger (org.jboss.logging.Logger)9 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)8 ArrayList (java.util.ArrayList)8 Reason (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason)8 Status (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status)8 ManagedKafkaUtils.exampleManagedKafka (org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka)8