Search in sources :

Example 1 with StackGresClusterContext

use of io.stackgres.cluster.common.StackGresClusterContext in project stackgres by ongres.

the class ClusterControllerReconciliator method reconcile.

@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "False positives")
@Override
protected ReconciliationResult<?> reconcile(KubernetesClient client, StackGresClusterContext context) throws Exception {
    ReconciliationResult<Boolean> extensionReconciliationResult = extensionReconciliator.reconcile(client, context);
    if (extensionReconciliationResult.result().orElse(false)) {
        final String podName = propertyContext.getString(ClusterControllerProperty.CLUSTER_CONTROLLER_POD_NAME);
        final StackGresCluster cluster = context.getCluster();
        final StackGresClusterStatus status = cluster.getStatus();
        String clusterName = cluster.getMetadata().getName();
        String namespace = cluster.getMetadata().getNamespace();
        clusterFinder.findByNameAndNamespace(clusterName, namespace).ifPresent(savedCluster -> {
            var newPodStatus = findPodStatus(status.getPodStatuses(), podName).orElseThrow();
            Optional.ofNullable(savedCluster.getStatus()).ifPresentOrElse(savedStatus -> Optional.ofNullable(savedStatus.getPodStatuses()).ifPresentOrElse(savedPodStatuses -> findPodStatus(savedPodStatuses, podName).ifPresentOrElse(savedPodStatus -> applyPodStatusChanges(newPodStatus, savedPodStatus), () -> savedPodStatuses.add(newPodStatus)), () -> savedStatus.setPodStatuses(status.getPodStatuses())), () -> savedCluster.setStatus(status));
            clusterScheduler.updateStatus(savedCluster);
        });
    }
    return extensionReconciliationResult;
}
Also used : StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) ClusterControllerProperty(io.stackgres.common.ClusterControllerProperty) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ReconciliationResult(io.stackgres.operatorframework.reconciliation.ReconciliationResult) Reconciliator(io.stackgres.operatorframework.reconciliation.Reconciliator) ClusterControllerPropertyContext(io.stackgres.cluster.configuration.ClusterControllerPropertyContext) Inject(javax.inject.Inject) CdiUtil(io.stackgres.common.CdiUtil) List(java.util.List) Dependent(javax.enterprise.context.Dependent) CustomResourceScheduler(io.stackgres.common.resource.CustomResourceScheduler) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) CustomResourceFinder(io.stackgres.common.resource.CustomResourceFinder) ApplicationScoped(javax.enterprise.context.ApplicationScoped) StackGresClusterContext(io.stackgres.cluster.common.StackGresClusterContext) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StackGresClusterPodStatus(io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 StackGresClusterContext (io.stackgres.cluster.common.StackGresClusterContext)1 ClusterControllerPropertyContext (io.stackgres.cluster.configuration.ClusterControllerPropertyContext)1 CdiUtil (io.stackgres.common.CdiUtil)1 ClusterControllerProperty (io.stackgres.common.ClusterControllerProperty)1 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)1 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)1 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)1 CustomResourceFinder (io.stackgres.common.resource.CustomResourceFinder)1 CustomResourceScheduler (io.stackgres.common.resource.CustomResourceScheduler)1 ReconciliationResult (io.stackgres.operatorframework.reconciliation.ReconciliationResult)1 Reconciliator (io.stackgres.operatorframework.reconciliation.Reconciliator)1 List (java.util.List)1 Optional (java.util.Optional)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1