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

The following examples show how to use io.fabric8.kubernetes.api.model.EmptyDirVolumeSource. 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: 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 #2
Source File: EphemeralWorkspaceAdapter.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void replacePVCsWithEmptyDir(KubernetesEnvironment k8sEnv) {
  for (PodData pod : k8sEnv.getPodsData().values()) {
    PodSpec podSpec = pod.getSpec();
    podSpec
        .getVolumes()
        .stream()
        .filter(v -> v.getPersistentVolumeClaim() != null)
        .forEach(
            v -> {
              v.setPersistentVolumeClaim(null);
              v.setEmptyDir(new EmptyDirVolumeSource());
            });
  }
}
 
Example #3
Source File: EphemeralWorkspaceAdapterTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testConvertsAllPVCsToEmptyDir() throws Exception {
  // given
  k8sEnv.getPersistentVolumeClaims().put("pvc1", mock(PersistentVolumeClaim.class));
  k8sEnv.getPersistentVolumeClaims().put("pvc2", mock(PersistentVolumeClaim.class));

  io.fabric8.kubernetes.api.model.Volume configMapVolume =
      new VolumeBuilder().withNewConfigMap().withName("configMap").endConfigMap().build();
  io.fabric8.kubernetes.api.model.Volume emptyDirVolume =
      new VolumeBuilder().withNewEmptyDir().endEmptyDir().build();
  io.fabric8.kubernetes.api.model.Volume pvcVolume =
      new VolumeBuilder()
          .withNewPersistentVolumeClaim()
          .withClaimName("pvc1")
          .endPersistentVolumeClaim()
          .build();
  Pod pod =
      new PodBuilder()
          .withNewMetadata()
          .withName(POD_NAME)
          .endMetadata()
          .withNewSpec()
          .withVolumes(
              new VolumeBuilder(pvcVolume).build(),
              new VolumeBuilder(configMapVolume).build(),
              new VolumeBuilder(emptyDirVolume).build())
          .endSpec()
          .build();

  k8sEnv.addPod(pod);

  ephemeralWorkspaceAdapter.provision(k8sEnv, identity);

  assertTrue(k8sEnv.getPersistentVolumeClaims().isEmpty());
  assertNull(pod.getSpec().getVolumes().get(0).getPersistentVolumeClaim());
  assertEquals(pod.getSpec().getVolumes().get(0).getEmptyDir(), new EmptyDirVolumeSource());
  assertEquals(pod.getSpec().getVolumes().get(1), configMapVolume);
  assertEquals(pod.getSpec().getVolumes().get(2), emptyDirVolume);
}
 
Example #4
Source File: RabbitMQPods.java    From rabbitmq-operator with Apache License 2.0 4 votes vote down vote up
public PodSpec buildPodSpec(
        final String rabbitName,
        final String initContainerImage,
        final Container container
) {
    return new PodSpecBuilder()
            .withServiceAccountName("rabbitmq-user")
            .addNewInitContainer()
            .withName("copy-rabbitmq-config")
            .withImage(initContainerImage)
            .withCommand(new String[]{"sh", "-c", "cp /configmap/* /etc/rabbitmq"})
            .addNewVolumeMount().withName("config").withMountPath("/etc/rabbitmq").endVolumeMount()
            .addNewVolumeMount().withName("configmap").withMountPath("/configmap").endVolumeMount()
            .endInitContainer()
            .withContainers(container)
            .addNewVolume().withName("config").withEmptyDir(new EmptyDirVolumeSource()).endVolume()
            .addNewVolume().withName("configmap").withConfigMap(
                    new ConfigMapVolumeSourceBuilder()
                            .withName("rabbitmq-config")
                            .addNewItem("rabbitmq.conf", 0644, "rabbitmq.conf")
                            .addNewItem("enabled_plugins", 0644, "enabled_plugins")
                            .build()
            ).endVolume()
            .addNewVolume().withName("probes").withConfigMap(
                    new ConfigMapVolumeSourceBuilder()
                            .withName("rabbitmq-probes")
                            .addNewItem("readiness.sh", 0755, "readiness.sh")
                            .build()
            ).endVolume()
            .addNewVolume().withName("startup-scripts").withConfigMap(
                    new ConfigMapVolumeSourceBuilder()
                            .withName("rabbitmq-startup-scripts")
                            .addNewItem("users.sh", 0755, "users.sh")
                            .build()
            ).endVolume()
            .withNewAffinity().withNewPodAntiAffinity().withPreferredDuringSchedulingIgnoredDuringExecution(
                    new WeightedPodAffinityTermBuilder()
                            .withNewWeight(1)
                            .withNewPodAffinityTerm()
                                    .withNewLabelSelector()
                                            .addToMatchLabels(Labels.Kubernetes.INSTANCE, rabbitName)
                                    .endLabelSelector()
                                    .withTopologyKey("kubernetes.io/hostname")
                            .endPodAffinityTerm()
                            .build()
            ).endPodAntiAffinity().endAffinity()
            .build();
}