YARN-8675. Remove default hostname for docker containers when net=host. Contributed by Suma Shivaprasad
(cherry picked from commit 05b2bbeb35
)
This commit is contained in:
parent
271ed86ac0
commit
eefd780918
|
@ -137,8 +137,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. This variable is
|
* hostname will be derived from the container ID and set as default
|
||||||
* ignored if the network is 'host' and Registry DNS is not enabled.
|
* hostname for networks other than 'host'.
|
||||||
* </li>
|
* </li>
|
||||||
* <li>
|
* <li>
|
||||||
* {@code YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER}
|
* {@code YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER}
|
||||||
|
@ -553,22 +553,34 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set a DNS friendly hostname. */
|
/** Set a DNS friendly hostname.
|
||||||
private void setHostname(DockerRunCommand runCommand, String
|
* Only add hostname if network is not host or if hostname is
|
||||||
containerIdStr, String name)
|
* specified via YARN_CONTAINER_RUNTIME_DOCKER_CONTAINER_HOSTNAME
|
||||||
|
* in host network mode
|
||||||
|
*/
|
||||||
|
private void setHostname(DockerRunCommand runCommand,
|
||||||
|
String containerIdStr, String network, String name)
|
||||||
throws ContainerExecutionException {
|
throws ContainerExecutionException {
|
||||||
if (name == null || name.isEmpty()) {
|
|
||||||
name = RegistryPathUtils.encodeYarnID(containerIdStr);
|
|
||||||
|
|
||||||
String domain = conf.get(RegistryConstants.KEY_DNS_DOMAIN);
|
if (network.equalsIgnoreCase("host")) {
|
||||||
if (domain != null) {
|
if (name != null && !name.isEmpty()) {
|
||||||
name += ("." + domain);
|
LOG.info("setting hostname in container to: " + name);
|
||||||
|
runCommand.setHostname(name);
|
||||||
}
|
}
|
||||||
validateHostname(name);
|
} else {
|
||||||
}
|
//get default hostname
|
||||||
|
if (name == null || name.isEmpty()) {
|
||||||
|
name = RegistryPathUtils.encodeYarnID(containerIdStr);
|
||||||
|
|
||||||
LOG.info("setting hostname in container to: " + name);
|
String domain = conf.get(RegistryConstants.KEY_DNS_DOMAIN);
|
||||||
runCommand.setHostname(name);
|
if (domain != null) {
|
||||||
|
name += ("." + domain);
|
||||||
|
}
|
||||||
|
validateHostname(name);
|
||||||
|
}
|
||||||
|
LOG.info("setting hostname in container to: " + name);
|
||||||
|
runCommand.setHostname(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -827,12 +839,9 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
|
||||||
DockerRunCommand runCommand = new DockerRunCommand(containerIdStr,
|
DockerRunCommand runCommand = new DockerRunCommand(containerIdStr,
|
||||||
dockerRunAsUser, imageName)
|
dockerRunAsUser, imageName)
|
||||||
.setNetworkType(network);
|
.setNetworkType(network);
|
||||||
// Only add hostname if network is not host or if Registry DNS is enabled.
|
|
||||||
if (!network.equalsIgnoreCase("host") ||
|
setHostname(runCommand, containerIdStr, network, hostname);
|
||||||
conf.getBoolean(RegistryConstants.KEY_DNS_ENABLED,
|
|
||||||
RegistryConstants.DEFAULT_DNS_ENABLED)) {
|
|
||||||
setHostname(runCommand, containerIdStr, hostname);
|
|
||||||
}
|
|
||||||
runCommand.setCapabilities(capabilities);
|
runCommand.setCapabilities(capabilities);
|
||||||
|
|
||||||
runCommand.addAllReadWriteMountLocations(containerLogDirs);
|
runCommand.addAllReadWriteMountLocations(containerLogDirs);
|
||||||
|
|
Loading…
Reference in New Issue