Search in sources :

Example 1 with StackGresDistributedLogsStatus

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatus in project stackgres by ongres.

the class DistributedLogsStatusManager method isPendingRestart.

/**
 * Check pending restart status condition.
 */
public boolean isPendingRestart(StackGresDistributedLogs distributedLogs) {
    List<StackGresClusterPodStatus> clusterPodStatuses = Optional.ofNullable(distributedLogs.getStatus()).map(StackGresDistributedLogsStatus::getPodStatuses).orElse(ImmutableList.of());
    Optional<StatefulSet> clusterStatefulSet = getClusterStatefulSet(distributedLogs);
    List<Pod> clusterPods = clusterStatefulSet.map(sts -> getStsPods(sts, distributedLogs)).orElse(ImmutableList.of());
    RestartReasons reasons = ClusterPendingRestartUtil.getRestartReasons(clusterPodStatuses, clusterStatefulSet, clusterPods);
    for (RestartReason reason : reasons.getReasons()) {
        switch(reason) {
            case OPERATOR_VERSION:
                LOGGER.debug("Distributed Logs {} requires restart due to operator version change", getDistributedLogsId(distributedLogs));
                break;
            case PATRONI:
                LOGGER.debug("Distributed Logs {} requires restart due to patroni's indication", getDistributedLogsId(distributedLogs));
                break;
            case POD_STATUS:
                LOGGER.debug("Distributed Logs {} requires restart due to pod status indication", getDistributedLogsId(distributedLogs));
                break;
            case STATEFULSET:
                LOGGER.debug("Distributed Logs {} requires restart due to pod template changes", getDistributedLogsId(distributedLogs));
                break;
            default:
                break;
        }
    }
    return reasons.requiresRestart();
}
Also used : StatusManager(io.stackgres.operator.conciliation.StatusManager) LoggerFactory(org.slf4j.LoggerFactory) ConditionUpdater(io.stackgres.operatorframework.resource.ConditionUpdater) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) StackGresDistributedLogsStatus(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatus) Map(java.util.Map) KubernetesClientFactory(io.stackgres.common.KubernetesClientFactory) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) StackGresClusterPodStatus(io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus) StackGresDistributedLogsCondition(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsCondition) RestartReasons(io.stackgres.common.ClusterPendingRestartUtil.RestartReasons) DistributedLogsStatusCondition(io.stackgres.common.crd.sgdistributedlogs.DistributedLogsStatusCondition) Logger(org.slf4j.Logger) LabelFactoryForCluster(io.stackgres.common.LabelFactoryForCluster) Pod(io.fabric8.kubernetes.api.model.Pod) Collectors(java.util.stream.Collectors) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) RestartReason(io.stackgres.common.ClusterPendingRestartUtil.RestartReason) List(java.util.List) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ClusterPendingRestartUtil(io.stackgres.common.ClusterPendingRestartUtil) RestartReason(io.stackgres.common.ClusterPendingRestartUtil.RestartReason) Pod(io.fabric8.kubernetes.api.model.Pod) RestartReasons(io.stackgres.common.ClusterPendingRestartUtil.RestartReasons) StackGresClusterPodStatus(io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet)

Example 2 with StackGresDistributedLogsStatus

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatus in project stackgres by ongres.

the class DistributedLogsControllerReconciliator method reconcile.

@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "False positives")
@Override
protected ReconciliationResult<Void> reconcile(KubernetesClient client, StackGresDistributedLogsContext context) throws Exception {
    boolean statusUpdated = false;
    ReconciliationResult<Boolean> extensionReconciliationResult = extensionReconciliator.reconcile(client, context);
    if (extensionReconciliationResult.result().orElse(false) && context.getCluster().getStatus() != null && context.getCluster().getStatus().getPodStatuses() != null) {
        if (context.getDistributedLogs().getStatus() == null) {
            context.getDistributedLogs().setStatus(new StackGresDistributedLogsStatus());
        }
        context.getDistributedLogs().getStatus().setPodStatuses(context.getCluster().getStatus().getPodStatuses());
    }
    ReconciliationResult<Boolean> clusterReconciliationResult = clusterReconciliator.reconcile(client, context);
    statusUpdated = statusUpdated || clusterReconciliationResult.result().orElse(false);
    if (extensionReconciliationResult.result().orElse(false) || clusterReconciliationResult.result().orElse(false)) {
        distributedLogsScheduler.updateStatus(context.getDistributedLogs(), StackGresDistributedLogs::getStatus, StackGresDistributedLogs::setStatus);
    }
    return extensionReconciliationResult.join(clusterReconciliationResult);
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) StackGresDistributedLogsStatus(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatus) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with StackGresDistributedLogsStatus

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatus in project stackgres by ongres.

the class DistributedLogsTransformer method getResourceStatus.

private DistributedLogsStatus getResourceStatus(StackGresDistributedLogsStatus source, List<String> clusters) {
    DistributedLogsStatus transformation = new DistributedLogsStatus();
    transformation.setClusters(clusters);
    if (source == null) {
        return transformation;
    }
    final List<StackGresDistributedLogsCondition> sourceConditions = source.getConditions();
    if (sourceConditions != null) {
        transformation.setConditions(sourceConditions.stream().map(this::getResourceCondition).collect(ImmutableList.toImmutableList()));
    }
    return transformation;
}
Also used : StackGresDistributedLogsCondition(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsCondition) DistributedLogsStatus(io.stackgres.apiweb.dto.distributedlogs.DistributedLogsStatus) StackGresDistributedLogsStatus(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatus)

Aggregations

StackGresDistributedLogsStatus (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatus)3 StackGresDistributedLogs (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs)2 StackGresDistributedLogsCondition (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsCondition)2 ImmutableList (com.google.common.collect.ImmutableList)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 DistributedLogsStatus (io.stackgres.apiweb.dto.distributedlogs.DistributedLogsStatus)1 ClusterPendingRestartUtil (io.stackgres.common.ClusterPendingRestartUtil)1 RestartReason (io.stackgres.common.ClusterPendingRestartUtil.RestartReason)1 RestartReasons (io.stackgres.common.ClusterPendingRestartUtil.RestartReasons)1 KubernetesClientFactory (io.stackgres.common.KubernetesClientFactory)1 LabelFactoryForCluster (io.stackgres.common.LabelFactoryForCluster)1 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)1 DistributedLogsStatusCondition (io.stackgres.common.crd.sgdistributedlogs.DistributedLogsStatusCondition)1 StatusManager (io.stackgres.operator.conciliation.StatusManager)1 ConditionUpdater (io.stackgres.operatorframework.resource.ConditionUpdater)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1