Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Add pod readiness check #5595

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Boolean call() throws Exception {
}

for (Pod pod : pods) {
result = result && Objects.equal(PodStatusType.OK, KubernetesHelper.getPodStatus(pod));
result = result && KubernetesHelper.isPodReady(pod);
if (!result) {
PodStatus podStatus = pod.getStatus();
if (podStatus != null) {
Expand All @@ -59,9 +59,11 @@ public Boolean call() throws Exception {
ContainerState state = containerStatus.getState();
if (state != null) {
ContainerStateWaiting waiting = state.getWaiting();
String containerName = containerStatus.getName();
if (waiting != null) {
String containerName = containerStatus.getName();
session.getLogger().warn("Waiting for container:" + containerName + ". Reason:" + waiting.getReason());
} else {
session.getLogger().warn("Waiting for container:" + containerName + ".");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.fabric8.kubernetes.api.model.KubernetesResource;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodCondition;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.api.model.PodSpec;
import io.fabric8.kubernetes.api.model.PodStatus;
Expand Down Expand Up @@ -1430,6 +1431,34 @@ public static boolean isPodRunning(Pod pod) {
return Objects.equal(status, PodStatusType.OK);
}

/**
* 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;
}

public static String getPodStatusText(Pod pod) {
if (pod != null) {
PodStatus podStatus = pod.getStatus();
Expand Down