use of io.fabric8.kubernetes.api.model.PodList in project fabric8 by jboss-fuse.
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;
}
use of io.fabric8.kubernetes.api.model.PodList in project che by eclipse.
the class OpenShiftConnector method getChePodByContainerId.
private Pod getChePodByContainerId(String containerId) throws IOException {
PodList pods = openShiftClient.pods().inNamespace(this.openShiftCheProjectName).withLabel(CHE_CONTAINER_IDENTIFIER_LABEL_KEY, KubernetesStringUtils.getLabelFromContainerID(containerId)).list();
List<Pod> items = pods.getItems();
if (items.isEmpty()) {
LOG.error("An OpenShift Pod with label {}={} could not be found", CHE_CONTAINER_IDENTIFIER_LABEL_KEY, containerId);
throw new IOException("An OpenShift Pod with label " + CHE_CONTAINER_IDENTIFIER_LABEL_KEY + "=" + containerId + " could not be found");
}
if (items.size() > 1) {
LOG.error("There are {} pod with label {}={} (just one was expeced)", items.size(), CHE_CONTAINER_IDENTIFIER_LABEL_KEY, containerId);
throw new IOException("There are " + items.size() + " pod with label " + CHE_CONTAINER_IDENTIFIER_LABEL_KEY + "=" + containerId + " (just one was expeced)");
}
return items.get(0);
}
use of io.fabric8.kubernetes.api.model.PodList in project che by eclipse.
the class OpenShiftConnector method inspectNetwork.
@Override
public Network inspectNetwork(InspectNetworkParams params) throws IOException {
String netId = params.getNetworkId();
ServiceList services = openShiftClient.services().inNamespace(this.openShiftCheProjectName).list();
Map<String, ContainerInNetwork> containers = new HashMap<>();
for (Service svc : services.getItems()) {
String selector = svc.getSpec().getSelector().get(OPENSHIFT_DEPLOYMENT_LABEL);
if (selector == null || !selector.startsWith(CHE_OPENSHIFT_RESOURCES_PREFIX)) {
continue;
}
PodList pods = openShiftClient.pods().inNamespace(openShiftCheProjectName).withLabel(OPENSHIFT_DEPLOYMENT_LABEL, selector).list();
for (Pod pod : pods.getItems()) {
String podName = pod.getMetadata().getName();
ContainerInNetwork container = new ContainerInNetwork().withName(podName).withIPv4Address(svc.getSpec().getClusterIP());
String podId = KubernetesStringUtils.getLabelFromContainerID(pod.getMetadata().getLabels().get(CHE_CONTAINER_IDENTIFIER_LABEL_KEY));
if (podId == null) {
continue;
}
containers.put(podId, container);
}
}
List<IpamConfig> ipamConfig = new ArrayList<>();
Ipam ipam = new Ipam().withDriver("bridge").withOptions(Collections.emptyMap()).withConfig(ipamConfig);
return new Network().withName("OpenShift").withId(netId).withContainers(containers).withLabels(Collections.emptyMap()).withOptions(Collections.emptyMap()).withDriver("default").withIPAM(ipam).withScope("local").withInternal(false).withEnableIPv6(false);
}
use of io.fabric8.kubernetes.api.model.PodList in project camel by apache.
the class KubernetesPodsProducer method doList.
protected void doList(Exchange exchange, String operation) throws Exception {
PodList podList = getEndpoint().getKubernetesClient().pods().list();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(podList.getItems());
}
use of io.fabric8.kubernetes.api.model.PodList in project fabric8-maven-plugin by fabric8io.
the class DebugMojo method waitForRunningPodWithEnvVar.
private String waitForRunningPodWithEnvVar(final KubernetesClient kubernetes, final String namespace, LabelSelector selector, final Map<String, String> envVars) throws MojoExecutionException {
// wait for the newest pod to be ready with the given env var
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> pods = withSelector(kubernetes.pods().inNamespace(namespace), selector, log);
log.info("Waiting for debug pod with selector " + selector + " and environment variables " + envVars);
podWaitLog = createExternalProcessLogger("[[Y]][W][[Y]] ");
PodList list = pods.list();
if (list != null) {
Pod latestPod = KubernetesResourceUtil.getNewestPod(list.getItems());
if (latestPod != null && podHasEnvVars(latestPod, envVars)) {
return getName(latestPod);
}
}
podWatcher = pods.watch(new Watcher<Pod>() {
@Override
public void eventReceived(Watcher.Action action, Pod pod) {
podWaitLog.info(getName(pod) + " status: " + getPodStatusDescription(pod) + getPodStatusMessagePostfix(action));
if (isAddOrModified(action) && isPodRunning(pod) && isPodReady(pod) && podHasEnvVars(pod, envVars)) {
foundPod = pod;
terminateLatch.countDown();
}
}
@Override
public void onClose(KubernetesClientException e) {
// ignore
}
});
// now lets wait forever?
while (terminateLatch.getCount() > 0) {
try {
terminateLatch.await();
} catch (InterruptedException e) {
// ignore
}
if (foundPod != null) {
return getName(foundPod);
}
}
throw new MojoExecutionException("Could not find a running pod with environment variables " + envVars);
}
Aggregations