Search in sources :

Example 1 with ManagedKafkaAgent

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent 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);
    }
}
Also used : ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) ManagedKafkaAgent(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent)

Example 2 with ManagedKafkaAgent

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

the class StrimziManager method updateStatus.

private void updateStatus() {
    List<StrimziVersionStatus> versions = new ArrayList<>(this.strimziVersions.values());
    // create the Kafka informer only when a Strimzi bundle is installed (aka at least one available version)
    if (!versions.isEmpty()) {
        informerManager.createKafkaInformer();
    }
    ManagedKafkaAgent resource = agentClient.getByName(agentClient.getNamespace(), ManagedKafkaAgentResourceClient.RESOURCE_NAME);
    if (resource != null && resource.getStatus() != null) {
        List<StrimziVersionStatus> existing = resource.getStatus().getStrimzi();
        if (!versions.equals(existing)) {
            log.debugf("Updating Strimzi versions %s", versions);
            resource.getStatus().setStrimzi(versions);
            agentClient.replaceStatus(resource);
            // version changes should sync the managed kafkas
            if (existing == null || !toVersionKeySet(versions).equals(toVersionKeySet(existing))) {
                informerManager.resyncManagedKafka();
            }
        }
    }
}
Also used : StrimziVersionStatus(org.bf2.operator.resources.v1alpha1.StrimziVersionStatus) ArrayList(java.util.ArrayList) ManagedKafkaAgent(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent)

Example 3 with ManagedKafkaAgent

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

the class ManagedKafkaAgentController method buildStatus.

/**
 * TODO: this needs to be replaced with actual metrics
 * @return
 */
private ManagedKafkaAgentStatus buildStatus(ManagedKafkaAgent resource) {
    ManagedKafkaAgentStatus status = resource.getStatus();
    ManagedKafkaCondition readyCondition = null;
    if (status != null) {
        readyCondition = ConditionUtils.findManagedKafkaCondition(status.getConditions(), Type.Ready).orElse(null);
    }
    List<StrimziVersionStatus> strimziVersions = this.strimziManager.getStrimziVersions();
    log.debugf("Strimzi versions %s", strimziVersions);
    // consider the fleetshard operator ready when observability is running and a Strimzi bundle is installed (aka at least one available version)
    Status statusValue = this.observabilityManager.isObservabilityRunning() && !strimziVersions.isEmpty() ? ManagedKafkaCondition.Status.True : ManagedKafkaCondition.Status.False;
    if (readyCondition == null) {
        readyCondition = ConditionUtils.buildCondition(ManagedKafkaCondition.Type.Ready, statusValue);
    } else {
        ConditionUtils.updateConditionStatus(readyCondition, statusValue, null, null);
    }
    ClusterCapacity total = new ClusterCapacityBuilder().withConnections(10000).withDataRetentionSize(Quantity.parse("40Gi")).withIngressEgressThroughputPerSec(Quantity.parse("40Gi")).withPartitions(10000).build();
    ClusterCapacity remaining = new ClusterCapacityBuilder().withConnections(10000).withDataRetentionSize(Quantity.parse("40Gi")).withIngressEgressThroughputPerSec(Quantity.parse("40Gi")).withPartitions(10000).build();
    ClusterCapacity delta = new ClusterCapacityBuilder().withConnections(10000).withDataRetentionSize(Quantity.parse("40Gi")).withIngressEgressThroughputPerSec(Quantity.parse("40Gi")).withPartitions(10000).build();
    NodeCounts nodeInfo = new NodeCountsBuilder().withCeiling(0).withCurrent(0).withCurrentWorkLoadMinimum(0).withFloor(0).build();
    ClusterResizeInfo resize = new ClusterResizeInfoBuilder().withDelta(delta).withNodeDelta(3).build();
    return new ManagedKafkaAgentStatusBuilder().withConditions(status == null ? Arrays.asList(readyCondition) : status.getConditions()).withTotal(total).withRemaining(remaining).withNodeInfo(nodeInfo).withResizeInfo(resize).withUpdatedTimestamp(ConditionUtils.iso8601Now()).withStrimzi(strimziVersions).build();
}
Also used : Status(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status) StrimziVersionStatus(org.bf2.operator.resources.v1alpha1.StrimziVersionStatus) ManagedKafkaAgentStatus(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentStatus) ManagedKafkaAgentStatusBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentStatusBuilder) StrimziVersionStatus(org.bf2.operator.resources.v1alpha1.StrimziVersionStatus) ClusterResizeInfoBuilder(org.bf2.operator.resources.v1alpha1.ClusterResizeInfoBuilder) ClusterCapacity(org.bf2.operator.resources.v1alpha1.ClusterCapacity) ClusterCapacityBuilder(org.bf2.operator.resources.v1alpha1.ClusterCapacityBuilder) NodeCountsBuilder(org.bf2.operator.resources.v1alpha1.NodeCountsBuilder) NodeCounts(org.bf2.operator.resources.v1alpha1.NodeCounts) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) ClusterResizeInfo(org.bf2.operator.resources.v1alpha1.ClusterResizeInfo) ManagedKafkaAgentStatus(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentStatus)

Example 4 with ManagedKafkaAgent

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

the class ManagedKafkaAgentSync method createOrUpdateManagedKafkaAgent.

private void createOrUpdateManagedKafkaAgent(ManagedKafkaAgent remoteAgent) {
    ManagedKafkaAgent resource = lookup.getLocalManagedKafkaAgent();
    if (resource == null) {
        // the informer may not have run yet, so check more definitively
        resource = this.agentClient.getByName(this.agentClient.getNamespace(), ManagedKafkaAgentResourceClient.RESOURCE_NAME);
    }
    if (resource == null) {
        remoteAgent.getMetadata().setNamespace(agentClient.getNamespace());
        remoteAgent.getMetadata().setName(ManagedKafkaAgentResourceClient.RESOURCE_NAME);
        this.agentClient.create(remoteAgent);
        log.infof("ManagedKafkaAgent CR created");
    } else if (!remoteAgent.getSpec().equals(resource.getSpec())) {
        this.agentClient.edit(this.agentClient.getNamespace(), ManagedKafkaAgentResourceClient.RESOURCE_NAME, mka -> {
            mka.setSpec(remoteAgent.getSpec());
            return mka;
        });
        log.infof("ManagedKafkaAgent CR updated");
    }
}
Also used : Inject(javax.inject.Inject) Objects(java.util.Objects) ControlPlane(org.bf2.sync.controlplane.ControlPlane) Counted(io.micrometer.core.annotation.Counted) LocalLookup(org.bf2.sync.informer.LocalLookup) Scheduled(io.quarkus.scheduler.Scheduled) Timed(io.micrometer.core.annotation.Timed) Logger(org.jboss.logging.Logger) ManagedKafkaAgent(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ConcurrentExecution(io.quarkus.scheduler.Scheduled.ConcurrentExecution) ManagedKafkaAgentResourceClient(org.bf2.common.ManagedKafkaAgentResourceClient) ManagedKafkaAgent(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent)

Example 5 with ManagedKafkaAgent

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

the class ManagedKafkaAgentSync method loop.

@Timed(value = "sync.poll", extraTags = { "resource", "ManagedKafkaAgent" }, description = "The time spent processing polling calls")
@Counted(value = "sync.poll", extraTags = { "resource", "ManagedKafkaAgent" }, description = "The number of polling calls")
@Scheduled(every = "{poll.interval}", concurrentExecution = ConcurrentExecution.SKIP)
void loop() {
    ManagedKafkaAgent managedKafkaAgent = controlPlane.getManagedKafkaAgent();
    Objects.requireNonNull(managedKafkaAgent);
    createOrUpdateManagedKafkaAgent(managedKafkaAgent);
}
Also used : ManagedKafkaAgent(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent) Scheduled(io.quarkus.scheduler.Scheduled) Counted(io.micrometer.core.annotation.Counted) Timed(io.micrometer.core.annotation.Timed)

Aggregations

ManagedKafkaAgent (org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent)8 Counted (io.micrometer.core.annotation.Counted)3 Timed (io.micrometer.core.annotation.Timed)3 Scheduled (io.quarkus.scheduler.Scheduled)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 ClusterCapacityBuilder (org.bf2.operator.resources.v1alpha1.ClusterCapacityBuilder)2 ManagedKafkaAgentStatus (org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentStatus)2 ManagedKafkaAgentStatusBuilder (org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentStatusBuilder)2 ManagedKafkaCondition (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition)2 StrimziVersionStatus (org.bf2.operator.resources.v1alpha1.StrimziVersionStatus)2 Test (org.junit.jupiter.api.Test)2 ConcurrentExecution (io.quarkus.scheduler.Scheduled.ConcurrentExecution)1 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 ManagedKafkaAgentResourceClient (org.bf2.common.ManagedKafkaAgentResourceClient)1 ClusterCapacity (org.bf2.operator.resources.v1alpha1.ClusterCapacity)1 ClusterResizeInfo (org.bf2.operator.resources.v1alpha1.ClusterResizeInfo)1 ClusterResizeInfoBuilder (org.bf2.operator.resources.v1alpha1.ClusterResizeInfoBuilder)1