-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed test and moved constants into standalone func #3536
Merged
preetapan
merged 4 commits into
hashicorp:master
from
angrycub:b-resource-memory-test-fix
Nov 13, 2017
+53
−16
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,7 @@ import ( | |
|
||
"github.com/gorhill/cronexpr" | ||
"github.com/hashicorp/consul/api" | ||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/go-version" | ||
multierror "github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/nomad/acl" | ||
"github.com/hashicorp/nomad/helper" | ||
"github.com/hashicorp/nomad/helper/args" | ||
|
@@ -1222,8 +1221,24 @@ const ( | |
BytesInMegabyte = 1024 * 1024 | ||
) | ||
|
||
// DefaultResources returns the default resources for a task. | ||
// DefaultResources is a small resources object that contains the | ||
// default resources requests that we will provide to an object. | ||
// --- THIS FUNCTION IS REPLICATED IN api/resources.go and should | ||
// be kept in sync. | ||
func DefaultResources() *Resources { | ||
return &Resources{ | ||
CPU: 100, | ||
MemoryMB: 300, | ||
IOPS: 0, | ||
} | ||
} | ||
|
||
// MinResources is a small resources object that contains the | ||
// absolute minimum resources that we will provide to an object. | ||
// This should not be confused with the defaults which are | ||
// provided in Canonicalize() --- THIS FUNCTION IS REPLICATED IN | ||
// api/resources.go and should be kept in sync. | ||
func MinResources() *Resources { | ||
return &Resources{ | ||
CPU: 100, | ||
MemoryMB: 10, | ||
|
@@ -1269,15 +1284,17 @@ func (r *Resources) Canonicalize() { | |
|
||
// MeetsMinResources returns an error if the resources specified are less than | ||
// the minimum allowed. | ||
// This is based on the minimums defined in the Resources type | ||
func (r *Resources) MeetsMinResources() error { | ||
var mErr multierror.Error | ||
if r.CPU < 20 { | ||
minResources := MinResources() | ||
if r.CPU < minResources.CPU { | ||
mErr.Errors = append(mErr.Errors, fmt.Errorf("minimum CPU value is 20; got %d", r.CPU)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This hard codes 20 but should use the value from the min resources. Same for all others. |
||
} | ||
if r.MemoryMB < 10 { | ||
if r.MemoryMB < minResources.MemoryMB { | ||
mErr.Errors = append(mErr.Errors, fmt.Errorf("minimum MemoryMB value is 10; got %d", r.MemoryMB)) | ||
} | ||
if r.IOPS < 0 { | ||
if r.IOPS < minResources.IOPS { | ||
mErr.Errors = append(mErr.Errors, fmt.Errorf("minimum IOPS value is 0; got %d", r.IOPS)) | ||
} | ||
for i, n := range r.Networks { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was only used in unit tests and is now replaced by DefaultResources, so why do we need MinResources here again?