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

Commit

Permalink
align resource requirement with oam spec v1.0.0-alpha.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wonderflow committed Nov 14, 2019
1 parent 025b039 commit 7b30a20
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/concepts/component-schematic.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ resources:
cpu:
required: "0.5"
memory:
required: 100M
required: "128"
```

#### `volumes`
Expand Down
32 changes: 31 additions & 1 deletion examples/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
cpu:
required: 0.5
memory:
required: 100M
required: "128"
---
apiVersion: core.oam.dev/v1alpha1
kind: ComponentSchematic
Expand All @@ -30,6 +30,11 @@ spec:
- name: http
containerPort: 80
protocol: TCP
resources:
cpu:
required: 0.1
memory:
required: "128"
---
apiVersion: core.oam.dev/v1alpha1
kind: ComponentSchematic
Expand All @@ -44,6 +49,11 @@ spec:
- name: http
containerPort: 80
protocol: TCP
resources:
cpu:
required: 0.1
memory:
required: "128"
---
apiVersion: core.oam.dev/v1alpha1
kind: ComponentSchematic
Expand All @@ -55,6 +65,11 @@ spec:
containers:
- name: runner
image: alpine:latest
resources:
cpu:
required: 0.1
memory:
required: "128"
---
apiVersion: core.oam.dev/v1alpha1
kind: ComponentSchematic
Expand All @@ -66,6 +81,11 @@ spec:
containers:
- name: runner
image: alpine:latest
resources:
cpu:
required: 0.1
memory:
required: "128"
---
apiVersion: core.oam.dev/v1alpha1
kind: ComponentSchematic
Expand All @@ -77,6 +97,11 @@ spec:
containers:
- name: worker
image: nginx:latest
resources:
cpu:
required: 0.1
memory:
required: "128"
---
apiVersion: core.oam.dev/v1alpha1
kind: ComponentSchematic
Expand All @@ -88,3 +113,8 @@ spec:
containers:
- name: worker
image: nginx:latest
resources:
cpu:
required: 0.1
memory:
required: "128"
5 changes: 5 additions & 0 deletions examples/helloworld-python-component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ spec:
- type: tcp
containerPort: 9999
name: http
resources:
cpu:
required: "0.1"
memory:
required: "128"
parameters:
- name: target
type: string
Expand Down
5 changes: 5 additions & 0 deletions examples/image-pull-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ spec:
- name: runner
image: alpine:latest
imagePullSecret: example-image-pull-secret
resources:
cpu:
required: "0.1"
memory:
required: "128"
---
apiVersion: core.oam.dev/v1alpha1
kind: ApplicationConfiguration
Expand Down
5 changes: 5 additions & 0 deletions examples/nginx-component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ spec:
- type: tcp
containerPort: 80
name: http
resources:
cpu:
required: 0.1
memory:
required: "128"
parameters:
- name: poet
type: string
Expand Down
4 changes: 4 additions & 0 deletions examples/volumes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ spec:
disk:
required: "50M"
ephemeral: false
cpu:
required: 0.1
memory:
required: "128"
---
apiVersion: core.oam.dev/v1alpha1
kind: ApplicationConfiguration
Expand Down
9 changes: 6 additions & 3 deletions src/schematic/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,10 @@ impl Resources {
fn to_resource_requirements(&self) -> core::ResourceRequirements {
let mut requests = BTreeMap::new();
requests.insert("cpu".to_string(), Quantity(self.cpu.required.to_string().clone()));
requests.insert("memory".to_string(), Quantity(self.memory.required.clone()));
requests.insert(
"memory".to_string(),
Quantity(self.memory.required.clone() + "Mi"),
);
// TODO: Kubernetes does not have a built-in type for GPUs. What do we use?
core::ResourceRequirements {
requests: Some(requests),
Expand All @@ -547,10 +550,10 @@ impl Default for Resources {
fn default() -> Self {
Resources {
cpu: CPU {
required: "1".into(),
required: 0.1,
},
memory: Memory {
required: "1G".into(),
required: "128".into(),
},
gpu: None,
volumes: None,
Expand Down
10 changes: 5 additions & 5 deletions src/schematic/component_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ fn test_container_deserialize() {
"livenessProbe": {},
"resources": {
"memory": {
"required": "100M"
"required": "128"
},
"cpu": {
"required": "0.1"
"required": 0.1
},
"volumes": [
{
Expand Down Expand Up @@ -178,8 +178,8 @@ fn test_container_deserialize() {

let res = &container.resources;

assert_eq!("100M", res.memory.required);
assert_eq!("0.1", res.cpu.required);
assert_eq!("128", res.memory.required);
assert_eq!(0.1, res.cpu.required);

let vols = res.volumes.clone().expect("expected volumes");
let path1 = vols.get(0).expect("expect a first volume");
Expand Down Expand Up @@ -512,7 +512,7 @@ fn test_to_volume_mounts() {
required: 0.1.into(),
},
memory: Memory {
required: "128M".into(),
required: "128".into(),
},
gpu: Some(GPU {
required: 0.into(),
Expand Down

0 comments on commit 7b30a20

Please sign in to comment.