当前位置: 首页>>代码示例>>Java>>正文


Java PodList.getItems方法代码示例

本文整理汇总了Java中io.fabric8.kubernetes.api.model.PodList.getItems方法的典型用法代码示例。如果您正苦于以下问题:Java PodList.getItems方法的具体用法?Java PodList.getItems怎么用?Java PodList.getItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.fabric8.kubernetes.api.model.PodList的用法示例。


在下文中一共展示了PodList.getItems方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tryPollPods

import io.fabric8.kubernetes.api.model.PodList; //导入方法依赖的package包/类
private synchronized void tryPollPods() {
  final Set<WorkflowInstance> runningWorkflowInstances = getRunningWorkflowInstances();
  final PodList list = client.pods().list();
  examineRunningWFISandAssociatedPods(runningWorkflowInstances, list);


  for (Pod pod : list.getItems()) {
    logEvent(Watcher.Action.MODIFIED, pod, list.getMetadata().getResourceVersion(), true);
    final Optional<WorkflowInstance> workflowInstance = readPodWorkflowInstance(pod);
    if (!workflowInstance.isPresent()) {
      continue;
    }
    final Optional<RunState> runState = lookupPodRunState(pod, workflowInstance.get());
    if (runState.isPresent()) {
      emitPodEvents(Watcher.Action.MODIFIED, pod, runState.get());
      cleanupWithRunState(workflowInstance.get(), pod.getMetadata().getName());
    } else {
      cleanupWithoutRunState(workflowInstance.get(), pod.getMetadata().getName());
    }
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:22,代码来源:KubernetesDockerRunner.java

示例2: buildAppStatus

import io.fabric8.kubernetes.api.model.PodList; //导入方法依赖的package包/类
protected AppStatus buildAppStatus(String id, PodList podList, ServiceList services) {
	AppStatus.Builder statusBuilder = AppStatus.of(id);
	Service service = null;
	if (podList != null && podList.getItems() != null) {
		for (Pod pod : podList.getItems()) {
			for (Service svc : services.getItems()) {
				if (svc.getMetadata().getName()
						.equals(pod.getMetadata().getLabels().get(SPRING_DEPLOYMENT_KEY))) {
					service = svc;
					break;
				}
			}
			statusBuilder.with(new KubernetesAppInstanceStatus(pod, service, properties));
		}
	}
	return statusBuilder.build();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:18,代码来源:AbstractKubernetesDeployer.java

示例3: refreshAll

import io.fabric8.kubernetes.api.model.PodList; //导入方法依赖的package包/类
@Override
public void refreshAll(PluginRequest pluginRequest) throws Exception {
    LOG.debug("[Refresh Instances]. Syncing k8s elastic agent pod information");
    KubernetesClient client = factory.kubernetes(pluginRequest.getPluginSettings());
    PodList list = client.pods().inNamespace(Constants.KUBERNETES_NAMESPACE_KEY).list();

    for (Pod pod : list.getItems()) {
        Map<String, String> podLabels = pod.getMetadata().getLabels();
        if (podLabels != null) {
            if (StringUtils.equals(Constants.KUBERNETES_POD_KIND_LABEL_VALUE, podLabels.get(Constants.KUBERNETES_POD_KIND_LABEL_KEY))) {
                register(kubernetesInstanceFactory.fromKubernetesPod(pod));
            }
        }
    }
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:16,代码来源:KubernetesAgentInstances.java

示例4: getPodsByLabel

import io.fabric8.kubernetes.api.model.PodList; //导入方法依赖的package包/类
/**
 * Retrieves all the pods labeled with the given string.
 *
 * @param label  the string label to be used to select the pods
 * @return  the list of pods selected with the provided label. Empty list if not pod is found.
 * @throws VmidcException  if a K8s SDK specific exception is caught
 */
public List<KubernetesPod> getPodsByLabel(String label) throws VmidcException {
    List<KubernetesPod> resultPodList = new ArrayList<KubernetesPod>();

    if (label == null) {
        throw new IllegalArgumentException("Label should not be null");
    }

    try {
        PodList pods = getKubernetesClient().pods().withLabel(label).list();
        if (pods == null || pods.getItems() == null || pods.getItems().isEmpty()) {
            return resultPodList;
        }

        for (Pod pod : pods.getItems()) {
            resultPodList.add(
                    new KubernetesPod(
                            pod.getMetadata().getName(),
                            pod.getMetadata().getNamespace(),
                            pod.getMetadata().getUid(),
                            pod.getSpec().getNodeName())
                    );
        }

    } catch (KubernetesClientException e) {
        throw new VmidcException("Failed to get Pods");
    }

    return resultPodList;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:37,代码来源:KubernetesPodApi.java

示例5: podsAsTable

import io.fabric8.kubernetes.api.model.PodList; //导入方法依赖的package包/类
protected TablePrinter podsAsTable(PodList pods) {
    TablePrinter table = new TablePrinter();
    table.columns("id", "image(s)", "host", "labels", "status");
    List<Pod> items = pods.getItems();
    if (items == null) {
        items = Collections.EMPTY_LIST;
    }
    Filter<Pod> filter = KubernetesHelper.createPodFilter(filterText.getValue());
    for (Pod item : items) {
        if (filter.matches(item)) {
            String id = KubernetesHelper.getName(item);
            PodStatus podStatus = item.getStatus();
            String status = "";
            String host = "";
            if (podStatus != null) {
                status = KubernetesHelper.getStatusText(podStatus);
                host = podStatus.getHostIP();
            }
            Map<String, String> labelMap = item.getMetadata().getLabels();
            String labels = KubernetesHelper.toLabelsString(labelMap);
            PodSpec spec = item.getSpec();
            if (spec != null) {
                List<Container> containerList = spec.getContainers();
                for (Container container : containerList) {
                    String image = container.getImage();
                    table.row(id, image, host, labels, status);

                    id = "";
                    host = "";
                    status = "";
                    labels = "";
                }
            }
        }
    }
    return table;
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:38,代码来源:PodsList.java

示例6: getPodIdsForTaskName

import io.fabric8.kubernetes.api.model.PodList; //导入方法依赖的package包/类
private List<String> getPodIdsForTaskName(String taskName) {
	List<String> ids = new ArrayList<>();
	try {
		PodList pods = client.pods().inNamespace(client.getNamespace()).withLabel("task-name", taskName).list();
		for (Pod pod : pods.getItems()) {
			ids.add(pod.getMetadata().getName());
		}
	}
	catch (KubernetesClientException kce) {
		logger.warn(String.format("Failed to retrieve pods for task: %s", taskName), kce);
	}
	return ids;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:14,代码来源:KubernetesTaskLauncher.java

示例7: addProvisionedSlave

import io.fabric8.kubernetes.api.model.PodList; //导入方法依赖的package包/类
/**
 * Check not too many already running.
 *
 */
private boolean addProvisionedSlave(@Nonnull PodTemplate template, @CheckForNull Label label) throws Exception {
    if (containerCap == 0) {
        return true;
    }

    KubernetesClient client = connect();
    String templateNamespace = template.getNamespace();
    // If template's namespace is not defined, take the
    // Kubernetes Namespace.
    if (Strings.isNullOrEmpty(templateNamespace)) {
        templateNamespace = client.getNamespace();
    }

    PodList slaveList = client.pods().inNamespace(templateNamespace).withLabels(getLabels()).list();
    List<Pod> slaveListItems = slaveList.getItems();

    Map<String, String> labelsMap = getLabelsMap(template.getLabelSet());
    PodList namedList = client.pods().inNamespace(templateNamespace).withLabels(labelsMap).list();
    List<Pod> namedListItems = namedList.getItems();

    if (slaveListItems != null && containerCap <= slaveListItems.size()) {
        LOGGER.log(Level.INFO,
                "Total container cap of {0} reached, not provisioning: {1} running or errored in namespace {2} with Kubernetes labels {3}",
                new Object[] { containerCap, slaveListItems.size(), client.getNamespace(), getLabels() });
        return false;
    }

    if (namedListItems != null && slaveListItems != null && template.getInstanceCap() <= namedListItems.size()) {
        LOGGER.log(Level.INFO,
                "Template instance cap of {0} reached for template {1}, not provisioning: {2} running or errored in namespace {3} with label \"{4}\" and Kubernetes labels {5}",
                new Object[] { template.getInstanceCap(), template.getName(), slaveListItems.size(),
                        client.getNamespace(), label == null ? "" : label.toString(), labelsMap });
        return false; // maxed out
    }
    return true;
}
 
开发者ID:carlossg,项目名称:jenkins-kubernetes-plugin,代码行数:41,代码来源:KubernetesCloud.java


注:本文中的io.fabric8.kubernetes.api.model.PodList.getItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。