From 737a872ac902e283f28ff785455c56a50c1dc2c5 Mon Sep 17 00:00:00 2001 From: Drew Bailey Date: Fri, 15 Jan 2021 11:05:03 -0500 Subject: [PATCH 1/3] Persist shared allocated ports for inplace update Ports were not copied over when performing inplace updates in the generic scheduler --- scheduler/generic_sched_test.go | 10 ++++++++++ scheduler/util.go | 3 ++- scheduler/util_test.go | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) 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 diff --git a/scheduler/util_test.go b/scheduler/util_test.go index 7ca5255e67c..661ebb9f9c0 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -5,6 +5,7 @@ import ( "reflect" "testing" + "github.com/davecgh/go-spew/spew" "github.com/stretchr/testify/require" "github.com/hashicorp/nomad/helper" @@ -943,6 +944,8 @@ func TestInplaceUpdate_AllocatedResources(t *testing.T) { require.NoError(t, state.UpsertJobSummary(1000, mock.JobSummary(alloc.JobID))) require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc})) + spew.Dump(job) + // Update TG to add a new service (inplace) tg := job.TaskGroups[0] tg.Services = []*structs.Service{ From 74c923f9c87e30e4a201c4fa4a1ddcdb3955bc01 Mon Sep 17 00:00:00 2001 From: Drew Bailey Date: Fri, 15 Jan 2021 11:07:36 -0500 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3fd04e5b9a..37c4f0cd637 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: From c63960186f8955ecdb15f64a80f68339f1ec13ff Mon Sep 17 00:00:00 2001 From: Drew Bailey Date: Fri, 15 Jan 2021 11:08:55 -0500 Subject: [PATCH 3/3] drop spew --- scheduler/util_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/scheduler/util_test.go b/scheduler/util_test.go index 661ebb9f9c0..7ca5255e67c 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -5,7 +5,6 @@ import ( "reflect" "testing" - "github.com/davecgh/go-spew/spew" "github.com/stretchr/testify/require" "github.com/hashicorp/nomad/helper" @@ -944,8 +943,6 @@ func TestInplaceUpdate_AllocatedResources(t *testing.T) { require.NoError(t, state.UpsertJobSummary(1000, mock.JobSummary(alloc.JobID))) require.NoError(t, state.UpsertAllocs(structs.MsgTypeTestSetup, 1001, []*structs.Allocation{alloc})) - spew.Dump(job) - // Update TG to add a new service (inplace) tg := job.TaskGroups[0] tg.Services = []*structs.Service{