33
44//! Kubernetes compute driver.
55
6- use crate :: config:: { KubernetesComputeConfig , SupervisorSideloadMethod } ;
6+ use crate :: config:: {
7+ DEFAULT_WORKSPACE_STORAGE_SIZE , KubernetesComputeConfig , SupervisorSideloadMethod ,
8+ } ;
79use futures:: { Stream , StreamExt , TryStreamExt } ;
810use k8s_openapi:: api:: core:: v1:: { Event as KubeEventObj , Node } ;
911use kube:: api:: { Api , ApiResource , DeleteParams , ListParams , PostParams } ;
@@ -106,8 +108,6 @@ const WORKSPACE_INIT_MOUNT_PATH: &str = "/workspace-pvc";
106108/// Name of the init container that seeds the workspace PVC.
107109const WORKSPACE_INIT_CONTAINER_NAME : & str = "workspace-init" ;
108110
109- /// Default storage request for the workspace PVC.
110- const WORKSPACE_DEFAULT_STORAGE : & str = "2Gi" ;
111111
112112/// Sentinel file written by the init container after copying the image's
113113/// `/sandbox` contents. Subsequent pod starts skip the copy.
@@ -327,6 +327,7 @@ impl KubernetesComputeDriver {
327327 client_tls_secret_name : & self . config . client_tls_secret_name ,
328328 host_gateway_ip : & self . config . host_gateway_ip ,
329329 enable_user_namespaces : self . config . enable_user_namespaces ,
330+ workspace_default_storage_size : & self . config . workspace_default_storage_size ,
330331 } ;
331332 obj. data = sandbox_to_k8s_spec ( sandbox. spec . as_ref ( ) , & params) ;
332333 let api = self . api ( ) ;
@@ -1025,7 +1026,12 @@ fn apply_workspace_persistence(
10251026///
10261027/// Provides a single PVC named "workspace" that backs the `/sandbox`
10271028/// directory. The init container seeds it from the image on first use.
1028- fn default_workspace_volume_claim_templates ( ) -> serde_json:: Value {
1029+ fn default_workspace_volume_claim_templates ( storage_size : & str ) -> serde_json:: Value {
1030+ let size = if storage_size. is_empty ( ) {
1031+ DEFAULT_WORKSPACE_STORAGE_SIZE
1032+ } else {
1033+ storage_size
1034+ } ;
10291035 serde_json:: json!( [ {
10301036 "metadata" : {
10311037 "name" : WORKSPACE_VOLUME_NAME
@@ -1034,7 +1040,7 @@ fn default_workspace_volume_claim_templates() -> serde_json::Value {
10341040 "accessModes" : [ "ReadWriteOnce" ] ,
10351041 "resources" : {
10361042 "requests" : {
1037- "storage" : WORKSPACE_DEFAULT_STORAGE
1043+ "storage" : size
10381044 }
10391045 }
10401046 }
@@ -1056,6 +1062,7 @@ struct SandboxPodParams<'a> {
10561062 client_tls_secret_name : & ' a str ,
10571063 host_gateway_ip : & ' a str ,
10581064 enable_user_namespaces : bool ,
1065+ workspace_default_storage_size : & ' a str ,
10591066}
10601067
10611068fn spec_pod_env ( spec : Option < & SandboxSpec > ) -> std:: collections:: HashMap < String , String > {
@@ -1112,7 +1119,7 @@ fn sandbox_to_k8s_spec(
11121119 if inject_workspace {
11131120 root. insert (
11141121 "volumeClaimTemplates" . to_string ( ) ,
1115- default_workspace_volume_claim_templates ( ) ,
1122+ default_workspace_volume_claim_templates ( params . workspace_default_storage_size ) ,
11161123 ) ;
11171124 }
11181125
@@ -2572,4 +2579,18 @@ mod tests {
25722579 assert_eq ! ( tolerations[ 0 ] [ "operator" ] , "Exists" ) ;
25732580 assert_eq ! ( tolerations[ 0 ] [ "effect" ] , "NoSchedule" ) ;
25742581 }
2582+
2583+ #[ test]
2584+ fn default_workspace_vct_uses_provided_storage_size ( ) {
2585+ let vct = default_workspace_volume_claim_templates ( "5Gi" ) ;
2586+ let storage = & vct[ 0 ] [ "spec" ] [ "resources" ] [ "requests" ] [ "storage" ] ;
2587+ assert_eq ! ( storage, "5Gi" ) ;
2588+ }
2589+
2590+ #[ test]
2591+ fn default_workspace_vct_falls_back_to_const_when_empty ( ) {
2592+ let vct = default_workspace_volume_claim_templates ( "" ) ;
2593+ let storage = & vct[ 0 ] [ "spec" ] [ "resources" ] [ "requests" ] [ "storage" ] ;
2594+ assert_eq ! ( storage, DEFAULT_WORKSPACE_STORAGE_SIZE ) ;
2595+ }
25752596}
0 commit comments