From ecb60cc7666a5f732fa3fd7c21f95e22648e1893 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sun, 13 Sep 2015 14:59:34 -0700 Subject: [PATCH] nomad: Resource Superset ignores network in favor of NetworkIndex --- nomad/structs/structs.go | 26 ++-------------- nomad/structs/structs_test.go | 57 ----------------------------------- 2 files changed, 2 insertions(+), 81 deletions(-) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index ef1f6c04b..3f6b66cce 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -602,7 +602,8 @@ func (r *Resources) NetIndexByIP(ip string) int { } // Superset checks if one set of resources is a superset -// of another. +// of another. This ignores network resources, and the NetworkIndex +// should be used for that. func (r *Resources) Superset(other *Resources) bool { if r.CPU < other.CPU { return false @@ -616,29 +617,6 @@ func (r *Resources) Superset(other *Resources) bool { if r.IOPS < other.IOPS { return false } - - // Compute the MBits available by index - mbitsByIdx := make(map[int]int) - for idx, n := range r.Networks { - mbitsByIdx[idx] = n.MBits - } - - // Ensure all networks exist and do not exhaust bandwidth - for _, n := range other.Networks { - // Find the matching interface by IP or CIDR - idx := r.NetIndex(n) - if idx == -1 { - return false - } - - // Deduct the allocation - mbitsByIdx[idx] -= n.MBits - - // Check if we've exhaused our allocation - if mbitsByIdx[idx] < 0 { - return false - } - } return true } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 068863b53..676ba421b 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -47,24 +47,12 @@ func TestResource_Superset(t *testing.T) { MemoryMB: 2048, DiskMB: 10000, IOPS: 100, - Networks: []*NetworkResource{ - &NetworkResource{ - CIDR: "10.0.0.0/8", - MBits: 100, - }, - }, } r2 := &Resources{ CPU: 1.0, MemoryMB: 1024, DiskMB: 5000, IOPS: 50, - Networks: []*NetworkResource{ - &NetworkResource{ - CIDR: "10.0.0.0/8", - MBits: 50, - }, - }, } if !r1.Superset(r1) { @@ -81,51 +69,6 @@ func TestResource_Superset(t *testing.T) { } } -func TestResource_Superset_IPCIDR(t *testing.T) { - r1 := &Resources{ - CPU: 2.0, - MemoryMB: 2048, - DiskMB: 10000, - IOPS: 100, - Networks: []*NetworkResource{ - &NetworkResource{ - CIDR: "10.0.0.0/8", - MBits: 100, - }, - }, - } - r2 := &Resources{ - CPU: 1.0, - MemoryMB: 1024, - DiskMB: 5000, - IOPS: 50, - Networks: []*NetworkResource{ - &NetworkResource{ - IP: "10.0.0.5", - MBits: 50, - }, - &NetworkResource{ - IP: "10.0.0.6", - MBits: 50, - }, - }, - } - - if !r1.Superset(r2) { - t.Fatalf("bad") - } - - // Use more network - r2.Networks = append(r2.Networks, &NetworkResource{ - IP: "10.0.0.7", - MBits: 50, - }) - - if r1.Superset(r2) { - t.Fatalf("bad") - } -} - func TestResource_Add(t *testing.T) { r1 := &Resources{ CPU: 2.0,