@@ -173,6 +173,20 @@ impl std::fmt::Debug for KubernetesComputeDriver {
173173 }
174174}
175175
176+ fn gpu_request_validation_error ( sandbox : & Sandbox ) -> Option < & ' static str > {
177+ if sandbox
178+ . spec
179+ . as_ref ( )
180+ . is_some_and ( |spec| !spec. gpu_device . is_empty ( ) )
181+ {
182+ return Some (
183+ "gpu_device is not supported by the kubernetes compute driver; use gpu or gpu_count" ,
184+ ) ;
185+ }
186+
187+ None
188+ }
189+
176190impl KubernetesComputeDriver {
177191 pub async fn new ( config : KubernetesComputeConfig ) -> Result < Self , KubeError > {
178192 let base_config = match kube:: Config :: incluster ( ) {
@@ -245,6 +259,10 @@ impl KubernetesComputeDriver {
245259 }
246260
247261 pub async fn validate_sandbox_create ( & self , sandbox : & Sandbox ) -> Result < ( ) , tonic:: Status > {
262+ if let Some ( message) = gpu_request_validation_error ( sandbox) {
263+ return Err ( tonic:: Status :: invalid_argument ( message) ) ;
264+ }
265+
248266 let gpu_requested = sandbox. spec . as_ref ( ) . is_some_and ( |spec| spec. gpu ) ;
249267 if gpu_requested
250268 && !self . has_gpu_capacity ( ) . await . map_err ( |err| {
@@ -2288,6 +2306,39 @@ mod tests {
22882306 ) ;
22892307 }
22902308
2309+ #[ test]
2310+ fn gpu_request_validation_error_rejects_gpu_device ( ) {
2311+ let sandbox = Sandbox {
2312+ spec : Some ( SandboxSpec {
2313+ gpu : true ,
2314+ gpu_device : "nvidia.com/gpu=0" . to_string ( ) ,
2315+ ..Default :: default ( )
2316+ } ) ,
2317+ ..Default :: default ( )
2318+ } ;
2319+
2320+ assert_eq ! (
2321+ gpu_request_validation_error( & sandbox) ,
2322+ Some (
2323+ "gpu_device is not supported by the kubernetes compute driver; use gpu or gpu_count"
2324+ )
2325+ ) ;
2326+ }
2327+
2328+ #[ test]
2329+ fn gpu_request_validation_error_accepts_gpu_count ( ) {
2330+ let sandbox = Sandbox {
2331+ spec : Some ( SandboxSpec {
2332+ gpu : true ,
2333+ gpu_count : Some ( 2 ) ,
2334+ ..Default :: default ( )
2335+ } ) ,
2336+ ..Default :: default ( )
2337+ } ;
2338+
2339+ assert_eq ! ( gpu_request_validation_error( & sandbox) , None ) ;
2340+ }
2341+
22912342 #[ test]
22922343 fn gpu_sandbox_uses_template_runtime_class_name_when_set ( ) {
22932344 let template = SandboxTemplate {
0 commit comments