io.fabric8.kubernetes.api.model.PodTemplateBuilder Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.PodTemplateBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VolumePermissionEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void alreadyExistingInitContainer(@Mocked final ProcessorConfig config) throws Exception {
    new Expectations() {{
        context.getConfiguration(); result = 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());
}
 
Example #2
Source File: PortNameEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
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());
}
 
Example #3
Source File: VolumePermissionEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: VolumePermissionEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public PodTemplateBuilder createEmptyPodTemplate() {
    return new PodTemplateBuilder().withNewMetadata().endMetadata()
                            .withNewTemplate()
                              .withNewMetadata().endMetadata()
                              .withNewSpec().addNewContainer().endContainer().endSpec()
                            .endTemplate();
}
 
Example #5
Source File: PodTemplateTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@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();
  KubernetesClient client = server.getClient();

  // When
  PodTemplate podTemplate = client.v1().podTemplates().inNamespace("test").withName("pt1").edit().editMetadata().addToLabels("foo", "bar").endMetadata().done();

  // Then
  assertEquals("pt1", podTemplate.getMetadata().getName());
  assertEquals("bar", podTemplate.getMetadata().getLabels().get("foo"));
  assertEquals(1, podTemplate.getTemplate().getSpec().getContainers().size());
}
 
Example #6
Source File: PodTemplateTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
private PodTemplate getPodTemplate() {
  return new PodTemplateBuilder()
    .withNewMetadata().withName("pt1").endMetadata()
    .withNewTemplate()
    .withNewSpec()
    .addNewContainer()
    .withName("foo")
    .withImage("docker.io/matzew/eventing-display@sha256:f1c948343622a75b5f7a9058aacdffd2dc1732e07a339477f7d1d6ef09da872a")
    .endContainer()
    .endSpec()
    .endTemplate()
    .build();
}