use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method yamlOverrideContainerEnvvar.
@Issue("JENKINS-58374")
@Test
public void yamlOverrideContainerEnvvar() throws Exception {
PodTemplate parent = new PodTemplate();
parent.setYaml("kind: Pod\n" + "spec:\n" + " containers:\n" + " - name: jnlp\n" + " env:\n" + " - name: VAR1\n" + " value: \"1\"\n" + " - name: VAR2\n" + " value: \"1\"\n");
PodTemplate child = new PodTemplate();
child.setYamlMergeStrategy(merge());
child.setYaml("kind: Pod\n" + "spec:\n" + " containers:\n" + " - name: jnlp\n" + " env:\n" + " - name: VAR1\n" + " value: \"2\"\n");
setupStubs();
PodTemplate result = combine(parent, child);
Pod pod = new PodTemplateBuilder(result, slave).build();
Map<String, Container> containers = toContainerMap(pod);
Container jnlp = containers.get("jnlp");
assertThat(jnlp.getEnv(), hasItems(// value from child
new EnvVar("VAR1", "2", null), // value from parent
new EnvVar("VAR2", "1", null)));
}
use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method testValidateDockerRegistryPrefixOverride.
@Test
@TestCaseName("{method}(directConnection={0})")
@Parameters({ "true", "false" })
public void testValidateDockerRegistryPrefixOverride(boolean directConnection) throws Exception {
cloud.setDirectConnection(directConnection);
DEFAULT_JNLP_DOCKER_REGISTRY_PREFIX = "jenkins.docker.com/docker-hub";
PodTemplate template = new PodTemplate();
template.setYaml(loadYamlFile("pod-busybox.yaml"));
setupStubs();
Pod pod = new PodTemplateBuilder(template, slave).build();
// check containers
Map<String, Container> containers = toContainerMap(pod);
assertEquals(2, containers.size());
assertEquals("busybox", containers.get("busybox").getImage());
assertEquals(DEFAULT_JNLP_DOCKER_REGISTRY_PREFIX + "/" + DEFAULT_JNLP_IMAGE, containers.get("jnlp").getImage());
assertThat(pod.getMetadata().getLabels(), hasEntry("jenkins", "slave"));
}
use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method yamlOverrideSchedulerName.
@Test
public void yamlOverrideSchedulerName() {
PodTemplate parent = new PodTemplate();
parent.setYaml("apiVersion: v1\n" + "kind: Pod\n" + "metadata:\n" + " labels:\n" + " some-label: some-label-value\n" + "spec:\n" + " schedulerName: default-scheduler\n");
PodTemplate child = new PodTemplate();
child.setYaml("spec:\n" + " schedulerName: custom-scheduler\n");
child.setInheritFrom("parent");
child.setYamlMergeStrategy(merge());
PodTemplate result = combine(parent, child);
Pod pod = new PodTemplateBuilder(result, slave).build();
assertEquals("custom-scheduler", pod.getSpec().getSchedulerName());
}
use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method testBuildFromYaml.
@Test
@TestCaseName("{method}(directConnection={0})")
@Parameters({ "true", "false" })
public void testBuildFromYaml(boolean directConnection) throws Exception {
cloud.setDirectConnection(directConnection);
PodTemplate template = new PodTemplate();
template.setYaml(loadYamlFile("pod-busybox.yaml"));
setupStubs();
Pod pod = new PodTemplateBuilder(template, slave).build();
validatePod(pod, directConnection);
assertThat(pod.getMetadata().getLabels(), hasEntry("jenkins", "slave"));
Map<String, Container> containers = toContainerMap(pod);
assertEquals(2, containers.size());
Container container0 = containers.get("busybox");
assertNotNull(container0.getResources());
assertNotNull(container0.getResources().getRequests());
assertNotNull(container0.getResources().getLimits());
assertThat(container0.getResources().getRequests(), hasEntry("example.com/dongle", new Quantity("42")));
assertThat(container0.getResources().getLimits(), hasEntry("example.com/dongle", new Quantity("42")));
}
use of org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodTemplateBuilderTest method yamlMergeContainers.
@Test
public void yamlMergeContainers() throws Exception {
PodTemplate parent = new PodTemplate();
parent.setYaml("apiVersion: v1\n" + "kind: Pod\n" + "metadata:\n" + " labels:\n" + " some-label: some-label-value\n" + "spec:\n" + " containers:\n" + " - name: container1\n" + " image: busybox\n" + " command:\n" + " - cat\n" + " tty: true\n");
PodTemplate child = new PodTemplate();
child.setYaml("spec:\n" + " containers:\n" + " - name: container2\n" + " image: busybox\n" + " command:\n" + " - cat\n" + " tty: true\n");
child.setYamlMergeStrategy(merge());
child.setInheritFrom("parent");
setupStubs();
PodTemplate result = combine(parent, child);
Pod pod = new PodTemplateBuilder(result, slave).build();
// inherit from parent
assertEquals("some-label-value", pod.getMetadata().getLabels().get("some-label"));
assertThat(pod.getSpec().getContainers(), hasSize(3));
Optional<Container> container1 = pod.getSpec().getContainers().stream().filter(c -> "container1".equals(c.getName())).findFirst();
assertTrue(container1.isPresent());
Optional<Container> container2 = pod.getSpec().getContainers().stream().filter(c -> "container2".equals(c.getName())).findFirst();
assertTrue(container2.isPresent());
}
Aggregations