@@ -475,6 +475,150 @@ def test_add_gcsfuse_preserves_existing_metadata(self):
475475 self .assertEqual (pod_meta .get ("annotations" , {}).get ("existing-pod-anno" ), "value" )
476476 self .assertEqual (pod_meta .get ("annotations" , {}).get ("gke-gcsfuse/volumes" ), "true" )
477477
478+ def test_add_colocated_python_sidecar (self ):
479+ pw_jobset = self ._create_jobset (topology = "2x2" , num_slices = 1 )
480+
481+ pw_jobset .add_colocated_python (image = "gcr.io/my-project/colocated-python:custom" )
482+ helper = JobSetManifestHelper (pw_jobset .to_dict ())
483+
484+ self .assertIn ("colocated-python-sidecar" , helper .init_containers ["pathways-worker" ])
485+ sidecar = helper .init_containers ["pathways-worker" ]["colocated-python-sidecar" ]
486+ self .assertEqual (sidecar ["restartPolicy" ], "Always" )
487+ self .assertEqual (sidecar ["image" ], "gcr.io/my-project/colocated-python:custom" )
488+ self .assertTrue (
489+ any (
490+ m ["name" ] == "shared-memory" and m ["mountPath" ] == "/tmp/shared-memory"
491+ for m in sidecar ["volumeMounts" ]
492+ )
493+ )
494+ self .assertTrue (
495+ any (
496+ e ["name" ] == "CLOUD_PATHWAYS_SIDECAR_SHM_DIRECTORY"
497+ and e ["value" ] == "/tmp/shared-memory"
498+ for e in sidecar ["env" ]
499+ )
500+ )
501+
502+ def test_add_colocated_python_preserves_init_containers (self ):
503+ pw_jobset = self ._create_jobset (topology = "2x2" , num_slices = 1 )
504+
505+ # Pre-populate init container on worker pod
506+ worker_spec = pw_jobset ._worker_job_template .spec .template .spec
507+ existing_init = client .V1Container (name = "existing-init-container" , image = "ubuntu:latest" )
508+ worker_spec .init_containers = [existing_init ]
509+
510+ pw_jobset .add_colocated_python (image = "gcr.io/my-project/colocated-python:custom" )
511+ helper = JobSetManifestHelper (pw_jobset .to_dict ())
512+
513+ # Verify both exist
514+ self .assertIn ("existing-init-container" , helper .init_containers ["pathways-worker" ])
515+ self .assertIn ("colocated-python-sidecar" , helper .init_containers ["pathways-worker" ])
516+
517+ def test_add_colocated_python_volume_default (self ):
518+ pw_jobset = self ._create_jobset (topology = "2x2" , num_slices = 1 )
519+
520+ pw_jobset .add_colocated_python (image = "gcr.io/my-project/colocated-python:custom" )
521+ helper = JobSetManifestHelper (pw_jobset .to_dict ())
522+
523+ self .assertIn ("shared-memory" , helper .volumes ["pathways-worker" ])
524+ shm_vol = helper .volumes ["pathways-worker" ]["shared-memory" ]
525+ self .assertNotIn ("sizeLimit" , shm_vol ["emptyDir" ])
526+
527+ def test_add_colocated_python_worker_mount (self ):
528+ pw_jobset = self ._create_jobset (topology = "2x2" , num_slices = 1 )
529+
530+ pw_jobset .add_colocated_python (image = "gcr.io/my-project/colocated-python:custom" )
531+ helper = JobSetManifestHelper (pw_jobset .to_dict ())
532+
533+ self .assertIn ("pathways-worker" , helper .containers ["pathways-worker" ])
534+ worker_container = helper .containers ["pathways-worker" ]["pathways-worker" ]
535+ self .assertTrue (
536+ any (
537+ m ["name" ] == "shared-memory" and m ["mountPath" ] == "/tmp/shared-memory"
538+ for m in worker_container ["volumeMounts" ]
539+ )
540+ )
541+ self .assertTrue (
542+ any (
543+ e ["name" ] == "cloud_pathways_sidecar_shm_directory"
544+ and e ["value" ] == "/tmp/shared-memory"
545+ for e in worker_container ["env" ]
546+ )
547+ )
548+
549+ def test_add_colocated_python_custom_shm (self ):
550+ pw_jobset = self ._create_jobset (topology = "2x2" , num_slices = 1 )
551+
552+ pw_jobset .add_colocated_python (
553+ image = "gcr.io/my-project/colocated-python:custom" ,
554+ shm_mount_path = "/tmp/custom-shm" ,
555+ shm_size_limit = "50Gi" ,
556+ )
557+ helper = JobSetManifestHelper (pw_jobset .to_dict ())
478558
559+ self .assertIn ("colocated-python-sidecar" , helper .init_containers ["pathways-worker" ])
560+ sidecar = helper .init_containers ["pathways-worker" ]["colocated-python-sidecar" ]
561+ self .assertTrue (
562+ any (
563+ m ["name" ] == "shared-memory" and m ["mountPath" ] == "/tmp/custom-shm"
564+ for m in sidecar ["volumeMounts" ]
565+ )
566+ )
567+ self .assertTrue (
568+ any (
569+ e ["name" ] == "CLOUD_PATHWAYS_SIDECAR_SHM_DIRECTORY"
570+ and e ["value" ] == "/tmp/custom-shm"
571+ for e in sidecar ["env" ]
572+ )
573+ )
574+
575+ self .assertIn ("shared-memory" , helper .volumes ["pathways-worker" ])
576+ shm_vol = helper .volumes ["pathways-worker" ]["shared-memory" ]
577+ self .assertEqual (shm_vol ["emptyDir" ]["sizeLimit" ], "50Gi" )
578+
579+ self .assertIn ("pathways-worker" , helper .containers ["pathways-worker" ])
580+ worker_container = helper .containers ["pathways-worker" ]["pathways-worker" ]
581+ self .assertTrue (
582+ any (
583+ m ["name" ] == "shared-memory" and m ["mountPath" ] == "/tmp/custom-shm"
584+ for m in worker_container ["volumeMounts" ]
585+ )
586+ )
587+ self .assertTrue (
588+ any (
589+ e ["name" ] == "cloud_pathways_sidecar_shm_directory"
590+ and e ["value" ] == "/tmp/custom-shm"
591+ for e in worker_container ["env" ]
592+ )
593+ )
594+
595+ def test_colocated_python_with_jax_command (self ):
596+ jax_command = "import jax; print(jax.devices());"
597+ user_pod_template = {
598+ "spec" : {
599+ "containers" : [{
600+ "name" : "jax-tpu" ,
601+ "image" : "gcr.io/my-project/jax-tpu:latest" ,
602+ "command" : ["python3" , "-c" , jax_command ],
603+ }]
604+ }
605+ }
606+ pw_jobset = self ._create_jobset (
607+ topology = "2x2" ,
608+ num_slices = 1 ,
609+ user_pod_template = user_pod_template ,
610+ main_container_name = "jax-tpu" ,
611+ )
612+
613+ pw_jobset .add_colocated_python (image = "gcr.io/my-project/colocated-python:custom" )
614+ helper = JobSetManifestHelper (pw_jobset .to_dict ())
615+
616+ self .assertIn ("pathways-head" , helper .jobs )
617+ self .assertIn ("jax-tpu" , helper .containers ["pathways-head" ])
618+ jax_container = helper .containers ["pathways-head" ]["jax-tpu" ]
619+ self .assertEqual (jax_container ["command" ], ["python3" , "-c" , jax_command ])
620+
621+ self .assertIn ("pathways-worker" , helper .jobs )
622+ self .assertIn ("colocated-python-sidecar" , helper .init_containers ["pathways-worker" ])
479623if __name__ == "__main__" :
480624 absltest .main ()
0 commit comments