[AIRFLOW-5641] Support running git sync container as root (#6312)
This commit is contained in:
Родитель
e62056b225
Коммит
133085eb47
|
@ -21,6 +21,7 @@ import json
|
|||
import multiprocessing
|
||||
import re
|
||||
from queue import Empty
|
||||
from typing import Union
|
||||
from uuid import uuid4
|
||||
|
||||
import kubernetes
|
||||
|
@ -206,10 +207,10 @@ class KubeConfig: # pylint: disable=too-many-instance-attributes
|
|||
|
||||
# pod security context items should return integers
|
||||
# and only return a blank string if contexts are not set.
|
||||
def _get_security_context_val(self, scontext):
|
||||
def _get_security_context_val(self, scontext: str) -> Union[str, int]:
|
||||
val = conf.get(self.kubernetes_section, scontext)
|
||||
if not val:
|
||||
return 0
|
||||
return ""
|
||||
else:
|
||||
return int(val)
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ class WorkerConfiguration(LoggingMixin):
|
|||
|
||||
if self.kube_config.git_sync_run_as_user != "":
|
||||
init_containers.security_context = k8s.V1SecurityContext(
|
||||
run_as_user=self.kube_config.git_sync_run_as_user or 65533
|
||||
run_as_user=self.kube_config.git_sync_run_as_user
|
||||
) # git-sync user
|
||||
|
||||
return [init_containers]
|
||||
|
|
|
@ -137,6 +137,32 @@ class TestKubeConfig(unittest.TestCase):
|
|||
annotations = KubeConfig().kube_annotations
|
||||
self.assertIsNone(annotations)
|
||||
|
||||
@conf_vars({
|
||||
('kubernetes', 'git_repo'): 'foo',
|
||||
('kubernetes', 'git_branch'): 'foo',
|
||||
('kubernetes', 'git_dags_folder_mount_point'): 'foo',
|
||||
('kubernetes', 'git_sync_run_as_user'): '0',
|
||||
})
|
||||
def test_kube_config_git_sync_run_as_user_root(self):
|
||||
self.assertEqual(KubeConfig().git_sync_run_as_user, 0)
|
||||
|
||||
@conf_vars({
|
||||
('kubernetes', 'git_repo'): 'foo',
|
||||
('kubernetes', 'git_branch'): 'foo',
|
||||
('kubernetes', 'git_dags_folder_mount_point'): 'foo',
|
||||
})
|
||||
def test_kube_config_git_sync_run_as_user_not_present(self):
|
||||
self.assertEqual(KubeConfig().git_sync_run_as_user, 65533)
|
||||
|
||||
@conf_vars({
|
||||
('kubernetes', 'git_repo'): 'foo',
|
||||
('kubernetes', 'git_branch'): 'foo',
|
||||
('kubernetes', 'git_dags_folder_mount_point'): 'foo',
|
||||
('kubernetes', 'git_sync_run_as_user'): '',
|
||||
})
|
||||
def test_kube_config_git_sync_run_as_user_empty_string(self):
|
||||
self.assertEqual(KubeConfig().git_sync_run_as_user, '')
|
||||
|
||||
|
||||
class TestKubernetesExecutor(unittest.TestCase):
|
||||
"""
|
||||
|
|
|
@ -317,6 +317,21 @@ class TestKubernetesWorkerConfiguration(unittest.TestCase):
|
|||
|
||||
self.assertIsNone(init_containers[0].security_context)
|
||||
|
||||
def test_init_environment_using_git_sync_run_as_user_root(self):
|
||||
# Tests if git_syn_run_as_user is '0', securityContext is created with
|
||||
# the right uid
|
||||
|
||||
self.kube_config.dags_volume_claim = None
|
||||
self.kube_config.dags_volume_host = None
|
||||
self.kube_config.dags_in_image = None
|
||||
self.kube_config.git_sync_run_as_user = 0
|
||||
|
||||
worker_config = WorkerConfiguration(self.kube_config)
|
||||
init_containers = worker_config._get_init_containers()
|
||||
self.assertTrue(init_containers) # check not empty
|
||||
|
||||
self.assertEqual(0, init_containers[0].security_context.run_as_user)
|
||||
|
||||
def test_make_pod_run_as_user_0(self):
|
||||
# Tests the pod created with run-as-user 0 actually gets that in it's config
|
||||
self.kube_config.worker_run_as_user = 0
|
||||
|
|
Загрузка…
Ссылка в новой задаче