Search in sources :

Example 1 with PodTemplateBuilder

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());
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Container(io.fabric8.kubernetes.api.model.Container) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder)

Example 2 with PodTemplateBuilder

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;
}
Also used : ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder)

Example 3 with PodTemplateBuilder

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());
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Configuration(io.fabric8.maven.core.model.Configuration) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) Test(org.junit.Test)

Example 4 with PodTemplateBuilder

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());
}
Also used : PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with PodTemplateBuilder

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"));
}
Also used : PodTemplateBuilder(org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) PodTemplate(org.csanchez.jenkins.plugins.kubernetes.PodTemplate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 Container (io.fabric8.kubernetes.api.model.Container)23 Pod (io.fabric8.kubernetes.api.model.Pod)23 PodTemplateBuilder (org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder)21 Parameters (junitparams.Parameters)13 TestCaseName (junitparams.naming.TestCaseName)13 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)10 Quantity (io.fabric8.kubernetes.api.model.Quantity)9 PodTemplateBuilder (io.fabric8.kubernetes.api.model.PodTemplateBuilder)8 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)8 KeyValueEnvVar (org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar)8 TemplateEnvVar (org.csanchez.jenkins.plugins.kubernetes.model.TemplateEnvVar)8 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)7 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)7 PodSecurityContext (io.fabric8.kubernetes.api.model.PodSecurityContext)7 PodTemplate (io.fabric8.kubernetes.api.model.PodTemplate)7 ResourceRequirements (io.fabric8.kubernetes.api.model.ResourceRequirements)7 ArrayList (java.util.ArrayList)7 Volume (io.fabric8.kubernetes.api.model.Volume)6 IOException (java.io.IOException)6