本文整理汇总了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());
}
}
}
示例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));
}
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}