mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Fixed test and moved constants into standalone func
In #3520, work was done to true up the defaults for Nomad resource stanzas with the documentation. This fixes the tests that I accidentally broke in the process. Some questions were raised about using dynamic elements as part of expects, which is why I opted to copy the MinResources pattern. During this refactor I also noticed that structs.go had a similar issue and an inconsistent minium for CPU.
This commit is contained in:
@@ -139,7 +139,7 @@ func TestJobs_Canonicalize(t *testing.T) {
|
||||
{
|
||||
KillTimeout: helper.TimeToPtr(5 * time.Second),
|
||||
LogConfig: DefaultLogConfig(),
|
||||
Resources: MinResources(),
|
||||
Resources: DefaultResources(),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -201,7 +201,7 @@ func TestJobs_Canonicalize(t *testing.T) {
|
||||
{
|
||||
Name: "task1",
|
||||
LogConfig: DefaultLogConfig(),
|
||||
Resources: MinResources(),
|
||||
Resources: DefaultResources(),
|
||||
KillTimeout: helper.TimeToPtr(5 * time.Second),
|
||||
},
|
||||
},
|
||||
@@ -550,7 +550,7 @@ func TestJobs_Canonicalize(t *testing.T) {
|
||||
{
|
||||
Name: "task1",
|
||||
LogConfig: DefaultLogConfig(),
|
||||
Resources: MinResources(),
|
||||
Resources: DefaultResources(),
|
||||
KillTimeout: helper.TimeToPtr(5 * time.Second),
|
||||
},
|
||||
},
|
||||
@@ -582,7 +582,7 @@ func TestJobs_Canonicalize(t *testing.T) {
|
||||
{
|
||||
Name: "task1",
|
||||
LogConfig: DefaultLogConfig(),
|
||||
Resources: MinResources(),
|
||||
Resources: DefaultResources(),
|
||||
KillTimeout: helper.TimeToPtr(5 * time.Second),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -12,28 +12,47 @@ type Resources struct {
|
||||
Networks []*NetworkResource
|
||||
}
|
||||
|
||||
// Canonicalize will supply missing values in the cases
|
||||
// where they are not provided.
|
||||
func (r *Resources) Canonicalize() {
|
||||
defaultResources := DefaultResources()
|
||||
if r.CPU == nil {
|
||||
r.CPU = helper.IntToPtr(100)
|
||||
r.CPU = defaultResources.CPU
|
||||
}
|
||||
if r.MemoryMB == nil {
|
||||
r.MemoryMB = helper.IntToPtr(300)
|
||||
r.MemoryMB = defaultResources.MemoryMB
|
||||
}
|
||||
if r.IOPS == nil {
|
||||
r.IOPS = helper.IntToPtr(0)
|
||||
r.IOPS = defaultResources.IOPS
|
||||
}
|
||||
for _, n := range r.Networks {
|
||||
n.Canonicalize()
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultResources is a small resources object that contains the
|
||||
// default resources requests that we will provide to an object.
|
||||
// --- THIS FUNCTION IS REPLICATED IN nomad/structs/structs.go
|
||||
// and should be kept in sync.
|
||||
func DefaultResources() *Resources {
|
||||
return &Resources{
|
||||
CPU: helper.IntToPtr(100),
|
||||
MemoryMB: helper.IntToPtr(300),
|
||||
IOPS: helper.IntToPtr(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 DefaultResources() --- THIS LOGIC IS REPLICATED
|
||||
// IN nomad/structs/structs.go and should be kept in sync.
|
||||
func MinResources() *Resources {
|
||||
return &Resources{
|
||||
CPU: helper.IntToPtr(100),
|
||||
MemoryMB: helper.IntToPtr(10),
|
||||
IOPS: helper.IntToPtr(0),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Merge merges this resource with another resource.
|
||||
|
||||
Reference in New Issue
Block a user