use of io.kubernetes.client.openapi.models.V1ContainerState in project pravega by pravega.
the class K8sClient method createAWatchAndReturnOnTermination.
/**
* Create a Watch for a pod and return once the pod has terminated.
* @param namespace Namespace.
* @param podName Name of the pod.
* @return V1ContainerStateTerminated.
*/
@SneakyThrows({ ApiException.class, IOException.class })
private Optional<V1ContainerStateTerminated> createAWatchAndReturnOnTermination(String namespace, String podName) {
log.debug("Creating a watch for pod {}/{}", namespace, podName);
CoreV1Api api = new CoreV1Api();
K8AsyncCallback<V1ServiceAccount> callback = new K8AsyncCallback<>("createAWatchAndReturnOnTermination-" + podName);
@Cleanup Watch<V1Pod> watch = Watch.createWatch(client, api.listNamespacedPodCall(namespace, PRETTY_PRINT, ALLOW_WATCH_BOOKMARKS, null, null, "POD_NAME=" + podName, null, null, null, Boolean.TRUE, callback), new TypeToken<Watch.Response<V1Pod>>() {
}.getType());
for (Watch.Response<V1Pod> v1PodResponse : watch) {
List<V1ContainerStatus> containerStatuses = v1PodResponse.object.getStatus().getContainerStatuses();
log.debug("Container status for the pod {} is {}", podName, containerStatuses);
if (containerStatuses == null || containerStatuses.size() == 0) {
log.debug("Container status is not part of the pod {}/{}, wait for the next update from KUBERNETES Cluster", namespace, podName);
continue;
}
// We check only the first container as there is only one container in the pod.
V1ContainerState containerStatus = containerStatuses.get(0).getState();
log.debug("Current container status is {}", containerStatus);
if (containerStatus.getTerminated() != null) {
log.info("Pod {}/{} has terminated", namespace, podName);
return Optional.of(containerStatus.getTerminated());
}
}
return Optional.empty();
}
Aggregations