da4f6b60a2
The CSI Spec requires us to attach and stage volumes based on different types of usage information when it may effect how they are bound. Here we pass through some basic usage options in the CSI Hook (specifically the volume aliases ReadOnly field), and the attachment/access mode from the volume. We pass the attachment/access mode seperately from the volume as it simplifies some handling and doesn't necessarily force every attachment to use the same mode should more be supported (I.e if we let each `volume "foo" {}` specify an override in the future).
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package csimanager
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/nomad/client/pluginmanager"
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
)
|
|
|
|
var (
|
|
PluginNotFoundErr = errors.New("Plugin not found")
|
|
)
|
|
|
|
type MountInfo struct {
|
|
Source string
|
|
IsDevice bool
|
|
}
|
|
|
|
type UsageOptions struct {
|
|
ReadOnly bool
|
|
AttachmentMode string
|
|
AccessMode string
|
|
}
|
|
|
|
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()
|
|
}
|
|
|
|
type VolumeMounter interface {
|
|
MountVolume(ctx context.Context, vol *structs.CSIVolume, alloc *structs.Allocation, usageOpts *UsageOptions) (*MountInfo, error)
|
|
UnmountVolume(ctx context.Context, vol *structs.CSIVolume, alloc *structs.Allocation, usageOpts *UsageOptions) error
|
|
}
|
|
|
|
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.
|
|
// If there is no plugin registered for this volume type, a PluginNotFoundErr
|
|
// will be returned.
|
|
MounterForVolume(ctx context.Context, volume *structs.CSIVolume) (VolumeMounter, error)
|
|
|
|
// Shutdown shuts down the Manager and unmounts any locally attached volumes.
|
|
Shutdown()
|
|
}
|