Search in sources :

Example 1 with DynamicPVCWorkspaceVolume

use of org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume 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 DynamicPVCWorkspaceVolume

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

the class CasCTest method assertConfiguredAsExpected.

@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule r, String configContent) {
    List<KubernetesCloud> all = r.j.jenkins.clouds.getAll(KubernetesCloud.class);
    assertThat(all, hasSize(1));
    KubernetesCloud cloud = all.get(0);
    assertNotNull(cloud);
    assertEquals(10, cloud.getContainerCap());
    assertEquals("http://jenkinshost:8080/jenkins/", cloud.getJenkinsUrl());
    assertEquals(32, cloud.getMaxRequestsPerHost());
    assertEquals("kubernetes", cloud.name);
    List<PodTemplate> templates = cloud.getTemplates();
    assertNotNull(templates);
    assertEquals(3, templates.size());
    PodTemplate podTemplate = templates.get(0);
    assertFalse(podTemplate.isHostNetwork());
    assertEquals("java", podTemplate.getLabel());
    assertEquals("default-java", podTemplate.getName());
    assertEquals(10, podTemplate.getInstanceCap());
    assertEquals(123, podTemplate.getSlaveConnectTimeout());
    assertEquals(5, podTemplate.getIdleMinutes());
    assertEquals(66, podTemplate.getActiveDeadlineSeconds());
    assertThat(podTemplate.getYamlMergeStrategy(), isA(Overrides.class));
    podTemplate = templates.get(1);
    assertFalse(podTemplate.isHostNetwork());
    assertEquals("dynamic-pvc", podTemplate.getLabel());
    assertEquals("dynamic-pvc", podTemplate.getName());
    assertThat(podTemplate.getYamlMergeStrategy(), isA(Overrides.class));
    WorkspaceVolume workspaceVolume = podTemplate.getWorkspaceVolume();
    assertNotNull(workspaceVolume);
    assertThat(workspaceVolume, isA(DynamicPVCWorkspaceVolume.class));
    DynamicPVCWorkspaceVolume dynamicPVCVolume = (DynamicPVCWorkspaceVolume) workspaceVolume;
    assertEquals("ReadWriteOnce", dynamicPVCVolume.getAccessModes());
    assertEquals("1", dynamicPVCVolume.getRequestsSize());
    assertEquals("hostpath", dynamicPVCVolume.getStorageClassName());
    podTemplate = templates.get(2);
    assertFalse(podTemplate.isHostNetwork());
    assertEquals("test", podTemplate.getLabel());
    assertEquals("test", podTemplate.getName());
    assertThat(podTemplate.getYamlMergeStrategy(), isA(Merge.class));
    List<ContainerTemplate> containers = podTemplate.getContainers();
    assertNotNull(containers);
    assertEquals(1, containers.size());
    ContainerTemplate container = containers.get(0);
    assertEquals("cat", container.getArgs());
    assertEquals("/bin/sh -c", container.getCommand());
    assertEquals("maven:3.6.3-jdk-8", container.getImage());
    ContainerLivenessProbe livenessProbe = container.getLivenessProbe();
    assertEquals(1, livenessProbe.getFailureThreshold());
    assertEquals(2, livenessProbe.getInitialDelaySeconds());
    assertEquals(3, livenessProbe.getPeriodSeconds());
    assertEquals(4, livenessProbe.getSuccessThreshold());
    assertEquals(5, livenessProbe.getTimeoutSeconds());
    assertEquals("maven", container.getName());
    assertTrue(container.isTtyEnabled());
    assertEquals("/src", container.getWorkingDir());
}
Also used : DynamicPVCWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume) ContainerTemplate(org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate) Merge(org.csanchez.jenkins.plugins.kubernetes.pod.yaml.Merge) WorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.WorkspaceVolume) DynamicPVCWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume) KubernetesCloud(org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud) Overrides(org.csanchez.jenkins.plugins.kubernetes.pod.yaml.Overrides) ContainerLivenessProbe(org.csanchez.jenkins.plugins.kubernetes.ContainerLivenessProbe) PodTemplate(org.csanchez.jenkins.plugins.kubernetes.PodTemplate)

Example 3 with DynamicPVCWorkspaceVolume

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

the class PodTemplateBuilderTest method testBuildWithDynamicPVCWorkspaceVolume.

@Test
public void testBuildWithDynamicPVCWorkspaceVolume() {
    PodTemplate template = new PodTemplate();
    template.setWorkspaceVolume(new DynamicPVCWorkspaceVolume());
    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());
    assertNotNull(pod.getSpec().getVolumes().get(0).getPersistentVolumeClaim());
}
Also used : DynamicPVCWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume) 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) Test(org.junit.Test)

Example 4 with DynamicPVCWorkspaceVolume

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

the class KubernetesDeclarativeAgentUnitTest method serialization.

@Test
public void serialization() throws Exception {
    instance.setCloud("cloud");
    instance.setLabel("label");
    instance.setYaml("yaml");
    instance.setYamlMergeStrategy(new Merge());
    DynamicPVCWorkspaceVolume workspaceVolume = new DynamicPVCWorkspaceVolume();
    workspaceVolume.setStorageClassName("sc");
    workspaceVolume.setRequestsSize("1G");
    workspaceVolume.setAccessModes("ReadWrite");
    instance.setWorkspaceVolume(workspaceVolume);
    instance.setIdleMinutes(1);
    instance.setInheritFrom("inheritFrom");
    Map<String, Object> args = instance.getAsArgs();
    assertThat(args.get("cloud"), equalTo("cloud"));
    assertThat(args.get("label"), equalTo("label"));
    assertThat(args.get("yaml"), equalTo("yaml"));
    assertThat(args.get("yamlMergeStrategy"), isA(Merge.class));
    assertThat(args.get("workspaceVolume"), equalTo(workspaceVolume));
    assertThat(args.get("idleMinutes"), equalTo(1));
    assertThat(args.get("inheritFrom"), equalTo("inheritFrom"));
}
Also used : DynamicPVCWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume) Merge(org.csanchez.jenkins.plugins.kubernetes.pod.yaml.Merge) Test(org.junit.Test)

Example 5 with DynamicPVCWorkspaceVolume

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

the class KubernetesDeclarativeAgentUnitTest method complexGenerator.

@Test
public void complexGenerator() throws Exception {
    instance.setCloud("cloud");
    instance.setYaml("yaml");
    instance.setYamlMergeStrategy(new Merge());
    DynamicPVCWorkspaceVolume workspaceVolume = new DynamicPVCWorkspaceVolume();
    workspaceVolume.setStorageClassName("sc");
    workspaceVolume.setRequestsSize("1G");
    workspaceVolume.setAccessModes("ReadWrite");
    instance.setWorkspaceVolume(workspaceVolume);
    instance.setPodRetention(new Never());
    instance.setInheritFrom("inheritFrom");
    dg.assertGenerateDirective(directive, "agent {\n" + "  kubernetes {\n" + "    cloud 'cloud'\n" + "    inheritFrom 'inheritFrom'\n" + "    podRetention never()\n" + "    workspaceVolume dynamicPVC(accessModes: 'ReadWrite', requestsSize: '1G', storageClassName: 'sc')\n" + "    yaml 'yaml'\n" + "    yamlMergeStrategy merge()\n" + "  }\n" + "}");
}
Also used : DynamicPVCWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume) Merge(org.csanchez.jenkins.plugins.kubernetes.pod.yaml.Merge) Never(org.csanchez.jenkins.plugins.kubernetes.pod.retention.Never) Test(org.junit.Test)

Aggregations

DynamicPVCWorkspaceVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume)5 Test (org.junit.Test)4 Merge (org.csanchez.jenkins.plugins.kubernetes.pod.yaml.Merge)3 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 ContainerLivenessProbe (org.csanchez.jenkins.plugins.kubernetes.ContainerLivenessProbe)1 ContainerTemplate (org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate)1 KubernetesCloud (org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud)1 PodTemplate (org.csanchez.jenkins.plugins.kubernetes.PodTemplate)1 PodTemplateBuilder (org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder)1 Never (org.csanchez.jenkins.plugins.kubernetes.pod.retention.Never)1 OnFailure (org.csanchez.jenkins.plugins.kubernetes.pod.retention.OnFailure)1 Overrides (org.csanchez.jenkins.plugins.kubernetes.pod.yaml.Overrides)1 EmptyDirWorkspaceVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume)1 WorkspaceVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.WorkspaceVolume)1 SnippetizerTester (org.jenkinsci.plugins.workflow.cps.SnippetizerTester)1 Issue (org.jvnet.hudson.test.Issue)1