From faeb3fcd4420cb438cd092a191b7a4c0b1673112 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Fri, 13 May 2022 11:34:04 -0400 Subject: [PATCH] scheduler: volume updates should always be destructive (#13008) --- .changelog/13008.txt | 3 +++ scheduler/util.go | 9 +++++++++ scheduler/util_test.go | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 .changelog/13008.txt diff --git a/.changelog/13008.txt b/.changelog/13008.txt new file mode 100644 index 000000000..b12e5294b --- /dev/null +++ b/.changelog/13008.txt @@ -0,0 +1,3 @@ +```release-note:bug +volumes: Fixed a bug where additions, updates, or removals of host volumes or CSI volumes were not treated as destructive updates +``` diff --git a/scheduler/util.go b/scheduler/util.go index 9f938d1ba..796f84b5a 100644 --- a/scheduler/util.go +++ b/scheduler/util.go @@ -524,6 +524,12 @@ func tasksUpdated(jobA, jobB *structs.Job, taskGroup string) bool { return true } + // Check if volumes are updated (no task driver can support + // altering mounts in-place) + if !reflect.DeepEqual(a.Volumes, b.Volumes) { + return true + } + // Check each task for _, at := range a.Tasks { bt := b.LookupTask(at.Name) @@ -554,6 +560,9 @@ func tasksUpdated(jobA, jobB *structs.Job, taskGroup string) bool { if !reflect.DeepEqual(at.CSIPluginConfig, bt.CSIPluginConfig) { return true } + if !reflect.DeepEqual(at.VolumeMounts, bt.VolumeMounts) { + return true + } // Check the metadata if !reflect.DeepEqual( diff --git a/scheduler/util_test.go b/scheduler/util_test.go index 65e5498a1..ff7984fb5 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -811,6 +811,32 @@ func TestTasksUpdated(t *testing.T) { // Compare changed Template wait configs j23.TaskGroups[0].Tasks[0].Templates[0].Wait.Max = helper.TimeToPtr(10 * time.Second) require.True(t, tasksUpdated(j22, j23, name)) + + // Add a volume + j24 := mock.Job() + j25 := j24.Copy() + j25.TaskGroups[0].Volumes = map[string]*structs.VolumeRequest{ + "myvolume": { + Name: "myvolume", + Type: "csi", + Source: "test-volume[0]", + }} + require.True(t, tasksUpdated(j24, j25, name)) + + // Alter a volume + j26 := j25.Copy() + j26.TaskGroups[0].Volumes["myvolume"].ReadOnly = true + require.True(t, tasksUpdated(j25, j26, name)) + + // Alter a CSI plugin + j27 := mock.Job() + j27.TaskGroups[0].Tasks[0].CSIPluginConfig = &structs.TaskCSIPluginConfig{ + ID: "myplugin", + Type: "node", + } + j28 := j27.Copy() + j28.TaskGroups[0].Tasks[0].CSIPluginConfig.Type = "monolith" + require.True(t, tasksUpdated(j27, j28, name)) } func TestTasksUpdated_connectServiceUpdated(t *testing.T) {