f6b3d38eb8
If a volume-claiming alloc stops and the CSI Node plugin that serves that alloc's volumes is missing, there's no way for the allocrunner hook to send the `NodeUnpublish` and `NodeUnstage` RPCs. This changeset addresses this issue with a redesign of the client-side for CSI. Rather than unmounting in the alloc runner hook, the alloc runner hook will simply exit. When the server gets the `Node.UpdateAlloc` for the terminal allocation that had a volume claim, it creates a volume claim GC job. This job will made client RPCs to a new node plugin RPC endpoint, and only once that succeeds, move on to making the client RPCs to the controller plugin. If the node plugin is unavailable, the GC job will fail and be requeued.
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package csimanager
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/nomad/client/pluginmanager"
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
)
|
|
|
|
type MountInfo struct {
|
|
Source string
|
|
IsDevice bool
|
|
}
|
|
|
|
type UsageOptions struct {
|
|
ReadOnly bool
|
|
AttachmentMode string
|
|
AccessMode string
|
|
MountOptions *structs.CSIMountOptions
|
|
}
|
|
|
|
// 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).
|
|
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, publishContext map[string]string) (*MountInfo, error)
|
|
UnmountVolume(ctx context.Context, volID, allocID string, usageOpts *UsageOptions) error
|
|
}
|
|
|
|
type Manager interface {
|
|
// PluginManager returns a PluginManager for use by the node fingerprinter.
|
|
PluginManager() pluginmanager.PluginManager
|
|
|
|
// MounterForPlugin returns a VolumeMounter for the plugin ID associated
|
|
// with the volume. Returns an error if this plugin isn't registered.
|
|
MounterForPlugin(ctx context.Context, pluginID string) (VolumeMounter, error)
|
|
|
|
// Shutdown shuts down the Manager and unmounts any locally attached volumes.
|
|
Shutdown()
|
|
}
|