use of io.fabric8.kubernetes.api.model.PodTemplateBuilder in project fabric8-maven-plugin by fabric8io.
the class PortNameEnricherTest method getPodTemplateList.
private KubernetesListBuilder getPodTemplateList() {
Container container = new ContainerBuilder().withName("test-port-enricher").withImage("test-image").withPorts(new ContainerPortBuilder().withContainerPort(80).withProtocol("TCP").build()).build();
PodTemplateBuilder ptb = new PodTemplateBuilder().withNewMetadata().withName("test-pod").endMetadata().withNewTemplate().withNewSpec().withContainers(container).endSpec().endTemplate();
return new KubernetesListBuilder().addToPodTemplateItems(ptb.build());
}
use of io.fabric8.kubernetes.api.model.PodTemplateBuilder in project fabric8-maven-plugin by fabric8io.
the class VolumePermissionEnricherTest method addVolume.
public PodTemplateBuilder addVolume(PodTemplateBuilder ptb, String vn) {
ptb = ptb.editTemplate().editSpec().addNewVolume().withName(vn).withNewPersistentVolumeClaim().and().and().addNewVolume().withName("non-pvc").withNewEmptyDir().and().and().and().and();
ptb = ptb.editTemplate().editSpec().withContainers(new ContainerBuilder(ptb.buildTemplate().getSpec().getContainers().get(0)).addNewVolumeMount().withName(vn).withMountPath("/tmp/" + vn).and().addNewVolumeMount().withName("non-pvc").withMountPath("/tmp/non-pvc").and().build()).and().and();
return ptb;
}
use of io.fabric8.kubernetes.api.model.PodTemplateBuilder in project fabric8-maven-plugin by fabric8io.
the class VolumePermissionEnricherTest method alreadyExistingInitContainer.
@Test
public void alreadyExistingInitContainer(@Mocked final ProcessorConfig config) throws Exception {
new Expectations() {
{
context.getConfiguration();
result = new Configuration.Builder().processorConfig(config).build();
}
};
PodTemplateBuilder ptb = createEmptyPodTemplate();
addVolume(ptb, "VolumeA");
Container initContainer = new ContainerBuilder().withName(VolumePermissionEnricher.ENRICHER_NAME).withVolumeMounts(new VolumeMountBuilder().withName("vol-blub").withMountPath("blub").build()).build();
ptb.editTemplate().editSpec().withInitContainers(Collections.singletonList(initContainer)).endSpec().endTemplate();
KubernetesListBuilder klb = new KubernetesListBuilder().addToPodTemplateItems(ptb.build());
VolumePermissionEnricher enricher = new VolumePermissionEnricher(context);
enricher.enrich(PlatformMode.kubernetes, klb);
List<Container> initS = ((PodTemplate) klb.build().getItems().get(0)).getTemplate().getSpec().getInitContainers();
assertNotNull(initS);
assertEquals(1, initS.size());
Container actualInitContainer = initS.get(0);
assertEquals("blub", actualInitContainer.getVolumeMounts().get(0).getMountPath());
}
use of io.fabric8.kubernetes.api.model.PodTemplateBuilder in project kubernetes-client by fabric8io.
the class PodTemplateTest method testEdit.
@Test
@DisplayName("Should be able to edit a PodTemplate")
public void testEdit() {
// Given
PodTemplate updatedPodTemplate = new PodTemplateBuilder().withNewMetadata().withName("pt1").addToLabels("foo", "bar").endMetadata().withNewTemplate().withNewSpec().addNewContainer().withName("foo").withImage("docker.io/matzew/eventing-display@sha256:f1c948343622a75b5f7a9058aacdffd2dc1732e07a339477f7d1d6ef09da872a").endContainer().endSpec().endTemplate().build();
server.expect().get().withPath("/api/v1/namespaces/test/podtemplates/pt1").andReturn(200, getPodTemplate()).times(3);
server.expect().patch().withPath("/api/v1/namespaces/test/podtemplates/pt1").andReturn(200, updatedPodTemplate).once();
// When
PodTemplate podTemplate = client.v1().podTemplates().inNamespace("test").withName("pt1").edit(p -> new PodTemplateBuilder(p).editMetadata().addToLabels("foo", "bar").endMetadata().build());
// Then
assertEquals("pt1", podTemplate.getMetadata().getName());
assertEquals("bar", podTemplate.getMetadata().getLabels().get("foo"));
assertEquals(1, podTemplate.getTemplate().getSpec().getContainers().size());
}
use of io.fabric8.kubernetes.api.model.PodTemplateBuilder in project kubernetes-plugin by jenkinsci.
the class PodDecoratorTest method activeDecorator.
@Test
public void activeDecorator() {
PodTemplate podTemplate = new PodTemplate();
PodTemplateBuilder podTemplateBuilder = new PodTemplateBuilder(podTemplate, slave);
Pod pod = podTemplateBuilder.build();
assertEquals("true", pod.getMetadata().getLabels().get("poddecoratorimpl"));
}
Aggregations