Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Op that runs a kubernetes job (#8161)
* WIP: Op that runs a kubernetes job Summary: This introduces a more direct analogue to a 'pod that manages a k8s container' - to handle cases where you want to stitch together a mixture of ops, or orchestrate non-Python languages. A nice thing is that we can use container_context to still pass config through to ops like this (so you can set up a default set of secrets to include in all ops even when you're not launching the run in k8s, for example). And we can expose raw job_config on the op as well to give you access to the full k8s api for the job. * Make wait_for_pod disable timeout on 0 Co-authored-by: Johann Miller <johann@elementl.com>
- Loading branch information
Showing
12 changed files
with
404 additions
and
15 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
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
83 changes: 83 additions & 0 deletions
83
integration_tests/test_suites/k8s-test-suite/tests/test_k8s_job_op.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,83 @@ | ||
import pytest | ||
from dagster_k8s import k8s_job_op | ||
from dagster_k8s.client import DagsterK8sError | ||
|
||
from dagster import job | ||
|
||
|
||
@pytest.mark.default | ||
def test_k8s_job_op(namespace, cluster_provider): | ||
first_op = k8s_job_op.configured( | ||
{ | ||
"image": "busybox", | ||
"command": ["/bin/sh", "-c"], | ||
"args": ["echo HI"], | ||
"namespace": namespace, | ||
"load_incluster_config": False, | ||
"kubeconfig_file": cluster_provider.kubeconfig_file, | ||
}, | ||
name="first_op", | ||
) | ||
second_op = k8s_job_op.configured( | ||
{ | ||
"image": "busybox", | ||
"command": ["/bin/sh", "-c"], | ||
"args": ["echo GOODBYE"], | ||
"namespace": namespace, | ||
"load_incluster_config": False, | ||
"kubeconfig_file": cluster_provider.kubeconfig_file, | ||
}, | ||
name="second_op", | ||
) | ||
|
||
@job | ||
def my_full_job(): | ||
second_op(first_op()) | ||
|
||
my_full_job.execute_in_process() | ||
|
||
|
||
@pytest.mark.default | ||
def test_k8s_job_op_with_timeout(namespace, cluster_provider): | ||
timeout_op = k8s_job_op.configured( | ||
{ | ||
"image": "busybox", | ||
"command": ["/bin/sh", "-c"], | ||
"args": ["sleep 15 && echo HI"], | ||
"namespace": namespace, | ||
"load_incluster_config": False, | ||
"kubeconfig_file": cluster_provider.kubeconfig_file, | ||
"timeout": 5, | ||
}, | ||
name="timeout_op", | ||
) | ||
|
||
@job | ||
def timeout_job(): | ||
timeout_op() | ||
|
||
with pytest.raises(DagsterK8sError, match="Timed out while waiting for pod to become ready"): | ||
timeout_job.execute_in_process() | ||
|
||
|
||
@pytest.mark.default | ||
def test_k8s_job_op_with_failure(namespace, cluster_provider): | ||
failure_op = k8s_job_op.configured( | ||
{ | ||
"image": "busybox", | ||
"command": ["/bin/sh", "-c"], | ||
"args": ["sleep 10 && exit 1"], | ||
"namespace": namespace, | ||
"load_incluster_config": False, | ||
"kubeconfig_file": cluster_provider.kubeconfig_file, | ||
"timeout": 5, | ||
}, | ||
name="failure_op", | ||
) | ||
|
||
@job | ||
def failure_job(): | ||
failure_op() | ||
|
||
with pytest.raises(DagsterK8sError, match="Timed out while waiting for pod to become ready"): | ||
failure_job.execute_in_process() |
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
1 change: 1 addition & 0 deletions
1
python_modules/libraries/dagster-k8s/dagster_k8s/ops/__init__.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 @@ | ||
from .k8s_job_op import k8s_job_op |
Oops, something went wrong.