YARN-9906. Fix Docker container multi volume mounts bug

This commit is contained in:
lynnyuan 2019-10-16 17:37:04 +08:00
parent c39e9fc9a3
commit 9bb25cd28f
3 changed files with 9 additions and 9 deletions

View File

@ -717,9 +717,9 @@ public class DockerLinuxContainerRuntime extends OCIContainerRuntime {
} }
runCommand.addMountLocation(src, dst, mode); runCommand.addMountLocation(src, dst, mode);
} }
long commaCount = environment.get(ENV_DOCKER_CONTAINER_MOUNTS).chars() long semicolonCount = environment.get(ENV_DOCKER_CONTAINER_MOUNTS).chars()
.filter(c -> c == ',').count(); .filter(c -> c == ';').count();
if (mountCount != commaCount + 1) { if (mountCount != semicolonCount + 1) {
// this means the matcher skipped an improperly formatted mount // this means the matcher skipped an improperly formatted mount
throw new ContainerExecutionException( throw new ContainerExecutionException(
"Unable to parse some mounts in user supplied mount list: " "Unable to parse some mounts in user supplied mount list: "

View File

@ -71,8 +71,8 @@ public abstract class OCIContainerRuntime implements LinuxContainerRuntime {
private static final Pattern HOSTNAME_PATTERN = Pattern.compile( private static final Pattern HOSTNAME_PATTERN = Pattern.compile(
"^[a-zA-Z0-9][a-zA-Z0-9_.-]+$"); "^[a-zA-Z0-9][a-zA-Z0-9_.-]+$");
static final Pattern USER_MOUNT_PATTERN = Pattern.compile( static final Pattern USER_MOUNT_PATTERN = Pattern.compile(
"(?<=^|,)([^:\\x00]+):([^:\\x00]+)" + "(?<=^|;)([^:\\x00]+):([^:\\x00]+)" +
"(:(r[ow]|(r[ow][+])?(r?shared|r?slave|r?private)))?(?:,|$)"); "(:(r[ow]|(r[ow][+])?(r?shared|r?slave|r?private)))?(?:;|$)");
static final Pattern TMPFS_MOUNT_PATTERN = Pattern.compile( static final Pattern TMPFS_MOUNT_PATTERN = Pattern.compile(
"^/[^:\\x00]+$"); "^/[^:\\x00]+$");
static final String PORTS_MAPPING_PATTERN = static final String PORTS_MAPPING_PATTERN =

View File

@ -1345,7 +1345,7 @@ public class TestDockerContainerRuntime {
env.put( env.put(
DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS, DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS,
"test_dir/test_resource_file:test_mount1:ro," + "test_dir/test_resource_file:test_mount1:ro;" +
"test_dir/test_resource_file:test_mount2:ro"); "test_dir/test_resource_file:test_mount2:ro");
runtime.launchContainer(builder.build()); runtime.launchContainer(builder.build());
@ -1395,8 +1395,8 @@ public class TestDockerContainerRuntime {
env.put( env.put(
DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS, DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS,
"/tmp/foo:/tmp/foo:ro,/tmp/bar:/tmp/bar:rw,/tmp/baz:/tmp/baz," + "/tmp/foo:/tmp/foo:ro;/tmp/bar:/tmp/bar:rw;/tmp/baz:/tmp/baz;" +
"/a:/a:shared,/b:/b:ro+shared,/c:/c:rw+rshared,/d:/d:private"); "/a:/a:shared;/b:/b:ro+shared;/c:/c:rw+rshared;/d:/d:private");
runtime.launchContainer(builder.build()); runtime.launchContainer(builder.build());
List<String> dockerCommands = readDockerCommands(); List<String> dockerCommands = readDockerCommands();
@ -1444,7 +1444,7 @@ public class TestDockerContainerRuntime {
env.put( env.put(
DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS, DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS,
"/source:target:ro,/source:target:other,/source:target:rw"); "/source:target:ro;/source:target:other;/source:target:rw");
try { try {
runtime.launchContainer(builder.build()); runtime.launchContainer(builder.build());