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

The following examples show how to use io.fabric8.kubernetes.api.model.EmptyDirVolumeSourceBuilder. 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: TektonHandler.java    From dekorate with Apache License 2.0 6 votes vote down vote up
public TaskRun createTaskRun(TektonConfig config) {
  return new TaskRunBuilder()
    .withNewMetadata()
      .withName(config.getName() + DASH + RUN + DASH + NOW)
    .endMetadata()
    .withNewSpec()
    .withServiceAccountName(config.getName())
    .addNewWorkspace().withName(config.getSourceWorkspace()).withEmptyDir(new EmptyDirVolumeSourceBuilder().withMedium("Memory").build()).endWorkspace()
      .withNewTaskRef().withName(monolithTaskName(config)).endTaskRef()
      .withNewResources()
      .addNewInput().withName(GIT_SOURCE).withNewResourceRef().withName(gitResourceName(config)).endResourceRef().endInput()
      .addNewOutput().withName(IMAGE).withNewResourceRef().withName(outputImageResourceName(config)).endResourceRef().endOutput()
      .endResources()
      .withTimeout(DEFAULT_TIMEOUT)
    .endSpec()
    .build();
}
 
Example #2
Source File: VolumeUtils.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an empty directory volume
 *
 * @param name      Name of the Volume
 * @param sizeLimit Volume size
 * @return The Volume created
 */
public static Volume createEmptyDirVolume(String name, String sizeLimit) {
    String validName = getValidVolumeName(name);

    EmptyDirVolumeSource emptyDirVolumeSource = new EmptyDirVolumeSourceBuilder().build();
    if (sizeLimit != null && !sizeLimit.isEmpty()) {
        emptyDirVolumeSource.setSizeLimit(new Quantity(sizeLimit));
    }

    Volume volume = new VolumeBuilder()
            .withName(validName)
            .withEmptyDir(emptyDirVolumeSource)
            .build();
    log.trace("Created emptyDir Volume named '{}' with sizeLimit '{}'", validName, sizeLimit);
    return volume;
}
 
Example #3
Source File: PodPresetExamples.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public static void main(String args[]) {
  String master = "https://192.168.42.193:8443/";
  if (args.length == 1) {
    master = args[0];
  }

  Config config = new ConfigBuilder().withMasterUrl(master).build();
  try (final KubernetesClient client = new DefaultKubernetesClient(config)) {
    String namespace = "default";
    log("namespace", namespace);
    Pod pod = client.pods().inNamespace(namespace).load(PodPresetExamples.class.getResourceAsStream("/pod-preset-example.yml")).get();
    log("Pod created");
    client.pods().inNamespace(namespace).create(pod);

    PodPreset podPreset = new PodPresetBuilder()
      .withNewMetadata().withName("allow-database").endMetadata()
      .withNewSpec()
      .withNewSelector().withMatchLabels(Collections.singletonMap("role", "frontend")).endSelector()
      .withEnv(new EnvVarBuilder().withName("DB_PORT").withValue("6379").build())
      .withVolumeMounts(new VolumeMountBuilder().withMountPath("/cache").withName("cache-volume").build())
      .withVolumes(new VolumeBuilder().withName("cache-volume").withEmptyDir(new EmptyDirVolumeSourceBuilder().build()).build())
      .endSpec()
      .build();

    log("Creating Pod Preset : " + podPreset.getMetadata().getName());
    client.settings().podPresets().inNamespace(namespace).create(podPreset);

    pod = client.pods().inNamespace(namespace).withName(pod.getMetadata().getName()).get();
    log("Updated pod: ");
    log(SerializationUtils.dumpAsYaml(pod));
  } catch (Exception e) {
    log("Exception occurred: ", e.getMessage());
    e.printStackTrace();
  }
}
 
Example #4
Source File: PodPresetTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testPodUpdate() {
  try{
    server.expect().withPath("/apis/settings.k8s.io/v1alpha1/namespaces/test/podpresets/podpreset-test").andReturn(200, new PodPresetBuilder()
      .withNewMetadata().withName("podpreset-test").endMetadata()
      .withNewSpec()
      .withNewSelector().withMatchLabels(Collections.singletonMap("app", "website")).endSelector()
      .withEnv(new EnvVarBuilder()
        .withName("DB_PORT")
        .withValue("6379")
        .build())
      .withVolumeMounts(new VolumeMountBuilder()
        .withMountPath("/cache")
        .withName("cache-volume")
        .build())
      .withVolumes(
        new VolumeBuilder()
          .withName("cache-volume")
          .withEmptyDir(new EmptyDirVolumeSourceBuilder().build())
          .build())
      .endSpec()
      .build())
      .once();

    Pod pod = new PodBuilder().withNewMetadata().withName("pod").withNamespace("test").withLabels(Collections.singletonMap("app", "website")).endMetadata()
      .withNewSpec()
      .addToContainers(new ContainerBuilder().withName("website").withImage("nginx").withImagePullPolicy("IfNotPresent").build())
      .endSpec()
      .build();
    server.expect().withPath("/api/v1/namespaces/test/pods/pod").andReturn(200, pod).once();

    KubernetesClient client = server.getClient();
    pod = client.pods().inNamespace("test").withName(pod.getMetadata().getName()).get();
    assertNotNull(pod);
    assertEquals("pod", pod.getMetadata().getName());
    assertNotNull(pod.getSpec().getVolumes().get(0).getName());
    assertEquals("cache-volume", pod.getSpec().getVolumes().get(0).getName());
    PodPreset podpreset = client.settings().podPresets().withName("podpreset-test").get();
    assertNotNull(pod.getSpec().getAdditionalProperties().get("DB_PORT"));
    assertEquals(6379, pod.getSpec().getAdditionalProperties().get("DB_PORT"));
    assertEquals("podpreset-test", podpreset.getMetadata().getName());
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example #5
Source File: PodPresetTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testDelete() {
  server.expect().withPath("/apis/settings.k8s.io/v1alpha1/namespaces/test/podpresets/podpreset1").andReturn(200, new PodPresetBuilder()
    .withNewMetadata().withName("podpreset1").endMetadata()
    .withNewSpec()
    .withNewSelector().withMatchLabels(Collections.singletonMap("app", "website")).endSelector()
    .withEnv(new EnvVarBuilder()
      .withName("DB_PORT")
      .withValue("6379")
      .build())
    .withVolumeMounts(new VolumeMountBuilder()
      .withMountPath("/cache")
      .withName("cache-volume")
      .build())
    .withVolumes(
      new VolumeBuilder()
        .withName("cache-volume")
        .withEmptyDir(new EmptyDirVolumeSourceBuilder().build())
        .build())
    .endSpec()
    .build())
    .once();

  server.expect().withPath("/apis/settings.k8s.io/v1alpha1/namespaces/ns1/podpresets/podpreset2").andReturn(200, new PodPresetBuilder()
    .withNewMetadata().withName("podpreset2").endMetadata()
    .withNewSpec()
    .withNewSelector().withMatchLabels(Collections.singletonMap("app", "website")).endSelector()
    .withEnv(new EnvVarBuilder()
      .withName("DB_PORT")
      .withValue("6379")
      .build())
    .withVolumeMounts(new VolumeMountBuilder()
      .withMountPath("/cache")
      .withName("cache-volume")
      .build())
    .withVolumes(
      new VolumeBuilder()
        .withName("cache-volume")
        .withEmptyDir(new io.fabric8.kubernetes.api.model
          .EmptyDirVolumeSourceBuilder()
          .build())
        .build())
    .endSpec()
    .build())
    .once();

  KubernetesClient client = server.getClient();

  Boolean deleted = client.settings().podPresets().withName("podpreset1").delete();
  assertTrue(deleted);

  deleted = client.settings().podPresets().withName("podpreset2").delete();
  assertFalse(deleted);

  deleted = client.settings().podPresets().inNamespace("ns1").withName("podpreset2").delete();
  assertTrue(deleted);
}