YARN-8027. Setting hostname of docker container breaks for --net=host in docker 1.13. Contributed by Jim Brennan
This commit is contained in:
parent
3717df89ee
commit
d416a0c9b7
|
@ -106,7 +106,8 @@ import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.r
|
||||||
* <li>
|
* <li>
|
||||||
* {@code YARN_CONTAINER_RUNTIME_DOCKER_CONTAINER_HOSTNAME} sets the
|
* {@code YARN_CONTAINER_RUNTIME_DOCKER_CONTAINER_HOSTNAME} sets the
|
||||||
* hostname to be used by the Docker container. If not specified, a
|
* hostname to be used by the Docker container. If not specified, a
|
||||||
* hostname will be derived from the container ID.
|
* hostname will be derived from the container ID. This variable is
|
||||||
|
* ignored if the network is 'host'.
|
||||||
* </li>
|
* </li>
|
||||||
* <li>
|
* <li>
|
||||||
* {@code YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER}
|
* {@code YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER}
|
||||||
|
@ -584,7 +585,10 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
|
||||||
.detachOnRun()
|
.detachOnRun()
|
||||||
.setContainerWorkDir(containerWorkDir.toString())
|
.setContainerWorkDir(containerWorkDir.toString())
|
||||||
.setNetworkType(network);
|
.setNetworkType(network);
|
||||||
setHostname(runCommand, containerIdStr, hostname);
|
// Only add hostname if network is not host.
|
||||||
|
if (!network.equalsIgnoreCase("host")) {
|
||||||
|
setHostname(runCommand, containerIdStr, hostname);
|
||||||
|
}
|
||||||
runCommand.setCapabilities(capabilities);
|
runCommand.setCapabilities(capabilities);
|
||||||
|
|
||||||
if(cgroupsRootDirectory != null) {
|
if(cgroupsRootDirectory != null) {
|
||||||
|
|
|
@ -160,6 +160,8 @@ public class TestDockerContainerRuntime {
|
||||||
LOG.info("Could not run id -G command: " + e);
|
LOG.info("Could not run id -G command: " + e);
|
||||||
}
|
}
|
||||||
uidGidPair = uid + ":" + gid;
|
uidGidPair = uid + ":" + gid;
|
||||||
|
// Prevent gid threshold failures for these tests
|
||||||
|
conf.setInt(YarnConfiguration.NM_DOCKER_USER_REMAPPING_GID_THRESHOLD, 0);
|
||||||
|
|
||||||
user = "user";
|
user = "user";
|
||||||
appId = "app_id";
|
appId = "app_id";
|
||||||
|
@ -329,7 +331,7 @@ public class TestDockerContainerRuntime {
|
||||||
List<String> dockerCommands = Files.readAllLines(Paths.get
|
List<String> dockerCommands = Files.readAllLines(Paths.get
|
||||||
(dockerCommandFile), Charset.forName("UTF-8"));
|
(dockerCommandFile), Charset.forName("UTF-8"));
|
||||||
|
|
||||||
int expected = 14;
|
int expected = 13;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
Assert.assertEquals(expected, dockerCommands.size());
|
Assert.assertEquals(expected, dockerCommands.size());
|
||||||
Assert.assertEquals("[docker-command-execution]",
|
Assert.assertEquals("[docker-command-execution]",
|
||||||
|
@ -341,7 +343,6 @@ public class TestDockerContainerRuntime {
|
||||||
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
||||||
dockerCommands.get(counter++));
|
dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" hostname=ctr-id", dockerCommands.get(counter++));
|
|
||||||
Assert
|
Assert
|
||||||
.assertEquals(" image=busybox:latest", dockerCommands.get(counter++));
|
.assertEquals(" image=busybox:latest", dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
@ -379,7 +380,7 @@ public class TestDockerContainerRuntime {
|
||||||
List<String> dockerCommands = Files.readAllLines(
|
List<String> dockerCommands = Files.readAllLines(
|
||||||
Paths.get(dockerCommandFile), Charset.forName("UTF-8"));
|
Paths.get(dockerCommandFile), Charset.forName("UTF-8"));
|
||||||
|
|
||||||
Assert.assertEquals(14, dockerCommands.size());
|
Assert.assertEquals(13, dockerCommands.size());
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
Assert.assertEquals("[docker-command-execution]",
|
Assert.assertEquals("[docker-command-execution]",
|
||||||
dockerCommands.get(counter++));
|
dockerCommands.get(counter++));
|
||||||
|
@ -390,8 +391,6 @@ public class TestDockerContainerRuntime {
|
||||||
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
||||||
dockerCommands.get(counter++));
|
dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" hostname=ctr-id",
|
|
||||||
dockerCommands.get(counter++));
|
|
||||||
Assert
|
Assert
|
||||||
.assertEquals(" image=busybox:latest", dockerCommands.get(counter++));
|
.assertEquals(" image=busybox:latest", dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
@ -437,7 +436,7 @@ public class TestDockerContainerRuntime {
|
||||||
runtime =
|
runtime =
|
||||||
new DockerLinuxContainerRuntime(mockExecutor, mockCGroupsHandler);
|
new DockerLinuxContainerRuntime(mockExecutor, mockCGroupsHandler);
|
||||||
runtime.initialize(conf);
|
runtime.initialize(conf);
|
||||||
Assert.fail("Invalid default network configuration should did not "
|
Assert.fail("Invalid default network configuration did not "
|
||||||
+ "trigger initialization failure.");
|
+ "trigger initialization failure.");
|
||||||
} catch (ContainerExecutionException e) {
|
} catch (ContainerExecutionException e) {
|
||||||
LOG.info("Caught expected exception : " + e);
|
LOG.info("Caught expected exception : " + e);
|
||||||
|
@ -477,10 +476,7 @@ public class TestDockerContainerRuntime {
|
||||||
LOG.info("Caught expected exception: " + e);
|
LOG.info("Caught expected exception: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = YarnConfiguration
|
String allowedNetwork = "bridge";
|
||||||
.DEFAULT_NM_DOCKER_ALLOWED_CONTAINER_NETWORKS.length;
|
|
||||||
String allowedNetwork = YarnConfiguration
|
|
||||||
.DEFAULT_NM_DOCKER_ALLOWED_CONTAINER_NETWORKS[randEngine.nextInt(size)];
|
|
||||||
env.put(DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_NETWORK,
|
env.put(DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_NETWORK,
|
||||||
allowedNetwork);
|
allowedNetwork);
|
||||||
String expectedHostname = "test.hostname";
|
String expectedHostname = "test.hostname";
|
||||||
|
@ -675,7 +671,7 @@ public class TestDockerContainerRuntime {
|
||||||
List<String> dockerCommands = Files.readAllLines(Paths.get
|
List<String> dockerCommands = Files.readAllLines(Paths.get
|
||||||
(dockerCommandFile), Charset.forName("UTF-8"));
|
(dockerCommandFile), Charset.forName("UTF-8"));
|
||||||
|
|
||||||
int expected = 14;
|
int expected = 13;
|
||||||
Assert.assertEquals(expected, dockerCommands.size());
|
Assert.assertEquals(expected, dockerCommands.size());
|
||||||
|
|
||||||
String command = dockerCommands.get(0);
|
String command = dockerCommands.get(0);
|
||||||
|
@ -784,7 +780,7 @@ public class TestDockerContainerRuntime {
|
||||||
List<String> dockerCommands = Files.readAllLines(Paths.get
|
List<String> dockerCommands = Files.readAllLines(Paths.get
|
||||||
(dockerCommandFile), Charset.forName("UTF-8"));
|
(dockerCommandFile), Charset.forName("UTF-8"));
|
||||||
|
|
||||||
int expected = 15;
|
int expected = 14;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
Assert.assertEquals(expected, dockerCommands.size());
|
Assert.assertEquals(expected, dockerCommands.size());
|
||||||
Assert.assertEquals("[docker-command-execution]",
|
Assert.assertEquals("[docker-command-execution]",
|
||||||
|
@ -796,7 +792,6 @@ public class TestDockerContainerRuntime {
|
||||||
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
||||||
dockerCommands.get(counter++));
|
dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" hostname=ctr-id", dockerCommands.get(counter++));
|
|
||||||
Assert
|
Assert
|
||||||
.assertEquals(" image=busybox:latest", dockerCommands.get(counter++));
|
.assertEquals(" image=busybox:latest", dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
@ -903,7 +898,7 @@ public class TestDockerContainerRuntime {
|
||||||
List<String> dockerCommands = Files.readAllLines(Paths.get
|
List<String> dockerCommands = Files.readAllLines(Paths.get
|
||||||
(dockerCommandFile), Charset.forName("UTF-8"));
|
(dockerCommandFile), Charset.forName("UTF-8"));
|
||||||
|
|
||||||
int expected = 15;
|
int expected = 14;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
Assert.assertEquals(expected, dockerCommands.size());
|
Assert.assertEquals(expected, dockerCommands.size());
|
||||||
Assert.assertEquals("[docker-command-execution]",
|
Assert.assertEquals("[docker-command-execution]",
|
||||||
|
@ -915,7 +910,6 @@ public class TestDockerContainerRuntime {
|
||||||
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
||||||
dockerCommands.get(counter++));
|
dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" hostname=ctr-id", dockerCommands.get(counter++));
|
|
||||||
Assert.assertEquals(" image=busybox:latest",
|
Assert.assertEquals(" image=busybox:latest",
|
||||||
dockerCommands.get(counter++));
|
dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
@ -979,7 +973,7 @@ public class TestDockerContainerRuntime {
|
||||||
List<String> dockerCommands = Files.readAllLines(Paths.get
|
List<String> dockerCommands = Files.readAllLines(Paths.get
|
||||||
(dockerCommandFile), Charset.forName("UTF-8"));
|
(dockerCommandFile), Charset.forName("UTF-8"));
|
||||||
|
|
||||||
int expected = 15;
|
int expected = 14;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
Assert.assertEquals(expected, dockerCommands.size());
|
Assert.assertEquals(expected, dockerCommands.size());
|
||||||
Assert.assertEquals("[docker-command-execution]",
|
Assert.assertEquals("[docker-command-execution]",
|
||||||
|
@ -991,7 +985,6 @@ public class TestDockerContainerRuntime {
|
||||||
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
Assert.assertEquals(" group-add=" + String.join(",", groups),
|
||||||
dockerCommands.get(counter++));
|
dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(" hostname=ctr-id", dockerCommands.get(counter++));
|
|
||||||
Assert.assertEquals(" image=busybox:latest",
|
Assert.assertEquals(" image=busybox:latest",
|
||||||
dockerCommands.get(counter++));
|
dockerCommands.get(counter++));
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
|
Loading…
Reference in New Issue