Skip to content

Commit 710acaa

Browse files
committed
no-jira: don't allow ttl_seconds_after_finished for longlived clusters
1 parent 4e4a181 commit 710acaa

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/codeflare_sdk/ray/rayjobs/rayjob.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ def __init__(
118118
"to specify which existing cluster to use."
119119
)
120120

121+
if cluster_name is not None and ttl_seconds_after_finished != 0:
122+
raise ValueError(
123+
"❌ Configuration Error: 'ttl_seconds_after_finished' cannot be set when targeting "
124+
"an existing cluster (via 'cluster_name').\n"
125+
"TTL controls automatic cleanup of RayJob-managed clusters, which only applies "
126+
"when creating a new cluster via 'cluster_config'.\n"
127+
"For existing clusters, the RayJob CR will remain after completion for inspection."
128+
)
129+
121130
self.name = job_name
122131
self.entrypoint = entrypoint
123132

src/codeflare_sdk/ray/rayjobs/test/test_rayjob.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ def test_build_rayjob_cr_with_existing_cluster(auto_mock_setup):
245245
cluster_name="existing-cluster",
246246
namespace="test-namespace",
247247
entrypoint="python main.py",
248-
ttl_seconds_after_finished=300,
249248
)
250249

251250
rayjob_cr = rayjob._build_rayjob_cr()
@@ -256,7 +255,6 @@ def test_build_rayjob_cr_with_existing_cluster(auto_mock_setup):
256255
spec = rayjob_cr["spec"]
257256
assert spec["entrypoint"] == "python main.py"
258257
assert spec["shutdownAfterJobFinishes"] is False
259-
assert spec["ttlSecondsAfterFinished"] == 300
260258

261259
assert spec["clusterSelector"]["ray.io/cluster"] == "existing-cluster"
262260
assert "rayClusterSpec" not in spec
@@ -526,12 +524,14 @@ def test_rayjob_with_runtime_env_dict(auto_mock_setup):
526524
def test_rayjob_with_active_deadline_and_ttl(auto_mock_setup):
527525
"""
528526
Test RayJob with both active deadline and TTL settings.
527+
Note: TTL can only be set when creating a new cluster (via cluster_config).
529528
"""
530529

530+
cluster_config = ManagedClusterConfig()
531531
rayjob = RayJob(
532532
job_name="test-job",
533533
entrypoint="python -c 'print()'",
534-
cluster_name="test-cluster",
534+
cluster_config=cluster_config,
535535
active_deadline_seconds=300,
536536
ttl_seconds_after_finished=600,
537537
namespace="test-namespace",
@@ -594,11 +594,13 @@ def test_rayjob_error_handling_invalid_cluster_config(auto_mock_setup):
594594
def test_rayjob_constructor_parameter_validation(auto_mock_setup):
595595
"""
596596
Test constructor parameter validation.
597+
Note: TTL can only be set when creating a new cluster (via cluster_config).
597598
"""
599+
cluster_config = ManagedClusterConfig()
598600
rayjob = RayJob(
599601
job_name="test-job",
600602
entrypoint="python -c 'print()'",
601-
cluster_name="test-cluster",
603+
cluster_config=cluster_config,
602604
namespace="test-ns",
603605
runtime_env=RuntimeEnv(pip=["numpy"]),
604606
ttl_seconds_after_finished=300,
@@ -607,7 +609,7 @@ def test_rayjob_constructor_parameter_validation(auto_mock_setup):
607609

608610
assert rayjob.name == "test-job"
609611
assert rayjob.entrypoint == "python -c 'print()'"
610-
assert rayjob.cluster_name == "test-cluster"
612+
assert rayjob.cluster_name == "test-job-cluster" # Generated from job name
611613
assert rayjob.namespace == "test-ns"
612614
# Check that runtime_env is a RuntimeEnv object and contains pip dependencies
613615
assert isinstance(rayjob.runtime_env, RuntimeEnv)

0 commit comments

Comments
 (0)