use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodDecoratorTest method activeDecorator.
@Test
public void activeDecorator() {
PodTemplate podTemplate = new PodTemplate();
PodTemplateBuilder podTemplateBuilder = new PodTemplateBuilder(podTemplate, slave);
Pod pod = podTemplateBuilder.build();
assertEquals("true", pod.getMetadata().getLabels().get("poddecoratorimpl"));
}
use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method testOverridesContainerSpec.
@Test
@TestCaseName("{method}(directConnection={0})")
@Parameters({ "true", "false" })
public void testOverridesContainerSpec(boolean directConnection) throws Exception {
cloud.setDirectConnection(directConnection);
PodTemplate template = new PodTemplate();
ContainerTemplate cT = new ContainerTemplate("jnlp", "jenkinsci/jnlp-slave:latest");
template.setContainers(Arrays.asList(cT));
template.setYaml(loadYamlFile("pod-overrides.yaml"));
setupStubs();
Pod pod = new PodTemplateBuilder(template, slave).build();
Map<String, Container> containers = toContainerMap(pod);
assertEquals(1, containers.size());
Container jnlp = containers.get("jnlp");
assertEquals("Wrong number of volume mounts: " + jnlp.getVolumeMounts(), 1, jnlp.getVolumeMounts().size());
validateContainers(pod, slave, directConnection);
}
use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method testValidateDockerRegistryPrefixOverrideWithSlashSuffix.
@Test
@TestCaseName("{method}(directConnection={0})")
@Parameters({ "true", "false" })
public void testValidateDockerRegistryPrefixOverrideWithSlashSuffix(boolean directConnection) throws Exception {
cloud.setDirectConnection(directConnection);
DEFAULT_JNLP_DOCKER_REGISTRY_PREFIX = "jenkins.docker.com/docker-hub/";
PodTemplate template = new PodTemplate();
template.setYaml(loadYamlFile("pod-busybox.yaml"));
setupStubs();
Pod pod = new PodTemplateBuilder(template, slave).build();
// check containers
Map<String, Container> containers = toContainerMap(pod);
assertEquals(2, containers.size());
assertEquals("busybox", containers.get("busybox").getImage());
assertEquals(DEFAULT_JNLP_DOCKER_REGISTRY_PREFIX + DEFAULT_JNLP_IMAGE, containers.get("jnlp").getImage());
assertThat(pod.getMetadata().getLabels(), hasEntry("jenkins", "slave"));
}
use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method testBuildWithCustomWorkspaceVolume.
@Test
@Issue("JENKINS-50525")
public void testBuildWithCustomWorkspaceVolume() throws Exception {
PodTemplate template = new PodTemplate();
template.setWorkspaceVolume(new EmptyDirWorkspaceVolume(true));
ContainerTemplate containerTemplate = new ContainerTemplate("name", "image");
containerTemplate.setWorkingDir("");
template.getContainers().add(containerTemplate);
setupStubs();
Pod pod = new PodTemplateBuilder(template, slave).build();
List<Container> containers = pod.getSpec().getContainers();
assertEquals(2, containers.size());
Container container0 = containers.get(0);
Container container1 = containers.get(1);
List<VolumeMount> volumeMounts = Collections.singletonList(new VolumeMountBuilder().withMountPath("/home/jenkins/agent").withName("workspace-volume").withReadOnly(false).build());
assertEquals(volumeMounts, container0.getVolumeMounts());
assertEquals(volumeMounts, container1.getVolumeMounts());
assertEquals("Memory", pod.getSpec().getVolumes().get(0).getEmptyDir().getMedium());
}
use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method yamlOverrideSecurityContext.
@Test
public void yamlOverrideSecurityContext() {
PodTemplate parent = new PodTemplate();
parent.setYaml("apiVersion: v1\n" + "kind: Pod\n" + "metadata:\n" + " labels:\n" + " some-label: some-label-value\n" + "spec:\n" + " securityContext:\n" + " runAsUser: 2000\n" + " runAsGroup: 2000\n" + " containers:\n" + " - name: container\n" + " securityContext:\n" + " runAsUser: 1000\n" + " runAsGroup: 1000\n" + " image: busybox\n" + " command:\n" + " - cat\n" + " tty: true\n");
PodTemplate child = new PodTemplate();
child.setYaml("spec:\n" + " securityContext:\n" + " runAsUser: 3000\n" + " runAsGroup: 3000\n" + " containers:\n" + " - name: container\n" + " image: busybox2\n" + " securityContext:\n" + " runAsUser: 2000\n" + " runAsGroup: 2000\n" + " command:\n" + " - cat\n" + " tty: true\n");
child.setInheritFrom("parent");
child.setYamlMergeStrategy(merge());
setupStubs();
PodTemplate result = combine(parent, child);
Pod pod = new PodTemplateBuilder(result, slave).build();
assertThat(pod.getSpec().getContainers(), hasSize(2));
Optional<Container> container = pod.getSpec().getContainers().stream().filter(c -> "container".equals(c.getName())).findFirst();
assertTrue(container.isPresent());
assertEquals(Long.valueOf(3000L), pod.getSpec().getSecurityContext().getRunAsUser());
assertEquals(Long.valueOf(3000L), pod.getSpec().getSecurityContext().getRunAsGroup());
assertEquals(Long.valueOf(2000L), container.get().getSecurityContext().getRunAsUser());
assertEquals(Long.valueOf(2000L), container.get().getSecurityContext().getRunAsGroup());
}
Aggregations