Parse resource limits from the sandbox template, falling back to defaults.
(sandbox: &DriverSandbox, config: &PodmanComputeConfig)
| 450 | |
| 451 | /// Parse resource limits from the sandbox template, falling back to defaults. |
| 452 | fn build_resource_limits(sandbox: &DriverSandbox, config: &PodmanComputeConfig) -> ResourceLimits { |
| 453 | let resources = sandbox |
| 454 | .spec |
| 455 | .as_ref() |
| 456 | .and_then(|s| s.template.as_ref()) |
| 457 | .and_then(|t| t.resources.as_ref()); |
| 458 | |
| 459 | let cpu_micros = resources |
| 460 | .filter(|r| !r.cpu_limit.is_empty()) |
| 461 | .and_then(|r| parse_cpu_to_microseconds(&r.cpu_limit)) |
| 462 | .unwrap_or(DEFAULT_CPU_QUOTA); |
| 463 | |
| 464 | let mem_bytes = resources |
| 465 | .filter(|r| !r.memory_limit.is_empty()) |
| 466 | .and_then(|r| parse_memory_to_bytes(&r.memory_limit)) |
| 467 | .unwrap_or(DEFAULT_MEMORY_LIMIT); |
| 468 | |
| 469 | ResourceLimits { |
| 470 | cpu: CpuLimits { |
| 471 | quota: cpu_micros, |
| 472 | period: DEFAULT_CPU_PERIOD, |
| 473 | }, |
| 474 | memory: MemoryLimits { limit: mem_bytes }, |
| 475 | pids_limit: podman_pids_limit(config.sandbox_pids_limit), |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | fn podman_pids_limit(value: i64) -> Option<i64> { |
| 480 | if value > 0 { Some(value) } else { None } |
no test coverage detected