mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-24 11:00:39 +00:00
implement basic cpu resource limits
This commit is contained in:
parent
a16b72d961
commit
5eb70c1034
@ -84,7 +84,7 @@ func toResourceObject(from *yaml.ResourceObject) *engine.ResourceObject {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &engine.ResourceObject{
|
return &engine.ResourceObject{
|
||||||
// TODO(bradrydzewski) set the CPU resource limit.
|
CPU: from.CPU,
|
||||||
Memory: int64(from.Memory),
|
Memory: int64(from.Memory),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ type (
|
|||||||
// ResourceObject describes compute resource
|
// ResourceObject describes compute resource
|
||||||
// requirements.
|
// requirements.
|
||||||
ResourceObject struct {
|
ResourceObject struct {
|
||||||
CPU string `json:"cpu"`
|
CPU int64 `json:"cpu" yaml:"cpu"`
|
||||||
Memory BytesSize `json:"memory"`
|
Memory BytesSize `json:"memory"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
yaml/pretty/testdata/pipeline_resources.yml
vendored
4
yaml/pretty/testdata/pipeline_resources.yml
vendored
@ -8,8 +8,8 @@ steps:
|
|||||||
- go build
|
- go build
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 200m
|
cpu: 2
|
||||||
memory: '100Mi'
|
memory: '100Mi'
|
||||||
requests:
|
requests:
|
||||||
cpu: 100m
|
cpu: 1
|
||||||
memory: '50Mi'
|
memory: '50Mi'
|
||||||
|
@ -13,10 +13,10 @@ steps:
|
|||||||
- go build
|
- go build
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 200m
|
cpu: 2
|
||||||
memory: 100MiB
|
memory: 100MiB
|
||||||
requests:
|
requests:
|
||||||
cpu: 100m
|
cpu: 1
|
||||||
memory: 50MiB
|
memory: 50MiB
|
||||||
|
|
||||||
...
|
...
|
||||||
|
@ -18,7 +18,7 @@ import "github.com/drone/drone-yaml/yaml"
|
|||||||
|
|
||||||
func isPrimative(v interface{}) bool {
|
func isPrimative(v interface{}) bool {
|
||||||
switch v.(type) {
|
switch v.(type) {
|
||||||
case bool, string, int, float64:
|
case bool, string, int, int64, float64:
|
||||||
return true
|
return true
|
||||||
case yaml.BytesSize:
|
case yaml.BytesSize:
|
||||||
return true
|
return true
|
||||||
|
@ -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) {
|
func writeEncode(w writer, v string) {
|
||||||
if len(v) == 0 {
|
if len(v) == 0 {
|
||||||
w.WriteByte('"')
|
w.WriteByte('"')
|
||||||
@ -204,7 +210,7 @@ func writeValue(w writer, v interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case bool, int, float64, string:
|
case bool, int, int64, float64, string:
|
||||||
writeScalar(w, v)
|
writeScalar(w, v)
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
writeSequence(w, v)
|
writeSequence(w, v)
|
||||||
@ -225,6 +231,8 @@ func writeScalar(w writer, v interface{}) {
|
|||||||
writeBool(w, v)
|
writeBool(w, v)
|
||||||
case int:
|
case int:
|
||||||
writeInt(w, v)
|
writeInt(w, v)
|
||||||
|
case int64:
|
||||||
|
writeInt64(w, v)
|
||||||
case float64:
|
case float64:
|
||||||
writeFloat(w, v)
|
writeFloat(w, v)
|
||||||
case string:
|
case string:
|
||||||
|
Loading…
Reference in New Issue
Block a user