io.fabric8.kubernetes.api.model.DoneablePod Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.DoneablePod. 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: PodOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public PodOperationsImpl(PodOperationContext context) {
  super(context.withPlural("pods"));
  this.type = Pod.class;
  this.listType = PodList.class;
  this.doneableType = DoneablePod.class;

  this.containerId = context.getContainerId();
  this.in = context.getIn();
  this.inPipe = context.getInPipe();
  this.out = context.getOut();
  this.outPipe = context.getOutPipe();
  this.err = context.getErr();
  this.errPipe = context.getErrPipe();
  this.errChannel = context.getErrChannel();
  this.errChannelPipe = context.getErrChannelPipe();
  this.withTTY = context.isTty();
  this.withTerminatedStatus = context.isTerminatedStatus();
  this.withTimestamps = context.isTimestamps();
  this.sinceTimestamp = context.getSinceTimestamp();
  this.sinceSeconds = context.getSinceSeconds();
  this.withTailingLines = context.getTailingLines();
  this.withPrettyOutput = context.isPrettyOutput();
  this.execListener = context.getExecListener();
  this.limitBytes = context.getLimitBytes();
  this.bufferSize = context.getBufferSize();
}
 
Example #2
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 #3
Source File: PatchService.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private static EntityPatcher<Pod> podPatcher() {
    return (KubernetesClient client, String namespace, Pod newObj, Pod oldObj) -> {
        if (UserConfigurationCompare.configEqual(newObj, oldObj)) {
            return oldObj;
        }

        DoneablePod entity =
            client.pods()
                  .inNamespace(namespace)
                  .withName(oldObj.getMetadata().getName())
                  .edit();

        if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) {
            entity.withMetadata(newObj.getMetadata());
        }

        if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) {
                entity.withSpec(newObj.getSpec());
        }
        return entity.done();
    };
}
 
Example #4
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 #5
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 #6
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 #7
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 #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: 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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
Source File: SystemtestsKubernetesApps.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private static void deployH2SQLSchema(final PodResource<Pod, DoneablePod> podAccess, final Path sql) throws IOException, InterruptedException, TimeoutException {
    log.info("Deploying SQL schema: {}", sql);

    try (InputStream sqlFile = Files.newInputStream(sql)) {
        executeWithInput(
                podAccess, sqlFile,
                input -> input.write("\nexit\n".getBytes(UTF_8)),
                Duration.ofSeconds(10),
                H2_SHELL_COMMAND);
    }

}
 
Example #24
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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
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();
    }
  };
}