RunConfigUtil { static Container containerFromConfig(RunConfig runConfig) { final ContainerBuilder containerBuilder = new ContainerBuilder(); containerBuilder.withName(runConfig.getName()); containerBuilder.withImage(runConfig.getImage()); containerBuilder.withImagePullPolicy(runConfig.getImagePullPolicy()); containerBuilder.withArgs(argsFromConfig(runConfig)); containerBuilder.withCommand(commandFromConfig(runConfig)); if (runConfig.getEnv() != null) { containerBuilder.withEnv(KubernetesResourceUtil.convertMapToEnvVarList(runConfig.getEnv())); } if (runConfig.getPort() > 0) { containerBuilder.withPorts(new ContainerPortBuilder() .withContainerPort(runConfig.getPort()) .build()); } if (runConfig.getLimits() != null) { containerBuilder.editOrNewResources() .addToLimits(runConfig.getLimits()) .endResources(); } if (runConfig.getRequests() != null) { containerBuilder.editOrNewResources() .addToRequests(runConfig.getRequests()) .endResources(); } return containerBuilder.build(); } private  RunConfigUtil(); static ObjectMeta getObjectMetadataFromRunConfig(RunConfig generatorRunConfig); static PodSpec getPodSpecFromRunConfig(RunConfig generatorRunConfig);  }
@Test void testContainerFromConfig() { RunConfig config = initMockRunConfigBuilder().build(); Container container = RunConfigUtil.containerFromConfig(config); assertNotNull(container); assertEquals("test", container.getName()); assertEquals("IfNotPresent", container.getImagePullPolicy()); assertEquals("test:latest", container.getImage()); assertEquals(Collections.emptyList(), container.getArgs()); assertEquals(Collections.emptyList(), container.getCommand()); assertEquals(1, container.getEnv().size()); assertEquals(1, container.getPorts().size()); assertEquals(5701, container.getPorts().get(0).getContainerPort()); assertEquals("TEST_KEY", container.getEnv().get(0).getName()); assertEquals("TEST_VALUE", container.getEnv().get(0).getValue()); assertEquals(new Quantity("200m"), container.getResources().getLimits().get("cpu")); assertEquals(new Quantity("512Mi"), container.getResources().getLimits().get("memory")); assertEquals(new Quantity("150m"), container.getResources().getRequests().get("cpu")); assertEquals(new Quantity("64Mi"), container.getResources().getRequests().get("memory")); }
@Test void testContainerFromConfigWithArgs() { final RunConfig runConfig = initMockRunConfigBuilder() .withArgs("arg1", "arg2") .build(); final Container result = RunConfigUtil.containerFromConfig(runConfig); assertThat(result) .hasFieldOrPropertyWithValue("command", Collections.emptyList()) .extracting(Container::getArgs) .asList().containsExactly("arg1", "arg2"); }
@Test void testContainerFromConfigWithCommand() { final RunConfig runConfig = initMockRunConfigBuilder() .withCommand("/bin/sh") .build(); final Container result = RunConfigUtil.containerFromConfig(runConfig); assertThat(result) .hasFieldOrPropertyWithValue("args", Collections.emptyList()) .extracting(Container::getCommand) .asList().containsExactly("/bin/sh"); }
@Test void testContainerFromConfigWithCommandAndArgs() { final RunConfig runConfig = initMockRunConfigBuilder() .withCommand("/bin/sh") .withArgs("-c", "echo hello") .build(); final Container result = RunConfigUtil.containerFromConfig(runConfig); assertThat(result) .hasFieldOrPropertyWithValue("args", Collections.emptyList()) .extracting(Container::getCommand) .asList().containsExactly("/bin/sh", "-c", "echo hello"); }