Skip to content

Commit

Permalink
add structs.Resources Equals
Browse files Browse the repository at this point in the history
  • Loading branch information
langmartin committed Apr 11, 2019
1 parent 8ee02dd commit 8528a2a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,31 @@ func (r *Resources) Merge(other *Resources) {
}
}

// Equals deeply equates the value of this resource with another
func (r *Resources) Equals(o *Resources) bool {
if r == nil && o == nil {
return true
}
if r == nil || o == nil {
return false
}
if r.CPU == o.CPU &&
r.MemoryMB == o.MemoryMB &&
r.DiskMB == o.DiskMB &&
r.IOPS == o.IOPS {
for i, n := range r.Networks {
if !n.Equals(o.Networks[i]) {
return false
}
}
if !DevicesEquals(r.Devices, o.Devices) {
return false
}
return true
}
return false
}

func (r *Resources) Canonicalize() {
// Ensure that an empty and nil slices are treated the same to avoid scheduling
// problems since we use reflect DeepEquals.
Expand Down

0 comments on commit 8528a2a

Please sign in to comment.