From 0db70d6027bad0ad6a3fc7cf3faeb82452f88b34 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 3 Apr 2023 13:35:52 +0000 Subject: [PATCH] backport of commit a9b2ac844093863c731540caf57cb6cc8d7626fd --- client/pluginmanager/csimanager/interface.go | 10 ++++++++++ client/structs/allochook.go | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/client/pluginmanager/csimanager/interface.go b/client/pluginmanager/csimanager/interface.go index 9f7e067c89e..0e4a1f03a11 100644 --- a/client/pluginmanager/csimanager/interface.go +++ b/client/pluginmanager/csimanager/interface.go @@ -13,6 +13,16 @@ type MountInfo struct { IsDevice bool } +func (mi *MountInfo) Copy() *MountInfo { + if mi == nil { + return nil + } + + nmi := new(MountInfo) + *nmi = *mi + return nmi +} + type UsageOptions struct { ReadOnly bool AttachmentMode structs.CSIVolumeAttachmentMode diff --git a/client/structs/allochook.go b/client/structs/allochook.go index a1fce3cf988..3a694d85abc 100644 --- a/client/structs/allochook.go +++ b/client/structs/allochook.go @@ -4,6 +4,7 @@ import ( "sync" "github.com/hashicorp/nomad/client/pluginmanager/csimanager" + "github.com/hashicorp/nomad/helper" ) // AllocHookResources contains data that is provided by AllocRunner Hooks for @@ -22,13 +23,17 @@ func NewAllocHookResources() *AllocHookResources { } } +// GetCSIMounts returns a copy of the CSI mount info previously written by the +// CSI allocrunner hook func (a *AllocHookResources) GetCSIMounts() map[string]*csimanager.MountInfo { a.mu.RLock() defer a.mu.RUnlock() - return a.csiMounts + return helper.DeepCopyMap(a.csiMounts) } +// SetCSIMounts stores the CSI mount info for later use by the volume taskrunner +// hook func (a *AllocHookResources) SetCSIMounts(m map[string]*csimanager.MountInfo) { a.mu.Lock() defer a.mu.Unlock()