| 1601 | } |
| 1602 | |
| 1603 | fn build_sandbox_resource_limits( |
| 1604 | cpu: Option<&str>, |
| 1605 | memory: Option<&str>, |
| 1606 | ) -> Result<Option<prost_types::Struct>> { |
| 1607 | use prost_types::{Struct, Value, value::Kind}; |
| 1608 | |
| 1609 | fn string_value(value: String) -> Value { |
| 1610 | Value { |
| 1611 | kind: Some(Kind::StringValue(value)), |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | let mut limits = std::collections::BTreeMap::new(); |
| 1616 | if let Some(cpu) = cpu { |
| 1617 | limits.insert("cpu".to_string(), string_value(validate_cpu_quantity(cpu)?)); |
| 1618 | } |
| 1619 | if let Some(memory) = memory { |
| 1620 | limits.insert( |
| 1621 | "memory".to_string(), |
| 1622 | string_value(validate_memory_quantity(memory)?), |
| 1623 | ); |
| 1624 | } |
| 1625 | |
| 1626 | if limits.is_empty() { |
| 1627 | return Ok(None); |
| 1628 | } |
| 1629 | |
| 1630 | let mut fields = std::collections::BTreeMap::new(); |
| 1631 | fields.insert( |
| 1632 | "limits".to_string(), |
| 1633 | Value { |
| 1634 | kind: Some(Kind::StructValue(Struct { fields: limits })), |
| 1635 | }, |
| 1636 | ); |
| 1637 | Ok(Some(Struct { fields })) |
| 1638 | } |
| 1639 | |
| 1640 | fn parse_driver_config_json(value: &str) -> Result<prost_types::Struct> { |
| 1641 | let parsed: serde_json::Value = serde_json::from_str(value) |