This is an automated email from the ASF dual-hosted git repository. saadurrahman pushed a commit to branch saadurrahman/3821-Remove-Deprecated-Volumes-K8s-dev in repository https://gitbox.apache.org/repos/asf/incubator-heron.git
commit 44d859e70a95830029b347d9afe061c30e16bd69 Author: Saad Ur Rahman <[email protected]> AuthorDate: Mon May 2 13:28:40 2022 -0400 [K8s] switched to using Volume Factory for Volume Mount generation. --- .../heron/scheduler/kubernetes/V1Controller.java | 41 +-------- .../scheduler/kubernetes/V1ControllerTest.java | 97 ---------------------- 2 files changed, 4 insertions(+), 134 deletions(-) diff --git a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java index a065790df5d..7812ed6aae9 100644 --- a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java +++ b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java @@ -80,7 +80,6 @@ import io.kubernetes.client.openapi.models.V1Toleration; import io.kubernetes.client.openapi.models.V1Volume; import io.kubernetes.client.openapi.models.V1VolumeBuilder; import io.kubernetes.client.openapi.models.V1VolumeMount; -import io.kubernetes.client.openapi.models.V1VolumeMountBuilder; import io.kubernetes.client.util.PatchUtils; import io.kubernetes.client.util.Yaml; import okhttp3.Response; @@ -1160,38 +1159,6 @@ public class V1Controller extends KubernetesController { return listOfPVCs; } - /** - * Generates the <code>Volume Mounts</code> to be placed in the <code>Executor</code> - * and <code>Manager</code> from options on the CLI. - * @param volumeName Name of the <code>Volume</code>. - * @param configs Mapping of <code>Volume</code> option <code>key-value</code> configuration pairs. - * @return A configured <code>V1VolumeMount</code>. - */ - @VisibleForTesting - protected V1VolumeMount createVolumeMountsCLI(final String volumeName, - final Map<KubernetesConstants.VolumeConfigKeys, String> configs) { - final V1VolumeMount volumeMount = new V1VolumeMountBuilder() - .withName(volumeName) - .build(); - for (Map.Entry<KubernetesConstants.VolumeConfigKeys, String> config : configs.entrySet()) { - switch (config.getKey()) { - case path: - volumeMount.mountPath(config.getValue()); - break; - case subPath: - volumeMount.subPath(config.getValue()); - break; - case readOnly: - volumeMount.readOnly(Boolean.parseBoolean(config.getValue())); - break; - default: - break; - } - } - - return volumeMount; - } - /** * Generates the <code>Volume</code>s and <code>Volume Mounts</code> for <code>Persistent Volume Claims</code>s * to be placed in the <code>Executor</code> and <code>Manager</code> from options on the CLI. @@ -1220,7 +1187,7 @@ public class V1Controller extends KubernetesController { .build() ); } - volumeMounts.add(createVolumeMountsCLI(volumeName, configs.getValue())); + volumeMounts.add(Volumes.get().createMount(volumeName, configs.getValue())); } } @@ -1241,7 +1208,7 @@ public class V1Controller extends KubernetesController { final V1Volume volume = Volumes.get() .createVolume(Volumes.VolumeType.EmptyDir, volumeName, configs.getValue()); volumes.add(volume); - volumeMounts.add(createVolumeMountsCLI(volumeName, configs.getValue())); + volumeMounts.add(Volumes.get().createMount(volumeName, configs.getValue())); } } @@ -1262,7 +1229,7 @@ public class V1Controller extends KubernetesController { final V1Volume volume = Volumes.get() .createVolume(Volumes.VolumeType.HostPath, volumeName, configs.getValue()); volumes.add(volume); - volumeMounts.add(createVolumeMountsCLI(volumeName, configs.getValue())); + volumeMounts.add(Volumes.get().createMount(volumeName, configs.getValue())); } } @@ -1283,7 +1250,7 @@ public class V1Controller extends KubernetesController { final V1Volume volume = Volumes.get() .createVolume(Volumes.VolumeType.NetworkFileSystem, volumeName, configs.getValue()); volumes.add(volume); - volumeMounts.add(createVolumeMountsCLI(volumeName, configs.getValue())); + volumeMounts.add(Volumes.get().createMount(volumeName, configs.getValue())); } } diff --git a/heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/V1ControllerTest.java b/heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/V1ControllerTest.java index e9fd8673153..3e667d81fd6 100644 --- a/heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/V1ControllerTest.java +++ b/heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/V1ControllerTest.java @@ -1151,103 +1151,6 @@ public class V1ControllerTest { } } - @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); - } - - } - @Test public void testCreateVolumeAndMountsEmptyDirCLI() { final String volumeName = "volume-name-empty-dir";
