YARN-8228. Added hostname length check for docker container.
Contributed by Shane Kumpf
(cherry picked from commit a966ec6e23
)
This commit is contained in:
parent
4c13e7e3a0
commit
0fc55a8f57
|
@ -197,6 +197,7 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
|
|||
HOSTNAME_PATTERN);
|
||||
private static final Pattern USER_MOUNT_PATTERN = Pattern.compile(
|
||||
"(?<=^|,)([^:\\x00]+):([^:\\x00]+):([a-z]+)");
|
||||
private static final int HOST_NAME_LENGTH = 64;
|
||||
|
||||
@InterfaceAudience.Private
|
||||
public static final String ENV_DOCKER_CONTAINER_IMAGE =
|
||||
|
@ -534,6 +535,11 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
|
|||
throw new ContainerExecutionException("Hostname '" + hostname
|
||||
+ "' doesn't match docker hostname pattern");
|
||||
}
|
||||
if (hostname.length() > HOST_NAME_LENGTH) {
|
||||
throw new ContainerExecutionException(
|
||||
"Hostname can not be greater than " + HOST_NAME_LENGTH
|
||||
+ " characters: " + hostname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1529,6 +1529,19 @@ public class TestDockerContainerRuntime {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidDockerHostnameLength() throws Exception {
|
||||
String validLength = "example.test.site";
|
||||
DockerLinuxContainerRuntime.validateHostname(validLength);
|
||||
}
|
||||
|
||||
@Test(expected = ContainerExecutionException.class)
|
||||
public void testInvalidDockerHostnameLength() throws Exception {
|
||||
String invalidLength =
|
||||
"exampleexampleexampleexampleexampleexampleexampleexample.test.site";
|
||||
DockerLinuxContainerRuntime.validateHostname(invalidLength);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void checkVolumeCreateCommand()
|
||||
throws PrivilegedOperationException, IOException {
|
||||
|
|
Loading…
Reference in New Issue