use of io.kubernetes.client.openapi.models.V1VolumeMount 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.V1VolumeMount in project heron by twitter.
the class V1ControllerTest method testCreateVolumeAndMountsNFSCLI.
@Test
public void testCreateVolumeAndMountsNFSCLI() {
final String volumeName = "volume-name-nfs";
final String server = "nfs.server.address";
final String pathOnNFS = "path.on.host";
final String readOnly = "true";
final String path = "/path/to/mount";
final String subPath = "/sub/path/to/mount";
// NFS.
final Map<String, Map<VolumeConfigKeys, String>> config = ImmutableMap.of(volumeName, new HashMap<VolumeConfigKeys, String>() {
{
put(VolumeConfigKeys.server, server);
put(VolumeConfigKeys.readOnly, readOnly);
put(VolumeConfigKeys.pathOnNFS, pathOnNFS);
put(VolumeConfigKeys.path, path);
put(VolumeConfigKeys.subPath, subPath);
}
});
final List<V1Volume> expectedVolumes = Collections.singletonList(new V1VolumeBuilder().withName(volumeName).withNewNfs().withServer(server).withPath(pathOnNFS).withReadOnly(Boolean.parseBoolean(readOnly)).endNfs().build());
final List<V1VolumeMount> expectedMounts = Collections.singletonList(new V1VolumeMountBuilder().withName(volumeName).withMountPath(path).withSubPath(subPath).withReadOnly(true).build());
List<V1Volume> actualVolumes = new LinkedList<>();
List<V1VolumeMount> actualMounts = new LinkedList<>();
v1ControllerPodTemplate.createVolumeAndMountsNFSCLI(config, actualVolumes, actualMounts);
Assert.assertEquals("NFS Volume populated", expectedVolumes, actualVolumes);
Assert.assertEquals("NFS Volume Mount populated", expectedMounts, actualMounts);
}
use of io.kubernetes.client.openapi.models.V1VolumeMount in project heron by twitter.
the class V1ControllerTest method testCreateVolumeAndMountsEmptyDirCLI.
@Test
public void testCreateVolumeAndMountsEmptyDirCLI() {
final String volumeName = "volume-name-empty-dir";
final String medium = "Memory";
final String sizeLimit = "1Gi";
final String path = "/path/to/mount";
final String subPath = "/sub/path/to/mount";
// Empty Dir.
final Map<String, Map<VolumeConfigKeys, String>> config = ImmutableMap.of(volumeName, new HashMap<VolumeConfigKeys, String>() {
{
put(VolumeConfigKeys.sizeLimit, sizeLimit);
put(VolumeConfigKeys.medium, "Memory");
put(VolumeConfigKeys.path, path);
put(VolumeConfigKeys.subPath, subPath);
}
});
final List<V1Volume> expectedVolumes = Collections.singletonList(new V1VolumeBuilder().withName(volumeName).withNewEmptyDir().withMedium(medium).withNewSizeLimit(sizeLimit).endEmptyDir().build());
final List<V1VolumeMount> expectedMounts = Collections.singletonList(new V1VolumeMountBuilder().withName(volumeName).withMountPath(path).withSubPath(subPath).build());
List<V1Volume> actualVolumes = new LinkedList<>();
List<V1VolumeMount> actualMounts = new LinkedList<>();
v1ControllerPodTemplate.createVolumeAndMountsEmptyDirCLI(config, actualVolumes, actualMounts);
Assert.assertEquals("Empty Dir Volume populated", expectedVolumes, actualVolumes);
Assert.assertEquals("Empty Dir Volume Mount populated", expectedMounts, actualMounts);
}
use of io.kubernetes.client.openapi.models.V1VolumeMount in project heron by twitter.
the class V1ControllerTest method testCreatePersistentVolumeClaimVolumesAndMounts.
@Test
public void testCreatePersistentVolumeClaimVolumesAndMounts() {
final String volumeNameOne = "VolumeNameONE";
final String volumeNameTwo = "VolumeNameTWO";
final String claimNameOne = "claim-name-one";
final String claimNameTwo = "OnDemand";
final String mountPathOne = "/mount/path/ONE";
final String mountPathTwo = "/mount/path/TWO";
final String mountSubPathTwo = "/mount/sub/path/TWO";
Map<String, Map<VolumeConfigKeys, String>> mapOfOpts = ImmutableMap.of(volumeNameOne, ImmutableMap.of(VolumeConfigKeys.claimName, claimNameOne, VolumeConfigKeys.path, mountPathOne), volumeNameTwo, ImmutableMap.of(VolumeConfigKeys.claimName, claimNameTwo, VolumeConfigKeys.path, mountPathTwo, VolumeConfigKeys.subPath, mountSubPathTwo));
final V1Volume volumeOne = new V1VolumeBuilder().withName(volumeNameOne).withNewPersistentVolumeClaim().withClaimName(claimNameOne).endPersistentVolumeClaim().build();
final V1Volume volumeTwo = new V1VolumeBuilder().withName(volumeNameTwo).withNewPersistentVolumeClaim().withClaimName(claimNameTwo).endPersistentVolumeClaim().build();
final V1VolumeMount volumeMountOne = new V1VolumeMountBuilder().withName(volumeNameOne).withMountPath(mountPathOne).build();
final V1VolumeMount volumeMountTwo = new V1VolumeMountBuilder().withName(volumeNameTwo).withMountPath(mountPathTwo).withSubPath(mountSubPathTwo).build();
// Test case container.
// Input: Map of Volume configurations.
// Output: The expected lists of Volumes and Volume Mounts.
final List<TestTuple<Map<String, Map<VolumeConfigKeys, String>>, Pair<List<V1Volume>, List<V1VolumeMount>>>> testCases = new LinkedList<>();
// Default case: No PVC provided.
testCases.add(new TestTuple<>("Generated an empty list of Volumes", new HashMap<>(), new Pair<>(new LinkedList<>(), new LinkedList<>())));
// PVC Provided.
final Pair<List<V1Volume>, List<V1VolumeMount>> expectedFull = new Pair<>(new LinkedList<>(Arrays.asList(volumeOne, volumeTwo)), new LinkedList<>(Arrays.asList(volumeMountOne, volumeMountTwo)));
testCases.add(new TestTuple<>("Generated a list of Volumes", mapOfOpts, new Pair<>(expectedFull.first, expectedFull.second)));
// Testing loop.
for (TestTuple<Map<String, Map<VolumeConfigKeys, String>>, Pair<List<V1Volume>, List<V1VolumeMount>>> testCase : testCases) {
List<V1Volume> actualVolume = new LinkedList<>();
List<V1VolumeMount> actualVolumeMount = new LinkedList<>();
v1ControllerPodTemplate.createVolumeAndMountsPersistentVolumeClaimCLI(testCase.input, actualVolume, actualVolumeMount);
Assert.assertTrue(testCase.description, (testCase.expected.first).containsAll(actualVolume));
Assert.assertTrue(testCase.description + " Mounts", (testCase.expected.second).containsAll(actualVolumeMount));
}
}
use of io.kubernetes.client.openapi.models.V1VolumeMount in project heron by twitter.
the class V1ControllerTest method testCreateVolumeMountsCLI.
@Test
public void testCreateVolumeMountsCLI() {
final String volumeNamePVC = "volume-name-pvc";
final String volumeNameHostPath = "volume-name-host-path";
final String volumeNameEmptyDir = "volume-name-empty-dir";
final String volumeNameNFS = "volume-name-nfs";
final String value = "inserted-value";
// Test case container.
// Input: [0] volume name, [1] volume options
// Output: The expected <V1VolumeMount>.
final List<TestTuple<Pair<String, Map<VolumeConfigKeys, String>>, V1VolumeMount>> testCases = new LinkedList<>();
// PVC.
final Map<VolumeConfigKeys, String> configPVC = ImmutableMap.<VolumeConfigKeys, String>builder().put(VolumeConfigKeys.claimName, value).put(VolumeConfigKeys.storageClassName, value).put(VolumeConfigKeys.sizeLimit, value).put(VolumeConfigKeys.accessModes, value).put(VolumeConfigKeys.volumeMode, value).put(VolumeConfigKeys.path, value).put(VolumeConfigKeys.subPath, value).put(VolumeConfigKeys.readOnly, "true").build();
final V1VolumeMount volumeMountPVC = new V1VolumeMountBuilder().withName(volumeNamePVC).withMountPath(value).withSubPath(value).withReadOnly(true).build();
testCases.add(new TestTuple<>("PVC volume mount", new Pair<>(volumeNamePVC, configPVC), volumeMountPVC));
// Host Path.
final Map<VolumeConfigKeys, String> configHostPath = ImmutableMap.<VolumeConfigKeys, String>builder().put(VolumeConfigKeys.type, "DirectoryOrCreate").put(VolumeConfigKeys.pathOnHost, value).put(VolumeConfigKeys.path, value).put(VolumeConfigKeys.subPath, value).put(VolumeConfigKeys.readOnly, "true").build();
final V1VolumeMount volumeMountHostPath = new V1VolumeMountBuilder().withName(volumeNameHostPath).withMountPath(value).withSubPath(value).withReadOnly(true).build();
testCases.add(new TestTuple<>("Host Path volume mount", new Pair<>(volumeNameHostPath, configHostPath), volumeMountHostPath));
// Empty Dir.
final Map<VolumeConfigKeys, String> configEmptyDir = ImmutableMap.<VolumeConfigKeys, String>builder().put(VolumeConfigKeys.sizeLimit, value).put(VolumeConfigKeys.medium, "Memory").put(VolumeConfigKeys.path, value).put(VolumeConfigKeys.subPath, value).put(VolumeConfigKeys.readOnly, "true").build();
final V1VolumeMount volumeMountEmptyDir = new V1VolumeMountBuilder().withName(volumeNameEmptyDir).withMountPath(value).withSubPath(value).withReadOnly(true).build();
testCases.add(new TestTuple<>("Empty Dir volume mount", new Pair<>(volumeNameEmptyDir, configEmptyDir), volumeMountEmptyDir));
// NFS.
final Map<VolumeConfigKeys, String> configNFS = ImmutableMap.<VolumeConfigKeys, String>builder().put(VolumeConfigKeys.server, "nfs.server.address").put(VolumeConfigKeys.readOnly, "true").put(VolumeConfigKeys.pathOnNFS, value).put(VolumeConfigKeys.path, value).put(VolumeConfigKeys.subPath, value).build();
final V1VolumeMount volumeMountNFS = new V1VolumeMountBuilder().withName(volumeNameNFS).withMountPath(value).withSubPath(value).withReadOnly(true).build();
testCases.add(new TestTuple<>("NFS volume mount", new Pair<>(volumeNameNFS, configNFS), volumeMountNFS));
// Test loop.
for (TestTuple<Pair<String, Map<VolumeConfigKeys, String>>, V1VolumeMount> testCase : testCases) {
V1VolumeMount actual = v1ControllerPodTemplate.createVolumeMountsCLI(testCase.input.first, testCase.input.second);
Assert.assertEquals(testCase.description, testCase.expected, actual);
}
}
Aggregations