mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 02:45:42 +03:00
nomad: Resource Superset ignores network in favor of NetworkIndex
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user