implement basic cpu resource limits

This commit is contained in:
Brad Rydzewski 2019-03-17 20:03:27 -07:00
parent a16b72d961
commit 5eb70c1034
6 changed files with 16 additions and 8 deletions

View File

@ -84,7 +84,7 @@ func toResourceObject(from *yaml.ResourceObject) *engine.ResourceObject {
return nil
}
return &engine.ResourceObject{
// TODO(bradrydzewski) set the CPU resource limit.
CPU: from.CPU,
Memory: int64(from.Memory),
}
}

View File

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

View File

@ -8,8 +8,8 @@ steps:
- go build
resources:
limits:
cpu: 200m
cpu: 2
memory: '100Mi'
requests:
cpu: 100m
cpu: 1
memory: '50Mi'

View File

@ -13,10 +13,10 @@ steps:
- go build
resources:
limits:
cpu: 200m
cpu: 2
memory: 100MiB
requests:
cpu: 100m
cpu: 1
memory: 50MiB
...

View File

@ -18,7 +18,7 @@ import "github.com/drone/drone-yaml/yaml"
func isPrimative(v interface{}) bool {
switch v.(type) {
case bool, string, int, float64:
case bool, string, int, int64, float64:
return true
case yaml.BytesSize:
return true

View File

@ -183,6 +183,12 @@ func writeInt(w writer, v int) {
)
}
func writeInt64(w writer, v int64) {
w.WriteString(
strconv.FormatInt(v, 10),
)
}
func writeEncode(w writer, v string) {
if len(v) == 0 {
w.WriteByte('"')
@ -204,7 +210,7 @@ func writeValue(w writer, v interface{}) {
return
}
switch v := v.(type) {
case bool, int, float64, string:
case bool, int, int64, float64, string:
writeScalar(w, v)
case []interface{}:
writeSequence(w, v)
@ -225,6 +231,8 @@ func writeScalar(w writer, v interface{}) {
writeBool(w, v)
case int:
writeInt(w, v)
case int64:
writeInt64(w, v)
case float64:
writeFloat(w, v)
case string: