Fix k8s support to allow a specific network for the docker (do not use the parent daemon network definition)

This commit is contained in:
allegroai 2020-03-09 12:38:32 +02:00
parent e3d0680d39
commit f2d2d702de

View File

@ -1898,13 +1898,14 @@ class Worker(ServiceCommandSection):
# check if running inside a kubernetes # check if running inside a kubernetes
if os.environ.get('KUBERNETES_SERVICE_HOST') and os.environ.get('KUBERNETES_PORT'): if os.environ.get('KUBERNETES_SERVICE_HOST') and os.environ.get('KUBERNETES_PORT'):
# map network to sibling docker # map network to sibling docker, unless we have other network argument
try: if not any(a.strip().startswith('--network') for a in base_cmd):
network_mode = get_bash_output( try:
'docker inspect --format=\'{{.HostConfig.NetworkMode}}\' $(basename $(cat /proc/1/cpuset))') network_mode = get_bash_output(
base_cmd += ['--network', network_mode] 'docker inspect --format=\'{{.HostConfig.NetworkMode}}\' $(basename $(cat /proc/1/cpuset))')
except: base_cmd += ['--network', network_mode]
pass except:
pass
base_cmd += ['-e', 'NVIDIA_VISIBLE_DEVICES={}'.format(dockers_nvidia_visible_devices)] base_cmd += ['-e', 'NVIDIA_VISIBLE_DEVICES={}'.format(dockers_nvidia_visible_devices)]
# check if we need to map host folders # check if we need to map host folders