Search in sources :

Example 1 with EmptyDirVolume

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());
}
Also used : KeyValueEnvVar(org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar) HostPathVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume) EmptyDirVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume)

Example 2 with EmptyDirVolume

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());
}
Also used : TemplateEnvVar(org.csanchez.jenkins.plugins.kubernetes.model.TemplateEnvVar) PodTemplateBuilder(org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) HostPathVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume) KeyValueEnvVar(org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar) ArrayList(java.util.ArrayList) Container(io.fabric8.kubernetes.api.model.Container) EmptyDirVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume) PodVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.PodVolume) Parameters(junitparams.Parameters) Test(org.junit.Test) TestCaseName(junitparams.naming.TestCaseName)

Example 3 with EmptyDirVolume

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);
}
Also used : EmptyDirVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume) PodVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.PodVolume) Test(org.junit.Test)

Aggregations

EmptyDirVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume)3 KeyValueEnvVar (org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar)2 HostPathVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume)2 PodVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.PodVolume)2 Test (org.junit.Test)2 Container (io.fabric8.kubernetes.api.model.Container)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodSecurityContext (io.fabric8.kubernetes.api.model.PodSecurityContext)1 ArrayList (java.util.ArrayList)1 Parameters (junitparams.Parameters)1 TestCaseName (junitparams.naming.TestCaseName)1 PodTemplateBuilder (org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder)1 TemplateEnvVar (org.csanchez.jenkins.plugins.kubernetes.model.TemplateEnvVar)1