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);
}
}
}
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);
}
}
}
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);
}
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);
}
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);
}
Aggregations