Search in sources :

Example 1 with PodCondition

use of io.fabric8.kubernetes.api.model.PodCondition in project strimzi-kafka-operator by strimzi.

the class ResourceManager method logCurrentResourceStatus.

/**
 * Log actual status of custom resource with pods.
 * @param customResource - Kafka, KafkaConnect etc. - every resource that HasMetadata and HasStatus (Strimzi status)
 */
public static <T extends CustomResource<? extends Spec, ? extends Status>> void logCurrentResourceStatus(T customResource) {
    if (customResource != null) {
        List<String> printWholeCR = Arrays.asList(KafkaConnector.RESOURCE_KIND, KafkaTopic.RESOURCE_KIND, KafkaUser.RESOURCE_KIND);
        String kind = customResource.getKind();
        String name = customResource.getMetadata().getName();
        if (printWholeCR.contains(kind)) {
            LOGGER.info(customResource);
        } else {
            List<String> log = new ArrayList<>(asList(kind, " status:\n", "\nConditions:\n"));
            if (customResource.getStatus() != null) {
                List<Condition> conditions = customResource.getStatus().getConditions();
                if (conditions != null) {
                    for (Condition condition : customResource.getStatus().getConditions()) {
                        if (condition.getMessage() != null) {
                            log.add("\tType: " + condition.getType() + "\n");
                            log.add("\tMessage: " + condition.getMessage() + "\n");
                        }
                    }
                }
                log.add("\nPods with conditions and messages:\n\n");
                for (Pod pod : kubeClient().namespace(customResource.getMetadata().getNamespace()).listPodsByPrefixInName(name)) {
                    log.add(pod.getMetadata().getName() + ":");
                    for (PodCondition podCondition : pod.getStatus().getConditions()) {
                        if (podCondition.getMessage() != null) {
                            log.add("\n\tType: " + podCondition.getType() + "\n");
                            log.add("\tMessage: " + podCondition.getMessage() + "\n");
                        } else {
                            log.add("\n\tType: <EMPTY>\n");
                            log.add("\tMessage: <EMPTY>\n");
                        }
                    }
                    log.add("\n\n");
                }
                LOGGER.info("{}", String.join("", log).strip());
            }
        }
    }
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) PodCondition(io.fabric8.kubernetes.api.model.PodCondition) Pod(io.fabric8.kubernetes.api.model.Pod) ArrayList(java.util.ArrayList) PodCondition(io.fabric8.kubernetes.api.model.PodCondition)

Example 2 with PodCondition

use of io.fabric8.kubernetes.api.model.PodCondition in project strimzi-kafka-operator by strimzi.

the class DeploymentUtils method logCurrentDeploymentStatus.

/**
 * Log actual status of deployment with pods
 * @param deployment - every Deployment, that HasMetadata and has status (fabric8 status)
 */
public static void logCurrentDeploymentStatus(Deployment deployment, String namespaceName) {
    if (deployment != null) {
        String kind = deployment.getKind();
        String name = deployment.getMetadata().getName();
        List<String> log = new ArrayList<>(asList("\n", kind, " status:\n", "\nConditions:\n"));
        for (DeploymentCondition deploymentCondition : deployment.getStatus().getConditions()) {
            log.add("\tType: " + deploymentCondition.getType() + "\n");
            log.add("\tMessage: " + deploymentCondition.getMessage() + "\n");
        }
        if (kubeClient(namespaceName).listPodsByPrefixInName(name).size() != 0) {
            log.add("\nPods with conditions and messages:\n\n");
            for (Pod pod : kubeClient(namespaceName).listPodsByPrefixInName(name)) {
                log.add(pod.getMetadata().getName() + ":");
                for (PodCondition podCondition : pod.getStatus().getConditions()) {
                    if (podCondition.getMessage() != null) {
                        log.add("\n\tType: " + podCondition.getType() + "\n");
                        log.add("\tMessage: " + podCondition.getMessage() + "\n");
                    }
                }
                log.add("\n\n");
            }
            LOGGER.info("{}", String.join("", log));
        }
        LOGGER.info("{}", String.join("", log));
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) ArrayList(java.util.ArrayList) PodCondition(io.fabric8.kubernetes.api.model.PodCondition) DeploymentCondition(io.fabric8.kubernetes.api.model.apps.DeploymentCondition)

Example 3 with PodCondition

use of io.fabric8.kubernetes.api.model.PodCondition in project fabric8-maven-plugin by fabric8io.

the class KubernetesClientUtil method getPodCondition.

protected static String getPodCondition(Pod pod) {
    PodStatus podStatus = pod.getStatus();
    if (podStatus == null) {
        return "";
    }
    List<PodCondition> conditions = podStatus.getConditions();
    if (conditions == null || conditions.isEmpty()) {
        return "";
    }
    for (PodCondition condition : conditions) {
        String type = condition.getType();
        if (Strings.isNotBlank(type)) {
            if ("ready".equalsIgnoreCase(type)) {
                String statusText = condition.getStatus();
                if (Strings.isNotBlank(statusText)) {
                    if (Boolean.parseBoolean(statusText)) {
                        return type;
                    }
                }
            }
        }
    }
    return "";
}
Also used : PodStatus(io.fabric8.kubernetes.api.model.PodStatus) PodCondition(io.fabric8.kubernetes.api.model.PodCondition)

Example 4 with PodCondition

use of io.fabric8.kubernetes.api.model.PodCondition in project fabric8-maven-plugin by fabric8io.

the class KubernetesHelper method isPodReady.

/**
 * Returns true if the pod is running and ready
 */
public static boolean isPodReady(Pod pod) {
    if (!isPodRunning(pod)) {
        return false;
    }
    PodStatus podStatus = pod.getStatus();
    if (podStatus == null) {
        return true;
    }
    List<PodCondition> conditions = podStatus.getConditions();
    if (conditions == null || conditions.isEmpty()) {
        return true;
    }
    // Check "ready" condition
    for (PodCondition condition : conditions) {
        if ("ready".equalsIgnoreCase(condition.getType())) {
            return Boolean.parseBoolean(condition.getStatus());
        }
    }
    return true;
}
Also used : PodStatus(io.fabric8.kubernetes.api.model.PodStatus) PodCondition(io.fabric8.kubernetes.api.model.PodCondition)

Example 5 with PodCondition

use of io.fabric8.kubernetes.api.model.PodCondition in project fabric8-maven-plugin by fabric8io.

the class KubernetesClientUtil method getPodCondition.

protected static String getPodCondition(Pod pod) {
    PodStatus podStatus = pod.getStatus();
    if (podStatus == null) {
        return "";
    }
    List<PodCondition> conditions = podStatus.getConditions();
    if (conditions == null || conditions.isEmpty()) {
        return "";
    }
    for (PodCondition condition : conditions) {
        String type = condition.getType();
        if (StringUtils.isNotBlank(type)) {
            if ("ready".equalsIgnoreCase(type)) {
                String statusText = condition.getStatus();
                if (StringUtils.isNotBlank(statusText)) {
                    if (Boolean.parseBoolean(statusText)) {
                        return type;
                    }
                }
            }
        }
    }
    return "";
}
Also used : PodStatus(io.fabric8.kubernetes.api.model.PodStatus) PodCondition(io.fabric8.kubernetes.api.model.PodCondition)

Aggregations

PodCondition (io.fabric8.kubernetes.api.model.PodCondition)8 Pod (io.fabric8.kubernetes.api.model.Pod)5 PodStatus (io.fabric8.kubernetes.api.model.PodStatus)4 ArrayList (java.util.ArrayList)4 DeploymentCondition (io.fabric8.kubernetes.api.model.apps.DeploymentCondition)2 Condition (io.strimzi.api.kafka.model.status.Condition)2 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)1 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)1 CurrentThreadExecutorService (com.epam.pipeline.util.CurrentThreadExecutorService)1 KubernetesTestUtils (com.epam.pipeline.util.KubernetesTestUtils)1 DoneableNode (io.fabric8.kubernetes.api.model.DoneableNode)1 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)1 Node (io.fabric8.kubernetes.api.model.Node)1 NodeList (io.fabric8.kubernetes.api.model.NodeList)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 Config (io.fabric8.kubernetes.client.Config)1 PodResource (io.fabric8.kubernetes.client.dsl.PodResource)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1 Before (org.junit.Before)1