Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #278 from technosophos/fix/277-cpu-overload
Browse files Browse the repository at this point in the history
remove hefty CPU requirements
  • Loading branch information
suhuruli authored Oct 6, 2019
2 parents c617038 + 5ba8fca commit 8b3244b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
21 changes: 11 additions & 10 deletions src/schematic/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ type ExtendedResources = Vec<ExtendedResource>;
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct Resources {
pub cpu: CPU,
pub memory: Memory,
pub cpu: Option<CPU>,
pub memory: Option<Memory>,
pub gpu: Option<GPU>,
pub volumes: Option<Vec<Volume>>,
pub extended: Option<ExtendedResources>,
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/schematic/component_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/schematic/configuration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ fn test_application_configuration() {
.expect("JSON must parse");

assert!(conf.variables.is_some());
}
}

0 comments on commit 8b3244b

Please sign in to comment.