@@ -211,6 +211,68 @@ pub struct KubernetesComputeConfig {
211211 deserialize_with = "deserialize_provider_spiffe_workload_api_socket_path"
212212 ) ]
213213 pub provider_spiffe_workload_api_socket_path : String ,
214+ /// Warm-pool configuration. When enabled, the gateway pre-declares one or
215+ /// more operator-owned `SandboxWarmPool`s and satisfies matching
216+ /// `CreateSandbox` requests by binding a pre-warmed pod via a `SandboxClaim`
217+ /// instead of cold-creating a `Sandbox`. Off by default.
218+ #[ serde( default ) ]
219+ pub warm_pool : KubernetesWarmPoolConfig ,
220+ }
221+
222+ /// Warm-pool configuration for the Kubernetes driver.
223+ ///
224+ /// Only **operator-declared** pools using the gateway's trusted default image
225+ /// are warm-pooled. Requests for a user-supplied image or that carry a custom
226+ /// template fall back to the cold path — per-tenant pool isolation for
227+ /// untrusted images is out of scope (see RFC 0005 / issue #1879).
228+ #[ derive( Debug , Clone , Default , Serialize , Deserialize ) ]
229+ #[ serde( default , deny_unknown_fields) ]
230+ pub struct KubernetesWarmPoolConfig {
231+ /// Master switch. When false the driver never creates extension CRDs and
232+ /// every request takes the cold path.
233+ pub enabled : bool ,
234+ /// Declared pools. Each maps to exactly one (image, runtimeClass, gpu)
235+ /// shape; the image is always the driver `default_image`.
236+ pub pools : Vec < WarmPoolSpec > ,
237+ }
238+
239+ /// One operator-declared warm pool.
240+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
241+ #[ serde( deny_unknown_fields) ]
242+ pub struct WarmPoolSpec {
243+ /// Pool name. Also names the backing `SandboxWarmPool` and `SandboxTemplate`
244+ /// (suffixed). Must be a DNS-1123 label.
245+ pub name : String ,
246+ /// Number of pods to keep warm.
247+ pub replicas : i32 ,
248+ /// `runtimeClassName` baked into the pool's `SandboxTemplate`. Empty uses
249+ /// the driver's `default_runtime_class_name`.
250+ #[ serde( default ) ]
251+ pub runtime_class_name : String ,
252+ /// Whether pooled pods request a GPU. GPU pools hold accelerators idle, so
253+ /// they are opt-in per pool.
254+ #[ serde( default ) ]
255+ pub gpu : bool ,
256+ /// Optional shared, read-only data volume mounted into every pooled pod
257+ /// (datasets / models / caches). Safe to share precisely because it is
258+ /// read-only and holds no per-agent state.
259+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
260+ pub shared_volume : Option < SharedVolumeSpec > ,
261+ }
262+
263+ /// A pre-existing PVC mounted read-only into pooled pods.
264+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
265+ #[ serde( deny_unknown_fields) ]
266+ pub struct SharedVolumeSpec {
267+ /// Name of an existing `PersistentVolumeClaim` in the sandbox namespace.
268+ /// Must support a read-many access mode (`ReadOnlyMany`/`ReadWriteMany`)
269+ /// when pods land on multiple nodes.
270+ pub claim_name : String ,
271+ /// Absolute path the volume is mounted at inside the sandbox.
272+ pub mount_path : String ,
273+ /// Optional sub-path within the volume to mount.
274+ #[ serde( default , skip_serializing_if = "String::is_empty" ) ]
275+ pub sub_path : String ,
214276}
215277
216278/// Lower bound enforced by kubelet for projected SA tokens.
@@ -246,6 +308,7 @@ impl Default for KubernetesComputeConfig {
246308 default_runtime_class_name : String :: new ( ) ,
247309 sa_token_ttl_secs : 3600 ,
248310 provider_spiffe_workload_api_socket_path : String :: new ( ) ,
311+ warm_pool : KubernetesWarmPoolConfig :: default ( ) ,
249312 }
250313 }
251314}
@@ -459,4 +522,56 @@ mod tests {
459522 let cfg: KubernetesComputeConfig = serde_json:: from_value ( json) . unwrap ( ) ;
460523 assert_eq ! ( cfg. image_pull_secrets, [ "regcred" , "backup-regcred" ] ) ;
461524 }
525+
526+ #[ test]
527+ fn default_warm_pool_is_disabled ( ) {
528+ let cfg = KubernetesComputeConfig :: default ( ) ;
529+ assert ! ( !cfg. warm_pool. enabled) ;
530+ assert ! ( cfg. warm_pool. pools. is_empty( ) ) ;
531+ }
532+
533+ #[ test]
534+ fn serde_override_warm_pool ( ) {
535+ let json = serde_json:: json!( {
536+ "warm_pool" : {
537+ "enabled" : true ,
538+ "pools" : [
539+ { "name" : "default" , "replicas" : 3 } ,
540+ {
541+ "name" : "gpu" ,
542+ "replicas" : 1 ,
543+ "gpu" : true ,
544+ "runtime_class_name" : "nvidia" ,
545+ "shared_volume" : {
546+ "claim_name" : "models" ,
547+ "mount_path" : "/models" ,
548+ "sub_path" : "llama"
549+ }
550+ }
551+ ]
552+ }
553+ } ) ;
554+ let cfg: KubernetesComputeConfig = serde_json:: from_value ( json) . unwrap ( ) ;
555+ assert ! ( cfg. warm_pool. enabled) ;
556+ assert_eq ! ( cfg. warm_pool. pools. len( ) , 2 ) ;
557+ assert_eq ! ( cfg. warm_pool. pools[ 0 ] . name, "default" ) ;
558+ assert_eq ! ( cfg. warm_pool. pools[ 0 ] . replicas, 3 ) ;
559+ assert ! ( !cfg. warm_pool. pools[ 0 ] . gpu) ;
560+ assert ! ( cfg. warm_pool. pools[ 0 ] . shared_volume. is_none( ) ) ;
561+ let gpu = & cfg. warm_pool . pools [ 1 ] ;
562+ assert ! ( gpu. gpu) ;
563+ assert_eq ! ( gpu. runtime_class_name, "nvidia" ) ;
564+ let shared = gpu. shared_volume . as_ref ( ) . unwrap ( ) ;
565+ assert_eq ! ( shared. claim_name, "models" ) ;
566+ assert_eq ! ( shared. mount_path, "/models" ) ;
567+ assert_eq ! ( shared. sub_path, "llama" ) ;
568+ }
569+
570+ #[ test]
571+ fn serde_rejects_unknown_warm_pool_field ( ) {
572+ let json = serde_json:: json!( {
573+ "warm_pool" : { "enabled" : true , "bogus" : 1 }
574+ } ) ;
575+ assert ! ( serde_json:: from_value:: <KubernetesComputeConfig >( json) . is_err( ) ) ;
576+ }
462577}
0 commit comments