-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[k8s] Add validation for pod_config #4206 #4466
Changes from all commits
12f1208
64bb66a
a0f29e5
47e724d
699961d
164f436
0471b4c
98a1d84
7e501f3
ef562da
2b5dba1
81029d7
d349c37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import sky | ||
from sky import skypilot_config | ||
import sky.exceptions | ||
from sky.skylet import constants | ||
from sky.utils import common_utils | ||
from sky.utils import kubernetes_enums | ||
|
@@ -99,6 +100,29 @@ def _create_task_yaml_file(task_file_path: pathlib.Path) -> None: | |
""")) | ||
|
||
|
||
def _create_invalid_config_yaml_file(task_file_path: pathlib.Path) -> None: | ||
task_file_path.write_text( | ||
textwrap.dedent("""\ | ||
experimental: | ||
config_overrides: | ||
kubernetes: | ||
pod_config: | ||
metadata: | ||
labels: | ||
test-key: test-value | ||
annotations: | ||
abc: def | ||
spec: | ||
containers: | ||
- name: | ||
imagePullSecrets: | ||
- name: my-secret-2 | ||
|
||
setup: echo 'Setting up...' | ||
run: echo 'Running...' | ||
""")) | ||
|
||
|
||
def test_nested_config(monkeypatch) -> None: | ||
"""Test that the nested config works.""" | ||
config = skypilot_config.Config() | ||
|
@@ -335,6 +359,28 @@ def test_k8s_config_with_override(monkeypatch, tmp_path, | |
assert cluster_pod_config['spec']['runtimeClassName'] == 'nvidia' | ||
|
||
|
||
def test_k8s_config_with_invalid_config(monkeypatch, tmp_path, | ||
enable_all_clouds) -> None: | ||
config_path = tmp_path / 'config.yaml' | ||
_create_config_file(config_path) | ||
monkeypatch.setattr(skypilot_config, 'CONFIG_PATH', config_path) | ||
|
||
_reload_config() | ||
task_path = tmp_path / 'task.yaml' | ||
_create_invalid_config_yaml_file(task_path) | ||
task = sky.Task.from_yaml(task_path) | ||
|
||
# Test Kubernetes pod_config invalid | ||
cluster_name = 'test_k8s_config_with_invalid_config' | ||
task.set_resources_override({'cloud': sky.Kubernetes()}) | ||
exception_occurred = False | ||
try: | ||
sky.launch(task, cluster_name=cluster_name, dryrun=True) | ||
except sky.exceptions.ResourcesUnavailableError: | ||
exception_occurred = True | ||
Comment on lines
+379
to
+380
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also verify the error message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to validate this error message, but it's meaningless for this test because the error message returned by |
||
assert exception_occurred | ||
|
||
|
||
def test_gcp_config_with_override(monkeypatch, tmp_path, | ||
enable_all_clouds) -> None: | ||
config_path = tmp_path / 'config.yaml' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we retain just the relevant
kubernetes
field and remove the docker, gcp, nvidia_gpus and other fields?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can we put a quick comment on what's the invalid field here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the
deserialize
api will ignore other invalid field here, as we can see the implement in the https://github.com/kubernetes-client/python/blob/e10470291526c82f12a0a3405910ccc3f3cdeb26/kubernetes/client/api_client.py#L620There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I meant for readability in tests, let's have only this: