Search in sources :

Example 1 with V1Volume

use of io.kubernetes.client.openapi.models.V1Volume in project heron by twitter.

the class V1Controller method mountSecretsAsVolumes.

/**
 * Adds <code>Volume Mounts</code> for <code>Secrets</code> to a pod.
 * @param podSpec <code>Pod Spec</code> to add secrets to.
 */
private void mountSecretsAsVolumes(V1PodSpec podSpec) {
    final Config config = getConfiguration();
    final Map<String, String> secrets = KubernetesContext.getPodSecretsToMount(config);
    for (Map.Entry<String, String> secret : secrets.entrySet()) {
        final V1VolumeMount mount = new V1VolumeMount().name(secret.getKey()).mountPath(secret.getValue());
        final V1Volume secretVolume = new V1Volume().name(secret.getKey()).secret(new V1SecretVolumeSourceBuilder().withSecretName(secret.getKey()).build());
        podSpec.addVolumesItem(secretVolume);
        for (V1Container container : podSpec.getContainers()) {
            container.addVolumeMountsItem(mount);
        }
    }
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) V1SecretVolumeSourceBuilder(io.kubernetes.client.openapi.models.V1SecretVolumeSourceBuilder) V1Volume(io.kubernetes.client.openapi.models.V1Volume) Config(org.apache.heron.spi.common.Config) Map(java.util.Map) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount)

Example 2 with V1Volume

use of io.kubernetes.client.openapi.models.V1Volume in project heron by twitter.

the class V1Controller method addVolumesIfPresent.

/**
 * Adds volume to the <code>Pod Spec</code> that Heron requires. Heron's values taking precedence.
 * @param spec <code>Pod Spec</code> to be configured.
 */
@VisibleForTesting
protected void addVolumesIfPresent(final V1PodSpec spec) {
    final Config config = getConfiguration();
    if (KubernetesContext.hasVolume(config)) {
        final V1Volume volumeFromConfig = Volumes.get().create(config);
        if (volumeFromConfig != null) {
            // Merge volumes. Deduplicate using volume's name with Heron defaults taking precedence.
            KubernetesUtils.V1ControllerUtils<V1Volume> utils = new KubernetesUtils.V1ControllerUtils<>();
            spec.setVolumes(utils.mergeListsDedupe(Collections.singletonList(volumeFromConfig), spec.getVolumes(), Comparator.comparing(V1Volume::getName), "Pod Template Volumes"));
            LOG.fine("Adding volume: " + volumeFromConfig);
        }
    }
}
Also used : V1Volume(io.kubernetes.client.openapi.models.V1Volume) Config(org.apache.heron.spi.common.Config) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with V1Volume

use of io.kubernetes.client.openapi.models.V1Volume in project heron by twitter.

the class VolumesTests method testNfsVolume.

@Test
public void testNfsVolume() {
    final String path = "/test/dir1";
    final String server = "10.10.10.10";
    final Config config = Config.newBuilder().put(KubernetesContext.KUBERNETES_VOLUME_TYPE, "nfs").put(KubernetesContext.KUBERNETES_VOLUME_NFS_PATH, path).put(KubernetesContext.KUBERNETES_VOLUME_NFS_SERVER, server).build();
    final V1Volume volume = Volumes.get().create(config);
    Assert.assertNotNull(volume);
    Assert.assertNotNull(volume.getNfs());
    Assert.assertEquals(volume.getNfs().getPath(), path);
    Assert.assertEquals(volume.getNfs().getServer(), server);
}
Also used : V1Volume(io.kubernetes.client.openapi.models.V1Volume) Config(org.apache.heron.spi.common.Config) Test(org.junit.Test)

Example 4 with V1Volume

use of io.kubernetes.client.openapi.models.V1Volume in project heron by twitter.

the class VolumesTests method testHostPathVolume.

@Test
public void testHostPathVolume() {
    final String path = "/test/dir1";
    final Config config = Config.newBuilder().put(KubernetesContext.KUBERNETES_VOLUME_TYPE, "hostPath").put(KubernetesContext.KUBERNETES_VOLUME_HOSTPATH_PATH, path).build();
    final V1Volume volume = Volumes.get().create(config);
    Assert.assertNotNull(volume);
    Assert.assertNotNull(volume.getHostPath());
    Assert.assertEquals(volume.getHostPath().getPath(), path);
}
Also used : V1Volume(io.kubernetes.client.openapi.models.V1Volume) Config(org.apache.heron.spi.common.Config) Test(org.junit.Test)

Example 5 with V1Volume

use of io.kubernetes.client.openapi.models.V1Volume in project heron by twitter.

the class VolumesTests method testNoVolume.

@Test
public void testNoVolume() {
    final Config config = Config.newBuilder().build();
    final V1Volume volume = Volumes.get().create(config);
    Assert.assertNull(volume);
}
Also used : V1Volume(io.kubernetes.client.openapi.models.V1Volume) Config(org.apache.heron.spi.common.Config) Test(org.junit.Test)

Aggregations

V1Volume (io.kubernetes.client.openapi.models.V1Volume)21 Test (org.junit.Test)10 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)9 V1VolumeBuilder (io.kubernetes.client.openapi.models.V1VolumeBuilder)9 HashMap (java.util.HashMap)9 Map (java.util.Map)9 Config (org.apache.heron.spi.common.Config)8 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)7 LinkedList (java.util.LinkedList)7 Matchers.anyString (org.mockito.Matchers.anyString)6 V1VolumeMountBuilder (io.kubernetes.client.openapi.models.V1VolumeMountBuilder)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 V1Container (io.kubernetes.client.openapi.models.V1Container)4 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)4 VolumeConfigKeys (org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys)4 V1EmptyDirVolumeSource (io.kubernetes.client.openapi.models.V1EmptyDirVolumeSource)3 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)3 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)3 Quantity (io.kubernetes.client.custom.Quantity)2