K8sContainerResolver { public Container resolve() throws InfrastructureException { Container container = new ContainerBuilder() .withImage(cheContainer.getImage()) .withImagePullPolicy(imagePullPolicy) .withName(buildContainerName(cheContainer.getName())) .withEnv(toK8sEnv(cheContainer.getEnv())) .withPorts(getContainerPorts()) .withCommand(cheContainer.getCommand()) .withArgs(cheContainer.getArgs()) .withLifecycle(toK8sLifecycle(cheContainer.getLifecycle())) .build(); provisionMemoryLimit(container, cheContainer); provisionMemoryRequest(container, cheContainer); provisionCpuLimit(container, cheContainer); provisionCpuRequest(container, cheContainer); return container; } K8sContainerResolver(
      String imagePullPolicy, CheContainer container, List<ChePluginEndpoint> containerEndpoints); List<ChePluginEndpoint> getEndpoints(); Container resolve();  }
@Test public void shouldSetImageFromSidecar() throws Exception { cheContainer.setImage(IMAGE); Container container = resolver.resolve(); assertEquals(container.getImage(), IMAGE); }
@Test public void shouldSetName() throws Exception { cheContainer.setName("cheContainerName"); Container container = resolver.resolve(); assertTrue(container.getName().startsWith((cheContainer.getName()).toLowerCase())); }
@Test public void shouldLimitNameByMaxAllowedLength() throws Exception { cheContainer.setName("cheContainerNameWhichIsGreatlySucceedsMaxAllowedLengthByKubernetes"); Container container = resolver.resolve(); assertEquals(container.getName().length(), MAX_CONTAINER_NAME_LENGTH); }
@Test public void shouldSetEnvVarsFromSidecar() throws Exception { Map<String, String> env = ImmutableMap.of("name1", "value1", "name2", "value2"); cheContainer.setEnv(toSidecarEnvVars(env)); Container container = resolver.resolve(); assertEqualsNoOrder(container.getEnv().toArray(), toK8sEnvVars(env).toArray()); }
@Test public void shouldSetPortsFromContainerEndpoints() throws Exception { Integer[] ports = new Integer[] {3030, 10000}; endpoints.addAll(toEndpoints(ports)); Container container = resolver.resolve(); assertEqualsNoOrder(container.getPorts().toArray(), toK8sPorts(ports).toArray()); }
@Test(dataProvider = "memLimitResourcesProvider") public void shouldProvisionSidecarMemoryLimitAndRequest( String sidecarMemLimit, ResourceRequirements resources) throws Exception { cheContainer.setMemoryLimit(sidecarMemLimit); cheContainer.setMemoryRequest(sidecarMemLimit); Container container = resolver.resolve(); assertEquals(container.getResources(), resources); }
@Test(dataProvider = "cpuLimitResourcesProvider") public void shouldProvisionSidecarCPULimitAndRequest( String sidecarCpuLimit, ResourceRequirements resources) throws Exception { cheContainer.setCpuLimit(sidecarCpuLimit); cheContainer.setCpuRequest(sidecarCpuLimit); Container container = resolver.resolve(); assertEquals(container.getResources(), resources); }
@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Sidecar memory limit field contains illegal value .*") public void shouldThrowExceptionIfMemoryLimitIsInIllegalFormat() throws Exception { cheContainer.setMemoryLimit("IllegalValue"); resolver.resolve(); }