io.fabric8.kubernetes.api.model.Pod Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.Pod.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KubernetesAgentInstances.java From kubernetes-elastic-agents with Apache License 2.0 | 6 votes |
private KubernetesAgentInstances unregisteredAfterTimeout(PluginSettings settings, Agents knownAgents) throws Exception { Period period = settings.getAutoRegisterPeriod(); KubernetesAgentInstances unregisteredInstances = new KubernetesAgentInstances(); KubernetesClient client = factory.client(settings); for (String instanceName : instances.keySet()) { if (knownAgents.containsAgentWithId(instanceName)) { continue; } Pod pod = getPod(client, instanceName); if (pod == null) { LOG.debug(String.format("[server-ping] Pod with name %s is already deleted.", instanceName)); continue; } Date createdAt = getSimpleDateFormat().parse(pod.getMetadata().getCreationTimestamp()); DateTime dateTimeCreated = new DateTime(createdAt); if (clock.now().isAfter(dateTimeCreated.plus(period))) { unregisteredInstances.register(kubernetesInstanceFactory.fromKubernetesPod(pod)); } } return unregisteredInstances; }
Example #2
Source File: BaseST.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
/** * Verifies container environment variables passed as a map. * @param podNamePrefix Name of pod where container is located * @param containerName The container where verifying is expected * @param config Expected environment variables with values */ protected void checkSpecificVariablesInContainer(String podNamePrefix, String containerName, Map<String, String> config) { LOGGER.info("Getting pods by prefix in name {}", podNamePrefix); List<Pod> pods = kubeClient().listPodsByPrefixInName(podNamePrefix); if (pods.size() != 0) { LOGGER.info("Testing EnvVars configuration for container {}", containerName); Map<String, Object> actual = pods.stream() .flatMap(p -> p.getSpec().getContainers().stream()) // get containers .filter(c -> c.getName().equals(containerName)) .flatMap(c -> c.getEnv().stream().filter(envVar -> config.containsKey(envVar.getName()))) .collect(Collectors.toMap(EnvVar::getName, EnvVar::getValue, (item, duplicatedItem) -> item)); assertThat(actual, is(config)); } else { fail("Pod with prefix " + podNamePrefix + " in name, not found"); } }
Example #3
Source File: OpenShiftInternalRuntimeTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldStartMachines() throws Exception { final Container container1 = mockContainer(CONTAINER_NAME_1, EXPOSED_PORT_1); final Container container2 = mockContainer(CONTAINER_NAME_2, EXPOSED_PORT_2, INTERNAL_PORT); final ImmutableMap<String, Pod> allPods = ImmutableMap.of(POD_NAME, mockPod(ImmutableList.of(container1, container2))); when(osEnv.getPodsCopy()).thenReturn(allPods); when(unrecoverablePodEventListenerFactory.isConfigured()).thenReturn(true); internalRuntime.startMachines(); verify(deployments).deploy(any(Pod.class)); verify(routes).create(any()); verify(services).create(any()); verify(secrets).create(any()); verify(configMaps).create(any()); verify(project.deployments(), times(2)).watchEvents(any()); verify(eventService, times(2)).publish(any()); verifyEventsOrder(newEvent(M1_NAME, STARTING), newEvent(M2_NAME, STARTING)); }
Example #4
Source File: KubernetesLookupTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testCluster() throws Exception { Pod pod = objectMapper.readValue(new File(clusterJson), Pod.class); Namespace namespace = createNamespace(); KubernetesLookup lookup = new KubernetesLookup(pod, namespace, masterUrl); try { assertEquals("Incorrect container name", "platform-forms-service", lookup.lookup("containerName")); assertEquals("Incorrect container id", "docker://2b7c2a93dfb48334aa549e29fdd38039ddd256eec43ba64c145fa4b75a1542f0", lookup.lookup("containerId")); assertEquals("Incorrect host name", "k8s-tmpcrm-worker-s03-04", lookup.lookup("host")); assertEquals("Incorrect pod name", "platform-forms-service-primary-5ddfc4f9b8-kfpzv", lookup.lookup("podName")); } finally { lookup.clearInfo(); } }
Example #5
Source File: KubernetesComputer.java From kubernetes-plugin with Apache License 2.0 | 6 votes |
@Exported public List<Container> getContainers() throws KubernetesAuthException, IOException { if(!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { LOGGER.log(Level.FINE, " Computer {0} getContainers, lack of admin permission, returning empty list", this); return Collections.emptyList(); } KubernetesSlave slave = getNode(); if(slave == null) { return Collections.emptyList(); } KubernetesCloud cloud = slave.getKubernetesCloud(); KubernetesClient client = cloud.connect(); String namespace = StringUtils.defaultIfBlank(slave.getNamespace(), client.getNamespace()); Pod pod = client.pods().inNamespace(namespace).withName(getName()).get(); return pod.getSpec().getContainers(); }
Example #6
Source File: DeltaFIFOTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test void testReplaceWithDeleteDeltaIn() throws InterruptedException { Pod oldPod = new PodBuilder().withNewMetadata().withNamespace("default").withName("foo1").endMetadata().build(); Pod newPod = new PodBuilder().withNewMetadata().withNamespace("default").withName("foo2").endMetadata().build(); Cache<Pod> mockCache = mock(Cache.class); doReturn(oldPod).when(mockCache).getByKey(Cache.deletionHandlingMetaNamespaceKeyFunc(oldPod)); DeltaFIFO<Pod> deltaFIFO = new DeltaFIFO<>(Cache::deletionHandlingMetaNamespaceKeyFunc, mockCache); deltaFIFO.delete(oldPod); deltaFIFO.replace(Collections.singletonList(newPod), "0"); deltaFIFO.pop( (deltas) -> { assertEquals(DeltaFIFO.DeltaType.DELETION, deltas.getFirst().getKey()); assertEquals(oldPod, deltas.getFirst().getValue()); }); deltaFIFO.pop( (deltas) -> { assertEquals(DeltaFIFO.DeltaType.SYNCHRONIZATION, deltas.getFirst().getKey()); assertEquals(newPod, deltas.getFirst().getValue()); }); }
Example #7
Source File: StatefulSetOperationsImpl.java From kubernetes-client with Apache License 2.0 | 6 votes |
private List<PodResource<Pod, DoneablePod>> doGetLog(boolean isPretty) { List<PodResource<Pod, DoneablePod>> pods = new ArrayList<>(); StatefulSet statefulSet = fromServer().get(); String rcUid = statefulSet.getMetadata().getUid(); PodOperationsImpl podOperations = new PodOperationsImpl(new PodOperationContext(context.getClient(), context.getConfig(), context.getPlural(), context.getNamespace(), context.getName(), null, "v1", context.getCascading(), context.getItem(), context.getLabels(), context.getLabelsNot(), context.getLabelsIn(), context.getLabelsNotIn(), context.getFields(), context.getFieldsNot(), context.getResourceVersion(), context.getReloadingFromServer(), context.getGracePeriodSeconds(), context.getPropagationPolicy(), context.getWatchRetryInitialBackoffMillis(), context.getWatchRetryBackoffMultiplier(), null, null, null, null, null, null, null, null, null, false, false, false, null, null, null, isPretty, null, null, null, null, null)); PodList jobPodList = podOperations.withLabels(statefulSet.getSpec().getTemplate().getMetadata().getLabels()).list(); for (Pod pod : jobPodList.getItems()) { OwnerReference ownerReference = KubernetesResourceUtil.getControllerUid(pod); if (ownerReference != null && ownerReference.getUid().equals(rcUid)) { pods.add(podOperations.withName(pod.getMetadata().getName())); } } return pods; }
Example #8
Source File: ProxySettingsProvisionerTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldNotApplyProxySettingsToJWTProxyContainer() throws Exception { Map<String, Pod> pods = new HashMap<>(); pods.put(JWT_PROXY_POD_NAME, buildPod(JWT_PROXY_POD_NAME, buildContainers(2))); KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setPods(pods).build(); provisioner.provision(k8sEnv, runtimeId); assertTrue( k8sEnv .getPodsData() .values() .stream() .filter(pod -> pod.getMetadata().getName().equals(JWT_PROXY_POD_NAME)) .flatMap(pod -> pod.getSpec().getContainers().stream()) .noneMatch( container -> container.getEnv().contains(new EnvVar(HTTP_PROXY, HTTP_PROXY_VALUE, null)) || container .getEnv() .contains(new EnvVar(HTTPS_PROXY, HTTPS_PROXY_VALUE, null)) || container .getEnv() .contains(new EnvVar(NO_PROXY, NO_PROXY_VALUE, null)))); }
Example #9
Source File: KubernetesTaskManagerFactory.java From flink with Apache License 2.0 | 6 votes |
public static KubernetesPod buildTaskManagerKubernetesPod(KubernetesTaskManagerParameters kubernetesTaskManagerParameters) { FlinkPod flinkPod = new FlinkPod.Builder().build(); final KubernetesStepDecorator[] stepDecorators = new KubernetesStepDecorator[] { new InitTaskManagerDecorator(kubernetesTaskManagerParameters), new JavaCmdTaskManagerDecorator(kubernetesTaskManagerParameters), new HadoopConfMountDecorator(kubernetesTaskManagerParameters), new FlinkConfMountDecorator(kubernetesTaskManagerParameters)}; for (KubernetesStepDecorator stepDecorator: stepDecorators) { flinkPod = stepDecorator.decorateFlinkPod(flinkPod); } final Pod resolvedPod = new PodBuilder(flinkPod.getPod()) .editOrNewSpec() .addToContainers(flinkPod.getMainContainer()) .endSpec() .build(); return new KubernetesPod(resolvedPod); }
Example #10
Source File: KubernetesDockerRunnerPodPollerTest.java From styx with Apache License 2.0 | 6 votes |
@Test public void shouldDeleteUnwantedStyxPods() { final Pod createdPod1 = createPod(WORKFLOW_INSTANCE, RUN_SPEC, SECRET_SPEC); final Pod createdPod2 = createPod(WORKFLOW_INSTANCE_2, RUN_SPEC_2, SECRET_SPEC); podList.setItems(Arrays.asList(createdPod1, createdPod2)); when(k8sClient.getPod(RUN_SPEC.executionId())).thenReturn(Optional.of(createdPod1)); when(k8sClient.getPod(RUN_SPEC_2.executionId())).thenReturn(Optional.of(createdPod2)); createdPod1.setStatus(podStatus1); when(podStatus1.getContainerStatuses()).thenReturn(List.of(containerStatus1)); when(containerStatus1.getName()).thenReturn(RUN_SPEC.executionId()); createdPod2.setStatus(podStatus2); when(podStatus2.getContainerStatuses()).thenReturn(List.of(containerStatus2)); when(containerStatus2.getName()).thenReturn(RUN_SPEC_2.executionId()); kdr.tryCleanupPods(); verify(k8sClient).deletePod(createdPod1.getMetadata().getName()); verify(k8sClient).deletePod(createdPod2.getMetadata().getName()); }
Example #11
Source File: CreateOrReplaceResourceTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testResourceReplaceFromLoad() throws Exception { server.expect().get().withPath("/api/v1/namespaces/test/pods/nginx").andReturn(200, new PodBuilder().withNewMetadata().withResourceVersion("12345").and().build()).always(); server.expect().put().withPath("/api/v1/namespaces/test/pods/nginx").andReturn(200, new PodBuilder() .withNewMetadata().withResourceVersion("12345").and().build()).once(); KubernetesClient client = server.getClient(); List<HasMetadata> result = client.load(getClass().getResourceAsStream("/test-pod-create-from-load.yml")).createOrReplace(); assertNotNull(result); assertEquals(1, result.size()); Pod pod = (Pod) result.get(0); assertEquals("12345", pod.getMetadata().getResourceVersion()); RecordedRequest request = server.getLastRequest(); assertEquals("/api/v1/namespaces/test/pods/nginx", request.getPath()); Pod requestPod = new ObjectMapper().readerFor(Pod.class).readValue(request.getBody().inputStream()); assertEquals("nginx", requestPod.getMetadata().getName()); }
Example #12
Source File: KubernetesEnvironment.java From che with Eclipse Public License 2.0 | 6 votes |
protected KubernetesEnvironment( InternalRecipe internalRecipe, Map<String, InternalMachineConfig> machines, List<Warning> warnings, Map<String, Pod> pods, Map<String, Deployment> deployments, Map<String, Service> services, Map<String, Ingress> ingresses, Map<String, PersistentVolumeClaim> persistentVolumeClaims, Map<String, Secret> secrets, Map<String, ConfigMap> configMaps) { super(internalRecipe, machines, warnings); setType(TYPE); this.pods = pods; this.deployments = deployments; this.services = services; this.ingresses = ingresses; this.persistentVolumeClaims = persistentVolumeClaims; this.secrets = secrets; this.configMaps = configMaps; this.podData = new HashMap<>(); this.injectablePods = new HashMap<>(); pods.forEach((name, pod) -> podData.put(name, new PodData(pod))); deployments.forEach((name, deployment) -> podData.put(name, new PodData(deployment))); }
Example #13
Source File: PodIT.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void listFromServer() { // Wait for resources to get ready ReadyEntity<Pod> podReady = new ReadyEntity<>(Pod.class, client, pod1.getMetadata().getName(), currentNamespace); await().atMost(30, TimeUnit.SECONDS).until(podReady); List<HasMetadata> resources = client.resourceList(pod1).inNamespace(currentNamespace).fromServer().get(); assertNotNull(resources); assertEquals(1, resources.size()); assertNotNull(resources.get(0)); HasMetadata fromServerPod = resources.get(0); assertEquals(pod1.getKind(), fromServerPod.getKind()); assertEquals(currentNamespace, fromServerPod.getMetadata().getNamespace()); assertEquals(pod1.getMetadata().getName(), fromServerPod.getMetadata().getName()); }
Example #14
Source File: KubernetesLocationYamlLiveTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups = {"Live"}) public void testTomcatPodExtras() throws Exception { String yaml = Joiner.on("\n").join( locationYaml, "services:", " - type: " + KubernetesPod.class.getName(), " brooklyn.config:", " docker.container.imageName: tomcat", " docker.container.inboundPorts: [ \"8080\" ]", " metadata:", " extra: test"); KubernetesPod entity = runTomcat(yaml, KubernetesPod.class); String namespace = entity.sensors().get(KubernetesPod.KUBERNETES_NAMESPACE); String podName = entity.sensors().get(KubernetesPod.KUBERNETES_POD); KubernetesClient client = getClient(entity); Pod pod = client.pods().inNamespace(namespace).withName(podName).get(); Map<String, String> labels = pod.getMetadata().getLabels(); assertTrue(labels.containsKey("extra")); assertEquals(labels.get("extra"), "test"); }
Example #15
Source File: KubernetesClientUtil.java From jkube with Eclipse Public License 2.0 | 6 votes |
protected static String getPodCondition(Pod pod) { PodStatus podStatus = pod.getStatus(); if (podStatus == null) { return ""; } List<PodCondition> conditions = podStatus.getConditions(); if (conditions == null || conditions.isEmpty()) { return ""; } for (PodCondition condition : conditions) { String type = condition.getType(); if (StringUtils.isNotBlank(type)) { if ("ready".equalsIgnoreCase(type)) { String statusText = condition.getStatus(); if (StringUtils.isNotBlank(statusText)) { if (Boolean.parseBoolean(statusText)) { return type; } } } } } return ""; }
Example #16
Source File: KubernetesInternalRuntime.java From che with Eclipse Public License 2.0 | 6 votes |
private List<PodData> getAllInjectablePods( ObjectMeta toCreateMeta, List<Container> toCreateContainers, Map<String, Map<String, Pod>> injectables) { return toCreateContainers .stream() .map(c -> Names.machineName(toCreateMeta, c)) .map(injectables::get) // we're only interested in pods for which we require injection .filter(Objects::nonNull) // now reduce to a map keyed by injected pod name so that if 2 pods require injection // of the same thing, we don't inject twice .flatMap(m -> m.entrySet().stream()) // collect to map, ignoring duplicate entries .collect(toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v1)) // ok, we only have 1 of each injectable pods keyed by their names, so let's just get them // all and return as list .values() .stream() .map(PodData::new) .collect(Collectors.toList()); }
Example #17
Source File: KubernetesLookupTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testLocal() throws Exception { Pod pod = objectMapper.readValue(new File(localJson), Pod.class); Namespace namespace = createNamespace(); KubernetesLookup lookup = new KubernetesLookup(pod, namespace, masterUrl); try { assertEquals("Incorrect container name", "sampleapp", lookup.lookup("containerName")); assertEquals("Incorrect container id", "docker://818b0098946c67e6ac56cb7c0934b7c2a9f50feb7244b422b2a7f566f7e5d0df", lookup.lookup("containerId")); assertEquals("Incorrect host name", "docker-desktop", lookup.lookup("host")); assertEquals("Incorrect pod name", "sampleapp-584f99476d-mnrp4", lookup.lookup("podName")); } finally { lookup.clearInfo();; } }
Example #18
Source File: K8sPodManagerTest.java From onos with Apache License 2.0 | 6 votes |
private static Pod createK8sPod(String uid, String name) { ObjectMeta meta = new ObjectMeta(); meta.setUid(uid); meta.setName(name); PodStatus status = new PodStatus(); status.setPhase("Running"); Pod pod = new Pod(); pod.setApiVersion("v1"); pod.setKind("pod"); pod.setMetadata(meta); pod.setStatus(status); return pod; }
Example #19
Source File: K8sPodManager.java From onos with Apache License 2.0 | 5 votes |
@Override public void createPod(Pod pod) { checkNotNull(pod, ERR_NULL_POD); checkArgument(!Strings.isNullOrEmpty(pod.getMetadata().getUid()), ERR_NULL_POD_UID); k8sPodStore.createPod(pod); log.info(String.format(MSG_POD, pod.getMetadata().getName(), MSG_CREATED)); }
Example #20
Source File: KubernetesInternalRuntimeTest.java From che with Eclipse Public License 2.0 | 5 votes |
private static Pod mockPod(List<Container> containers) { final Pod pod = new PodBuilder() .withNewMetadata() .withName(WORKSPACE_POD_NAME) .withLabels( ImmutableMap.of( POD_SELECTOR, WORKSPACE_POD_NAME, CHE_ORIGINAL_NAME_LABEL, WORKSPACE_POD_NAME)) .endMetadata() .withNewSpec() .withContainers(containers) .endSpec() .build(); return pod; }
Example #21
Source File: SimpleRunContainerProviderTest.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
private Pod createTemplate(Map<String, String> imageParameters){ final CloudInstanceUserData instanceTag = createInstanceTag(); final CloudClientParameters parameters = new CloudClientParametersImpl(createMap(), createSet()); KubeCloudImage image = createImage(imageParameters); String newPodName = myNameGenerator.generateNewVmName(image); return myContainerProvider.getPodTemplate(newPodName, instanceTag, image, new KubeCloudClientParametersImpl(parameters)); }
Example #22
Source File: ReplicaSetOperationsImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
public String getLog(Boolean isPretty) { StringBuilder stringBuilder = new StringBuilder(); List<PodResource<Pod, DoneablePod>> podOperationList = doGetLog(isPretty); for (PodResource<Pod, DoneablePod> podOperation : podOperationList) { stringBuilder.append(podOperation.getLog(isPretty)); } return stringBuilder.toString(); }
Example #23
Source File: Fabric8FlinkKubeClient.java From flink with Apache License 2.0 | 5 votes |
@Override public List<KubernetesPod> getPodsWithLabels(Map<String, String> labels) { final List<Pod> podList = this.internalClient.pods().withLabels(labels).list().getItems(); if (podList == null || podList.isEmpty()) { return new ArrayList<>(); } return podList .stream() .map(KubernetesPod::new) .collect(Collectors.toList()); }
Example #24
Source File: ReplicaSetOperationsImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
/** * Returns an unclosed Reader. It's the caller responsibility to close it. * @return Reader */ @Override public Reader getLogReader() { List<PodResource<Pod, DoneablePod>> podResources = doGetLog(false); if (podResources.size() > 1) { throw new KubernetesClientException("Reading logs is not supported for multicontainer jobs"); } else if (podResources.size() == 1) { return podResources.get(0).getLogReader(); } return null; }
Example #25
Source File: ResourceTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testWaitUntilReady() throws InterruptedException { Pod pod1 = new PodBuilder().withNewMetadata() .withName("pod1") .withResourceVersion("1") .withNamespace("test").and().build(); Pod noReady = new PodBuilder(pod1).withNewStatus() .addNewCondition() .withType("Ready") .withStatus("False") .endCondition() .endStatus() .build(); Pod ready = new PodBuilder(pod1).withNewStatus() .addNewCondition() .withType("Ready") .withStatus("True") .endCondition() .endStatus() .build(); server.expect().get().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, noReady).once(); server.expect().get().withPath("/api/v1/namespaces/test/pods?fieldSelector=metadata.name%3Dpod1&resourceVersion=1&watch=true").andUpgradeToWebSocket() .open() .waitFor(500).andEmit(new WatchEvent(ready, "MODIFIED")) .done() .always(); KubernetesClient client = server.getClient(); Pod p = client.resource(noReady).waitUntilReady(5, TimeUnit.SECONDS); Assert.assertTrue(Readiness.isPodReady(p)); }
Example #26
Source File: KafkaAssemblyOperator.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
/** * Perform a rolling update of the cluster so that CA certificates get added to their truststores, * or expired CA certificates get removed from their truststores. * Note this is only necessary when the CA certificate has changed due to a new CA key. * It is not necessary when the CA certificate is replace while retaining the existing key. */ @SuppressWarnings("deprecation") Future<ReconciliationState> rollingUpdateForNewCaKey() { List<String> reason = new ArrayList<>(4); if (this.clusterCa.keyReplaced()) { reason.add("trust new cluster CA certificate signed by new key"); } if (this.clientsCa.keyReplaced()) { reason.add("trust new clients CA certificate signed by new key"); } if (!reason.isEmpty()) { String reasons = reason.stream().collect(Collectors.joining(", ")); Future<Void> zkRollFuture; Function<Pod, String> rollPodAndLogReason = pod -> { log.debug("{}: Rolling Pod {} to {}", reconciliation, pod.getMetadata().getName(), reasons); return reasons; }; if (this.clusterCa.keyReplaced()) { zkRollFuture = zkSetOperations.getAsync(namespace, ZookeeperCluster.zookeeperClusterName(name)) .compose(sts -> zkSetOperations.maybeRollingUpdate(sts, rollPodAndLogReason, clusterCa.caCertSecret(), oldCoSecret)); } else { zkRollFuture = Future.succeededFuture(); } return zkRollFuture .compose(i -> kafkaSetOperations.getAsync(namespace, KafkaCluster.kafkaClusterName(name))) .compose(sts -> kafkaSetOperations.maybeRollingUpdate(sts, rollPodAndLogReason, clusterCa.caCertSecret(), oldCoSecret)) .compose(i -> rollDeploymentIfExists(EntityOperator.entityOperatorName(name), reasons)) .compose(i -> rollDeploymentIfExists(KafkaExporter.kafkaExporterName(name), reasons)) .compose(i -> rollDeploymentIfExists(CruiseControl.cruiseControlName(name), reasons)) .map(i -> this); } else { return Future.succeededFuture(this); } }
Example #27
Source File: KubernetesDeployments.java From che with Eclipse Public License 2.0 | 5 votes |
/** * Returns all existing pods. * * @throws InfrastructureException when any exception occurs */ public List<Pod> get() throws InfrastructureException { try { return clientFactory .create(workspaceId) .pods() .inNamespace(namespace) .withLabel(CHE_WORKSPACE_ID_LABEL, workspaceId) .list() .getItems(); } catch (KubernetesClientException e) { throw new KubernetesInfrastructureException(e); } }
Example #28
Source File: KubeTeamCityLabels.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
public static void addCustomLabel(@NotNull Pod pod, @NotNull String label, @NotNull String value){ final Map<String, String> labels = new HashMap<>(pod.getMetadata().getLabels()); labels.put(label, value); pod.getMetadata().setLabels(labels); }
Example #29
Source File: K8sNetworkPolicyHandler.java From onos with Apache License 2.0 | 5 votes |
private void processPodCreation(Pod pod) { if (!isRelevantHelper()) { return; } setBlockRulesByPod(pod, true); setAllowRulesByPod(pod, true); setNamespaceRulesByPod(pod, true); }
Example #30
Source File: PortForwardService.java From jkube with Eclipse Public License 2.0 | 5 votes |
private Pod getNewestPod(List<Pod> items) { Pod targetPod = null; if (items != null) { for (Pod pod : items) { if (KubernetesHelper.isPodWaiting(pod) || KubernetesHelper.isPodRunning(pod)) { if (targetPod == null || (KubernetesHelper.isPodReady(pod) && KubernetesHelper.isNewerResource(pod, targetPod))) { targetPod = pod; } } } } return targetPod; }