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}");
}
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());
}
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());
}
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"));
}
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" + "}");
}
Aggregations