client.namespaces().list() ); client.namespaces().withLabel("this", "works").list() ); client.pods().withLabel("this", "works").list() ); client.pods().inNamespace("test").withLabel("this", "works").list() ); client.pods().inNamespace("test").withName("testing").get() ); PodList podList = client.pods().inNamespace("myproject").list(5, null); podList.getItems().forEach((obj) -> { System.out.println(obj.getMetadata().getName()); }); podList = client.pods().inNamespace("myproject").list(5, podList.getMetadata().getContinue()); podList.getItems().forEach((obj) -> { System.out.println(obj.getMetadata().getName()); }); Integer services = client.services().inNamespace("myproject").list(1, null).getItems().size();
public PodListBuilder(){ this(new PodList()); } public PodListBuilder( PodListFluent<?> fluent ){
lb.setExists(client.services().inNamespace(namespace).withName(name).get() != null); res.setLoadBalancer(lb); List<Pod> pods = client.pods().inNamespace(namespace).withLabel("load-balancer-" + name, "true").list().getItems(); pods.addAll(client.pods().inNamespace(namespace).withLabel("load-balancer-" + name, "false").list().getItems()); String podName = pod.getMetadata().getName(); String serverGroupName = podName.substring(0, podName.lastIndexOf("-")); Names parsedName = Names.parseName(serverGroupName); String location = pod.getMetadata().getNamespace(); String id = pod.getMetadata().getName();
public List<Pod> listPods() { return new ArrayList<>(client.pods().inNamespace(globalNamespace).list().getItems()); }
public HashMap<String, String> getLogsOfTerminatedPods(String namespace) { HashMap<String, String> terminatedPodsLogs = new HashMap<>(); try { client.pods().inNamespace(namespace).list().getItems().forEach(pod -> { pod.getStatus().getContainerStatuses().forEach(containerStatus -> { log.info("pod:'{}' : restart count '{}'", pod.getMetadata().getName(), containerStatus.getRestartCount()); if (containerStatus.getRestartCount() > 0) { terminatedPodsLogs.put( pod.getMetadata().getName(), client.pods().inNamespace(namespace) .withName(pod.getMetadata().getName()) .inContainer(containerStatus.getName()) .terminated().getLog()); } }); }); } catch (Exception allExceptions) { log.warn("Searching in terminated pods failed! No logs of terminated pods will be stored."); allExceptions.printStackTrace(); } return terminatedPodsLogs; }
@Override public Set<String> discoverMembers() { LOGGER.debug("CELLAR KUBERNETES: query pods with labeled with [{}={}]", kubernetesPodLabelKey, kubernetesPodLabelValue); Set<String> members = new HashSet<String>(); try { PodList podList = kubernetesClient.pods().list(); for (Pod pod : podList.getItems()) { String value = pod.getMetadata().getLabels().get(kubernetesPodLabelKey); if (value != null && !value.isEmpty() && value.equals(kubernetesPodLabelValue)) { members.add(pod.getStatus().getPodIP()); } } } catch (Exception e) { LOGGER.error("CELLAR KUBERNETES: can't get pods", e); } return members; }
@Override public Boolean call() throws Exception { boolean result = true; List<Pod> pods = notNullList(kubernetesClient.pods().inNamespace(session.getNamespace()).list().getItems()); if (!KubernetesHelper.isPodReady(pod)) { PodStatus podStatus = pod.getStatus(); int restartCount = 0; String name = KubernetesHelper.getName(pod); File yamlFile = new File(session.getBaseDir(), "target/test-pod-status/" + name + ".yml"); yamlFile.getParentFile().mkdirs(); try { KubernetesHelper.saveYaml(pod, yamlFile); } catch (IOException e) { session.getLogger().warn("Failed to write " + yamlFile + ". " + e); if (KubernetesHelper.isPodRunning(pod)) { List<Container> containers = pod.getSpec().getContainers(); for (Container container : containers) { File logFile = LogHelpers.getLogFileName(session.getBaseDir(), name, container, restartCount); String log = kubernetesClient.pods().inNamespace(session.getNamespace()).withName(name).inContainer(container.getName()).getLog(); IOHelpers.writeFully(logFile, log);
PodList list = client.pods().withLabels(createdByZaleniumMap).list(); for (Pod pod : list.getItems()) { if (podIpAddress.equals(pod.getStatus().getPodIP())) { containerId = pod.getMetadata().getName(); currentPod = pod; break; List<EnvVar> podEnvironmentVariables = currentPod.getSpec().getContainers().get(0).getEnv(); Optional<EnvVar> noVncPort = podEnvironmentVariables.stream().filter(env -> "NOVNC_PORT".equals(env.getName())).findFirst();
return; if (client.isAdaptable(OpenShiftClient.class)){ OpenShiftClient oClient = client.adapt(OpenShiftClient.class); List<DeploymentConfig> deploymentConfigs = oClient.deploymentConfigs().inNamespace(session.getNamespace()).list().getItems(); if (deploymentConfigs == null) { throw new MultiException("No deployment configs found in namespace" + session.getNamespace()); session.getLogger().info("Deployment config:" + KubernetesHelper.getName(deploymentConfig)); List<Deployment> deployments = client.extensions().deployments().inNamespace(session.getNamespace()).list().getItems(); if (deployments == null) { throw new MultiException("No deployments found in namespace" + session.getNamespace()); session.getLogger().info("Deployment:" + KubernetesHelper.getName(deployment)); List<Pod> pods = client.pods().inNamespace(session.getNamespace()).list().getItems(); if (pods == null) { throw new MultiException("No pods found in namespace" + session.getNamespace()); session.getLogger().info("Pod:" + KubernetesHelper.getName(pod) + " Status:" + pod.getStatus());
if (openShiftClient != null) { try { openShiftClient.deploymentConfigs().inNamespace(sessionNamespace).delete(); } catch (KubernetesClientException e) { errors.add(e); openShiftClient.routes().inNamespace(sessionNamespace).delete(); } catch (KubernetesClientException e) { errors.add(e); client.extensions().deployments().inNamespace(sessionNamespace).delete(); } catch (KubernetesClientException e) { errors.add(e); client.extensions().replicaSets().inNamespace(sessionNamespace).delete(); } catch (KubernetesClientException e) { errors.add(e); client.replicationControllers().inNamespace(sessionNamespace).delete(); } catch (KubernetesClientException e) { errors.add(e); List<Pod> filteredPods = notNullList(client.pods().inNamespace(sessionNamespace).list().getItems()); if (filteredPods.isEmpty()) { return;
private Pod getPod(String jobName) { List<Pod> pods = client.pods().withLabel(SPRING_APP_KEY, jobName).list().getItems(); for (Pod pod : pods) { if (jobName.equals((pod.getMetadata().getName()))) { return pod; } } return null; } }
protected void killPod() { String namespace = getNamespace(); PodList pods = kubernetes.pods().inNamespace(namespace).list(); List<Pod> targets = new ArrayList<>(); if (pods != null) { List<Pod> podList = pods.getItems(); for (Pod pod : podList) { if (isTarget(pod)) { message = "No matching pods available to kill. Boo!"; } else { String name = KubernetesHelper.getName(pod); try { kubernetes.pods().inNamespace(namespace).withName(KubernetesHelper.getName(pod)).delete(); message = "Chaos Monkey killed pod " + name + " in namespace " + namespace; killed = true;
for (Pod pod : oldPods.getItems()) { try { pods().inNamespace(namespace).withName(pod.getMetadata().getName()) .edit() .editMetadata().addToLabels(DEPLOYMENT_KEY, oldDeploymentHash) D editable = resources().inNamespace(namespace).withName(oldName).cascading(false).edit(); updateDeploymentKey(editable, oldDeploymentHash); oldObj = editable.done(); T createdObj = resources().inNamespace(namespace).create(clonedObj);
templateNamespace = client.getNamespace(); PodList slaveList = client.pods().inNamespace(templateNamespace).withLabels(getLabels()).list(); List<Pod> slaveListItems = slaveList.getItems(); PodList namedList = client.pods().inNamespace(templateNamespace).withLabels(labelsMap).list(); List<Pod> namedListItems = namedList.getItems(); .filter(x -> x.getStatus() .getPhase().toLowerCase() .matches("(running|pending)")) .filter(x -> x.getStatus() .getPhase().toLowerCase() .matches("(running|pending)"))
public List<Pod> listPods(Map<String, String> labelSelector, Map<String, String> annotationSelector) { return client.pods().withLabels(labelSelector).list().getItems().stream().filter(pod -> { for (Map.Entry<String, String> entry : annotationSelector.entrySet()) { return pod.getMetadata().getAnnotations() != null && pod.getMetadata().getAnnotations().get(entry.getKey()) != null && pod.getMetadata().getAnnotations().get(entry.getKey()).equals(entry.getValue()); } return true; }).collect(Collectors.toList()); }
@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; } }
private Set<String> pullClusterMembers() { List<Pod> pods = kubernetesClient.pods() .inNamespace(this.lockConfiguration.getKubernetesResourcesNamespaceOrDefault(kubernetesClient)) .withLabels(this.lockConfiguration.getClusterLabels()) .list().getItems(); return pods.stream().map(pod -> pod.getMetadata().getName()).collect(Collectors.toSet()); }
public static void main(String[] args) throws InterruptedException { Config config = new ConfigBuilder().build(); KubernetesClient kubernetesClient = new DefaultKubernetesClient(config); OpenShiftClient client = kubernetesClient.adapt(OpenShiftClient.class); client.serviceAccounts().inNamespace("thisisatest").createOrReplace(fabric8); log("Created deployment", client.deploymentConfigs().inNamespace("thisisatest").createOrReplaceWithNew() .withNewMetadata() .withName("nginx") client.deploymentConfigs().inNamespace("thisisatest").withName("nginx").scale(2, true); log("Created pods:", client.pods().inNamespace("thisisatest").list().getItems()); client.deploymentConfigs().inNamespace("thisisatest").withName("nginx").delete(); log("Pods:", client.pods().inNamespace("thisisatest").list().getItems()); log("Replication Controllers:", client.replicationControllers().inNamespace("thisisatest").list().getItems());
@Override public AppStatus status(String appId) { Map<String, String> selector = new HashMap<>(); ServiceList services = client.services().withLabel(SPRING_APP_KEY, appId).list(); selector.put(SPRING_APP_KEY, appId); PodList podList = client.pods().withLabels(selector).list(); if (logger.isDebugEnabled()) { logger.debug(String.format("Building AppStatus for app: %s", appId)); if (podList != null && podList.getItems() != null) { logger.debug(String.format("Pods for appId %s: %d", appId, podList.getItems().size())); for (Pod pod : podList.getItems()) { logger.debug(String.format("Pod: %s", pod.getMetadata().getName())); } } } AppStatus status = buildAppStatus(appId, podList, services); logger.debug(String.format("Status for app: %s is %s", appId, status)); return status; }
private String waitForRunningPodWithEnvVar(final KubernetesClient kubernetes, final String namespace, LabelSelector selector, final Map<String, String> envVars) throws MojoExecutionException { 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);