2020-01-08 12:47:07 +00:00
|
|
|
package csimanager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2020-02-17 11:10:12 +00:00
|
|
|
"strings"
|
2020-01-08 12:47:07 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/pluginmanager"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-01-28 16:27:32 +00:00
|
|
|
PluginNotFoundErr = errors.New("Plugin not found")
|
2020-01-08 12:47:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MountInfo struct {
|
2020-01-31 13:45:48 +00:00
|
|
|
Source string
|
|
|
|
IsDevice bool
|
2020-01-08 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 11:10:12 +00:00
|
|
|
type UsageOptions struct {
|
|
|
|
ReadOnly bool
|
|
|
|
AttachmentMode string
|
|
|
|
AccessMode string
|
2020-03-23 17:55:26 +00:00
|
|
|
MountOptions *structs.CSIMountOptions
|
2020-02-17 11:10:12 +00:00
|
|
|
}
|
|
|
|
|
2020-02-19 10:14:13 +00:00
|
|
|
// ToFS is used by a VolumeManager to construct the path to where a volume
|
|
|
|
// should be staged/published. It should always return a string that is easy
|
|
|
|
// enough to manage as a filesystem path segment (e.g avoid starting the string
|
|
|
|
// with a special character).
|
2020-02-17 11:10:12 +00:00
|
|
|
func (u *UsageOptions) ToFS() string {
|
|
|
|
var sb strings.Builder
|
|
|
|
|
|
|
|
if u.ReadOnly {
|
|
|
|
sb.WriteString("ro-")
|
|
|
|
} else {
|
|
|
|
sb.WriteString("rw-")
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.WriteString(u.AttachmentMode)
|
|
|
|
sb.WriteString("-")
|
|
|
|
sb.WriteString(u.AccessMode)
|
|
|
|
|
|
|
|
return sb.String()
|
|
|
|
}
|
|
|
|
|
2020-01-08 12:47:07 +00:00
|
|
|
type VolumeMounter interface {
|
2020-02-17 12:57:25 +00:00
|
|
|
MountVolume(ctx context.Context, vol *structs.CSIVolume, alloc *structs.Allocation, usageOpts *UsageOptions, publishContext map[string]string) (*MountInfo, error)
|
2020-02-17 11:10:12 +00:00
|
|
|
UnmountVolume(ctx context.Context, vol *structs.CSIVolume, alloc *structs.Allocation, usageOpts *UsageOptions) error
|
2020-01-08 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Manager interface {
|
|
|
|
// PluginManager returns a PluginManager for use by the node fingerprinter.
|
|
|
|
PluginManager() pluginmanager.PluginManager
|
|
|
|
|
|
|
|
// MounterForVolume returns a VolumeMounter for the given requested volume.
|
2020-01-28 16:27:32 +00:00
|
|
|
// If there is no plugin registered for this volume type, a PluginNotFoundErr
|
2020-01-08 12:47:07 +00:00
|
|
|
// will be returned.
|
|
|
|
MounterForVolume(ctx context.Context, volume *structs.CSIVolume) (VolumeMounter, error)
|
|
|
|
|
|
|
|
// Shutdown shuts down the Manager and unmounts any locally attached volumes.
|
|
|
|
Shutdown()
|
|
|
|
}
|