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

The following examples show how to use io.fabric8.kubernetes.api.model.PodStatus#getContainerStatuses() . 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: PodWatcher.java    From data-highway with Apache License 2.0 6 votes vote down vote up
@Override
public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action action, Pod pod) {
  log.info("Event received for pod: {}, action: {}", podName, action);
  PodStatus status = pod.getStatus();
  List<ContainerStatus> containerStatuses = status.getContainerStatuses();
  if (!containerStatuses.isEmpty()) {
    ContainerStatus containerStatus = containerStatuses.get(0);
    ContainerState state = containerStatus.getState();
    ContainerStateTerminated terminated = state.getTerminated();
    if (terminated != null) {
      Integer exitCode = terminated.getExitCode();
      log.info("Container exit code for pod {}: {}", podName, exitCode);
      if (exitCode == 0) {
        exitCodeFuture.complete(0);
      } else {
        exitCodeFuture.completeExceptionally(new RuntimeException("Completed with non zero exit code: " + exitCode));
      }
      resource.delete();
      watch.close();
    } else {
      log.warn("ContainerStateTerminated was null for pod: {}, action {}", podName, action);
    }
  } else {
    log.warn("ContainerStatus list was empty for pod: {}, action {}", podName, action);
  }
}
 
Example 2
Source File: KubernetesResourceUtil.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
public static String getDockerContainerID(Pod pod) {
    PodStatus status = pod.getStatus();
    if (status != null) {
        List<ContainerStatus> containerStatuses = status.getContainerStatuses();
        if (containerStatuses != null) {
            for (ContainerStatus containerStatus : containerStatuses) {
                String containerID = containerStatus.getContainerID();
                if (StringUtils.isNotBlank(containerID)) {
                    String prefix = "://";
                    int idx = containerID.indexOf(prefix);
                    if (idx > 0) {
                        return containerID.substring(idx + prefix.length());
                    }
                    return containerID;
                }
            }
        }
    }
    return null;
}
 
Example 3
Source File: PodUtils.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
public static List<ContainerStatus> getContainerStatus(Pod pod) {
    PodStatus podStatus = pod.getStatus();
    if (podStatus == null) {
        return Collections.emptyList();
    }
    return podStatus.getContainerStatuses();
}