KubernetesInternalRuntime extends InternalRuntime<KubernetesRuntimeContext<E>> { public boolean isConsistent() throws InfrastructureException { Set<String> podNames = getInternalMachines() .values() .stream() .map(KubernetesMachineImpl::getPodName) .collect(Collectors.toSet()); for (String podName : podNames) { if (namespace.deployments().get(podName).isPresent()) { return true; } } return false; } @Inject  KubernetesInternalRuntime(
      @Named("che.infra.kubernetes.workspace_start_timeout_min") int workspaceStartTimeoutMin,
      @Named("che.infra.kubernetes.ingress_start_timeout_min") int ingressStartTimeoutMin,
      NoOpURLRewriter urlRewriter,
      UnrecoverablePodEventListenerFactory unrecoverableEventListenerFactory,
      ServersCheckerFactory serverCheckerFactory,
      WorkspaceVolumesStrategy volumesStrategy,
      ProbeScheduler probeScheduler,
      WorkspaceProbesFactory probesFactory,
      RuntimeEventsPublisher eventPublisher,
      KubernetesSharedPool sharedPool,
      KubernetesRuntimeStateCache runtimeStates,
      KubernetesMachineCache machines,
      StartSynchronizerFactory startSynchronizerFactory,
      Set<InternalEnvironmentProvisioner> internalEnvironmentProvisioners,
      KubernetesEnvironmentProvisioner<E> kubernetesEnvironmentProvisioner,
      SidecarToolingProvisioner<E> toolingProvisioner,
      RuntimeHangingDetector runtimeHangingDetector,
      PreviewUrlCommandProvisioner previewUrlCommandProvisioner,
      SecretAsContainerResourceProvisioner secretAsContainerResourceProvisioner,
      KubernetesServerResolverFactory kubernetesServerResolverFactory,
      RuntimeCleaner runtimeCleaner,
      CheNamespace cheNamespace,
      Tracer tracer,
      @Assisted KubernetesRuntimeContext<E> context,
      @Assisted KubernetesNamespace namespace); void scheduleRuntimeStateChecks(); CompletableFuture<Void> waitRunningAsync(
      List<CompletableFuture<?>> toCancelFutures, KubernetesMachineImpl machine); @Override Map<String, ? extends KubernetesMachineImpl> getInternalMachines(); @Override List<? extends Command> getCommands(); @Override Map<String, String> getProperties(); @Override WorkspaceStatus getStatus(); void scheduleServersCheckers(); boolean isConsistent();  }
@Test public void shouldReturnTrueIfAllPodsExistOnRuntimeConsistencyChecking() throws Exception { KubernetesMachineImpl machine1 = new KubernetesMachineImpl( WORKSPACE_ID, "machine1", "pod1", "container 1", null, emptyMap(), emptyMap()); KubernetesMachineImpl machine2 = new KubernetesMachineImpl( WORKSPACE_ID, "machine2", "pod1", "container 2", null, emptyMap(), emptyMap()); KubernetesMachineImpl machine3 = new KubernetesMachineImpl( WORKSPACE_ID, "machine3", "pod2", "container 1", null, emptyMap(), emptyMap()); machinesCache.put(IDENTITY, machine1); machinesCache.put(IDENTITY, machine2); machinesCache.put(IDENTITY, machine3); doReturn(Optional.of(mock(Pod.class))).when(deployments).get(anyString()); boolean isConsistent = internalRuntime.isConsistent(); assertTrue(isConsistent); }
@Test public void shouldReturnTrueIfOnlyOnePodExistsOnRuntimeConsistencyChecking() throws Exception { KubernetesMachineImpl machine1 = new KubernetesMachineImpl( WORKSPACE_ID, "machine1", "pod1", "container 1", null, emptyMap(), emptyMap()); KubernetesMachineImpl machine2 = new KubernetesMachineImpl( WORKSPACE_ID, "machine2", "pod1", "container 2", null, emptyMap(), emptyMap()); KubernetesMachineImpl machine3 = new KubernetesMachineImpl( WORKSPACE_ID, "machine3", "pod2", "container 1", null, emptyMap(), emptyMap()); machinesCache.put(IDENTITY, machine1); machinesCache.put(IDENTITY, machine2); machinesCache.put(IDENTITY, machine3); doReturn(Optional.of(mock(Pod.class))).when(deployments).get("pod1"); doReturn(Optional.empty()).when(deployments).get("pod2"); boolean isConsistent = internalRuntime.isConsistent(); assertTrue(isConsistent); }
@Test public void shouldReturnFalseIfAllPodsExistOnRuntimeConsistencyChecking() throws Exception { KubernetesMachineImpl machine1 = new KubernetesMachineImpl( WORKSPACE_ID, "machine1", "pod1", "container 1", null, emptyMap(), emptyMap()); KubernetesMachineImpl machine2 = new KubernetesMachineImpl( WORKSPACE_ID, "machine2", "pod1", "container 2", null, emptyMap(), emptyMap()); KubernetesMachineImpl machine3 = new KubernetesMachineImpl( WORKSPACE_ID, "machine3", "pod2", "container 1", null, emptyMap(), emptyMap()); machinesCache.put(IDENTITY, machine1); machinesCache.put(IDENTITY, machine2); machinesCache.put(IDENTITY, machine3); doReturn(Optional.empty()).when(deployments).get(anyString()); boolean isConsistent = internalRuntime.isConsistent(); assertFalse(isConsistent); }