builder.withContainers(containers.values().toArray(new Container[containers.size()])); Pod pod = builder.endSpec().build();
.withContainers(Lists.newArrayList(combinedContainers.values())) //
.withNodeSelector(node != null ? node.getMetadata().getLabels() : new HashMap<String, String>()) .withVolumes(volumes) .withContainers(containers) .withRestartPolicy("Never") .withServiceAccount(podTemplate.getServiceAccount())
@Test public void shouldCombineAllPodMounts() { VolumeMount vm1 = new VolumeMount("/host/mnt1", "volume-1", false, null); VolumeMount vm2 = new VolumeMount("/host/mnt2", "volume-2", false, null); VolumeMount vm3 = new VolumeMount("/host/mnt3", "volume-3", false, null); VolumeMount vm4 = new VolumeMount("/host/mnt1", "volume-4", false, null); Container container1 = containerBuilder().withName("jnlp").withVolumeMounts(vm1, vm2).build(); Pod pod1 = podBuilder().withContainers(container1).endSpec().build(); Container container2 = containerBuilder().withName("jnlp").withVolumeMounts(vm3, vm4).build(); Pod pod2 = podBuilder().withContainers(container2).endSpec().build(); Pod result = combine(pod1, pod2); List<Container> containers = result.getSpec().getContainers(); assertEquals(1, containers.size()); assertEquals(3, containers.get(0).getVolumeMounts().size()); assertThat(containers.get(0).getVolumeMounts(), containsInAnyOrder(vm2, vm3, vm4)); }
@Before public void configureCloud() throws Exception { client = setupCloud(this).connect(); deletePods(client, getLabels(this), false); String image = "busybox"; Container c = new ContainerBuilder().withName(image).withImagePullPolicy("IfNotPresent").withImage(image) .withCommand("cat").withTty(true).build(); String podName = "test-command-execution-" + RandomStringUtils.random(5, "bcdfghjklmnpqrstvwxz0123456789"); pod = client.pods().create(new PodBuilder().withNewMetadata().withName(podName).withLabels(getLabels(this)) .endMetadata().withNewSpec().withContainers(c).endSpec().build()); System.out.println("Created pod: " + pod.getMetadata().getName()); decorator = new ContainerExecDecorator(client, pod.getMetadata().getName(), image, client.getNamespace()); }