diff --git a/CHANGELOG.md b/CHANGELOG.md index bee4170e0aa..a7ee3458784 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/scheduler/generic_sched_test.go b/scheduler/generic_sched_test.go index dc34c78a90b..842a85b29c6 100644 --- a/scheduler/generic_sched_test.go +++ b/scheduler/generic_sched_test.go @@ -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++ { @@ -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)) @@ -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) diff --git a/scheduler/util.go b/scheduler/util.go index b42895a16b8..191cf5d0f7f 100644 --- a/scheduler/util.go +++ b/scheduler/util.go @@ -1014,7 +1014,7 @@ 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. // @@ -1022,6 +1022,7 @@ func genericAllocUpdateFn(ctx Context, stack Stack, evalID string) allocUpdateTy // 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