io.fabric8.kubernetes.client.dsl.PodResource Java Examples

The following examples show how to use io.fabric8.kubernetes.client.dsl.PodResource. 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: VerifyIntegrationTestAction.java    From yaks with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve log messages from given pod.
 * @param pod
 * @return
 */
private String getIntegrationPodLogs(Pod pod) {
    PodResource<Pod, DoneablePod> podRes = client.pods()
            .inNamespace(CamelKHelper.namespace())
            .withName(pod.getMetadata().getName());

    String containerName = null;
    if (pod.getSpec() != null && pod.getSpec().getContainers() != null && pod.getSpec().getContainers().size() > 1) {
        containerName = pod.getSpec().getContainers().get(0).getName();
    }

    String logs;
    if (containerName != null) {
        logs = podRes.inContainer(containerName).getLog();
    } else {
        logs = podRes.getLog();
    }
    return logs;
}
 
Example #2
Source File: ReplicationControllerOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
private List<PodResource<Pod, DoneablePod>> doGetLog(boolean isPretty) {
  List<PodResource<Pod, DoneablePod>> pods = new ArrayList<>();
  ReplicationController rc = fromServer().get();
  String rcUid = rc.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(rc.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 #3
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
private List<PodResource<Pod, DoneablePod>> doGetLog(boolean isPretty) {
  List<PodResource<Pod, DoneablePod>> pods = new ArrayList<>();
  Job job = fromServer().get();
  String jobUid = job.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.withLabel("controller-uid", jobUid).list();

  for (Pod pod : jobPodList.getItems()) {
    OwnerReference ownerReference = KubernetesResourceUtil.getControllerUid(pod);
    if (ownerReference != null && ownerReference.getUid().equals(jobUid)) {
      pods.add(podOperations.withName(pod.getMetadata().getName()));
    }
  }
  return pods;
}
 
Example #4
Source File: StatefulSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: ReplicaSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
private List<PodResource<Pod, DoneablePod>> doGetLog(boolean isPretty) {
  List<PodResource<Pod, DoneablePod>> pods = new ArrayList<>();
  ReplicaSet replicaSet = fromServer().get();
  String rcUid = replicaSet.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(replicaSet.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 #6
Source File: ReplicaSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public LogWatch watchLog(OutputStream out) {
  List<PodResource<Pod, DoneablePod>> podResources = doGetLog(false);
  if (podResources.size() > 1) {
    throw new KubernetesClientException("Watching logs is not supported for multicontainer jobs");
  } else if (podResources.size() == 1) {
    return podResources.get(0).watchLog(out);
  }
  return null;
}
 
Example #7
Source File: KubernetesCloudTest.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstanceCap() {
    KubernetesCloud cloud = new KubernetesCloud("name") {
        @Override
        public KubernetesClient connect() {
            KubernetesClient mockClient =  Mockito.mock(KubernetesClient.class);
            Mockito.when(mockClient.getNamespace()).thenReturn("default");
            MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> operation = Mockito.mock(MixedOperation.class);
            Mockito.when(operation.inNamespace(Mockito.anyString())).thenReturn(operation);
            Mockito.when(operation.withLabels(Mockito.anyMap())).thenReturn(operation);
            PodList podList = Mockito.mock(PodList.class);
            Mockito.when(podList.getItems()).thenReturn(new ArrayList<>());
            Mockito.when(operation.list()).thenReturn(podList);
            Mockito.when(mockClient.pods()).thenReturn(operation);
            return mockClient;
        }
    };

    PodTemplate podTemplate = new PodTemplate();
    podTemplate.setName("test");
    podTemplate.setLabel("test");

    cloud.addTemplate(podTemplate);

    Label test = Label.get("test");
    assertTrue(cloud.canProvision(test));

    Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(test, 200);
    assertEquals(200, plannedNodes.size());

    podTemplate.setInstanceCap(5);
    plannedNodes = cloud.provision(test, 200);
    assertEquals(5, plannedNodes.size());
}
 
Example #8
Source File: KubernetesCloudTest.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainerCap() {
    KubernetesCloud cloud = new KubernetesCloud("name") {
        @Override
        public KubernetesClient connect()  {
            KubernetesClient mockClient =  Mockito.mock(KubernetesClient.class);
            Mockito.when(mockClient.getNamespace()).thenReturn("default");
            MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> operation = Mockito.mock(MixedOperation.class);
            Mockito.when(operation.inNamespace(Mockito.anyString())).thenReturn(operation);
            Mockito.when(operation.withLabels(Mockito.anyMap())).thenReturn(operation);
            PodList podList = Mockito.mock(PodList.class);
            Mockito.when(podList.getItems()).thenReturn(new ArrayList<>());
            Mockito.when(operation.list()).thenReturn(podList);
            Mockito.when(mockClient.pods()).thenReturn(operation);
            return mockClient;
        }
    };

    PodTemplate podTemplate = new PodTemplate();
    podTemplate.setName("test");
    podTemplate.setLabel("test");

    cloud.addTemplate(podTemplate);

    Label test = Label.get("test");
    assertTrue(cloud.canProvision(test));

    Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(test, 200);
    assertEquals(200, plannedNodes.size());

    cloud.setContainerCapStr("10");
    podTemplate.setInstanceCap(20);
    plannedNodes = cloud.provision(test, 200);
    assertEquals(10, plannedNodes.size());
}
 
Example #9
Source File: PodTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
void testEvict() {
  server.expect().withPath("/api/v1/namespaces/test/pods/pod1/eviction").andReturn(200, new PodBuilder().build()).once();
  server.expect().withPath("/api/v1/namespaces/ns1/pods/pod2/eviction").andReturn(200, new PodBuilder().build()).once();
  server.expect().withPath("/api/v1/namespaces/ns1/pods/pod3/eviction").andReturn(PodOperationsImpl.HTTP_TOO_MANY_REQUESTS, new PodBuilder().build()).once();
  server.expect().withPath("/api/v1/namespaces/ns1/pods/pod3/eviction").andReturn(200, new PodBuilder().build()).once();
  server.expect().withPath("/api/v1/namespaces/ns1/pods/pod4/eviction").andReturn(500, new PodBuilder().build()).once();

  KubernetesClient client = server.getClient();

  Boolean deleted = client.pods().withName("pod1").evict();
  assertTrue(deleted);

  // not found
  deleted = client.pods().withName("pod2").evict();
  assertFalse(deleted);

  deleted = client.pods().inNamespace("ns1").withName("pod2").evict();
  assertTrue(deleted);

  // too many requests
  deleted = client.pods().inNamespace("ns1").withName("pod3").evict();
  assertFalse(deleted);

  deleted = client.pods().inNamespace("ns1").withName("pod3").evict();
  assertTrue(deleted);

  // unhandled error
  PodResource<Pod, DoneablePod> resource = client.pods().inNamespace("ns1").withName("pod4");
  assertThrows(KubernetesClientException.class, resource::evict);
}
 
Example #10
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public String getLog(Boolean isPretty) {
  StringBuilder stringBuilder = new StringBuilder();
  List<PodResource<Pod, DoneablePod>> podOperationList = doGetLog(false);
  for (PodResource<Pod, DoneablePod> podOperation : podOperationList) {
    stringBuilder.append(podOperation.getLog(isPretty));
  }
  return stringBuilder.toString();
}
 
Example #11
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #12
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public LogWatch watchLog(OutputStream out) {
  List<PodResource<Pod, DoneablePod>> podResources = doGetLog(false);
  if (podResources.size() > 1) {
    throw new KubernetesClientException("Watching logs is not supported for multicontainer jobs");
  } else if (podResources.size() == 1) {
    return podResources.get(0).watchLog(out);
  }
  return null;
}
 
Example #13
Source File: ReplicaSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: ReplicaSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #15
Source File: KubernetesLander.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<LanderConfiguration> run() {
  client.pods().withName(podName).delete();
  client.pods().create(pod);
  PodResource<Pod, DoneablePod> resource = client.pods().withName(podName);
  PodWatcher podWatcher = new PodWatcher(resource, podName);
  return podWatcher.get().thenApply(c -> config);
}
 
Example #16
Source File: StatefulSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
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 #17
Source File: StatefulSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #18
Source File: StatefulSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public LogWatch watchLog(OutputStream out) {
  List<PodResource<Pod, DoneablePod>> podResources = doGetLog(false);
  if (podResources.size() > 1) {
    throw new KubernetesClientException("Watching logs is not supported for multicontainer jobs");
  } else if (podResources.size() == 1) {
    return podResources.get(0).watchLog(out);
  }
  return null;
}
 
Example #19
Source File: ReplicationControllerOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
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 #20
Source File: ReplicationControllerOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #21
Source File: ReplicationControllerOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public LogWatch watchLog(OutputStream out) {
  List<PodResource<Pod, DoneablePod>> podResources = doGetLog(false);
  if (podResources.size() > 1) {
    throw new KubernetesClientException("Watching logs is not supported for multicontainer jobs");
  } else if (podResources.size() == 1) {
    return podResources.get(0).watchLog(out);
  }
  return null;
}
 
Example #22
Source File: SystemtestsKubernetesApps.java    From enmasse with Apache License 2.0 5 votes vote down vote up
public static Optional<PodResource<Pod, DoneablePod>> getH2ServerPod() {
    final var client = kube.getClient();
    return kube.getClient()
            .pods()
            .inNamespace(H2_PROJECT)
            .withLabel("app", "h2")
            .list().getItems().stream().findFirst()
            .map(pod -> client.pods()
                    .inNamespace(pod.getMetadata().getNamespace())
                    .withName(pod.getMetadata().getName()));
}
 
Example #23
Source File: PodWatcher.java    From data-highway with Apache License 2.0 5 votes vote down vote up
public PodWatcher(PodResource<Pod, DoneablePod> resource, String podName) {
  this.resource = resource;
  this.podName = podName;
  if (resource.get() == null) {
    throw new RuntimeException(String.format("pod %s does not exist.", podName));
  }
  watch = resource.watch(this);
  exitCodeFuture = new CompletableFuture<Integer>() {
    @Override
    public boolean cancel(boolean mayInterruptIfRunning) {
      resource.delete();
      return super.cancel(mayInterruptIfRunning);
    }
  };
}
 
Example #24
Source File: PodLogService.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private void watchLogOfPodName(KubernetesClient kubernetes, String namespace, String ctrlCMessage, boolean followLog, Pod pod, String name) {
    if (watchingPodName == null || !watchingPodName.equals(name)) {
        if (logWatcher != null) {
            log.info("Closing log watcher for %s as now watching %s", watchingPodName, name);
            closeLogWatcher();
        }
        PodResource<Pod, DoneablePod> podResource = kubernetes.pods().inNamespace(namespace).withName(name);
        List<Container> containers = KubernetesHelper.getContainers(pod);
        String containerName = null;
        if (followLog) {
            watchingPodName = name;
            logWatchTerminateLatch = new CountDownLatch(1);
            if (containers.size() < 2) {
                logWatcher = podResource.watchLog();
            } else {
                containerName = getLogContainerName(containers);
                logWatcher = podResource.inContainer(containerName).watchLog();
            }
            watchLog(logWatcher, name, "Failed to read log of pod " + name + ".", ctrlCMessage, containerName);
        } else {
            String logText;
            if (containers.size() < 2) {
                logText = podResource.getLog();
            } else {
                containerName = getLogContainerName(containers);
                logText = podResource.inContainer(containerName).getLog();
            }
            if (logText != null) {
                String[] lines = logText.split("\n");
                log.info("Log of pod: %s%s", name, containerNameMessage(containerName));
                log.info("");
                for (String line : lines) {
                    log.info("[[s]]%s", line);
                }
            }
            terminateLatch.countDown();
        }
    }
}
 
Example #25
Source File: KubernetesClientUtil.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, KitLogger log) {
    FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> answer = pods;
    Map<String, String> matchLabels = selector.getMatchLabels();
    if (matchLabels != null && !matchLabels.isEmpty()) {
        answer = answer.withLabels(matchLabels);
    }
    List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions();
    if (matchExpressions != null) {
        for (LabelSelectorRequirement expression : matchExpressions) {
            String key = expression.getKey();
            List<String> values = expression.getValues();
            if (StringUtils.isBlank(key)) {
                log.warn("Ignoring empty key in selector expression %s", expression);
                continue;
            }
            if (values == null || values.isEmpty()) {
                log.warn("Ignoring empty values in selector expression %s", expression);
                continue;
            }
            String[] valuesArray = values.toArray(new String[values.size()]);
            String operator = expression.getOperator();
            switch (operator) {
            case "In":
                answer = answer.withLabelIn(key, valuesArray);
                break;
            case "NotIn":
                answer = answer.withLabelNotIn(key, valuesArray);
                break;
            default:
                log.warn("Ignoring unknown operator %s in selector expression %s", operator, expression);
            }
        }
    }
    return answer;
}
 
Example #26
Source File: KubernetesHelper.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, KitLogger log) {
    FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> answer = pods;
    Map<String, String> matchLabels = selector.getMatchLabels();
    if (matchLabels != null && !matchLabels.isEmpty()) {
        answer = answer.withLabels(matchLabels);
    }
    List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions();
    if (matchExpressions != null) {
        for (LabelSelectorRequirement expression : matchExpressions) {
            String key = expression.getKey();
            List<String> values = expression.getValues();
            if (StringUtils.isBlank(key)) {
                log.warn("Ignoring empty key in selector expression %s", expression);
                continue;
            }
            if (values == null || values.isEmpty()) {
                log.warn("Ignoring empty values in selector expression %s", expression);
                continue;
            }
            String[] valuesArray = values.toArray(new String[values.size()]);
            String operator = expression.getOperator();
            switch (operator) {
                case "In":
                    answer = answer.withLabelIn(key, valuesArray);
                    break;
                case "NotIn":
                    answer = answer.withLabelNotIn(key, valuesArray);
                    break;
                default:
                    log.warn("Ignoring unknown operator %s in selector expression %s", operator, expression);
            }
        }
    }
    return answer;
}
 
Example #27
Source File: KafkaKubernetesCloudTest.java    From remoting-kafka-plugin with MIT License 5 votes vote down vote up
@Test
public void testProvisionCreateThenTerminatePod() throws Exception {
    KafkaKubernetesCloud cloud = new KafkaKubernetesCloud("kafka-kubernetes");
    cloud.setServerUrl(k.getMockServer().url("/").toString());
    cloud.setSkipTlsVerify(true);
    j.jenkins.clouds.add(cloud);

    Collection<NodeProvisioner.PlannedNode> provisionedNodes = cloud.provision(new LabelAtom("test"), 1);
    assertThat(provisionedNodes, hasSize(1));
    KafkaCloudSlave agent = (KafkaCloudSlave) provisionedNodes.iterator().next().future.get();
    TaskListener listener = new LogTaskListener(Logger.getLogger(KafkaKubernetesCloudTest.class.getName()), Level.INFO);
    PodResource<Pod, DoneablePod> pod = k.getClient().pods().inNamespace(cloud.getNamespace()).withName(agent.getNodeName());

    assertNull(pod.get());

    // Poll for pod creation
    j.jenkins.addNode(agent);
    final int TIMEOUT = 30;
    for(int i = 0; i < TIMEOUT; i++) {
        if (pod.get() != null) break;
        TimeUnit.SECONDS.sleep(1);
    }
    assertNotNull(pod.get());

    agent._terminate(listener);
    assertNull(pod.get());
}
 
Example #28
Source File: SupportUtil.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private Reader fetchLogsFor(String podName) {
    final PodResource<Pod, DoneablePod> pod = client.pods().withName(podName);
    String componentName = pod.get().getMetadata().getLabels().get(COMPONENT_LABEL);
    String container = PLATFORM_PODS_CONTAINER.get(componentName);
    if (container != null) {
        return pod.inContainer(container).getLogReader();
    } else {
        return pod.getLogReader();
    }
}
 
Example #29
Source File: FakeKubeClient.java    From teamcity-kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods() {
  if (myException != null){
    throw myException;
  }
  return new MyOperation(){
    @Override
    public Object create(final Object[] resources) throws KubernetesClientException {
      return new Pod();
    }
  };
}
 
Example #30
Source File: PodReadinessWatcher.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
public void start() {
	if (this.watch == null) {
		synchronized (this.lock) {
			if (this.watch == null) {
				LOGGER.debug("Starting pod readiness watcher for '{}'", this.podName);
				PodResource<Pod, DoneablePod> podResource = this.kubernetesClient
						.pods().withName(this.podName);
				this.previousState = podResource.isReady();
				this.watch = podResource.watch(this);
			}
		}
	}
}