Search in sources :

Example 1 with RestartReasons

use of io.stackgres.common.ClusterPendingRestartUtil.RestartReasons 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 RestartReasons

use of io.stackgres.common.ClusterPendingRestartUtil.RestartReasons in project stackgres by ongres.

the class ClusterStatusManager method isPendingRestart.

/**
 * Check pending restart status condition.
 */
public boolean isPendingRestart(StackGresCluster cluster) {
    List<StackGresClusterPodStatus> clusterPodStatuses = Optional.ofNullable(cluster.getStatus()).map(StackGresClusterStatus::getPodStatuses).orElse(ImmutableList.of());
    Optional<StatefulSet> clusterStatefulSet = getClusterStatefulSet(cluster);
    List<Pod> clusterPods = clusterStatefulSet.map(sts -> getStsPods(sts, cluster)).orElse(ImmutableList.of());
    RestartReasons reasons = ClusterPendingRestartUtil.getRestartReasons(clusterPodStatuses, clusterStatefulSet, clusterPods);
    for (RestartReason reason : reasons.getReasons()) {
        switch(reason) {
            case OPERATOR_VERSION:
                LOGGER.debug("Cluster {} requires restart due to operator version change", getClusterId(cluster));
                break;
            case PATRONI:
                LOGGER.debug("Cluster {} requires restart due to patroni's indication", getClusterId(cluster));
                break;
            case POD_STATUS:
                LOGGER.debug("Cluster {} requires restart due to pod status indication", getClusterId(cluster));
                break;
            case STATEFULSET:
                LOGGER.debug("Cluster {} requires restart due to pod template changes", getClusterId(cluster));
                break;
            default:
                break;
        }
    }
    return reasons.requiresRestart();
}
Also used : StatusManager(io.stackgres.operator.conciliation.StatusManager) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) LoggerFactory(org.slf4j.LoggerFactory) ConditionUpdater(io.stackgres.operatorframework.resource.ConditionUpdater) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) StackGresClusterCondition(io.stackgres.common.crd.sgcluster.StackGresClusterCondition) Map(java.util.Map) KubernetesClientFactory(io.stackgres.common.KubernetesClientFactory) StackGresClusterPodStatus(io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) RestartReasons(io.stackgres.common.ClusterPendingRestartUtil.RestartReasons) 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) ClusterStatusCondition(io.stackgres.common.crd.sgcluster.ClusterStatusCondition) 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)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 ClusterPendingRestartUtil (io.stackgres.common.ClusterPendingRestartUtil)2 RestartReason (io.stackgres.common.ClusterPendingRestartUtil.RestartReason)2 RestartReasons (io.stackgres.common.ClusterPendingRestartUtil.RestartReasons)2 KubernetesClientFactory (io.stackgres.common.KubernetesClientFactory)2 LabelFactoryForCluster (io.stackgres.common.LabelFactoryForCluster)2 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)2 StatusManager (io.stackgres.operator.conciliation.StatusManager)2 ConditionUpdater (io.stackgres.operatorframework.resource.ConditionUpdater)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2