Skip to content

Commit

Permalink
Add validation to watcher_kubeconfig_paths too, and a minimal test
Browse files Browse the repository at this point in the history
  • Loading branch information
jfongatyelp committed Jul 10, 2024
1 parent 48a5b4a commit 76ad701
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/config/config_parse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1744,5 +1744,40 @@ def test_invalid(self, url, context):
config_parse.valid_master_address(url, context)


class TestValidKubeconfigPaths:
@setup
def setup_context(self):
self.context = config_utils.NullConfigContext

@pytest.mark.parametrize(
"kubeconfig_path,watcher_kubeconfig_paths",
[("/some/kubeconfig.conf", []), ("/another/kube/config", ["a_watcher_kubeconfig"])],
)
def test_valid(self, kubeconfig_path, watcher_kubeconfig_paths):
k8s_options = {
"enabled": True,
"kubeconfig_path": kubeconfig_path,
"watcher_kubeconfig_paths": watcher_kubeconfig_paths,
}
assert config_parse.valid_kubernetes_options.validate(k8s_options, self.context)

@pytest.mark.parametrize(
"kubeconfig_path,watcher_kubeconfig_paths",
[
(["/a/kubeconfig/in/a/list"], ["/a/valid/kubeconfig"]),
(None, []),
("/some/kubeconfig.conf", "/not/a/list/kubeconfig"),
],
)
def test_invalid(self, kubeconfig_path, watcher_kubeconfig_paths):
k8s_options = {
"enabled": True,
"kubeconfig_path": kubeconfig_path,
"watcher_kubeconfig_paths": watcher_kubeconfig_paths,
}
with pytest.raises(ConfigError):
config_parse.valid_kubernetes_options.validate(k8s_options, self.context)


if __name__ == "__main__":
run()
1 change: 1 addition & 0 deletions tron/config/config_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ class ValidateKubernetes(Validator):
"kubeconfig_path": valid_string,
"enabled": valid_bool,
"default_volumes": build_list_of_type_validator(valid_volume, allow_empty=True),
"watcher_kubeconfig_paths": build_list_of_type_validator(valid_string, allow_empty=True),
}


Expand Down

0 comments on commit 76ad701

Please sign in to comment.