From 2a7120fa3f2e7cd6499622594aa56766f37cab5b Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Thu, 23 Jan 2025 19:06:32 +0000 Subject: [PATCH] backport of commit c1dc9ed75da559a0700a00e08b8b0df9fc9aecce --- .changelog/24922.txt | 3 +++ nomad/structs/csi.go | 10 +++++++--- nomad/structs/csi_test.go | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 .changelog/24922.txt diff --git a/.changelog/24922.txt b/.changelog/24922.txt new file mode 100644 index 00000000000..bbf1374bd3d --- /dev/null +++ b/.changelog/24922.txt @@ -0,0 +1,3 @@ +```release-note:bug +csi: Fixed a bug where volume context from the plugin would be erased on volume updates +``` diff --git a/nomad/structs/csi.go b/nomad/structs/csi.go index 8dd85db766e..4296b67c8c3 100644 --- a/nomad/structs/csi.go +++ b/nomad/structs/csi.go @@ -846,9 +846,13 @@ func (v *CSIVolume) Merge(other *CSIVolume) error { "volume parameters cannot be updated")) } - // Context is mutable and will be used during controller - // validation - v.Context = other.Context + // Context is mutable and will be used during controller validation, but we + // need to ensure we don't remove context that's been previously stored + // server-side if the user has submitted an update without adding it to the + // spec manually (which we should not require) + if len(other.Context) != 0 { + v.Context = other.Context + } return errs.ErrorOrNil() } diff --git a/nomad/structs/csi_test.go b/nomad/structs/csi_test.go index 9069d6e8b29..a2a087eddc9 100644 --- a/nomad/structs/csi_test.go +++ b/nomad/structs/csi_test.go @@ -711,6 +711,13 @@ func TestCSIVolume_Merge(t *testing.T) { {Segments: map[string]string{"rack": "R2"}}, }, }, + Context: map[string]string{ + // a typical context for democratic-csi + "provisioner_driver": "nfs-client", + "node_attach_driver": "nfs", + "server": "192.168.1.170", + "share": "/srv/nfs_data/v/csi-volume-nfs", + }, }, update: &CSIVolume{ Topologies: []*CSITopology{ @@ -745,6 +752,14 @@ func TestCSIVolume_Merge(t *testing.T) { test.Sprint("should add 2 requested capabilities")) test.Eq(t, []string{"noatime", "another"}, v.MountOptions.MountFlags, test.Sprint("should add mount flag")) + test.Eq(t, map[string]string{ + "provisioner_driver": "nfs-client", + "node_attach_driver": "nfs", + "server": "192.168.1.170", + "share": "/srv/nfs_data/v/csi-volume-nfs", + }, v.Context, + test.Sprint("context should not be overwritten with empty update")) + }, }, }