2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-02-11 16:39:16 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/pluginmanager/csimanager"
|
2023-04-03 15:03:36 +00:00
|
|
|
"github.com/hashicorp/nomad/helper"
|
2020-02-11 16:39:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// AllocHookResources contains data that is provided by AllocRunner Hooks for
|
2023-04-03 15:03:36 +00:00
|
|
|
// consumption by TaskRunners. This should be instantiated once in the
|
|
|
|
// AllocRunner and then only accessed via getters and setters that hold the
|
|
|
|
// lock.
|
2020-02-11 16:39:16 +00:00
|
|
|
type AllocHookResources struct {
|
2023-04-03 15:03:36 +00:00
|
|
|
csiMounts map[string]*csimanager.MountInfo
|
2020-02-11 16:39:16 +00:00
|
|
|
|
|
|
|
mu sync.RWMutex
|
|
|
|
}
|
|
|
|
|
2023-04-03 15:03:36 +00:00
|
|
|
func NewAllocHookResources() *AllocHookResources {
|
|
|
|
return &AllocHookResources{
|
|
|
|
csiMounts: map[string]*csimanager.MountInfo{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCSIMounts returns a copy of the CSI mount info previously written by the
|
|
|
|
// CSI allocrunner hook
|
2020-02-11 16:39:16 +00:00
|
|
|
func (a *AllocHookResources) GetCSIMounts() map[string]*csimanager.MountInfo {
|
|
|
|
a.mu.RLock()
|
|
|
|
defer a.mu.RUnlock()
|
|
|
|
|
2023-04-03 15:03:36 +00:00
|
|
|
return helper.DeepCopyMap(a.csiMounts)
|
2020-02-11 16:39:16 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 15:03:36 +00:00
|
|
|
// SetCSIMounts stores the CSI mount info for later use by the volume taskrunner
|
|
|
|
// hook
|
2020-02-11 16:39:16 +00:00
|
|
|
func (a *AllocHookResources) SetCSIMounts(m map[string]*csimanager.MountInfo) {
|
|
|
|
a.mu.Lock()
|
|
|
|
defer a.mu.Unlock()
|
|
|
|
|
2023-04-03 15:03:36 +00:00
|
|
|
a.csiMounts = m
|
2020-02-11 16:39:16 +00:00
|
|
|
}
|