Skip to content

Commit 95ad61a

Browse files
authored
Merge pull request #989 from Yelp/jfong/TRON-2195-old-kubeconfig-paths
TRON-2195: Support watcher_kubeconfig_paths
2 parents 9e978e3 + 1d0b396 commit 95ad61a

6 files changed

+48
-3
lines changed

requirements-minimal.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pytimeparse
2121
pytz
2222
PyYAML>=5.1
2323
requests
24-
task_processing[mesos_executor,k8s]>=1.1.0
24+
task_processing[mesos_executor,k8s]>=1.2.0
2525
Twisted>=19.7.0
2626
urllib3>=1.24.2
2727
Werkzeug>=0.15.3

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ setuptools==65.5.1
8080
six==1.15.0
8181
sshpubkeys==3.1.0
8282
stack-data==0.6.2
83-
task-processing==1.1.0
83+
task-processing==1.2.0
8484
traitlets==5.0.0
8585
Twisted==22.10.0
8686
typing-extensions==4.5.0

tests/config/config_parse_test.py

+35
Original file line numberDiff line numberDiff line change
@@ -1744,5 +1744,40 @@ def test_invalid(self, url, context):
17441744
config_parse.valid_master_address(url, context)
17451745

17461746

1747+
class TestValidKubeconfigPaths:
1748+
@setup
1749+
def setup_context(self):
1750+
self.context = config_utils.NullConfigContext
1751+
1752+
@pytest.mark.parametrize(
1753+
"kubeconfig_path,watcher_kubeconfig_paths",
1754+
[("/some/kubeconfig.conf", []), ("/another/kube/config", ["a_watcher_kubeconfig"])],
1755+
)
1756+
def test_valid(self, kubeconfig_path, watcher_kubeconfig_paths):
1757+
k8s_options = {
1758+
"enabled": True,
1759+
"kubeconfig_path": kubeconfig_path,
1760+
"watcher_kubeconfig_paths": watcher_kubeconfig_paths,
1761+
}
1762+
assert config_parse.valid_kubernetes_options.validate(k8s_options, self.context)
1763+
1764+
@pytest.mark.parametrize(
1765+
"kubeconfig_path,watcher_kubeconfig_paths",
1766+
[
1767+
(["/a/kubeconfig/in/a/list"], ["/a/valid/kubeconfig"]),
1768+
(None, []),
1769+
("/some/kubeconfig.conf", "/not/a/list/kubeconfig"),
1770+
],
1771+
)
1772+
def test_invalid(self, kubeconfig_path, watcher_kubeconfig_paths):
1773+
k8s_options = {
1774+
"enabled": True,
1775+
"kubeconfig_path": kubeconfig_path,
1776+
"watcher_kubeconfig_paths": watcher_kubeconfig_paths,
1777+
}
1778+
with pytest.raises(ConfigError):
1779+
config_parse.valid_kubernetes_options.validate(k8s_options, self.context)
1780+
1781+
17471782
if __name__ == "__main__":
17481783
run()

tron/config/config_parse.py

+1
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ class ValidateKubernetes(Validator):
874874
"kubeconfig_path": valid_string,
875875
"enabled": valid_bool,
876876
"default_volumes": build_list_of_type_validator(valid_volume, allow_empty=True),
877+
"watcher_kubeconfig_paths": build_list_of_type_validator(valid_string, allow_empty=True),
877878
}
878879

879880

tron/config/schema.py

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def config_object_factory(name, required=None, optional=None):
120120
"kubeconfig_path",
121121
"enabled",
122122
"default_volumes",
123+
"watcher_kubeconfig_paths",
123124
],
124125
)
125126

tron/kubernetes.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,14 @@ def __init__(
280280
enabled: bool = True,
281281
default_volumes: Optional[List[ConfigVolume]] = None,
282282
pod_launch_timeout: Optional[int] = None,
283+
watcher_kubeconfig_paths: Optional[List[str]] = None,
283284
):
284285
# general k8s config
285286
self.kubeconfig_path = kubeconfig_path
286287
self.enabled = enabled
287288
self.default_volumes: Optional[List[ConfigVolume]] = default_volumes or []
288289
self.pod_launch_timeout = pod_launch_timeout or DEFAULT_POD_LAUNCH_TIMEOUT_S
290+
self.watcher_kubeconfig_paths = watcher_kubeconfig_paths or []
289291
# creating a task_proc executor has a couple steps:
290292
# * create a TaskProcessor
291293
# * load the desired plugin (in this case, the k8s one)
@@ -340,6 +342,7 @@ def get_runner(self, kubeconfig_path: str, queue: PyDeferredQueue) -> Optional[S
340342
"namespace": "tron",
341343
"version": __version__,
342344
"kubeconfig_path": self.kubeconfig_path,
345+
"watcher_kubeconfig_paths": self.watcher_kubeconfig_paths,
343346
"task_configs": [task.get_config() for task in self.tasks.values()],
344347
},
345348
)
@@ -621,6 +624,7 @@ class KubernetesClusterRepository:
621624
kubeconfig_path: Optional[str] = None
622625
pod_launch_timeout: Optional[int] = None
623626
default_volumes: Optional[List[ConfigVolume]] = None
627+
watcher_kubeconfig_paths: Optional[List[str]] = None
624628

625629
# metadata config
626630
clusters: Dict[str, KubernetesCluster] = {}
@@ -643,7 +647,10 @@ def get_cluster(cls, kubeconfig_path: Optional[str] = None) -> Optional[Kubernet
643647
if kubeconfig_path not in cls.clusters:
644648
# will create the task_proc executor
645649
cluster = KubernetesCluster(
646-
kubeconfig_path=kubeconfig_path, enabled=cls.kubernetes_enabled, default_volumes=cls.default_volumes
650+
kubeconfig_path=kubeconfig_path,
651+
enabled=cls.kubernetes_enabled,
652+
default_volumes=cls.default_volumes,
653+
watcher_kubeconfig_paths=cls.watcher_kubeconfig_paths,
647654
)
648655
cls.clusters[kubeconfig_path] = cluster
649656

@@ -659,6 +666,7 @@ def configure(cls, kubernetes_options: ConfigKubernetes) -> None:
659666
cls.kubeconfig_path = kubernetes_options.kubeconfig_path
660667
cls.kubernetes_enabled = kubernetes_options.enabled
661668
cls.default_volumes = kubernetes_options.default_volumes
669+
cls.watcher_kubeconfig_paths = kubernetes_options.watcher_kubeconfig_paths
662670

663671
for cluster in cls.clusters.values():
664672
cluster.set_enabled(cls.kubernetes_enabled)

0 commit comments

Comments
 (0)