Skip to content
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

Only preempt for network when there is a network #5794

Merged
merged 2 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions scheduler/preemption.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,19 @@ func (p *Preemptor) PreemptForNetwork(networkResourceAsk *structs.NetworkResourc
continue
}

allocResources := p.allocDetails[alloc.ID].resources
networks := allocResources.Flattened.Networks
if len(networks) == 0 {
continue
}

// We only check first network - TODO: why?!?!
net := networks[0]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is presumably because allocs can only be assigned a single network?


// Filter out alloc that's ineligible due to priority
if p.jobPriority-alloc.Job.Priority < 10 {
// Populate any reserved ports used by
// this allocation that cannot be preempted
allocResources := p.allocDetails[alloc.ID].resources
networks := allocResources.Flattened.Networks
net := networks[0]
for _, port := range net.ReservedPorts {
portMap, ok := filteredReservedPorts[net.Device]
if !ok {
Expand All @@ -314,16 +320,12 @@ func (p *Preemptor) PreemptForNetwork(networkResourceAsk *structs.NetworkResourc
}
continue
}
allocResources := p.allocDetails[alloc.ID].resources
networks := allocResources.Flattened.Networks

// Only include if the alloc has a network device
if len(networks) > 0 {
device := networks[0].Device
allocsForDevice := deviceToAllocs[device]
allocsForDevice = append(allocsForDevice, alloc)
deviceToAllocs[device] = allocsForDevice
}
device := networks[0].Device
allocsForDevice := deviceToAllocs[device]
allocsForDevice = append(allocsForDevice, alloc)
deviceToAllocs[device] = allocsForDevice
}

// If no existing allocations use network resources, return early
Expand Down
80 changes: 79 additions & 1 deletion scheduler/preemption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,84 @@ func TestPreemption(t *testing.T) {
allocIDs[3]: {},
},
},
{
desc: "preempt allocs with network devices",
currentAllocations: []*structs.Allocation{
createAlloc(allocIDs[0], lowPrioJob, &structs.Resources{
CPU: 2800,
MemoryMB: 2256,
DiskMB: 4 * 1024,
}),
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
CPU: 200,
MemoryMB: 256,
DiskMB: 4 * 1024,
Networks: []*structs.NetworkResource{
{
Device: "eth0",
IP: "192.168.0.200",
MBits: 800,
},
},
}),
},
nodeReservedCapacity: reservedNodeResources,
nodeCapacity: defaultNodeResources,
jobPriority: 100,
resourceAsk: &structs.Resources{
CPU: 1100,
MemoryMB: 1000,
DiskMB: 25 * 1024,
Networks: []*structs.NetworkResource{
{
Device: "eth0",
IP: "192.168.0.100",
MBits: 840,
},
},
},
preemptedAllocIDs: map[string]struct{}{
allocIDs[1]: {},
},
},
{
desc: "ignore allocs with close enough priority for network devices",
currentAllocations: []*structs.Allocation{
createAlloc(allocIDs[0], lowPrioJob, &structs.Resources{
CPU: 2800,
MemoryMB: 2256,
DiskMB: 4 * 1024,
}),
createAlloc(allocIDs[1], lowPrioJob, &structs.Resources{
CPU: 200,
MemoryMB: 256,
DiskMB: 4 * 1024,
Networks: []*structs.NetworkResource{
{
Device: "eth0",
IP: "192.168.0.200",
MBits: 800,
},
},
}),
},
nodeReservedCapacity: reservedNodeResources,
nodeCapacity: defaultNodeResources,
jobPriority: lowPrioJob.Priority + 5,
resourceAsk: &structs.Resources{
CPU: 1100,
MemoryMB: 1000,
DiskMB: 25 * 1024,
Networks: []*structs.NetworkResource{
{
Device: "eth0",
IP: "192.168.0.100",
MBits: 840,
},
},
},
preemptedAllocIDs: nil,
},
{
desc: "Preemption needed for all resources except network",
currentAllocations: []*structs.Allocation{
Expand Down Expand Up @@ -1292,7 +1370,7 @@ func TestPreemption(t *testing.T) {
require.Equal(len(tc.preemptedAllocIDs), len(preemptedAllocs))
for _, alloc := range preemptedAllocs {
_, ok := tc.preemptedAllocIDs[alloc.ID]
require.True(ok)
require.Truef(ok, "alloc %s was preempted unexpectedly", alloc.ID)
}
}
})
Expand Down