KubernetesDeployments { 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); } } protected  KubernetesDeployments(
      String namespace,
      String workspaceId,
      KubernetesClientFactory clientFactory,
      Executor executor); Pod deploy(Pod pod); Pod deploy(Deployment deployment); Pod create(Pod pod); List<Pod> get(); Optional<Pod> get(String name); Pod wait(String name, int timeoutMin, Predicate<Pod> predicate); CompletableFuture<Void> waitRunningAsync(String name); void watch(PodActionHandler handler); void watchEvents(PodEventHandler handler); synchronized void watchLogs(
      PodLogHandler handler,
      RuntimeEventsPublisher eventsPublisher,
      LogWatchTimeouts timeouts,
      Set<String> podNames,
      long limitInputStreamBytes); void stopWatch(); void stopWatch(boolean failed); void exec(
      String name,
      String containerName,
      int timeoutMin,
      String[] command,
      BiConsumer<String, String> outputConsumer); void exec(String name, String containerName, int timeoutMin, String[] command); @Nullable String getPodLogs(String name); void delete(String name); void delete(); static final int POD_REMOVAL_TIMEOUT_MIN; static final int POD_CREATION_TIMEOUT_MIN; static final int ERROR_BUFF_INITIAL_CAP; static final String STDOUT; static final String STDERR; }
@Test public void shouldReturnEmptyOptionalWhenPodNorDeploymentWasNotFound() throws Exception { when(podResource.get()).thenReturn(null); when(deploymentResource.get()).thenReturn(null); Optional<Pod> pod = kubernetesDeployments.get("non-existing"); assertFalse(pod.isPresent()); }
@Test public void shouldReturnOptionalWithPodWhenPodWithSpecifiedNameExists() throws Exception { when(podResource.get()).thenReturn(pod); Optional<Pod> fetchedPodOpt = kubernetesDeployments.get("existing"); assertTrue(fetchedPodOpt.isPresent()); verify(podsNamespaceOperation).withName("existing"); assertEquals(fetchedPodOpt.get(), pod); }
@Test public void shouldReturnOptionalWithPodWhenPodWasNotFoundButDeploymentExists() throws Exception { when(podResource.get()).thenReturn(null); when(deploymentResource.get()).thenReturn(deployment); LabelSelector labelSelector = mock(LabelSelector.class); doReturn(labelSelector).when(deploymentSpec).getSelector(); doReturn(ImmutableMap.of("deployment", "existing")).when(labelSelector).getMatchLabels(); FilterWatchListDeletable filterList = mock(FilterWatchListDeletable.class); doReturn(filterList).when(podsNamespaceOperation).withLabels(any()); PodList podList = mock(PodList.class); doReturn(singletonList(pod)).when(podList).getItems(); doReturn(podList).when(filterList).list(); Optional<Pod> fetchedPodOpt = kubernetesDeployments.get("existing"); assertTrue(fetchedPodOpt.isPresent()); verify(podsNamespaceOperation).withName("existing"); verify(deploymentsNamespaceOperation).withName("existing"); assertEquals(fetchedPodOpt.get(), pod); }
@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Found multiple pods in Deployment 'existing'") public void shouldThrowExceptionWhenMultiplePodsExistsForDeploymentsOnPodFetching() throws Exception { when(podResource.get()).thenReturn(null); when(deploymentResource.get()).thenReturn(deployment); LabelSelector labelSelector = mock(LabelSelector.class); doReturn(labelSelector).when(deploymentSpec).getSelector(); doReturn(ImmutableMap.of("deployment", "existing")).when(labelSelector).getMatchLabels(); FilterWatchListDeletable filterList = mock(FilterWatchListDeletable.class); doReturn(filterList).when(podsNamespaceOperation).withLabels(any()); PodList podList = mock(PodList.class); doReturn(asList(pod, pod)).when(podList).getItems(); doReturn(podList).when(filterList).list(); kubernetesDeployments.get("existing"); }