use of io.fabric8.kubernetes.api.model.PodList in project fabric8-maven-plugin by fabric8io.
the class BaseBoosterIT method waitTillApplicationPodStarts.
/**
* This variation is used in order to check for the redeployment scenario, since some
* annotations are added while making changes in source code, and those are checked so
* that we are able to differentiate between the redeployed pod and the previously
* existing pod instance from previous deployment.
*
* @param key
* @param value
* @throws Exception
*/
protected void waitTillApplicationPodStarts(String key, String value) throws InterruptedException {
logger.info("Waiting for application pod .... ");
int nPolls = 0;
// Keep polling till 5 minutes
while (nPolls < APPLICATION_POD_WAIT_POLLS) {
PodList podList = openShiftClient.pods().withLabel("app", testsuiteRepositoryArtifactId).list();
for (Pod pod : podList.getItems()) {
logger.info("waitTillApplicationPodStarts(" + key + ", " + value + ") -> Pod : " + pod.getMetadata().getName() + ", STATUS : " + KubernetesHelper.getPodStatus(pod) + ", isPodReady : " + KubernetesHelper.isPodReady(pod));
if (pod.getMetadata().getAnnotations().containsKey(key)) {
logger.info(pod.getMetadata().getName() + " is redeployed pod.");
}
if (pod.getMetadata().getAnnotations().containsKey(key) && pod.getMetadata().getAnnotations().get(key).equalsIgnoreCase(value) && KubernetesHelper.isPodReady(pod)) {
logger.info("OK ✓ ... Pod wait over.");
TimeUnit.SECONDS.sleep(10);
return;
}
}
nPolls++;
TimeUnit.SECONDS.sleep(10);
}
throw new AssertionError("Pod wait timeout! Could not find application pod for " + testsuiteRepositoryArtifactId);
}
use of io.fabric8.kubernetes.api.model.PodList in project zalenium by zalando.
the class KubernetesContainerClient method registerNode.
@Override
public ContainerClientRegistration registerNode(String zaleniumContainerName, URL remoteHost) {
String podIpAddress = remoteHost.getHost();
// The only way to lookup a pod name by IP address is by looking at all pods in the namespace it seems.
PodList list = client.pods().withLabels(createdByZaleniumMap).list();
String containerId = null;
Pod currentPod = null;
for (Pod pod : list.getItems()) {
if (podIpAddress.equals(pod.getStatus().getPodIP())) {
containerId = pod.getMetadata().getName();
currentPod = pod;
break;
}
}
if (containerId == null) {
throw new IllegalStateException("Unable to locate pod by ip address, registration will fail");
}
ContainerClientRegistration registration = new ContainerClientRegistration();
List<EnvVar> podEnvironmentVariables = currentPod.getSpec().getContainers().get(0).getEnv();
Optional<EnvVar> noVncPort = podEnvironmentVariables.stream().filter(env -> "NOVNC_PORT".equals(env.getName())).findFirst();
if (noVncPort.isPresent()) {
Integer noVncPortInt = Integer.decode(noVncPort.get().getValue());
registration.setNoVncPort(noVncPortInt);
} else {
logger.warn(String.format("%s Couldn't find NOVNC_PORT, live preview will not work.", containerId));
}
registration.setIpAddress(currentPod.getStatus().getPodIP());
registration.setContainerId(containerId);
return registration;
}
use of io.fabric8.kubernetes.api.model.PodList in project fabric8 by fabric8io.
the class ExampleTest method testNavigationListAssertions.
@Test
public void testNavigationListAssertions() throws Exception {
final String id1 = "abc";
final String id2 = "def";
Map<String, String> labels1 = new HashMap<>();
labels1.put("foo", "bar");
Map<String, String> labels2 = new HashMap<>();
labels2.put("whatnot", "cheese");
final Pod pod1 = new Pod();
pod1.setMetadata(new ObjectMeta());
pod1.getMetadata().setName(id1);
pod1.getMetadata().setLabels(labels1);
final Pod pod2 = new Pod();
pod2.setMetadata(new ObjectMeta());
pod2.getMetadata().setName(id2);
pod2.getMetadata().setLabels(labels2);
final PodList emptyPodList = new PodList();
final PodList podList = new PodList();
podList.setItems(new ArrayList<Pod>(Arrays.asList(pod1, pod2)));
assertThat(emptyPodList).describedAs("emptyPodList").items().isEmpty();
assertThat(podList).describedAs("podListWith2Items").items().first().metadata().name().isEqualTo(id1);
assertThat(podList).describedAs("podListWith2Items").items().last().metadata().name().isEqualTo(id2);
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
assertThat(podList).describedAs("podListWith2Items").items().item(-1).isNotNull();
}
});
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
assertThat(podList).describedAs("podListWith2Items").items().item(2).isNotNull();
}
});
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
assertThat(podList).describedAs("podListWith2Items").items().first().metadata().name().isEqualTo("shouldNotMatch");
}
});
}
use of io.fabric8.kubernetes.api.model.PodList in project fabric8 by fabric8io.
the class Example method listPods.
protected static void listPods(KubernetesClient kube) {
System.out.println("\n\nLooking up pods");
System.out.println("=========================================================================");
PodList pods = kube.pods().list();
// System.out.println("Got pods: " + pods);
List<Pod> items = pods.getItems();
for (Pod item : items) {
System.out.println("Pod " + KubernetesHelper.getName(item) + " with ip: " + item.getStatus().getPodIP() + " created: " + item.getMetadata().getCreationTimestamp());
PodSpec spec = item.getSpec();
if (spec != null) {
List<Container> containers = spec.getContainers();
if (containers != null) {
for (Container container : containers) {
System.out.println("Container " + container.getImage() + " " + container.getCommand() + " ports: " + container.getPorts());
}
}
}
Map<String, ContainerStatus> currentContainers = KubernetesHelper.getCurrentContainers(item);
System.out.println("Has " + currentContainers.size() + " container(s)");
Set<Map.Entry<String, ContainerStatus>> entries = currentContainers.entrySet();
for (Map.Entry<String, ContainerStatus> entry : entries) {
String id = entry.getKey();
ContainerStatus info = entry.getValue();
System.out.println("Current container: " + id + " info: " + info);
}
}
System.out.println();
}
use of io.fabric8.kubernetes.api.model.PodList in project fabric8 by fabric8io.
the class PodResourceProvider method lookup.
@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
KubernetesClient client = this.clientInstance.get();
Session session = sessionInstance.get();
String name = getPodName(qualifiers);
if (name != null) {
return client.pods().inNamespace(session.getNamespace()).withName(name).get();
}
// Gets the first pod found that matches the labels.
Map<String, String> labels = getLabels(qualifiers);
PodList list = client.pods().inNamespace(session.getNamespace()).withLabels(labels).list();
List<Pod> pods = notNullList(list.getItems());
if (!pods.isEmpty()) {
return pods.get(0);
}
return null;
}
Aggregations