本文整理汇总了Java中io.fabric8.kubernetes.api.model.PodList类的典型用法代码示例。如果您正苦于以下问题:Java PodList类的具体用法?Java PodList怎么用?Java PodList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PodList类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了PodList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldCreateKubernetesClusterObject
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
@Test
public void shouldCreateKubernetesClusterObject() throws Exception {
final KubernetesClient kubernetesClient = mock(KubernetesClient.class);
NodeOperationsImpl nodes = mock(NodeOperationsImpl.class);
PodOperationsImpl pods = mock(PodOperationsImpl.class);
when(nodes.list()).thenReturn(new NodeList());
when(kubernetesClient.nodes()).thenReturn(nodes);
when(pods.inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)).thenReturn(pods);
when(pods.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)).thenReturn(pods);
when(pods.list()).thenReturn(new PodList());
when(kubernetesClient.pods()).thenReturn(pods);
final KubernetesCluster cluster = new KubernetesCluster(kubernetesClient);
verify(kubernetesClient, times(1)).nodes();
verify(kubernetesClient, times(1)).pods();
}
示例2: shouldBuildStatusReportView
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
@Test
public void shouldBuildStatusReportView() throws Exception {
NodeOperationsImpl nodes = mock(NodeOperationsImpl.class);
PodOperationsImpl pods = mock(PodOperationsImpl.class);
when(nodes.list()).thenReturn(new NodeList());
when(kubernetesClient.nodes()).thenReturn(nodes);
when(pods.inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)).thenReturn(pods);
when(pods.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)).thenReturn(pods);
when(pods.list()).thenReturn(new PodList());
when(kubernetesClient.pods()).thenReturn(pods);
final PluginStatusReportViewBuilder builder = mock(PluginStatusReportViewBuilder.class);
final Template template = mock(Template.class);
when(builder.getTemplate("status-report.template.ftlh")).thenReturn(template);
when(builder.build(eq(template), any(KubernetesCluster.class))).thenReturn("status-report");
final GoPluginApiResponse response = new StatusReportExecutor(pluginRequest, kubernetesClientFactory, builder).execute();
assertThat(response.responseCode(), is(200));
assertThat(response.responseBody(), is("{\"view\":\"status-report\"}"));
}
示例3: onRequest
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
LOGGER.info("Listing all failing pods for namespace:" + namespace);
try {
List<String> pods = list(ctx)
.getItems()
.stream()
.filter(p -> FAILED_PHASE.equalsIgnoreCase(p.getStatus().getPhase()))
.map(d -> d.getMetadata().getName()).collect(Collectors.toList());
if (pods.isEmpty()) {
return newResponse("No failing pods found in namespace " + namespace);
} else {
return newResponse("The failing pods in namespace " + namespace + " are: " + join(pods, ","));
}
} catch (KubernetesClientException e) {
return newFailureNotice(e.getStatus().getMessage());
}
}
示例4: onRequest
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
LOGGER.info("Listing all pods for namespace:" + namespace);
try {
List<String> pods = list(ctx)
.getItems()
.stream()
.map(d -> d.getMetadata().getName()).collect(Collectors.toList());
if (pods.isEmpty()) {
return newResponse("No pods found in namespace " + namespace);
} else {
return newResponse("The available pods in namespace " + namespace + " are: " + join(pods, ","));
}
} catch (KubernetesClientException e) {
return newFailureNotice(e.getStatus().getMessage());
}
}
示例5: 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());
}
}
}
示例6: 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
示例7: doListPodsByLabel
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
protected void doListPodsByLabel(Exchange exchange, String operation) {
Map<String, String> labels = exchange.getIn().getHeader(
KubernetesConstants.KUBERNETES_PODS_LABELS, Map.class);
if (ObjectHelper.isEmpty(labels)) {
LOG.error("Get pods by labels require specify a labels set");
throw new IllegalArgumentException(
"Get pods by labels require specify a labels set");
}
ClientMixedOperation<Pod, PodList, DoneablePod, ClientPodResource<Pod, DoneablePod>> pods;
pods = getEndpoint().getKubernetesClient().pods();
for (Map.Entry<String, String> entry : labels.entrySet()) {
pods.withLabel(entry.getKey(), entry.getValue());
}
PodList podList = pods.list();
exchange.getOut().setBody(podList.getItems());
}
示例8: getLocalPods
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
@GET
@Path("local/pods")
@Consumes("application/json")
@Override
public PodList getLocalPods() {
ImmutableMap<String, Installation> installMap = processManager.listInstallationMap();
ImmutableSet<String> keys = installMap.keySet();
List<Pod> pods = new ArrayList<>();
for (String key : keys) {
Pod pod = model.getPod(key);
if (pod != null) {
pods.add(pod);
}
}
PodList answer = new PodList();
answer.setItems(pods);
return answer;
}
示例9: 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));
}
}
}
}
示例10: findMatching
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
/**
* Returns the {@link PodList} that match the specified {@link Deployment}.
*
* @param deployment The {@link Deployment}
*/
public static PodList findMatching(KubernetesClient client, Deployment deployment) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podLister =
client.pods().inNamespace(deployment.getMetadata().getNamespace());
if (deployment.getSpec().getSelector().getMatchLabels() != null) {
podLister.withLabels(deployment.getSpec().getSelector().getMatchLabels());
}
if (deployment.getSpec().getSelector().getMatchExpressions() != null) {
for (LabelSelectorRequirement req : deployment.getSpec().getSelector().getMatchExpressions()) {
switch (req.getOperator()) {
case "In":
podLister.withLabelIn(req.getKey(), req.getValues().toArray(new String[]{}));
break;
case "NotIn":
podLister.withLabelNotIn(req.getKey(), req.getValues().toArray(new String[]{}));
break;
case "DoesNotExist":
podLister.withoutLabel(req.getKey());
break;
case "Exists":
podLister.withLabel(req.getKey());
break;
}
}
}
return podLister.list();
}
示例11: podsOf
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
/**
* Finds the pod that correspond to the specified resource.
*
* @param resource The resource.
* @return The podList with the matching pods.
*/
public static <T extends HasMetadata> PodList podsOf(KubernetesClient client, T resource) {
if (resource instanceof Pod) {
return new PodListBuilder().withItems((Pod) resource).build();
} else if (resource instanceof Endpoints) {
return podsOf(client, client.services()
.inNamespace(resource.getMetadata().getNamespace())
.withName(resource.getMetadata().getName())
.get());
} else if (resource instanceof Service) {
return client.pods()
.inNamespace(resource.getMetadata().getNamespace())
.withLabels(((Service) resource).getSpec().getSelector())
.list();
} else if (resource instanceof ReplicationController) {
return client.pods()
.inNamespace(resource.getMetadata().getNamespace())
.withLabels(((ReplicationController) resource).getSpec().getSelector())
.list();
} else if (resource instanceof Deployment) {
return findMatching(client, (Deployment) resource);
} else if (resource instanceof DeploymentConfig) {
return client.pods().inNamespace(resource.getMetadata().getNamespace()).withLabel("deploymentconfig",
resource.getMetadata().getName()).list();
} else {
return new PodListBuilder().build();
}
}
示例12: 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;
}
示例13: initializeUI
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
@Override
public void initializeUI(UIBuilder builder) throws Exception {
super.initializeUI(builder);
// populate autocompletion options
podId.setCompleter(new UICompleter<String>() {
@Override
public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
List<String> list = new ArrayList<String>();
PodList pods = getKubernetes().pods().list();
if (pods != null) {
List<Pod> items = pods.getItems();
if (items != null) {
for (Pod item : items) {
String id = KubernetesHelper.getName(item);
list.add(id);
}
}
}
Collections.sort(list);
System.out.println("Completion list is " + list);
return list;
}
});
builder.add(podId);
}
示例14: execute
import io.fabric8.kubernetes.api.model.PodList; //导入依赖的package包/类
@Override
public Result execute(UIExecutionContext uiExecutionContext) throws Exception {
PodList pods = getKubernetes().pods().inNamespace(getNamespace()).list();
KubernetesHelper.removeEmptyPods(pods);
TablePrinter table = podsAsTable(pods);
return tableResults(table);
}
示例15: 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;
}