diff --git a/backend/capellacollab/sessions/operators/k8s.py b/backend/capellacollab/sessions/operators/k8s.py index 73f151cab..5e2dcc1f6 100644 --- a/backend/capellacollab/sessions/operators/k8s.py +++ b/backend/capellacollab/sessions/operators/k8s.py @@ -736,6 +736,7 @@ def _create_job( image: str, job_labels: dict[str, str], environment: dict[str, str | None], + args: list[str] | None = None, timeout=18000, ) -> client.V1Job: job: client.V1Job = client.V1Job( diff --git a/backend/tests/sessions/test_session_operator_k8s.py b/backend/tests/sessions/test_session_operator_k8s.py index 39152ebed..ff7d61434 100644 --- a/backend/tests/sessions/test_session_operator_k8s.py +++ b/backend/tests/sessions/test_session_operator_k8s.py @@ -4,13 +4,13 @@ import base64 import os +import kubernetes.config import pytest -if not os.getenv("CI"): - from capellacollab.sessions.operators.k8s import ( - KubernetesOperator, - lazy_b64decode, - ) +from capellacollab.sessions.operators.k8s import ( + KubernetesOperator, + lazy_b64decode, +) hello = base64.b64encode(b"hello") # aGVsbG8= @@ -61,3 +61,36 @@ def is_open(self): def read_stdout(self, timeout=None): return self._blocks.pop(0) + + +def test_create_job(monkeypatch): + monkeypatch.setattr(kubernetes.config, "load_config", lambda **_: None) + operator = KubernetesOperator() + monkeypatch.setattr( + operator.v1_batch, "create_namespaced_job", lambda namespace, job: None + ) + result = operator.create_job( + image="fakeimage", + command="fakecmd", + labels={"key": "value"}, + environment={"ENVVAR": "value"}, + ) + + assert result + + +def test_create_cronjob(monkeypatch): + monkeypatch.setattr(kubernetes.config, "load_config", lambda **_: None) + operator = KubernetesOperator() + monkeypatch.setattr( + operator.v1_batch, + "create_namespaced_cron_job", + lambda namespace, job: None, + ) + result = operator.create_cronjob( + image="fakeimage", + command="fakecmd", + environment={"ENVVAR": "value"}, + ) + + assert result