-
Notifications
You must be signed in to change notification settings - Fork 529
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
base: master
Are you sure you want to change the base?
Conversation
Check pod_config when run 'sky check k8s' by using k8s api
e994181
to
12f1208
Compare
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.
Thanks @chesterli29! Left some questions. We may need to use an alternate approach since pod validation from k8s API server may be too strict.
sky/provision/kubernetes/utils.py
Outdated
kubernetes.core_api(context).create_namespaced_pod( | ||
namespace, | ||
body=pod_config, | ||
dry_run='All', | ||
field_validation='Strict', | ||
_request_timeout=kubernetes.API_TIMEOUT) |
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.
Does this approach work even if the pod_config is partially specified? E.g.,
kubernetes:
pod_config:
spec:
containers:
- env:
- name: MY_ENV_VAR
value: "my_value"
My hunch is k8s will reject this pod spec since it's not a complete pod spec, but it's a valid pod_config in our case.
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.
yes, the k8s will reject this pod spec.
if this pod_config is valid in this project. is there any definition about this config? for example: some filed is required or optional? or all the filed is optional here, but it must follow the k8s pod require only if it has been set ?
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.
here is my solution about this, we can check the pod config by using k8s api after combine_pod_config_fields
and combine_metadata_fields
during launch (that is the early stage of launching.).
it's really hard and complex to follow and maintain the k8s pod json/yaml schema in this project.
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.
all the filed is optional here, but it must follow the k8s pod require only if it has been set ?
Yes, this is the definition of a valid pod_spec.
can check the pod config by using k8s api after combine_pod_config_fields and combine_metadata_fields during launch (that is the early stage of launching.)
Yes, that sounds reasonable as long as we can surface to the user where the error comes in the user's pod config.
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.
Have we considered having a simple local schema check, with the json schema fetched and flattened from something like https://github.com/instrumenta/kubernetes-json-schema/tree/master?
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.
Have we considered having a simple local schema check, with the json schema fetched and flattened from something like https://github.com/instrumenta/kubernetes-json-schema/tree/master?
Yeah, I took a look at this before. The main problem with this setup is that it needs to grab JSON schema files from other repo eg: https://github.com/yannh/kubernetes-json-schema, depending on which version of k8s user using. I'm not sure if it's a good idea for sky to download dependencies to the local machine while it's running. Plus, if we want to check pod_config locally using JSON schema, we might need to let users choose their k8s version so we can get the right schema file.
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.
Let's try the approach you proposed above (check the pod config by using k8s api after combine_pod_config_fields and combine_metadata_fields
) if it can surface the exact errors to the users.
If that does not work, we may need to do schema validation locally. Pod API has been relatively stable, so might not be too bad to have a fixed version schema for validation.
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.
LGTM,
BTW i found a error case when i test the approach with json schema in kubernetes-json-schema.
here is my part of test yaml
containers:
- name: local_test
image: test
note, the name here local_test
with _
inside, it's invalid when we creating a pod, but will pass the check by json schema.
and if we use this config to create sky cluster, it will fail later because the invalid name.
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.
check merged pod_config during launch using k8s api
if there is no kube config in env, ignore ValueError when launch with dryrun. For now, we don't support check schema offline.
Check pod_config when run 'sky check k8s' by using k8s #4206
This commit extends the functionality of
sky check k8s
by adding a check forpod_config
in this step. The method used to check pod_config is by calling the K8s API. This approach has some advantages and disadvantages:Of course, any other suggestions are welcome for discussion.
The test config.yaml
And the Check Result:
Tested (run the relevant ones):
bash format.sh
pytest tests/test_smoke.py
pytest tests/test_smoke.py::test_fill_in_the_name
conda deactivate; bash -i tests/backward_compatibility_tests.sh