/** * Awaits at most 5 minutes until all pods meets the given predicate. * * @param filter used to wait to detect that a pod is up and running. */ public void awaitPodReadinessOrFail(Predicate<Pod> filter) { await().atMost(5, TimeUnit.MINUTES).until(() -> { List<Pod> list = client.pods().inNamespace(namespace).list().getItems(); return list.stream() .filter(filter) .filter(Readiness::isPodReady) .collect(Collectors.toList()).size() >= 1; } ); }
/** * Awaits at most 5 minutes until all pods meets the given predicate. * * @param filter used to wait to detect that a pod is up and running. */ public void awaitPodReadinessOrFail(Predicate<Pod> filter) { await().atMost(5, TimeUnit.MINUTES).until(() -> { List<Pod> list = client.pods().inNamespace(namespace).list().getItems(); return list.stream() .filter(filter) .filter(Readiness::isPodReady) .collect(Collectors.toList()).size() >= 1; } ); }
protected List<Pod> getPods(String label) { return this.client .pods() .inNamespace(this.namespace) .withLabel(label, this.applicationName) .list() .getItems(); }
public String getLog(String prefix, Map<String, String> labels) throws Exception { List<Pod> pods; NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> allPods = client.pods().inNamespace(configuration.getNamespace()); if (labels == null) { pods = allPods.list().getItems(); } else { pods = allPods.withLabels(labels).list().getItems(); } String actualName; if (prefix != null) { actualName = getActualName(prefix, pods, String.format("No pod found starting with '%s' and labels %s.", prefix, labels)); } else { if (pods.isEmpty()) { throw new Exception("No pod found with labels " + labels); } actualName = pods.get(0).getMetadata().getName(); } return getLog(actualName); }
protected List<Pod> getPods(String label) { return this.client .pods() .inNamespace(this.namespace) .withLabel(label, this.applicationName) .list() .getItems(); }
public void cleanPods(Map<String, String> labels) throws Exception { final PodList pods = client.pods().inNamespace(configuration.getNamespace()).withLabels(labels).list(); try { for (Pod pod : pods.getItems()) { String podId = getName(pod.getMetadata()); boolean exists = client.pods().inNamespace(configuration.getNamespace()).withName(podId).delete(); log.info(String.format("Pod [%s] delete: %s.", podId, exists)); } } catch (Exception e) { log.log(Level.WARNING, String.format("Exception while deleting pod [%s]: %s", labels, e), e); } }
protected List<Pod> getPods(Map<String, String> labels) { return client.pods().inNamespace(configuration.getNamespace()).withLabels(labels).list().getItems(); }
public String exec(Map<String, String> labels, int waitSeconds, String... input) throws Exception { List<Pod> pods = client.inAnyNamespace().pods().withLabels(labels).list().getItems(); if (pods.isEmpty()) { throw new IllegalStateException("No such pod: " + labels); } Pod targetPod = pods.get(0); ByteArrayOutputStream output = new ByteArrayOutputStream(); client.inNamespace(targetPod.getMetadata().getNamespace()).pods().withName(targetPod.getMetadata().getName()) .readingInput(System.in) .writingOutput(output) .writingError(System.err) .withTTY() .usingListener(new SimpleListener()) .exec(input); Thread.sleep(waitSeconds * 1000); output.flush(); return output.toString(); }
public List<String> getPods(String prefix) throws Exception { PodList pods; if (prefix == null) { pods = client.pods().inNamespace(configuration.getNamespace()).list(); } else { pods = client.pods().inNamespace(configuration.getNamespace()).withLabels(getLabels(prefix)).list(); } List<String> podNames = new ArrayList<>(); for (Pod pod : pods.getItems()) { podNames.add(pod.getMetadata().getName()); } return podNames; }
@Override public Object lookup(ArquillianResource resource, Annotation... qualifiers) { String name = getName(qualifiers); String namespace = getNamespace(qualifiers); if (name != null) { return getClient().pods().inNamespace(namespace).withName(name).get(); } // Gets the first pod found that matches the labels. Map<String, String> labels = getLabels(qualifiers); PodList list = getClient().pods().inNamespace(namespace).withLabels(labels).list(); List<Pod> pods = list.getItems(); if( !pods.isEmpty() ) { return pods.get(0); } return null; } }
@Override public Object lookup(ArquillianResource resource, Annotation... qualifiers) { String name = getName(qualifiers); String namespace = getNamespace(qualifiers); if (name != null) { return getClient().pods().inNamespace(namespace).withName(name).get(); } // Gets the first pod found that matches the labels. Map<String, String> labels = getLabels(qualifiers); PodList list = getClient().pods().inNamespace(namespace).withLabels(labels).list(); List<Pod> pods = list.getItems(); if( !pods.isEmpty() ) { return pods.get(0); } return null; } }
@Override public <T extends HasMetadata> void onResourceNotReady(T resource) { try { PodList podList = podsOf(resource); if (podList == null) { return; } for (Pod pod : podList.getItems()) { //That should only happen in tests. if (pod.getSpec() == null || pod.getSpec().getContainers() == null) { continue; } displayPodEvents(pod); for (Container container : pod.getSpec().getContainers()) { displayContainerLogs(pod, container); } } } catch (Throwable t) { //ignore } }
@Override public <T extends HasMetadata> void onResourceNotReady(T resource) { try { PodList podList = podsOf(resource); if (podList == null) { return; } for (Pod pod : podList.getItems()) { //That should only happen in tests. if (pod.getSpec() == null || pod.getSpec().getContainers() == null) { continue; } displayPodEvents(pod); for (Container container : pod.getSpec().getContainers()) { displayContainerLogs(pod, container); } } } catch (Throwable t) { //ignore } }
for (Pod pod : podList.getItems()) { session.getLogger() .info("Pod: [" + pod.getMetadata().getName() + "] Status: [" + pod.getStatus().getPhase() + "]");
@Test public void should_deploy_app_programmatically() throws IOException { openShiftAssistant.deployApplication("hello-openshift-deployment-config", "deployment.yml"); openShiftAssistant.awaitApplicationReadinessOrFail(); List<Pod> pods = openShiftAssistant.getClient() .pods() .inNamespace(openShiftAssistant.getCurrentProjectName()) .withLabel("name", "hello-openshift-deployment-config") .list() .getItems(); assertThat(pods.size()).isGreaterThan(1); assertThat(pods).allMatch(Readiness::isPodReady); }
for (Pod pod : podList.getItems()) { session.getLogger() .info("Pod: [" + pod.getMetadata().getName() + "] Status: [" + pod.getStatus().getPhase() + "]");
private List<Pod> podsByLabelName(final String podLabelName) { return openShiftAssistant.getClient() .pods() .inNamespace(openShiftAssistant.getCurrentProjectName()) .withLabel("name", podLabelName) .list() .getItems(); }