-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC: resolve k8s job and ops tag entirely using k8s_model_from_dict (#…
…6205) Summary: This is intended to resolve the confusing patchwork state we are in where some k8s config keys (env_from) need to be specified using underscores, but others need to be specified using camelCase. Also allows us to use the full range of k8s config available when configuring a job, while still getting schema validation. That said there are still some back-compat issues to sort out here. Curious for initial thoughts though.
- Loading branch information
Showing
15 changed files
with
698 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
examples/docs_snippets/docs_snippets/deploying/kubernetes/k8s_config_tag.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from dagster import job, op | ||
|
||
|
||
# fmt: off | ||
# start_k8s_config_op | ||
@op( | ||
tags={ | ||
"dagster-k8s/config": { | ||
"container_config": { | ||
"resources": { | ||
"requests": {"cpu": "200m", "memory": "32Mi"}, | ||
} | ||
}, | ||
} | ||
} | ||
) | ||
def my_op(context): | ||
context.log.info("running") | ||
# end_k8s_config_op | ||
|
||
# start_k8s_config_job | ||
@job( | ||
tags={ | ||
"dagster-k8s/config": { | ||
"container_config": { | ||
"resources": { | ||
"requests": {"cpu": "250m", "memory": "64Mi"}, | ||
"limits": {"cpu": "500m", "memory": "2560Mi"}, | ||
}, | ||
"volume_mounts": [ | ||
{"name": "volume1", "mount_path": "foo/bar", "sub_path": "file.txt"} | ||
], | ||
}, | ||
"pod_template_spec_metadata": { | ||
"annotations": {"cluster-autoscaler.kubernetes.io/safe-to-evict": "true"} | ||
}, | ||
"pod_spec_config": { | ||
"volumes": [{"name": "volume1", "secret": {"secret_name": "volume_secret_name"}}], | ||
"affinity": { | ||
"node_affinity": { | ||
"required_during_scheduling_ignored_during_execution": { | ||
"node_selector_terms": [ | ||
{ | ||
"match_expressions": [ | ||
{ | ||
"key": "beta.kubernetes.io/os", | ||
"operator": "In", | ||
"values": ["windows", "linux"], | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
}, | ||
}, | ||
}, | ||
) | ||
def my_job(): | ||
my_op() | ||
# end_k8s_config_job | ||
# fmt: on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
@op | ||
def my_op(): | ||
print("foo") | ||
print("foo") # pylint: disable=print-call | ||
|
||
|
||
# fmt: off | ||
|
38 changes: 38 additions & 0 deletions
38
examples/docs_snippets/docs_snippets_tests/deploying_tests/test_k8s_config_tag.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from dagster_k8s import DagsterK8sJobConfig, construct_dagster_k8s_job | ||
from dagster_k8s.job import get_user_defined_k8s_config | ||
|
||
from docs_snippets.deploying.kubernetes.k8s_config_tag import my_job, my_op | ||
|
||
|
||
def test_k8s_tag_job(): | ||
assert my_job | ||
user_defined_cfg = get_user_defined_k8s_config(my_job.tags) | ||
|
||
cfg = DagsterK8sJobConfig( | ||
job_image="test/foo:latest", | ||
dagster_home="/opt/dagster/dagster_home", | ||
instance_config_map="test", | ||
) | ||
job = construct_dagster_k8s_job(cfg, [], "job123", user_defined_k8s_config=user_defined_cfg) | ||
|
||
assert job.to_dict()["spec"]["template"]["spec"]["containers"][0]["resources"] == { | ||
"requests": {"cpu": "250m", "memory": "64Mi"}, | ||
"limits": {"cpu": "500m", "memory": "2560Mi"}, | ||
} | ||
|
||
|
||
def test_k8s_tag_op(): | ||
assert my_op | ||
user_defined_cfg = get_user_defined_k8s_config(my_op.tags) | ||
|
||
cfg = DagsterK8sJobConfig( | ||
job_image="test/foo:latest", | ||
dagster_home="/opt/dagster/dagster_home", | ||
instance_config_map="test", | ||
) | ||
job = construct_dagster_k8s_job(cfg, [], "job123", user_defined_k8s_config=user_defined_cfg) | ||
|
||
assert job.to_dict()["spec"]["template"]["spec"]["containers"][0]["resources"] == { | ||
"requests": {"cpu": "200m", "memory": "32Mi"}, | ||
"limits": None, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
c52b495
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.
Successfully deployed to the following URLs:
dagster – ./docs/next
dagster-elementl.vercel.app
docs.dagster.io
dagster.vercel.app
new-docs.dagster.io
dagster-git-master-elementl.vercel.app