use of org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume in project kubernetes-plugin by jenkinsci.
the class KubernetesTest method assertPodTemplates.
private void assertPodTemplates(List<PodTemplate> templates) {
assertEquals(1, templates.size());
PodTemplate podTemplate = templates.get(0);
assertEquals(Integer.MAX_VALUE, podTemplate.getInstanceCap());
assertEquals(1, podTemplate.getContainers().size());
ContainerTemplate containerTemplate = podTemplate.getContainers().get(0);
assertEquals("jenkins/inbound-agent", containerTemplate.getImage());
assertEquals("jnlp", containerTemplate.getName());
assertEquals(Arrays.asList(new KeyValueEnvVar("a", "b"), new KeyValueEnvVar("c", "d")), containerTemplate.getEnvVars());
assertEquals(2, podTemplate.getVolumes().size());
EmptyDirVolume emptyVolume = (EmptyDirVolume) podTemplate.getVolumes().get(0);
assertEquals("/mnt", emptyVolume.getMountPath());
assertFalse(emptyVolume.getMemory());
assertEquals(EmptyDirVolume.class.getName(), emptyVolume.getClass().getName());
HostPathVolume hostPathVolume = (HostPathVolume) podTemplate.getVolumes().get(1);
assertEquals("/host", hostPathVolume.getMountPath());
assertEquals("/mnt/host", hostPathVolume.getHostPath());
assertEquals(HostPathVolume.class.getName(), hostPathVolume.getClass().getName());
assertEquals(0, podTemplate.getActiveDeadlineSeconds());
}
use of org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method testBuildFromTemplate.
@Test
@TestCaseName("{method}(directConnection={0})")
@Parameters({ "true", "false" })
public void testBuildFromTemplate(boolean directConnection) throws Exception {
cloud.setDirectConnection(directConnection);
PodTemplate template = new PodTemplate();
template.setRunAsUser("1000");
template.setRunAsGroup("1000");
template.setSupplementalGroups("5001,5002");
template.setHostNetwork(false);
List<PodVolume> volumes = new ArrayList<PodVolume>();
volumes.add(new HostPathVolume("/host/data", "/container/data"));
volumes.add(new EmptyDirVolume("/empty/dir", false));
template.setVolumes(volumes);
List<ContainerTemplate> containers = new ArrayList<ContainerTemplate>();
ContainerTemplate busyboxContainer = new ContainerTemplate("busybox", "busybox");
busyboxContainer.setCommand("cat");
busyboxContainer.setTtyEnabled(true);
List<TemplateEnvVar> envVars = new ArrayList<TemplateEnvVar>();
envVars.add(new KeyValueEnvVar("CONTAINER_ENV_VAR", "container-env-var-value"));
busyboxContainer.setEnvVars(envVars);
busyboxContainer.setRunAsUser("2000");
busyboxContainer.setRunAsGroup("2000");
containers.add(busyboxContainer);
template.setContainers(containers);
setupStubs();
Pod pod = new PodTemplateBuilder(template, slave).build();
pod.getMetadata().setLabels(Collections.singletonMap("some-label", "some-label-value"));
validatePod(pod, false, directConnection);
ArrayList<Long> supplementalGroups = new ArrayList<Long>();
supplementalGroups.add(5001L);
supplementalGroups.add(5002L);
Map<String, Container> containersMap = toContainerMap(pod);
PodSecurityContext securityContext = pod.getSpec().getSecurityContext();
assertEquals(Long.valueOf(1000L), securityContext.getRunAsUser());
assertEquals(Long.valueOf(1000L), securityContext.getRunAsGroup());
assertEquals(supplementalGroups, securityContext.getSupplementalGroups());
assertEquals(Long.valueOf(2000L), containersMap.get("busybox").getSecurityContext().getRunAsUser());
assertEquals(Long.valueOf(2000L), containersMap.get("busybox").getSecurityContext().getRunAsGroup());
}
use of org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume in project kubernetes-plugin by jenkinsci.
the class KubernetesCloudTest method testInheritance.
@Test
public void testInheritance() {
ContainerTemplate jnlp = new ContainerTemplate("jnlp", "jnlp:1");
ContainerTemplate maven = new ContainerTemplate("maven", "maven:1");
maven.setTtyEnabled(true);
maven.setCommand("cat");
PodVolume podVolume = new EmptyDirVolume("/some/path", true);
PodTemplate parent = new PodTemplate();
parent.setName("parent");
parent.setLabel("parent");
parent.setContainers(Arrays.asList(jnlp));
parent.setVolumes(Arrays.asList(podVolume));
ContainerTemplate maven2 = new ContainerTemplate("maven", "maven:2");
PodTemplate withNewMavenVersion = new PodTemplate();
withNewMavenVersion.setContainers(Arrays.asList(maven2));
PodTemplate result = PodTemplateUtils.combine(parent, withNewMavenVersion);
}
Aggregations