use float64 to support docker-compose cpu syntax

This commit is contained in:
Brad Rydzewski 2019-03-18 09:24:31 -07:00
parent 5eb70c1034
commit 7a5539b9af
3 changed files with 13 additions and 2 deletions

View File

@ -84,7 +84,14 @@ func toResourceObject(from *yaml.ResourceObject) *engine.ResourceObject {
return nil
}
return &engine.ResourceObject{
CPU: from.CPU,
CPU: toCPUMillis(from.CPU),
Memory: int64(from.Memory),
}
}
func toCPUMillis(f float64) int64 {
if f > 0 {
f *= 1000
}
return int64(f)
}

View File

@ -136,9 +136,11 @@ func Test_toResources(t *testing.T) {
Resources: &yaml.Resources{
Limits: &yaml.ResourceObject{
Memory: yaml.BytesSize(1000),
CPU: 4,
},
Requests: &yaml.ResourceObject{
Memory: yaml.BytesSize(2000),
CPU: 0.1,
},
},
}
@ -146,9 +148,11 @@ func Test_toResources(t *testing.T) {
b = &engine.Resources{
Limits: &engine.ResourceObject{
Memory: 1000,
CPU: 4000,
},
Requests: &engine.ResourceObject{
Memory: 2000,
CPU: 100,
},
}
if diff := cmp.Diff(a, b); diff != "" {

View File

@ -97,7 +97,7 @@ type (
// ResourceObject describes compute resource
// requirements.
ResourceObject struct {
CPU int64 `json:"cpu" yaml:"cpu"`
CPU float64 `json:"cpu" yaml:"cpu"`
Memory BytesSize `json:"memory"`
}