Java Code Examples for io.fabric8.kubernetes.api.model.PodStatus#getConditions()

The following examples show how to use io.fabric8.kubernetes.api.model.PodStatus#getConditions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubernetesClientUtil.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
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 "";
}
 
Example 2
Source File: KubernetesHelper.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns true if the pod is running and ready
 *
 * @param pod Pod object
 * @return boolean value indicating it's status
 */
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;
}
 
Example 3
Source File: KubeCloudInstanceImpl.java    From teamcity-kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public Date getStartedTime() {
    final PodStatus podStatus = myPod.getStatus();
    if(podStatus == null) return myCreationTime;
    try {
        final List<PodCondition> podConditions = podStatus.getConditions();
        if (podConditions != null && !podConditions.isEmpty()) {
            for (PodCondition podCondition : podConditions) {
                if (PodConditionType.valueOf(podCondition.getType()) == PodConditionType.Ready)
                    return myPodTransitionTimeFormat.parse(podCondition.getLastTransitionTime());
            }
        }
        String startTime = podStatus.getStartTime();
        return !StringUtil.isEmpty(startTime) ? myPodStartTimeFormat.parse(startTime) : myCreationTime;
    } catch (ParseException e) {
        throw new KubeCloudException("Failed to get instance start date", e);
    }
}