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);
}
long commaCount = environment.get(ENV_DOCKER_CONTAINER_MOUNTS).chars()
.filter(c -> c == ',').count();
if (mountCount != commaCount + 1) {
long semicolonCount = environment.get(ENV_DOCKER_CONTAINER_MOUNTS).chars()
.filter(c -> c == ';').count();
if (mountCount != semicolonCount + 1) {
// this means the matcher skipped an improperly formatted mount
throw new ContainerExecutionException(
"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(
"^[a-zA-Z0-9][a-zA-Z0-9_.-]+$");
static final Pattern USER_MOUNT_PATTERN = Pattern.compile(
"(?<=^|,)([^:\\x00]+):([^:\\x00]+)" +
"(:(r[ow]|(r[ow][+])?(r?shared|r?slave|r?private)))?(?:,|$)");
"(?<=^|;)([^:\\x00]+):([^:\\x00]+)" +
"(:(r[ow]|(r[ow][+])?(r?shared|r?slave|r?private)))?(?:;|$)");
static final Pattern TMPFS_MOUNT_PATTERN = Pattern.compile(
"^/[^:\\x00]+$");
static final String PORTS_MAPPING_PATTERN =

View File

@ -1345,7 +1345,7 @@ public class TestDockerContainerRuntime {
env.put(
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");
runtime.launchContainer(builder.build());
@ -1395,8 +1395,8 @@ public class TestDockerContainerRuntime {
env.put(
DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS,
"/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");
"/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");
runtime.launchContainer(builder.build());
List<String> dockerCommands = readDockerCommands();
@ -1444,7 +1444,7 @@ public class TestDockerContainerRuntime {
env.put(
DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS,
"/source:target:ro,/source:target:other,/source:target:rw");
"/source:target:ro;/source:target:other;/source:target:rw");
try {
runtime.launchContainer(builder.build());