Allow setting hostname on sandbox mode
If sandbox is used, we can simply set the hostname of the sandbox container. Then, all containers inside the sandbox will share the hostname. Change-Id: Ib7a70df58137d92df7d76e85354e761df99b2425 Related-Bug: #1716849
This commit is contained in:
parent
d4ac683a6b
commit
339559e7a4
@ -230,11 +230,6 @@ class ContainersController(base.Controller):
|
||||
|
||||
hostname = container_dict.pop('hostname', None)
|
||||
if hostname is not None:
|
||||
if CONF.use_sandbox:
|
||||
raise exception.ConflictOptions(
|
||||
'Cannot set container\'s hostname when use sandbox. '
|
||||
'Because with sandbox, network_mode will be set, it '
|
||||
'is incompatible with legacy network (hostname).')
|
||||
req_version = pecan.request.version
|
||||
min_version = versions.Version('', '', '', '1.9')
|
||||
if req_version >= min_version:
|
||||
|
@ -132,8 +132,11 @@ class DockerDriver(driver.ContainerDriver):
|
||||
'labels': container.labels,
|
||||
'tty': container.interactive,
|
||||
'stdin_open': container.interactive,
|
||||
'hostname': container.hostname,
|
||||
}
|
||||
if not sandbox_id:
|
||||
# Sandbox is not used so it is legitimate to customize
|
||||
# the container's hostname
|
||||
kwargs['hostname'] = container.hostname
|
||||
|
||||
runtime = container.runtime if container.runtime\
|
||||
else CONF.container_runtime
|
||||
@ -656,8 +659,9 @@ class DockerDriver(driver.ContainerDriver):
|
||||
network_api = zun_network.api(context=context, docker_api=docker)
|
||||
self._provision_network(context, network_api, requested_networks)
|
||||
name = self.get_sandbox_name(container)
|
||||
sandbox = docker.create_container(image, name=name,
|
||||
hostname=name[:63])
|
||||
sandbox = docker.create_container(
|
||||
image, name=name,
|
||||
hostname=container.hostname or name[:63])
|
||||
container.set_sandbox_id(sandbox['Id'])
|
||||
addresses = self._setup_network_for_container(
|
||||
context, container, requested_networks, network_api)
|
||||
|
@ -343,12 +343,14 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
self.mock_docker.create_container = mock.Mock(
|
||||
return_value={'Id': 'val1', 'key1': 'val2'})
|
||||
mock_container = mock.MagicMock()
|
||||
hostname = 'my_hostname'
|
||||
mock_container.hostname = hostname
|
||||
requested_networks = []
|
||||
result_sandbox_id = self.driver.create_sandbox(
|
||||
self.context, mock_container, requested_networks,
|
||||
'kubernetes/pause')
|
||||
self.mock_docker.create_container.assert_called_once_with(
|
||||
'kubernetes/pause', name=sandbox_name, hostname=sandbox_name)
|
||||
'kubernetes/pause', name=sandbox_name, hostname=hostname)
|
||||
self.assertEqual(result_sandbox_id, 'val1')
|
||||
|
||||
@mock.patch('zun.network.kuryr_network.KuryrNetwork'
|
||||
@ -363,6 +365,7 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
self.mock_docker.create_container = mock.Mock(
|
||||
return_value={'Id': 'val1', 'key1': 'val2'})
|
||||
mock_container = mock.MagicMock()
|
||||
mock_container.hostname = None
|
||||
requested_networks = []
|
||||
result_sandbox_id = self.driver.create_sandbox(
|
||||
self.context, mock_container, requested_networks,
|
||||
|
Loading…
Reference in New Issue
Block a user