github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/client/pluginmanager/csimanager/interface.go (about)

     1  package csimanager
     2  
     3  import (
     4  	"context"
     5  	"strings"
     6  
     7  	"github.com/hashicorp/nomad/client/pluginmanager"
     8  	"github.com/hashicorp/nomad/nomad/structs"
     9  )
    10  
    11  type MountInfo struct {
    12  	Source   string
    13  	IsDevice bool
    14  }
    15  
    16  type UsageOptions struct {
    17  	ReadOnly       bool
    18  	AttachmentMode string
    19  	AccessMode     string
    20  	MountOptions   *structs.CSIMountOptions
    21  }
    22  
    23  // ToFS is used by a VolumeManager to construct the path to where a volume
    24  // should be staged/published. It should always return a string that is easy
    25  // enough to manage as a filesystem path segment (e.g avoid starting the string
    26  // with a special character).
    27  func (u *UsageOptions) ToFS() string {
    28  	var sb strings.Builder
    29  
    30  	if u.ReadOnly {
    31  		sb.WriteString("ro-")
    32  	} else {
    33  		sb.WriteString("rw-")
    34  	}
    35  
    36  	sb.WriteString(u.AttachmentMode)
    37  	sb.WriteString("-")
    38  	sb.WriteString(u.AccessMode)
    39  
    40  	return sb.String()
    41  }
    42  
    43  type VolumeMounter interface {
    44  	MountVolume(ctx context.Context, vol *structs.CSIVolume, alloc *structs.Allocation, usageOpts *UsageOptions, publishContext map[string]string) (*MountInfo, error)
    45  	UnmountVolume(ctx context.Context, volID, remoteID, allocID string, usageOpts *UsageOptions) error
    46  }
    47  
    48  type Manager interface {
    49  	// PluginManager returns a PluginManager for use by the node fingerprinter.
    50  	PluginManager() pluginmanager.PluginManager
    51  
    52  	// MounterForPlugin returns a VolumeMounter for the plugin ID associated
    53  	// with the volume.	Returns an error if this plugin isn't registered.
    54  	MounterForPlugin(ctx context.Context, pluginID string) (VolumeMounter, error)
    55  
    56  	// Shutdown shuts down the Manager and unmounts any locally attached volumes.
    57  	Shutdown()
    58  }