@Test public void simple() { when(podNameFactory.newName(any())).thenReturn(TRUCK_PARK_NAME); when(configMapSupplier.get()).thenReturn(configMap); when(configMap.getData()).thenReturn(ImmutableMap .<String, String> builder() .put(DOCKER_IMAGE, DOCKER_IMAGE_NAME) .put(VERSION, IMAGE_VERSION) .put(CPU, "cpu1") .put(MEMORY, "mem1") .put(JVM_ARGS, "args1") .put(CLOUDWATCH_REGION, "region") .put(CLOUDWATCH_GROUP, "group") .put("annotations", "{\"annotation1\": \"value1\", \"annotation2/slashsomething\": \"value2\"}") .build()); LanderConfiguration config = new LanderConfiguration(NAME, "topic", emptyMap(), "s3Prefix", false, PARTITION_COLUMN_VALUE, false); Pod pod = underTest.newInstance(config, singletonList(ARG)); ObjectMeta metadata = pod.getMetadata(); assertThat(metadata.getName(), is(TRUCK_PARK_NAME)); assertThat(metadata.getLabels(), is(ImmutableMap .<String, String> builder() .put(APP, TRUCK_PARK) .put(VERSION, IMAGE_VERSION) .put(ROAD, NAME) .build())); assertThat(metadata.getAnnotations(), is(ImmutableMap .<String, String> builder() .put("annotation1", "value1") .put("annotation2/slashsomething", "value2") .build())); PodSpec spec = pod.getSpec(); assertThat(spec.getRestartPolicy(), is(RESTART_POLICY_NEVER)); List<Container> containers = spec.getContainers(); assertThat(containers.size(), is(1)); Container container = containers.get(0); assertThat(container.getName(), is(TRUCK_PARK_NAME)); assertThat(container.getImage(), is(DOCKER_IMAGE_NAME)); assertThat(container.getArgs(), is(singletonList(ARG))); List<EnvVar> env = container.getEnv(); assertThat(env.size(), is(7)); EnvVar kubeNamespace = env.get(0); assertThat(kubeNamespace.getName(), is("KUBERNETES_NAMESPACE")); assertThat(kubeNamespace.getValue(), is(nullValue())); EnvVar podNameEnv = env.get(1); assertThat(podNameEnv.getName(), is("POD_NAME")); assertThat(podNameEnv.getValue(), is(TRUCK_PARK_NAME)); EnvVar environment = env.get(2); assertThat(environment.getName(), is("ENVIRONMENT")); assertThat(environment.getValue(), is("lab")); EnvVar jvmArgs = env.get(3); assertThat(jvmArgs.getName(), is("JVM_ARGS")); assertThat(jvmArgs.getValue(), is("args1")); EnvVar cloudwatchRegion = env.get(4); assertThat(cloudwatchRegion.getName(), is("CLOUDWATCH_REGION")); assertThat(cloudwatchRegion.getValue(), is("region")); EnvVar cloudwatchGroup = env.get(5); assertThat(cloudwatchGroup.getName(), is("CLOUDWATCH_GROUP")); assertThat(cloudwatchGroup.getValue(), is("group")); EnvVar cloudwatchStream = env.get(6); assertThat(cloudwatchStream.getName(), is("CLOUDWATCH_STREAM")); assertThat(cloudwatchStream.getValue(), is("${KUBERNETES_NAMESPACE}-truck-park-the_name")); ResourceRequirements resources = container.getResources(); assertThat(resources.getLimits().get(CPU), is(new Quantity("cpu1"))); assertThat(resources.getLimits().get(MEMORY), is(new Quantity("mem1"))); assertThat(resources.getRequests().get(CPU), is(new Quantity("cpu1"))); assertThat(resources.getRequests().get(MEMORY), is(new Quantity("mem1"))); }
public Pod newInstance(LanderConfiguration config, List<String> args) { String truckParkName = podNameFactory.newName(config); log.info("Creating pod named: {}", truckParkName); Map<String, String> configMap = configMapSupplier.get().getData(); return new PodBuilder() .withMetadata(new ObjectMetaBuilder() .withName(truckParkName) .withLabels(labels(config.getRoadName(), configMap)) .withAnnotations(annotations(configMap)) .build()) .withSpec(new PodSpecBuilder() .withRestartPolicy(RESTART_POLICY_NEVER) .withContainers(container(config.getRoadName(), args, configMap, truckParkName)) .build()) .build(); }
LanderPodFactory { public Pod newInstance(LanderConfiguration config, List<String> args) { String truckParkName = podNameFactory.newName(config); log.info("Creating pod named: {}", truckParkName); Map<String, String> configMap = configMapSupplier.get().getData(); return new PodBuilder() .withMetadata(new ObjectMetaBuilder() .withName(truckParkName) .withLabels(labels(config.getRoadName(), configMap)) .withAnnotations(annotations(configMap)) .build()) .withSpec(new PodSpecBuilder() .withRestartPolicy(RESTART_POLICY_NEVER) .withContainers(container(config.getRoadName(), args, configMap, truckParkName)) .build()) .build(); } }
LanderPodFactory { public Pod newInstance(LanderConfiguration config, List<String> args) { String truckParkName = podNameFactory.newName(config); log.info("Creating pod named: {}", truckParkName); Map<String, String> configMap = configMapSupplier.get().getData(); return new PodBuilder() .withMetadata(new ObjectMetaBuilder() .withName(truckParkName) .withLabels(labels(config.getRoadName(), configMap)) .withAnnotations(annotations(configMap)) .build()) .withSpec(new PodSpecBuilder() .withRestartPolicy(RESTART_POLICY_NEVER) .withContainers(container(config.getRoadName(), args, configMap, truckParkName)) .build()) .build(); } @Autowired  LanderPodFactory(
      Supplier<ConfigMap> configMapSupplier,
      PodNameFactory podNameFactory,
      @Value("${ENVIRONMENT}") String environment); }
LanderPodFactory { public Pod newInstance(LanderConfiguration config, List<String> args) { String truckParkName = podNameFactory.newName(config); log.info("Creating pod named: {}", truckParkName); Map<String, String> configMap = configMapSupplier.get().getData(); return new PodBuilder() .withMetadata(new ObjectMetaBuilder() .withName(truckParkName) .withLabels(labels(config.getRoadName(), configMap)) .withAnnotations(annotations(configMap)) .build()) .withSpec(new PodSpecBuilder() .withRestartPolicy(RESTART_POLICY_NEVER) .withContainers(container(config.getRoadName(), args, configMap, truckParkName)) .build()) .build(); } @Autowired  LanderPodFactory(
      Supplier<ConfigMap> configMapSupplier,
      PodNameFactory podNameFactory,
      @Value("${ENVIRONMENT}") String environment); Pod newInstance(LanderConfiguration config, List<String> args); }
LanderPodFactory { public Pod newInstance(LanderConfiguration config, List<String> args) { String truckParkName = podNameFactory.newName(config); log.info("Creating pod named: {}", truckParkName); Map<String, String> configMap = configMapSupplier.get().getData(); return new PodBuilder() .withMetadata(new ObjectMetaBuilder() .withName(truckParkName) .withLabels(labels(config.getRoadName(), configMap)) .withAnnotations(annotations(configMap)) .build()) .withSpec(new PodSpecBuilder() .withRestartPolicy(RESTART_POLICY_NEVER) .withContainers(container(config.getRoadName(), args, configMap, truckParkName)) .build()) .build(); } @Autowired  LanderPodFactory(
      Supplier<ConfigMap> configMapSupplier,
      PodNameFactory podNameFactory,
      @Value("${ENVIRONMENT}") String environment); Pod newInstance(LanderConfiguration config, List<String> args); static final String DOCKER_IMAGE; }