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); } }
private synchronized Pod internalGetPod() { try { if (isServiceAccountFound() && isHostNameEnvVarPresent()) { return client.pods().withName(hostName).get(); } else { return null; } } catch (Throwable t) { LOG.warn("Failed to get pod with name:[" + hostName + "]. You should look into this if things aren't working as you expect. Are you missing serviceaccount permissions?", t); return null; } }
zaleniumPod = client.pods().withName(hostname).get();
private synchronized Pod internalGetPod() { try { if (isServiceAccountFound() && isHostNameEnvVarPresent()) { return client.pods().withName(hostName).get(); } else { return null; } } catch (Throwable t) { LOGGER.warn("Failed to get pod with name:[" + hostName + "]. You should look into this if things aren't working as you expect. Are you missing serviceaccount permissions?", t); return null; } }
client.pods().inNamespace("test").withName("testing").get() );
String namespace = "default"; log("namespace", namespace); Pod pod = client.pods().inNamespace(namespace).load(PodPresetExamples.class.getResourceAsStream("/pod-preset-example.yml")).get(); log("Pod created"); client.pods().inNamespace(namespace).create(pod); client.settings().podPresets().inNamespace(namespace).create(podPreset); pod = client.pods().inNamespace(namespace).withName(pod.getMetadata().getName()).get(); log("Updated pod: "); log(SerializationUtils.dumpAsYaml(pod));
private void processPodUpdate(String podName, WorkflowInstance instance) { LOG.debug("Processing pod update: {}: {}", podName, instance); final Pod pod = client.pods().withName(podName).get(); if (pod == null) { return; } final Optional<RunState> runState = lookupPodRunState(pod, instance); if (!runState.isPresent()) { return; } emitPodEvents(pod, runState.get()); }
protected Pod getPod(String podName) { return client.pods().withName(podName).get(); }
public Pod getPod(String name) { return client.pods().withName(name).get(); }
private synchronized Pod internalGetPod() { try { if (isServiceAccountFound() && isHostNameEnvVarPresent()) { return client.pods().withName(hostName).get(); } else { return null; } } catch (Throwable t) { LOGGER.warn("Failed to get pod with name:[" + hostName + "]. You should look into this if things aren't working as you expect. Are you missing serviceaccount permissions?", t); return null; } }
protected boolean isPodRunning(String name) { Pod pod = client.pods().withName(name).get(); if (pod == null) { return false; } return "Running".equals(pod.getStatus().getPhase()); }
private synchronized Pod internalGetPod() { try { if (isServiceAccountFound() && isHostNameEnvVarPresent()) { return client.pods().withName(hostName).get(); } else { return null; } } catch (Throwable t) { LOG.warn("Failed to get pod with name:[" + hostName + "]. You should look into this if things aren't working as you expect. Are you missing serviceaccount permissions?", t); return null; } }
private void refreshAndDeleteNonTerminatedPodWithoutRunState(WorkflowInstance workflowInstance, String name) { // Fetch the pod here to avoid acting on stale information final Pod pod = client.pods().withName(name).get(); if (pod == null) { // The pod is gone, nothing left to do here return; } // if not terminated, delete directly if (!isTerminated(pod)) { deletePod(workflowInstance, pod, "No RunState, not terminated"); } }
public static Pod parseFromYaml(String yaml) { try (KubernetesClient client = new DefaultKubernetesClient()) { Pod podFromYaml = client.pods().load(new ByteArrayInputStream((yaml == null ? "" : yaml).getBytes(UTF_8))) .get(); LOGGER.log(Level.FINEST, "Parsed pod template from yaml: {0}", podFromYaml); // yaml can be just a fragment, avoid NPEs if (podFromYaml.getMetadata() == null) { podFromYaml.setMetadata(new ObjectMeta()); } if (podFromYaml.getSpec() == null) { podFromYaml.setSpec(new PodSpec()); } return podFromYaml; } }
/*** * 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(); }
/*** * Returns list of running containers in pod * @param podName name of pod * @return list of containers */ public List<Container> getContainersFromPod(String podName) { return client.pods().inNamespace(globalNamespace).withName(podName).get().getSpec().getContainers(); }
@Override Pod getCurrentResource() { return client .pods() .inNamespace(getNamespace()) .withName(getName()) .get(); }
@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); }