@@ -34,6 +34,61 @@ def test_instantiate_defaults():
3434 _ = KubeRayInteractiveJob ()
3535
3636
37+ def test_env_vars_injection ():
38+ interactive_rayjob = KubeRayInteractiveJob (
39+ image = "test-image" ,
40+ env_vars = {
41+ "RAY_LOG_TO_STDERR" : "1" ,
42+ "RAY_LOGGING_CONFIG_ENCODING" : "JSON" ,
43+ },
44+ )
45+ interactive_rayjob ._name = "test-rayjob"
46+ context = dg .build_init_resource_context ()
47+
48+ k8s_manifest = interactive_rayjob .ray_job .to_k8s (
49+ context ,
50+ image = "test-image" ,
51+ env_vars = interactive_rayjob .get_env_vars_to_inject (),
52+ )
53+
54+ # Check that env_vars are injected into head and worker group specs
55+ ray_cluster_spec = k8s_manifest ["spec" ]["rayClusterSpec" ]
56+ head_group_spec = ray_cluster_spec ["headGroupSpec" ]
57+ worker_group_specs = ray_cluster_spec .get ("workerGroupSpecs" , [])
58+
59+ for group_spec in [head_group_spec , * worker_group_specs ]:
60+ for container in group_spec ["template" ]["spec" ]["containers" ]:
61+ assert {"name" : "RAY_LOG_TO_STDERR" , "value" : "1" } in container ["env" ], container
62+ assert {"name" : "RAY_LOGGING_CONFIG_ENCODING" , "value" : "JSON" } in container ["env" ], container
63+
64+
65+ def test_env_vars_with_debug_flags ():
66+ interactive_rayjob = KubeRayInteractiveJob (
67+ image = "test-image" ,
68+ enable_debug_post_mortem = True ,
69+ enable_tracing = True ,
70+ enable_actor_task_logging = True ,
71+ )
72+ interactive_rayjob ._name = "test-rayjob"
73+ context = dg .build_init_resource_context ()
74+
75+ k8s_manifest = interactive_rayjob .ray_job .to_k8s (
76+ context ,
77+ image = "test-image" ,
78+ env_vars = interactive_rayjob .get_env_vars_to_inject (),
79+ )
80+
81+ ray_cluster_spec = k8s_manifest ["spec" ]["rayClusterSpec" ]
82+ head_group_spec = ray_cluster_spec ["headGroupSpec" ]
83+ worker_group_specs = ray_cluster_spec .get ("workerGroupSpecs" , [])
84+
85+ for group_spec in [head_group_spec , * worker_group_specs ]:
86+ for container in group_spec ["template" ]["spec" ]["containers" ]:
87+ assert {"name" : "RAY_DEBUG_POST_MORTEM" , "value" : "1" } in container ["env" ], container
88+ assert {"name" : "RAY_PROFILING" , "value" : "1" } in container ["env" ], container
89+ assert {"name" : "RAY_ENABLE_RECORD_ACTOR_TASK_LOGGING" , "value" : "1" } in container ["env" ], container
90+
91+
3792def test_no_lifecycle (dagster_instance : dg .DagsterInstance , rayjob_client : RayJobClient ):
3893 interactive_rayjob = KubeRayInteractiveJob (
3994 client = rayjob_client , lifecycle = Lifecycle (create = False , wait = False , connect = False )
0 commit comments