Search in sources :

Example 1 with EmptyDirWorkspaceVolume

use of org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume in project kubernetes-plugin by jenkinsci.

the class PodTemplateStepTest method configRoundTrip.

@Issue("JENKINS-57828")
@Test
public void configRoundTrip() throws Exception {
    SnippetizerTester st = new SnippetizerTester(rule);
    PodTemplateStep step = new PodTemplateStep();
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setName("podTest");
    st.assertRoundTrip(step, "podTemplate(name: 'podTest') {\n    // some block\n}");
    step.setName("");
    step.setInstanceCap(5);
    st.assertRoundTrip(step, "podTemplate(instanceCap: 5) {\n    // some block\n}");
    step.setInstanceCap(0);
    step.setInstanceCap(6);
    st.assertRoundTrip(step, "podTemplate(instanceCap: 6) {\n    // some block\n}");
    // make sure this resets instanceCap
    step.setInstanceCap(null);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setInstanceCap(7);
    st.assertRoundTrip(step, "podTemplate(instanceCap: 7) {\n    // some block\n}");
    // make sure this resets instanceCap
    step.setInstanceCap(Integer.MAX_VALUE);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setLabel("podLabel");
    st.assertRoundTrip(step, "podTemplate(label: 'podLabel') {\n    // some block\n}");
    step.setLabel("");
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    // this is the default, it should not appear in the snippet.
    step.setPodRetention(PodRetention.getPodTemplateDefault());
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setPodRetention(new OnFailure());
    st.assertRoundTrip(step, "podTemplate(podRetention: onFailure()) {\n    // some block\n}");
    step.setPodRetention(null);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setWorkspaceVolume(new DynamicPVCWorkspaceVolume());
    st.assertRoundTrip(step, "podTemplate(workspaceVolume: dynamicPVC()) {\n    // some block\n}");
    // this is the default, it should not be in the snippet.
    step.setWorkspaceVolume(new EmptyDirWorkspaceVolume(false));
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    DynamicPVCWorkspaceVolume workspaceVolume = new DynamicPVCWorkspaceVolume();
    workspaceVolume.setAccessModes("ReadWriteMany");
    step.setWorkspaceVolume(workspaceVolume);
    st.assertRoundTrip(step, "podTemplate(workspaceVolume: dynamicPVC(accessModes: 'ReadWriteMany')) {\n    // some block\n}");
    step.setWorkspaceVolume(null);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setActiveDeadlineSeconds(60);
    st.assertRoundTrip(step, "podTemplate(activeDeadlineSeconds: 60) {\n    // some block\n}");
    step.setActiveDeadlineSeconds(0);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setInheritFrom("fooBar");
    st.assertRoundTrip(step, "podTemplate(inheritFrom: 'fooBar') {\n    // some block\n}");
    step.setInheritFrom("");
    st.assertRoundTrip(step, "podTemplate(inheritFrom: '') {\n    // some block\n}");
    step.setInheritFrom(null);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
}
Also used : DynamicPVCWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume) SnippetizerTester(org.jenkinsci.plugins.workflow.cps.SnippetizerTester) EmptyDirWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume) OnFailure(org.csanchez.jenkins.plugins.kubernetes.pod.retention.OnFailure) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 2 with EmptyDirWorkspaceVolume

use of org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume 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());
}
Also used : PodTemplateBuilder(org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) EmptyDirWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

EmptyDirWorkspaceVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume)2 Test (org.junit.Test)2 Issue (org.jvnet.hudson.test.Issue)2 Container (io.fabric8.kubernetes.api.model.Container)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)1 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)1 PodTemplateBuilder (org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder)1 OnFailure (org.csanchez.jenkins.plugins.kubernetes.pod.retention.OnFailure)1 DynamicPVCWorkspaceVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume)1 SnippetizerTester (org.jenkinsci.plugins.workflow.cps.SnippetizerTester)1