@@ -587,6 +587,56 @@ def _build_shared_memory_volumes(self, shared_memory: str) -> Nested[Any]:
587587 "emptyDir" : {"medium" : "Memory" , "sizeLimit" : shared_memory },
588588 }
589589
590+ def set_up_gcsfuse (self , cfg : "TPUJobBuilder.Config" , volumes : list , annotations : dict ) -> None :
591+ """Sets up GCSFuse volumes and annotations.
592+
593+ Args:
594+ cfg: The TPUJobBuilder configuration.
595+ volumes: The list of volumes to append GCSFuse volumes to.
596+ annotations: The dictionary of annotations to update with GCSFuse settings.
597+ """
598+ # Increases the shared memory volumes when enabled gcsfuse. This is useful when grain
599+ # prefetch is enabled.
600+ volumes .append (self ._build_shared_memory_volumes (cfg .gcsfuse_mount .shared_memory ))
601+ # Mount a GCS bucket as a volume.
602+ annotations .update (
603+ {
604+ "gke-gcsfuse/volumes" : "true" ,
605+ "gke-gcsfuse/cpu-request" : cfg .gcsfuse_mount .cpu ,
606+ "gke-gcsfuse/memory-request" : cfg .gcsfuse_mount .memory ,
607+ "gke-gcsfuse/ephemeral-storage-request" : cfg .gcsfuse_mount .ephemeral_gb ,
608+ # GCSFuse will set limits=request if we only set requests:
609+ # https://github.com/GoogleCloudPlatform/gcs-fuse-csi-driver/blob/main/pkg/webhook/config.go#L110
610+ "gke-gcsfuse/cpu-limit" : "0" ,
611+ "gke-gcsfuse/memory-limit" : "0" ,
612+ "gke-gcsfuse/ephemeral-storage-limit" : "0" ,
613+ }
614+ )
615+ # Parse GCSFuseMount path into bucket, prefix.
616+ parsed = urlparse (cfg .gcsfuse_mount .gcs_path )
617+ # https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/cloud-storage-fuse-csi-driver#consume-ephemeral-volume-pod
618+ # Caveat: --implicit-dirs might have negative impacts on i/o performance. See
619+ # https://github.com/googlecloudplatform/gcsfuse/blob/master/docs/semantics.md .
620+ # See https://cloud.google.com/storage/docs/cloud-storage-fuse/config-file for more
621+ # details about mountOptions.
622+ # The mountOptions are following https://github.com/AI-Hypercomputer/maxtext/pull/1070.
623+ volumes .append (
624+ dict (
625+ name = cfg .gcsfuse_mount .name ,
626+ csi = dict (
627+ driver = "gcsfuse.csi.storage.gke.io" ,
628+ readOnly = cfg .gcsfuse_mount .read_only ,
629+ volumeAttributes = dict (
630+ bucketName = parsed .netloc ,
631+ # pylint: disable=line-too-long
632+ mountOptions = f"only-dir={ parsed .path .lstrip ('/' )} ,implicit-dirs,metadata-cache:ttl-secs:-1,metadata-cache:stat-cache-max-size-mb:-1,metadata-cache:type-cache-max-size-mb:-1,kernel-list-cache-ttl-secs=-1,gcs-connection:http-client-timeout:{ cfg .gcsfuse_mount .http_client_timeout } " ,
633+ gcsfuseMetadataPrefetchOnMount = "false" , # Improves first-time read.
634+ disableMetrics = "false" , # Enables GCSFuse metrics by default.
635+ ),
636+ ),
637+ )
638+ )
639+
590640 def _build_pod (self ) -> Nested [Any ]:
591641 """Builds a config for a single Pod, which is a set of containers.
592642
@@ -601,47 +651,7 @@ def _build_pod(self) -> Nested[Any]:
601651
602652 volumes .append (dict (name = "shared-output" , emptyDir = {}))
603653 if cfg .gcsfuse_mount :
604- # Increases the shared memory volumes when enabled gcsfuse. This is useful when grain
605- # prefetch is enabled.
606- volumes .append (self ._build_shared_memory_volumes (cfg .gcsfuse_mount .shared_memory ))
607- # Mount a GCS bucket as a volume.
608- annotations .update (
609- {
610- "gke-gcsfuse/volumes" : "true" ,
611- "gke-gcsfuse/cpu-request" : cfg .gcsfuse_mount .cpu ,
612- "gke-gcsfuse/memory-request" : cfg .gcsfuse_mount .memory ,
613- "gke-gcsfuse/ephemeral-storage-request" : cfg .gcsfuse_mount .ephemeral_gb ,
614- # GCSFuse will set limits=request if we only set requests:
615- # https://github.com/GoogleCloudPlatform/gcs-fuse-csi-driver/blob/main/pkg/webhook/config.go#L110
616- "gke-gcsfuse/cpu-limit" : "0" ,
617- "gke-gcsfuse/memory-limit" : "0" ,
618- "gke-gcsfuse/ephemeral-storage-limit" : "0" ,
619- }
620- )
621- # Parse GCSFuseMount path into bucket, prefix.
622- parsed = urlparse (cfg .gcsfuse_mount .gcs_path )
623- # https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/cloud-storage-fuse-csi-driver#consume-ephemeral-volume-pod
624- # Caveat: --implicit-dirs might have negative impacts on i/o performance. See
625- # https://github.com/googlecloudplatform/gcsfuse/blob/master/docs/semantics.md .
626- # See https://cloud.google.com/storage/docs/cloud-storage-fuse/config-file for more
627- # details about mountOptions.
628- # The mountOptions are following https://github.com/AI-Hypercomputer/maxtext/pull/1070.
629- volumes .append (
630- dict (
631- name = cfg .gcsfuse_mount .name ,
632- csi = dict (
633- driver = "gcsfuse.csi.storage.gke.io" ,
634- readOnly = cfg .gcsfuse_mount .read_only ,
635- volumeAttributes = dict (
636- bucketName = parsed .netloc ,
637- # pylint: disable=line-too-long
638- mountOptions = f"only-dir={ parsed .path .lstrip ('/' )} ,implicit-dirs,metadata-cache:ttl-secs:-1,metadata-cache:stat-cache-max-size-mb:-1,metadata-cache:type-cache-max-size-mb:-1,kernel-list-cache-ttl-secs=-1,gcs-connection:http-client-timeout:{ cfg .gcsfuse_mount .http_client_timeout } " ,
639- gcsfuseMetadataPrefetchOnMount = "false" , # Improves first-time read.
640- disableMetrics = "false" , # Enables GCSFuse metrics by default.
641- ),
642- ),
643- )
644- )
654+ self .set_up_gcsfuse (cfg , volumes , annotations )
645655 if cfg .host_mounts :
646656 for mount in cfg .host_mounts :
647657 volumes .append (
0 commit comments