From 5ba8fca02bd684a03f510cb0e35323a16fbc5143 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Sat, 5 Oct 2019 17:23:10 -0600 Subject: [PATCH] remove hefty CPU requirements Signed-off-by: Matt Butcher --- src/schematic/component.rs | 21 +++++++++++---------- src/schematic/component_test.rs | 8 ++++---- src/schematic/configuration_test.rs | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/schematic/component.rs b/src/schematic/component.rs index 1d0a566e..eba5faea 100644 --- a/src/schematic/component.rs +++ b/src/schematic/component.rs @@ -506,8 +506,8 @@ type ExtendedResources = Vec; #[serde(rename_all = "camelCase")] #[serde(default)] pub struct Resources { - pub cpu: CPU, - pub memory: Memory, + pub cpu: Option, + pub memory: Option, pub gpu: Option, pub volumes: Option>, pub extended: Option, @@ -516,8 +516,13 @@ pub struct Resources { impl Resources { fn to_resource_requirements(&self) -> core::ResourceRequirements { let mut requests = BTreeMap::new(); - requests.insert("cpu".to_string(), Quantity(self.cpu.required.clone())); - requests.insert("memory".to_string(), Quantity(self.memory.required.clone())); + + self.cpu.clone().and_then(|cpu|{ + requests.insert("cpu".to_string(), Quantity(cpu.required.clone())) + }); + self.memory.clone().and_then(|mem|{ + requests.insert("memory".to_string(), Quantity(mem.required.clone())) + }); // TODO: Kubernetes does not have a built-in type for GPUs. What do we use? core::ResourceRequirements { @@ -530,12 +535,8 @@ impl Resources { impl Default for Resources { fn default() -> Self { Resources { - cpu: CPU { - required: "1".into(), - }, - memory: Memory { - required: "1G".into(), - }, + cpu: None, + memory: None, gpu: None, volumes: None, extended: None, diff --git a/src/schematic/component_test.rs b/src/schematic/component_test.rs index 13e5d458..fb0d8400 100644 --- a/src/schematic/component_test.rs +++ b/src/schematic/component_test.rs @@ -175,8 +175,8 @@ fn test_container_deserialize() { let res = &container.resources; - assert_eq!("2G", res.memory.required); - assert_eq!("1", res.cpu.required); + assert_eq!("2G", res.memory.as_ref().expect("memory should be set").required); + assert!(res.cpu.is_none()); let vols = res.volumes.clone().expect("expected volumes"); let path1 = vols.get(0).expect("expect a first volume"); @@ -505,8 +505,8 @@ fn test_to_volume_mounts() { name: "test_container".into(), image: "test/image".into(), resources: Resources{ - cpu: CPU {required: "1".into()}, - memory: Memory {required: "128".into()}, + cpu: Some(CPU {required: "1".into()}), + memory: Some(Memory {required: "128".into()}), gpu: Some(GPU {required: "0".into()}), volumes: Some(vec![Volume{ name: "myvol".into(), diff --git a/src/schematic/configuration_test.rs b/src/schematic/configuration_test.rs index fbbc9c3b..eaea0164 100644 --- a/src/schematic/configuration_test.rs +++ b/src/schematic/configuration_test.rs @@ -41,4 +41,4 @@ fn test_application_configuration() { .expect("JSON must parse"); assert!(conf.variables.is_some()); -} \ No newline at end of file +}