public boolean isTerminated(ContainerCreationStatus container) { Pod pod = client.pods().withName(container.getContainerName()).get(); if (pod == null) { logger.info("Container {} has no pod - terminal.", container); return true; } else { List<ContainerStatus> containerStatuses = pod.getStatus().getContainerStatuses(); Optional<ContainerStateTerminated> terminated = containerStatuses.stream() .flatMap(status -> Optional.ofNullable(status.getState()).map(Stream::of).orElse(Stream.empty())) .flatMap(state -> Optional.ofNullable(state.getTerminated()).map(Stream::of).orElse(Stream.empty())) .findFirst(); terminated.ifPresent(state -> logger.info("Container {} is {} - terminal.", container, state)); return terminated.isPresent(); } }
@Override public String getContainerIp(String containerName) { Pod pod = client.pods().withName(containerName).get(); if (pod != null) { String podIP = pod.getStatus().getPodIP(); logger.debug(String.format("Pod %s, IP -> %s", containerName, podIP)); return podIP; } else { return null; } }
public boolean isReady(ContainerCreationStatus container) { Pod pod = client.pods().withName(container.getContainerName()).get(); if (pod == null) { return false; } else { return pod.getStatus().getConditions().stream() .filter(condition -> condition.getType().equals("Ready")) .map(condition -> condition.getStatus().equals("True")) .findFirst() .orElse(false); } }
@Override public void contribute(Builder builder) { try { Pod current = utils.currentPod().get(); Map<String, Object> details = new HashMap<>(); if (current != null) { details.put("inside", true); details.put("namespace", current.getMetadata().getNamespace()); details.put("podName", current.getMetadata().getName()); details.put("podIp", current.getStatus().getPodIP()); details.put("serviceAccount", current.getSpec().getServiceAccountName()); details.put("nodeName", current.getSpec().getNodeName()); details.put("hostIp", current.getStatus().getHostIP()); } else { details.put("inside", false); } builder.withDetail("kubernetes", details); } catch (Exception e) { LOG.warn("Failed to get pod details", e); } } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = utils.currentPod().get(); if (current != null) { builder.up().withDetail("inside", true) .withDetail("namespace", current.getMetadata().getNamespace()) .withDetail("podName", current.getMetadata().getName()) .withDetail("podIp", current.getStatus().getPodIP()) .withDetail("serviceAccount", current.getSpec().getServiceAccountName()) .withDetail("nodeName", current.getSpec().getNodeName()) .withDetail("hostIp", current.getStatus().getHostIP()); } else { builder.up().withDetail("inside", false); } } catch (Exception e) { builder.down(e); } } }
/** * Returns the ready condition of the pod. * @param pod The target pod. * @return The {@link PodCondition} or null if not found. */ private static PodCondition getPodReadyCondition(Pod pod) { Utils.checkNotNull(pod, "Pod can't be null."); if (pod.getStatus() == null || pod.getStatus().getConditions() == null) { return null; } for (PodCondition condition : pod.getStatus().getConditions()) { if (POD_READY.equals(condition.getType())) { return condition; } } return null; }
public void run() { PodList podList = listSelectedPods(obj); int count = 0; List<Pod> items = podList.getItems(); for (Pod item : items) { for (PodCondition c : item.getStatus().getConditions()) { if (c.getType().equals("Ready") && c.getStatus().equals("True")) { count++; } } } podCount.set(count); if (count == requiredPodCount) { countDownLatch.countDown(); } } };
@Override public void eventReceived(Action action, Pod aPod) { log(aPod.getMetadata().getName(), aPod.getStatus().getPhase()); if(aPod.getStatus().getPhase().equals("Succeeded")) { log("Logs -> ", client.pods().inNamespace(namespace).withName(aPod.getMetadata().getName()).getLog()); watchLatch.countDown(); } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = utils.currentPod().get(); if (current != null) { builder.up() .withDetail("inside", true) .withDetail("namespace", current.getMetadata().getNamespace()) .withDetail("podName", current.getMetadata().getName()) .withDetail("podIp", current.getStatus().getPodIP()) .withDetail("serviceAccount", current.getSpec().getServiceAccountName()) .withDetail("nodeName", current.getSpec().getNodeName()) .withDetail("hostIp", current.getStatus().getHostIP()); } else { builder.up() .withDetail("inside", false); } } catch (Exception e) { builder.down(e); } } }
static String getPodPhase(Pod pod) { if (pod != null) { PodStatus podStatus = pod.getStatus(); if (podStatus != null) { String actualPhase = podStatus.getPhase(); return actualPhase != null ? actualPhase : ""; } } return ""; }
static Optional<ContainerStatus> getMainContainerStatus(Pod pod) { return readPodWorkflowInstance(pod) .flatMap(wfi -> pod.getStatus().getContainerStatuses().stream() .filter(status -> isMainContainer(status.getName(), pod)) .findAny()); }
private Node getNodeFromPod(Pod pod) { Map<String,String> labels = pod.getMetadata().getLabels(); PodStatus status = pod.getStatus(); Node node = new Node(labels.remove(Protocol.HOST_NAME),status.getPodIP()); node.getProperties().putAll(labels); return node; }
private boolean isValidPod(Pod pod) { return pod.getMetadata().getName().startsWith(nodeName) && pod.getStatus().getPhase().equals("Running") && hasIpOfLB(pod.getMetadata().getLabels().get(Protocol.LB_LABEL)); }
@Override public Boolean call() { PodList result = client.pods().inNamespace(namespace).withLabels(metadata).list(); return result.getItems().size() >= 1 && result.getItems().get(0).getStatus().getPodIP() != null; }
public Pod(io.fabric8.kubernetes.api.model.Pod pod) { this.name = pod.getMetadata().getName(); if (pod.getMetadata().getAnnotations() != null) { this.annotations.putAll(pod.getMetadata().getAnnotations()); } this.kind = pod.getKind(); this.host = pod.getStatus().getPodIP(); this.phase = pod.getStatus().getPhase(); this.ready = getReadyCondition(pod.getStatus().getConditions()); this.portMap = getPortMap(pod.getSpec().getContainers()); }
/*** * Returns pod ip * @param namespace * @param podName * @return string ip */ public String getPodIp(String namespace, String podName) { return client.pods().inNamespace(namespace).withName(podName).get().getStatus().getPodIP(); }
@Before public void setUp() { final PrometheusConfigurationProperties config = new PrometheusConfigurationProperties(); config.setService("syndesis-prometheus-syndesis.192.168.64.22.nip.io"); NamespacedOpenShiftClient openshiftClient = mock(NamespacedOpenShiftClient.class); when(openshiftClient.pods().withName("syndesis-server") .get() .getStatus() .getStartTime()).thenReturn("2018-03-14T23:34:09Z"); metricsProvider = new PrometheusMetricsProviderImpl(config, openshiftClient); }
public PodBuilder(PodFluent<?> fluent,Pod instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; } public PodBuilder(Pod instance){
public PodFluentImpl(Pod instance){ this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }