8000 schema/resource isolator: Allow either 'limit' or 'request' to be empty. by yifan-gu · Pull Request #566 · appc/spec · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Aug 14, 2020. It is now read-only.

schema/resource isolator: Allow either 'limit' or 'request' to be empty. #566

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions schema/types/isolator_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ func (r ResourceCPU) AsIsolator() Isolator {
}

func NewResourceCPUIsolator(request, limit string) (*ResourceCPU, error) {
if request == "" {
request = limit
} else if limit == "" {
limit = request
}

req, err := resource.ParseQuantity(request)
if err != nil {
return nil, fmt.Errorf("error parsing request: %v", err)
Expand Down Expand Up @@ -198,6 +204,12 @@ func (r ResourceMemory) AsIsolator() Isolator {
}

func NewResourceMemoryIsolator(request, limit string) (*ResourceMemory, error) {
if request == "" {
request = limit
} else if limit == "" {
limit = request
}

req, err := resource.ParseQuantity(request)
if err != nil {
return nil, fmt.Errorf("error parsing request: %v", err)
Expand Down
72 changes: 70 additions & 2 deletions schema/types/isolator_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,44 @@ func TestResourceMemoryIsolator(t *testing.T) {
},
false,
},
// only empty request is valid.
{
"100M",
"",

&ResourceMemory{
ResourceBase{
resourceValue{
Request: mustQuantity("100M"),
Limit: mustQuantity("100M"),
},
},
},
false,
},
// only empty limit is valid.
{
"",
"200M",

&ResourceMemory{
ResourceBase{
resourceValue{
Request: mustQuantity("200M"),
Limit: mustQuantity("200M"),
},
},
},
false,
},
// both empty limit is invalid.
{
"",
"",

nil,
true,
},
}
for i, tt := range tests {
gres, err := NewResourceMemoryIsolator(tt.inreq, tt.inlim)
Expand All @@ -68,14 +106,44 @@ func TestResourceCPUIsolator(t *testing.T) {
wres *ResourceCPU
werr bool
}{
// empty is not valid
// both empty is not valid
{
"",
"2",
"",

nil,
true,
},
// only empty request is valid.
{
"1",
"",

&ResourceCPU{
ResourceBase{
resourceValue{
Request: mustQuantity("1"),
Limit: mustQuantity("1"),
},
},
},
false,
},
// only empty limit is valid.
{
"",
"2",

&ResourceCPU{
ResourceBase{
resourceValue{
Request: mustQuantity("2"),
Limit: mustQuantity("2"),
},
},
},
false,
},
// garbage value
{
"1",
Expand Down
1 change: 1 addition & 0 deletions spec/ace.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ If **request** is omitted, it defaults to the value of **limit**.

- **limit** is the maximum amount of a resource available to the app/pod.
If the app/pod consumes a resource in excess of its limit, it 4CDE must be terminated or throttled to no more than the limit.
If **limit** is ommitted, it defaults to the value of **request**.

Limit and request quantities must always be represented internally (i.e. for encoding and any processing) as an integer value (i.e. NOT floating point) in a resource type's natural base units (e.g., bytes, not megabytes or gigabytes).
For convenience, when specified by users quantities may either be unsuffixed, have metric suffices (E, P, T, G, M, K) or binary (power-of-two) suffices (Ei, Pi, Ti, Gi, Mi, Ki).
Expand Down
0