Skip to content

Commit

Permalink
Persist shared allocated ports for inplace update (#9830)
Browse files Browse the repository at this point in the history
* Persist shared allocated ports for inplace update

Ports were not copied over when performing inplace updates in the
generic scheduler

* changelog

* drop spew
  • Loading branch information
drewbailey authored and backspace committed Jan 22, 2021
1 parent 7b009bb commit 2c24c6e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 1.0.3 (Unreleased)

BUG FIXES:

* scheduler: Fixed a bug where shared ports were not persisted during inplace updates for service jobs. [[GH-9830](https://github.com/hashicorp/nomad/issues/9830)]

## 1.0.2 (January 14, 2020)

IMPROVEMENTS:
Expand Down
10 changes: 10 additions & 0 deletions scheduler/generic_sched_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,11 @@ func TestServiceSched_JobModify_InPlace(t *testing.T) {
DeviceIDs: []string{uuid.Generate()},
}

asr := structs.AllocatedSharedResources{
Ports: structs.AllocatedPorts{{Label: "http"}},
Networks: structs.Networks{{Mode: "bridge"}},
}

// Create allocs that are part of the old deployment
var allocs []*structs.Allocation
for i := 0; i < 10; i++ {
Expand All @@ -2091,6 +2096,7 @@ func TestServiceSched_JobModify_InPlace(t *testing.T) {
alloc.DeploymentID = d.ID
alloc.DeploymentStatus = &structs.AllocDeploymentStatus{Healthy: helper.BoolToPtr(true)}
alloc.AllocatedResources.Tasks[taskName].Devices = []*structs.AllocatedDeviceResource{&adr}
alloc.AllocatedResources.Shared = asr
allocs = append(allocs, alloc)
}
require.NoError(t, h.State.UpsertAllocs(structs.MsgTypeTestSetup, h.NextIndex(), allocs))
Expand Down Expand Up @@ -2167,6 +2173,10 @@ func TestServiceSched_JobModify_InPlace(t *testing.T) {
// Verify the allocated networks and devices did not change
rp := structs.Port{Label: "admin", Value: 5000}
for _, alloc := range out {
// Verify Shared Allocared Resources Persisted
require.Equal(t, alloc.AllocatedResources.Shared.Ports, asr.Ports)
require.Equal(t, alloc.AllocatedResources.Shared.Networks, asr.Networks)

for _, resources := range alloc.AllocatedResources.Tasks {
if resources.Networks[0].ReservedPorts[0] != rp {
t.Fatalf("bad: %#v", alloc)
Expand Down
3 changes: 2 additions & 1 deletion scheduler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,14 +1014,15 @@ func genericAllocUpdateFn(ctx Context, stack Stack, evalID string) allocUpdateTy
},
}

// Since this is an inplace update, we should copy network
// Since this is an inplace update, we should copy network and port
// information from the original alloc. This is similar to how
// we copy network info for task level networks above.
//
// existing.AllocatedResources is nil on Allocations created by
// Nomad v0.8 or earlier.
if existing.AllocatedResources != nil {
newAlloc.AllocatedResources.Shared.Networks = existing.AllocatedResources.Shared.Networks
newAlloc.AllocatedResources.Shared.Ports = existing.AllocatedResources.Shared.Ports
}

// Use metrics from existing alloc for in place upgrade
Expand Down

0 comments on commit 2c24c6e

Please sign in to comment.