2019-10-22 13:20:26 +00:00
|
|
|
package csi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-24 16:20:23 +00:00
|
|
|
"errors"
|
2020-01-23 11:11:59 +00:00
|
|
|
"fmt"
|
2019-10-22 13:20:26 +00:00
|
|
|
|
|
|
|
csipbv1 "github.com/container-storage-interface/spec/lib/go/csi"
|
2020-02-18 16:07:27 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2019-10-22 13:20:26 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/base"
|
2020-01-29 11:32:31 +00:00
|
|
|
"google.golang.org/grpc"
|
2019-10-22 13:20:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CSIPlugin implements a lightweight abstraction layer around a CSI Plugin.
|
|
|
|
// It validates that responses from storage providers (SP's), correctly conform
|
|
|
|
// to the specification before returning response data or erroring.
|
|
|
|
type CSIPlugin interface {
|
|
|
|
base.BasePlugin
|
|
|
|
|
|
|
|
// PluginProbe is used to verify that the plugin is in a healthy state
|
|
|
|
PluginProbe(ctx context.Context) (bool, error)
|
|
|
|
|
|
|
|
// PluginGetInfo is used to return semantic data about the plugin.
|
|
|
|
// Response:
|
|
|
|
// - string: name, the name of the plugin in domain notation format.
|
2020-03-09 13:57:59 +00:00
|
|
|
// - string: version, the vendor version of the plugin
|
|
|
|
PluginGetInfo(ctx context.Context) (string, string, error)
|
2019-10-22 13:20:26 +00:00
|
|
|
|
|
|
|
// PluginGetCapabilities is used to return the available capabilities from the
|
|
|
|
// identity service. This currently only looks for the CONTROLLER_SERVICE and
|
|
|
|
// Accessible Topology Support
|
|
|
|
PluginGetCapabilities(ctx context.Context) (*PluginCapabilitySet, error)
|
|
|
|
|
2019-12-18 10:57:55 +00:00
|
|
|
// GetControllerCapabilities is used to get controller-specific capabilities
|
|
|
|
// for a plugin.
|
|
|
|
ControllerGetCapabilities(ctx context.Context) (*ControllerCapabilitySet, error)
|
|
|
|
|
2019-12-16 12:31:09 +00:00
|
|
|
// ControllerPublishVolume is used to attach a remote volume to a cluster node.
|
2020-03-30 20:26:03 +00:00
|
|
|
ControllerPublishVolume(ctx context.Context, req *ControllerPublishVolumeRequest, opts ...grpc.CallOption) (*ControllerPublishVolumeResponse, error)
|
2019-12-16 12:31:09 +00:00
|
|
|
|
2020-02-10 16:45:06 +00:00
|
|
|
// ControllerUnpublishVolume is used to deattach a remote volume from a cluster node.
|
2020-03-30 20:26:03 +00:00
|
|
|
ControllerUnpublishVolume(ctx context.Context, req *ControllerUnpublishVolumeRequest, opts ...grpc.CallOption) (*ControllerUnpublishVolumeResponse, error)
|
2020-02-10 16:45:06 +00:00
|
|
|
|
2020-02-18 16:08:00 +00:00
|
|
|
// ControllerValidateCapabilities is used to validate that a volume exists and
|
|
|
|
// supports the requested capability.
|
2020-05-15 12:16:01 +00:00
|
|
|
ControllerValidateCapabilities(ctx context.Context, req *ControllerValidateVolumeRequest, opts ...grpc.CallOption) error
|
2020-02-18 16:08:00 +00:00
|
|
|
|
2021-03-15 20:07:52 +00:00
|
|
|
// ControllerCreateVolume is used to create a remote volume in the
|
|
|
|
// external storage provider
|
|
|
|
ControllerCreateVolume(ctx context.Context, req *ControllerCreateVolumeRequest, opts ...grpc.CallOption) (*ControllerCreateVolumeResponse, error)
|
|
|
|
|
|
|
|
// ControllerDeleteVolume is used to delete a remote volume in the
|
|
|
|
// external storage provider
|
|
|
|
ControllerDeleteVolume(ctx context.Context, req *ControllerDeleteVolumeRequest, opts ...grpc.CallOption) error
|
|
|
|
|
|
|
|
// ControllerListVolumes is used to list all volumes available in the
|
|
|
|
// external storage provider
|
|
|
|
ControllerListVolumes(ctx context.Context, req *ControllerListVolumesRequest, opts ...grpc.CallOption) (*ControllerListVolumesResponse, error)
|
|
|
|
|
2021-04-01 15:16:52 +00:00
|
|
|
// ControllerCreateSnapshot is used to create a volume snapshot in the
|
|
|
|
// external storage provider
|
|
|
|
ControllerCreateSnapshot(ctx context.Context, req *ControllerCreateSnapshotRequest, opts ...grpc.CallOption) (*ControllerCreateSnapshotResponse, error)
|
|
|
|
|
|
|
|
// ControllerDeleteSnapshot is used to delete a volume snapshot from the
|
|
|
|
// external storage provider
|
|
|
|
ControllerDeleteSnapshot(ctx context.Context, req *ControllerDeleteSnapshotRequest, opts ...grpc.CallOption) error
|
|
|
|
|
|
|
|
// ControllerListSnapshots is used to list all volume snapshots available
|
|
|
|
// in the external storage provider
|
|
|
|
ControllerListSnapshots(ctx context.Context, req *ControllerListSnapshotsRequest, opts ...grpc.CallOption) (*ControllerListSnapshotsResponse, error)
|
|
|
|
|
2019-12-18 12:18:07 +00:00
|
|
|
// NodeGetCapabilities is used to return the available capabilities from the
|
|
|
|
// Node Service.
|
|
|
|
NodeGetCapabilities(ctx context.Context) (*NodeCapabilitySet, error)
|
|
|
|
|
2019-10-22 13:20:26 +00:00
|
|
|
// NodeGetInfo is used to return semantic data about the current node in
|
|
|
|
// respect to the SP.
|
|
|
|
NodeGetInfo(ctx context.Context) (*NodeGetInfoResponse, error)
|
|
|
|
|
2020-01-23 11:24:37 +00:00
|
|
|
// NodeStageVolume is used when a plugin has the STAGE_UNSTAGE volume capability
|
|
|
|
// to prepare a volume for usage on a host. If err == nil, the response should
|
|
|
|
// be assumed to be successful.
|
2020-06-22 17:54:32 +00:00
|
|
|
NodeStageVolume(ctx context.Context, req *NodeStageVolumeRequest, opts ...grpc.CallOption) error
|
2020-01-23 11:24:37 +00:00
|
|
|
|
2020-01-24 13:34:04 +00:00
|
|
|
// NodeUnstageVolume is used when a plugin has the STAGE_UNSTAGE volume capability
|
|
|
|
// to undo the work performed by NodeStageVolume. If a volume has been staged,
|
|
|
|
// this RPC must be called before freeing the volume.
|
|
|
|
//
|
|
|
|
// If err == nil, the response should be assumed to be successful.
|
2020-01-31 11:11:17 +00:00
|
|
|
NodeUnstageVolume(ctx context.Context, volumeID string, stagingTargetPath string, opts ...grpc.CallOption) error
|
2020-01-24 13:34:04 +00:00
|
|
|
|
2020-01-24 16:20:23 +00:00
|
|
|
// NodePublishVolume is used to prepare a volume for use by an allocation.
|
|
|
|
// if err == nil the response should be assumed to be successful.
|
2020-01-31 13:45:05 +00:00
|
|
|
NodePublishVolume(ctx context.Context, req *NodePublishVolumeRequest, opts ...grpc.CallOption) error
|
2020-01-24 16:20:23 +00:00
|
|
|
|
2020-01-27 10:17:10 +00:00
|
|
|
// NodeUnpublishVolume is used to cleanup usage of a volume for an alloc. This
|
|
|
|
// MUST be called before calling NodeUnstageVolume or ControllerUnpublishVolume
|
|
|
|
// for the given volume.
|
2020-02-14 12:33:52 +00:00
|
|
|
NodeUnpublishVolume(ctx context.Context, volumeID, targetPath string, opts ...grpc.CallOption) error
|
2020-01-27 10:17:10 +00:00
|
|
|
|
2019-10-22 13:20:26 +00:00
|
|
|
// Shutdown the client and ensure any connections are cleaned up.
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:20:23 +00:00
|
|
|
type NodePublishVolumeRequest struct {
|
2020-05-14 15:56:07 +00:00
|
|
|
// The external ID of the volume to publish.
|
|
|
|
ExternalID string
|
2020-01-24 16:20:23 +00:00
|
|
|
|
|
|
|
// If the volume was attached via a call to `ControllerPublishVolume` then
|
|
|
|
// we need to provide the returned PublishContext here.
|
|
|
|
PublishContext map[string]string
|
|
|
|
|
|
|
|
// The path to which the volume was staged by `NodeStageVolume`.
|
|
|
|
// It MUST be an absolute path in the root filesystem of the process
|
|
|
|
// serving this request.
|
|
|
|
// E.g {the plugins internal mount path}/staging/volumeid/...
|
|
|
|
//
|
|
|
|
// It MUST be set if the Node Plugin implements the
|
|
|
|
// `STAGE_UNSTAGE_VOLUME` node capability.
|
|
|
|
StagingTargetPath string
|
|
|
|
|
|
|
|
// The path to which the volume will be published.
|
|
|
|
// It MUST be an absolute path in the root filesystem of the process serving this
|
|
|
|
// request.
|
|
|
|
// E.g {the plugins internal mount path}/per-alloc/allocid/volumeid/...
|
|
|
|
//
|
|
|
|
// The CO SHALL ensure uniqueness of target_path per volume.
|
|
|
|
// The CO SHALL ensure that the parent directory of this path exists
|
|
|
|
// and that the process serving the request has `read` and `write`
|
|
|
|
// permissions to that parent directory.
|
|
|
|
TargetPath string
|
|
|
|
|
|
|
|
// Volume capability describing how the CO intends to use this volume.
|
|
|
|
VolumeCapability *VolumeCapability
|
|
|
|
|
|
|
|
Readonly bool
|
|
|
|
|
2020-05-11 21:12:51 +00:00
|
|
|
// Secrets required by plugins to complete the node publish volume
|
|
|
|
// request. This field is OPTIONAL.
|
|
|
|
Secrets structs.CSISecrets
|
2020-06-22 17:54:32 +00:00
|
|
|
|
|
|
|
// Volume context as returned by SP in the CSI
|
|
|
|
// CreateVolumeResponse.Volume.volume_context which we don't implement but
|
|
|
|
// can be entered by hand in the volume spec. This field is OPTIONAL.
|
|
|
|
VolumeContext map[string]string
|
2020-01-24 16:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *NodePublishVolumeRequest) ToCSIRepresentation() *csipbv1.NodePublishVolumeRequest {
|
2020-01-25 09:39:21 +00:00
|
|
|
if r == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:20:23 +00:00
|
|
|
return &csipbv1.NodePublishVolumeRequest{
|
2020-05-14 15:56:07 +00:00
|
|
|
VolumeId: r.ExternalID,
|
2020-01-24 16:20:23 +00:00
|
|
|
PublishContext: r.PublishContext,
|
|
|
|
StagingTargetPath: r.StagingTargetPath,
|
|
|
|
TargetPath: r.TargetPath,
|
|
|
|
VolumeCapability: r.VolumeCapability.ToCSIRepresentation(),
|
|
|
|
Readonly: r.Readonly,
|
|
|
|
Secrets: r.Secrets,
|
2020-06-22 17:54:32 +00:00
|
|
|
VolumeContext: r.VolumeContext,
|
2020-01-24 16:20:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *NodePublishVolumeRequest) Validate() error {
|
2020-05-14 15:56:07 +00:00
|
|
|
if r.ExternalID == "" {
|
|
|
|
return errors.New("missing volume ID")
|
2020-01-24 16:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if r.TargetPath == "" {
|
|
|
|
return errors.New("missing TargetPath")
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.VolumeCapability == nil {
|
|
|
|
return errors.New("missing VolumeCapabilities")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-22 17:54:32 +00:00
|
|
|
type NodeStageVolumeRequest struct {
|
|
|
|
// The external ID of the volume to stage.
|
|
|
|
ExternalID string
|
|
|
|
|
|
|
|
// If the volume was attached via a call to `ControllerPublishVolume` then
|
|
|
|
// we need to provide the returned PublishContext here.
|
|
|
|
PublishContext map[string]string
|
|
|
|
|
|
|
|
// The path to which the volume MAY be staged. It MUST be an
|
|
|
|
// absolute path in the root filesystem of the process serving this
|
|
|
|
// request, and MUST be a directory. The CO SHALL ensure that there
|
|
|
|
// is only one `staging_target_path` per volume. The CO SHALL ensure
|
|
|
|
// that the path is directory and that the process serving the
|
|
|
|
// request has `read` and `write` permission to that directory. The
|
|
|
|
// CO SHALL be responsible for creating the directory if it does not
|
|
|
|
// exist.
|
|
|
|
// This is a REQUIRED field.
|
|
|
|
StagingTargetPath string
|
|
|
|
|
|
|
|
// Volume capability describing how the CO intends to use this volume.
|
|
|
|
VolumeCapability *VolumeCapability
|
|
|
|
|
|
|
|
// Secrets required by plugins to complete the node stage volume
|
|
|
|
// request. This field is OPTIONAL.
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
|
|
|
|
// Volume context as returned by SP in the CSI
|
|
|
|
// CreateVolumeResponse.Volume.volume_context which we don't implement but
|
|
|
|
// can be entered by hand in the volume spec. This field is OPTIONAL.
|
|
|
|
VolumeContext map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *NodeStageVolumeRequest) ToCSIRepresentation() *csipbv1.NodeStageVolumeRequest {
|
|
|
|
if r == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &csipbv1.NodeStageVolumeRequest{
|
|
|
|
VolumeId: r.ExternalID,
|
|
|
|
PublishContext: r.PublishContext,
|
|
|
|
StagingTargetPath: r.StagingTargetPath,
|
|
|
|
VolumeCapability: r.VolumeCapability.ToCSIRepresentation(),
|
|
|
|
Secrets: r.Secrets,
|
|
|
|
VolumeContext: r.VolumeContext,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *NodeStageVolumeRequest) Validate() error {
|
|
|
|
if r.ExternalID == "" {
|
|
|
|
return errors.New("missing volume ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.StagingTargetPath == "" {
|
|
|
|
return errors.New("missing StagingTargetPath")
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.VolumeCapability == nil {
|
|
|
|
return errors.New("missing VolumeCapabilities")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-22 13:20:26 +00:00
|
|
|
type PluginCapabilitySet struct {
|
|
|
|
hasControllerService bool
|
|
|
|
hasTopologies bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PluginCapabilitySet) HasControllerService() bool {
|
|
|
|
return p.hasControllerService
|
|
|
|
}
|
|
|
|
|
2021-08-30 09:08:12 +00:00
|
|
|
// HasToplogies indicates whether the volumes for this plugin are equally
|
2019-10-22 13:20:26 +00:00
|
|
|
// accessible by all nodes in the cluster.
|
|
|
|
// If true, we MUST use the topology information when scheduling workloads.
|
|
|
|
func (p *PluginCapabilitySet) HasToplogies() bool {
|
|
|
|
return p.hasTopologies
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PluginCapabilitySet) IsEqual(o *PluginCapabilitySet) bool {
|
|
|
|
return p.hasControllerService == o.hasControllerService && p.hasTopologies == o.hasTopologies
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTestPluginCapabilitySet(topologies, controller bool) *PluginCapabilitySet {
|
|
|
|
return &PluginCapabilitySet{
|
|
|
|
hasTopologies: topologies,
|
|
|
|
hasControllerService: controller,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPluginCapabilitySet(capabilities *csipbv1.GetPluginCapabilitiesResponse) *PluginCapabilitySet {
|
|
|
|
cs := &PluginCapabilitySet{}
|
|
|
|
|
|
|
|
pluginCapabilities := capabilities.GetCapabilities()
|
|
|
|
|
|
|
|
for _, pcap := range pluginCapabilities {
|
|
|
|
if svcCap := pcap.GetService(); svcCap != nil {
|
|
|
|
switch svcCap.Type {
|
|
|
|
case csipbv1.PluginCapability_Service_UNKNOWN:
|
|
|
|
continue
|
|
|
|
case csipbv1.PluginCapability_Service_CONTROLLER_SERVICE:
|
|
|
|
cs.hasControllerService = true
|
|
|
|
case csipbv1.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS:
|
|
|
|
cs.hasTopologies = true
|
|
|
|
default:
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cs
|
|
|
|
}
|
2019-12-16 12:31:09 +00:00
|
|
|
|
2019-12-18 10:57:55 +00:00
|
|
|
type ControllerCapabilitySet struct {
|
2021-03-24 18:10:44 +00:00
|
|
|
HasCreateDeleteVolume bool
|
2019-12-18 10:57:55 +00:00
|
|
|
HasPublishUnpublishVolume bool
|
|
|
|
HasListVolumes bool
|
2021-03-24 18:10:44 +00:00
|
|
|
HasGetCapacity bool
|
|
|
|
HasCreateDeleteSnapshot bool
|
|
|
|
HasListSnapshots bool
|
|
|
|
HasCloneVolume bool
|
|
|
|
HasPublishReadonly bool
|
|
|
|
HasExpandVolume bool
|
2019-12-18 10:57:55 +00:00
|
|
|
HasListVolumesPublishedNodes bool
|
2021-03-24 18:10:44 +00:00
|
|
|
HasVolumeCondition bool
|
|
|
|
HasGetVolume bool
|
2019-12-18 10:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewControllerCapabilitySet(resp *csipbv1.ControllerGetCapabilitiesResponse) *ControllerCapabilitySet {
|
|
|
|
cs := &ControllerCapabilitySet{}
|
|
|
|
|
|
|
|
pluginCapabilities := resp.GetCapabilities()
|
|
|
|
for _, pcap := range pluginCapabilities {
|
|
|
|
if c := pcap.GetRpc(); c != nil {
|
|
|
|
switch c.Type {
|
2021-03-24 18:10:44 +00:00
|
|
|
case csipbv1.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME:
|
|
|
|
cs.HasCreateDeleteVolume = true
|
2019-12-18 10:57:55 +00:00
|
|
|
case csipbv1.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME:
|
|
|
|
cs.HasPublishUnpublishVolume = true
|
|
|
|
case csipbv1.ControllerServiceCapability_RPC_LIST_VOLUMES:
|
|
|
|
cs.HasListVolumes = true
|
2021-03-24 18:10:44 +00:00
|
|
|
case csipbv1.ControllerServiceCapability_RPC_GET_CAPACITY:
|
|
|
|
cs.HasGetCapacity = true
|
|
|
|
case csipbv1.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT:
|
|
|
|
cs.HasCreateDeleteSnapshot = true
|
|
|
|
case csipbv1.ControllerServiceCapability_RPC_LIST_SNAPSHOTS:
|
|
|
|
cs.HasListSnapshots = true
|
|
|
|
case csipbv1.ControllerServiceCapability_RPC_CLONE_VOLUME:
|
|
|
|
cs.HasCloneVolume = true
|
|
|
|
case csipbv1.ControllerServiceCapability_RPC_PUBLISH_READONLY:
|
|
|
|
cs.HasPublishReadonly = true
|
|
|
|
case csipbv1.ControllerServiceCapability_RPC_EXPAND_VOLUME:
|
|
|
|
cs.HasExpandVolume = true
|
2019-12-18 10:57:55 +00:00
|
|
|
case csipbv1.ControllerServiceCapability_RPC_LIST_VOLUMES_PUBLISHED_NODES:
|
|
|
|
cs.HasListVolumesPublishedNodes = true
|
2021-03-24 18:10:44 +00:00
|
|
|
case csipbv1.ControllerServiceCapability_RPC_VOLUME_CONDITION:
|
|
|
|
cs.HasVolumeCondition = true
|
|
|
|
case csipbv1.ControllerServiceCapability_RPC_GET_VOLUME:
|
|
|
|
cs.HasGetVolume = true
|
2019-12-18 10:57:55 +00:00
|
|
|
default:
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cs
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:16:01 +00:00
|
|
|
type ControllerValidateVolumeRequest struct {
|
|
|
|
ExternalID string
|
|
|
|
Secrets structs.CSISecrets
|
2021-06-03 19:47:55 +00:00
|
|
|
Capabilities []*VolumeCapability
|
2020-05-15 12:16:01 +00:00
|
|
|
Parameters map[string]string
|
|
|
|
Context map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerValidateVolumeRequest) ToCSIRepresentation() *csipbv1.ValidateVolumeCapabilitiesRequest {
|
|
|
|
if r == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-06-03 19:47:55 +00:00
|
|
|
caps := make([]*csipbv1.VolumeCapability, 0, len(r.Capabilities))
|
|
|
|
for _, cap := range r.Capabilities {
|
|
|
|
caps = append(caps, cap.ToCSIRepresentation())
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:16:01 +00:00
|
|
|
return &csipbv1.ValidateVolumeCapabilitiesRequest{
|
2021-06-03 19:47:55 +00:00
|
|
|
VolumeId: r.ExternalID,
|
|
|
|
VolumeContext: r.Context,
|
|
|
|
VolumeCapabilities: caps,
|
|
|
|
Parameters: r.Parameters,
|
|
|
|
Secrets: r.Secrets,
|
2020-05-15 12:16:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 12:31:09 +00:00
|
|
|
type ControllerPublishVolumeRequest struct {
|
2020-05-14 15:56:07 +00:00
|
|
|
ExternalID string
|
2020-02-21 10:55:41 +00:00
|
|
|
NodeID string
|
|
|
|
ReadOnly bool
|
|
|
|
VolumeCapability *VolumeCapability
|
2020-05-11 21:12:51 +00:00
|
|
|
Secrets structs.CSISecrets
|
2020-05-15 12:16:01 +00:00
|
|
|
VolumeContext map[string]string
|
2019-12-16 12:31:09 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 16:45:06 +00:00
|
|
|
func (r *ControllerPublishVolumeRequest) ToCSIRepresentation() *csipbv1.ControllerPublishVolumeRequest {
|
|
|
|
if r == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &csipbv1.ControllerPublishVolumeRequest{
|
2020-05-14 15:56:07 +00:00
|
|
|
VolumeId: r.ExternalID,
|
2020-02-21 10:55:41 +00:00
|
|
|
NodeId: r.NodeID,
|
|
|
|
Readonly: r.ReadOnly,
|
|
|
|
VolumeCapability: r.VolumeCapability.ToCSIRepresentation(),
|
2020-05-11 21:12:51 +00:00
|
|
|
Secrets: r.Secrets,
|
2020-05-15 12:16:01 +00:00
|
|
|
VolumeContext: r.VolumeContext,
|
2020-02-10 16:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerPublishVolumeRequest) Validate() error {
|
2020-05-14 15:56:07 +00:00
|
|
|
if r.ExternalID == "" {
|
|
|
|
return errors.New("missing volume ID")
|
2020-02-10 16:45:06 +00:00
|
|
|
}
|
|
|
|
if r.NodeID == "" {
|
|
|
|
return errors.New("missing NodeID")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-16 12:31:09 +00:00
|
|
|
type ControllerPublishVolumeResponse struct {
|
|
|
|
PublishContext map[string]string
|
|
|
|
}
|
2019-12-18 12:18:07 +00:00
|
|
|
|
2020-02-10 16:45:06 +00:00
|
|
|
type ControllerUnpublishVolumeRequest struct {
|
2020-05-14 15:56:07 +00:00
|
|
|
ExternalID string
|
|
|
|
NodeID string
|
|
|
|
Secrets structs.CSISecrets
|
2020-02-10 16:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerUnpublishVolumeRequest) ToCSIRepresentation() *csipbv1.ControllerUnpublishVolumeRequest {
|
|
|
|
if r == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &csipbv1.ControllerUnpublishVolumeRequest{
|
2020-05-14 15:56:07 +00:00
|
|
|
VolumeId: r.ExternalID,
|
2020-02-10 16:45:06 +00:00
|
|
|
NodeId: r.NodeID,
|
2020-05-11 21:12:51 +00:00
|
|
|
Secrets: r.Secrets,
|
2020-02-10 16:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerUnpublishVolumeRequest) Validate() error {
|
2020-05-14 15:56:07 +00:00
|
|
|
if r.ExternalID == "" {
|
|
|
|
return errors.New("missing ExternalID")
|
2020-02-10 16:45:06 +00:00
|
|
|
}
|
|
|
|
if r.NodeID == "" {
|
|
|
|
// the spec allows this but it would unpublish the
|
|
|
|
// volume from all nodes
|
|
|
|
return errors.New("missing NodeID")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControllerUnpublishVolumeResponse struct{}
|
|
|
|
|
2021-03-15 20:07:52 +00:00
|
|
|
type ControllerCreateVolumeRequest struct {
|
|
|
|
// note that Name is intentionally differentiated from both CSIVolume.ID
|
|
|
|
// and ExternalVolumeID. This name is only a recommendation for the
|
|
|
|
// storage provider, and many will discard this suggestion
|
|
|
|
Name string
|
|
|
|
CapacityRange *CapacityRange
|
|
|
|
VolumeCapabilities []*VolumeCapability
|
|
|
|
Parameters map[string]string
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
ContentSource *VolumeContentSource
|
|
|
|
AccessibilityRequirements *TopologyRequirement
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerCreateVolumeRequest) ToCSIRepresentation() *csipbv1.CreateVolumeRequest {
|
|
|
|
if r == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
caps := make([]*csipbv1.VolumeCapability, 0, len(r.VolumeCapabilities))
|
|
|
|
for _, cap := range r.VolumeCapabilities {
|
|
|
|
caps = append(caps, cap.ToCSIRepresentation())
|
|
|
|
}
|
|
|
|
req := &csipbv1.CreateVolumeRequest{
|
|
|
|
Name: r.Name,
|
|
|
|
CapacityRange: r.CapacityRange.ToCSIRepresentation(),
|
|
|
|
VolumeCapabilities: caps,
|
|
|
|
Parameters: r.Parameters,
|
|
|
|
Secrets: r.Secrets,
|
|
|
|
VolumeContentSource: r.ContentSource.ToCSIRepresentation(),
|
|
|
|
AccessibilityRequirements: r.AccessibilityRequirements.ToCSIRepresentation(),
|
|
|
|
}
|
|
|
|
|
|
|
|
return req
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerCreateVolumeRequest) Validate() error {
|
|
|
|
if r.Name == "" {
|
|
|
|
return errors.New("missing Name")
|
|
|
|
}
|
|
|
|
if r.VolumeCapabilities == nil {
|
|
|
|
return errors.New("missing VolumeCapabilities")
|
|
|
|
}
|
|
|
|
if r.CapacityRange != nil {
|
|
|
|
if r.CapacityRange.LimitBytes == 0 && r.CapacityRange.RequiredBytes == 0 {
|
|
|
|
return errors.New(
|
|
|
|
"one of LimitBytes or RequiredBytes must be set if CapacityRange is set")
|
|
|
|
}
|
|
|
|
if r.CapacityRange.LimitBytes < r.CapacityRange.RequiredBytes {
|
|
|
|
return errors.New("LimitBytes cannot be less than RequiredBytes")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if r.ContentSource != nil {
|
|
|
|
if r.ContentSource.CloneID != "" && r.ContentSource.SnapshotID != "" {
|
|
|
|
return errors.New(
|
|
|
|
"one of SnapshotID or CloneID must be set if ContentSource is set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// VolumeContentSource is snapshot or volume that the plugin will use to
|
|
|
|
// create the new volume. At most one of these fields can be set, but nil (and
|
|
|
|
// not an empty struct) is expected by CSI plugins if neither field is set.
|
|
|
|
type VolumeContentSource struct {
|
|
|
|
SnapshotID string
|
|
|
|
CloneID string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vcr *VolumeContentSource) ToCSIRepresentation() *csipbv1.VolumeContentSource {
|
|
|
|
if vcr == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if vcr.CloneID != "" {
|
|
|
|
return &csipbv1.VolumeContentSource{
|
|
|
|
Type: &csipbv1.VolumeContentSource_Volume{
|
|
|
|
Volume: &csipbv1.VolumeContentSource_VolumeSource{
|
|
|
|
VolumeId: vcr.CloneID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else if vcr.SnapshotID != "" {
|
|
|
|
return &csipbv1.VolumeContentSource{
|
|
|
|
Type: &csipbv1.VolumeContentSource_Snapshot{
|
|
|
|
Snapshot: &csipbv1.VolumeContentSource_SnapshotSource{
|
|
|
|
SnapshotId: vcr.SnapshotID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Nomad's RPCs will hand us an empty struct, not nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newVolumeContentSource(src *csipbv1.VolumeContentSource) *VolumeContentSource {
|
|
|
|
return &VolumeContentSource{
|
|
|
|
SnapshotID: src.GetSnapshot().GetSnapshotId(),
|
|
|
|
CloneID: src.GetVolume().GetVolumeId(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type TopologyRequirement struct {
|
|
|
|
Requisite []*Topology
|
|
|
|
Preferred []*Topology
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tr *TopologyRequirement) ToCSIRepresentation() *csipbv1.TopologyRequirement {
|
|
|
|
if tr == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
result := &csipbv1.TopologyRequirement{
|
|
|
|
Requisite: []*csipbv1.Topology{},
|
|
|
|
Preferred: []*csipbv1.Topology{},
|
|
|
|
}
|
|
|
|
for _, topo := range tr.Requisite {
|
|
|
|
result.Requisite = append(result.Requisite,
|
|
|
|
&csipbv1.Topology{Segments: topo.Segments})
|
|
|
|
}
|
|
|
|
for _, topo := range tr.Preferred {
|
|
|
|
result.Preferred = append(result.Preferred,
|
|
|
|
&csipbv1.Topology{Segments: topo.Segments})
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTopologies(src []*csipbv1.Topology) []*Topology {
|
|
|
|
t := []*Topology{}
|
|
|
|
for _, topo := range src {
|
|
|
|
t = append(t, &Topology{Segments: topo.Segments})
|
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControllerCreateVolumeResponse struct {
|
|
|
|
Volume *Volume
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCreateVolumeResponse(resp *csipbv1.CreateVolumeResponse) *ControllerCreateVolumeResponse {
|
|
|
|
vol := resp.GetVolume()
|
|
|
|
return &ControllerCreateVolumeResponse{Volume: &Volume{
|
2022-03-01 15:15:46 +00:00
|
|
|
CapacityBytes: vol.GetCapacityBytes(),
|
|
|
|
ExternalVolumeID: vol.GetVolumeId(),
|
|
|
|
VolumeContext: vol.GetVolumeContext(),
|
|
|
|
ContentSource: newVolumeContentSource(vol.GetContentSource()),
|
|
|
|
AccessibleTopology: newTopologies(vol.GetAccessibleTopology()),
|
2021-03-15 20:07:52 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Volume struct {
|
|
|
|
CapacityBytes int64
|
|
|
|
|
|
|
|
// this is differentiated from VolumeID so as not to create confusion
|
|
|
|
// between the Nomad CSIVolume.ID and the storage provider's ID.
|
|
|
|
ExternalVolumeID string
|
|
|
|
VolumeContext map[string]string
|
|
|
|
ContentSource *VolumeContentSource
|
|
|
|
AccessibleTopology []*Topology
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControllerDeleteVolumeRequest struct {
|
|
|
|
ExternalVolumeID string
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerDeleteVolumeRequest) ToCSIRepresentation() *csipbv1.DeleteVolumeRequest {
|
|
|
|
if r == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &csipbv1.DeleteVolumeRequest{
|
|
|
|
VolumeId: r.ExternalVolumeID,
|
|
|
|
Secrets: r.Secrets,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerDeleteVolumeRequest) Validate() error {
|
|
|
|
if r.ExternalVolumeID == "" {
|
|
|
|
return errors.New("missing ExternalVolumeID")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControllerListVolumesRequest struct {
|
|
|
|
MaxEntries int32
|
|
|
|
StartingToken string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerListVolumesRequest) ToCSIRepresentation() *csipbv1.ListVolumesRequest {
|
|
|
|
if r == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &csipbv1.ListVolumesRequest{
|
|
|
|
MaxEntries: r.MaxEntries,
|
|
|
|
StartingToken: r.StartingToken,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerListVolumesRequest) Validate() error {
|
|
|
|
if r.MaxEntries < 0 {
|
|
|
|
return errors.New("MaxEntries cannot be negative")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControllerListVolumesResponse struct {
|
|
|
|
Entries []*ListVolumesResponse_Entry
|
|
|
|
NextToken string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewListVolumesResponse(resp *csipbv1.ListVolumesResponse) *ControllerListVolumesResponse {
|
|
|
|
if resp == nil {
|
|
|
|
return &ControllerListVolumesResponse{}
|
|
|
|
}
|
|
|
|
entries := []*ListVolumesResponse_Entry{}
|
|
|
|
if resp.Entries != nil {
|
|
|
|
for _, entry := range resp.Entries {
|
|
|
|
vol := entry.GetVolume()
|
|
|
|
status := entry.GetStatus()
|
|
|
|
entries = append(entries, &ListVolumesResponse_Entry{
|
|
|
|
Volume: &Volume{
|
|
|
|
CapacityBytes: vol.CapacityBytes,
|
|
|
|
ExternalVolumeID: vol.VolumeId,
|
|
|
|
VolumeContext: vol.VolumeContext,
|
|
|
|
ContentSource: newVolumeContentSource(vol.ContentSource),
|
|
|
|
AccessibleTopology: newTopologies(vol.AccessibleTopology),
|
|
|
|
},
|
|
|
|
Status: &ListVolumesResponse_VolumeStatus{
|
|
|
|
PublishedNodeIds: status.GetPublishedNodeIds(),
|
|
|
|
VolumeCondition: &VolumeCondition{
|
|
|
|
Abnormal: status.GetVolumeCondition().GetAbnormal(),
|
|
|
|
Message: status.GetVolumeCondition().GetMessage(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &ControllerListVolumesResponse{
|
|
|
|
Entries: entries,
|
|
|
|
NextToken: resp.NextToken,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ListVolumesResponse_Entry struct {
|
|
|
|
Volume *Volume
|
|
|
|
Status *ListVolumesResponse_VolumeStatus
|
|
|
|
}
|
|
|
|
|
|
|
|
type ListVolumesResponse_VolumeStatus struct {
|
|
|
|
PublishedNodeIds []string
|
|
|
|
VolumeCondition *VolumeCondition
|
|
|
|
}
|
|
|
|
|
|
|
|
type VolumeCondition struct {
|
|
|
|
Abnormal bool
|
|
|
|
Message string
|
|
|
|
}
|
|
|
|
|
2021-04-01 15:16:52 +00:00
|
|
|
type ControllerCreateSnapshotRequest struct {
|
|
|
|
VolumeID string
|
|
|
|
Name string
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
Parameters map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerCreateSnapshotRequest) ToCSIRepresentation() *csipbv1.CreateSnapshotRequest {
|
|
|
|
return &csipbv1.CreateSnapshotRequest{
|
|
|
|
SourceVolumeId: r.VolumeID,
|
|
|
|
Name: r.Name,
|
|
|
|
Secrets: r.Secrets,
|
|
|
|
Parameters: r.Parameters,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerCreateSnapshotRequest) Validate() error {
|
|
|
|
if r.VolumeID == "" {
|
|
|
|
return errors.New("missing VolumeID")
|
|
|
|
}
|
|
|
|
if r.Name == "" {
|
|
|
|
return errors.New("missing Name")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControllerCreateSnapshotResponse struct {
|
|
|
|
Snapshot *Snapshot
|
|
|
|
}
|
|
|
|
|
|
|
|
type Snapshot struct {
|
|
|
|
ID string
|
|
|
|
SourceVolumeID string
|
|
|
|
SizeBytes int64
|
|
|
|
CreateTime int64
|
|
|
|
IsReady bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControllerDeleteSnapshotRequest struct {
|
|
|
|
SnapshotID string
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerDeleteSnapshotRequest) ToCSIRepresentation() *csipbv1.DeleteSnapshotRequest {
|
|
|
|
return &csipbv1.DeleteSnapshotRequest{
|
|
|
|
SnapshotId: r.SnapshotID,
|
|
|
|
Secrets: r.Secrets,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerDeleteSnapshotRequest) Validate() error {
|
|
|
|
if r.SnapshotID == "" {
|
|
|
|
return errors.New("missing SnapshotID")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControllerListSnapshotsRequest struct {
|
|
|
|
MaxEntries int32
|
|
|
|
StartingToken string
|
2021-07-03 00:46:41 +00:00
|
|
|
Secrets structs.CSISecrets
|
2021-04-01 15:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerListSnapshotsRequest) ToCSIRepresentation() *csipbv1.ListSnapshotsRequest {
|
|
|
|
return &csipbv1.ListSnapshotsRequest{
|
|
|
|
MaxEntries: r.MaxEntries,
|
|
|
|
StartingToken: r.StartingToken,
|
2021-07-03 00:46:41 +00:00
|
|
|
Secrets: r.Secrets,
|
2021-04-01 15:16:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerListSnapshotsRequest) Validate() error {
|
|
|
|
if r.MaxEntries < 0 {
|
|
|
|
return errors.New("MaxEntries cannot be negative")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewListSnapshotsResponse(resp *csipbv1.ListSnapshotsResponse) *ControllerListSnapshotsResponse {
|
|
|
|
if resp == nil {
|
|
|
|
return &ControllerListSnapshotsResponse{}
|
|
|
|
}
|
|
|
|
entries := []*ListSnapshotsResponse_Entry{}
|
|
|
|
if resp.Entries != nil {
|
|
|
|
for _, entry := range resp.Entries {
|
|
|
|
snap := entry.GetSnapshot()
|
|
|
|
entries = append(entries, &ListSnapshotsResponse_Entry{
|
|
|
|
Snapshot: &Snapshot{
|
|
|
|
SizeBytes: snap.GetSizeBytes(),
|
|
|
|
ID: snap.GetSnapshotId(),
|
|
|
|
SourceVolumeID: snap.GetSourceVolumeId(),
|
2022-03-23 14:39:28 +00:00
|
|
|
CreateTime: snap.GetCreationTime().GetSeconds(),
|
2021-04-01 15:16:52 +00:00
|
|
|
IsReady: snap.GetReadyToUse(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &ControllerListSnapshotsResponse{
|
|
|
|
Entries: entries,
|
|
|
|
NextToken: resp.NextToken,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControllerListSnapshotsResponse struct {
|
|
|
|
Entries []*ListSnapshotsResponse_Entry
|
|
|
|
NextToken string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ListSnapshotsResponse_Entry struct {
|
|
|
|
Snapshot *Snapshot
|
|
|
|
}
|
|
|
|
|
2019-12-18 12:18:07 +00:00
|
|
|
type NodeCapabilitySet struct {
|
|
|
|
HasStageUnstageVolume bool
|
2021-04-01 19:39:38 +00:00
|
|
|
HasGetVolumeStats bool
|
|
|
|
HasExpandVolume bool
|
|
|
|
HasVolumeCondition bool
|
2019-12-18 12:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewNodeCapabilitySet(resp *csipbv1.NodeGetCapabilitiesResponse) *NodeCapabilitySet {
|
|
|
|
cs := &NodeCapabilitySet{}
|
|
|
|
pluginCapabilities := resp.GetCapabilities()
|
|
|
|
for _, pcap := range pluginCapabilities {
|
|
|
|
if c := pcap.GetRpc(); c != nil {
|
|
|
|
switch c.Type {
|
|
|
|
case csipbv1.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME:
|
|
|
|
cs.HasStageUnstageVolume = true
|
2021-04-01 19:39:38 +00:00
|
|
|
case csipbv1.NodeServiceCapability_RPC_GET_VOLUME_STATS:
|
|
|
|
cs.HasGetVolumeStats = true
|
|
|
|
case csipbv1.NodeServiceCapability_RPC_EXPAND_VOLUME:
|
|
|
|
cs.HasExpandVolume = true
|
|
|
|
case csipbv1.NodeServiceCapability_RPC_VOLUME_CONDITION:
|
|
|
|
cs.HasVolumeCondition = true
|
2019-12-18 12:18:07 +00:00
|
|
|
default:
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cs
|
|
|
|
}
|
2020-01-23 11:11:59 +00:00
|
|
|
|
|
|
|
// VolumeAccessMode represents the desired access mode of the CSI Volume
|
|
|
|
type VolumeAccessMode csipbv1.VolumeCapability_AccessMode_Mode
|
|
|
|
|
|
|
|
var _ fmt.Stringer = VolumeAccessModeUnknown
|
|
|
|
|
|
|
|
var (
|
|
|
|
VolumeAccessModeUnknown = VolumeAccessMode(csipbv1.VolumeCapability_AccessMode_UNKNOWN)
|
|
|
|
VolumeAccessModeSingleNodeWriter = VolumeAccessMode(csipbv1.VolumeCapability_AccessMode_SINGLE_NODE_WRITER)
|
|
|
|
VolumeAccessModeSingleNodeReaderOnly = VolumeAccessMode(csipbv1.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY)
|
|
|
|
VolumeAccessModeMultiNodeReaderOnly = VolumeAccessMode(csipbv1.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY)
|
|
|
|
VolumeAccessModeMultiNodeSingleWriter = VolumeAccessMode(csipbv1.VolumeCapability_AccessMode_MULTI_NODE_SINGLE_WRITER)
|
|
|
|
VolumeAccessModeMultiNodeMultiWriter = VolumeAccessMode(csipbv1.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER)
|
|
|
|
)
|
|
|
|
|
|
|
|
func (a VolumeAccessMode) String() string {
|
|
|
|
return a.ToCSIRepresentation().String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a VolumeAccessMode) ToCSIRepresentation() csipbv1.VolumeCapability_AccessMode_Mode {
|
|
|
|
return csipbv1.VolumeCapability_AccessMode_Mode(a)
|
|
|
|
}
|
|
|
|
|
|
|
|
// VolumeAccessType represents the filesystem apis that the user intends to use
|
|
|
|
// with the volume. E.g whether it will be used as a block device or if they wish
|
|
|
|
// to have a mounted filesystem.
|
|
|
|
type VolumeAccessType int32
|
|
|
|
|
|
|
|
var _ fmt.Stringer = VolumeAccessTypeBlock
|
|
|
|
|
|
|
|
var (
|
|
|
|
VolumeAccessTypeBlock VolumeAccessType = 1
|
|
|
|
VolumeAccessTypeMount VolumeAccessType = 2
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v VolumeAccessType) String() string {
|
|
|
|
if v == VolumeAccessTypeBlock {
|
|
|
|
return "VolumeAccessType.Block"
|
|
|
|
} else if v == VolumeAccessTypeMount {
|
|
|
|
return "VolumeAccessType.Mount"
|
|
|
|
} else {
|
|
|
|
return "VolumeAccessType.Unspecified"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// VolumeCapability describes the overall usage requirements for a given CSI Volume
|
|
|
|
type VolumeCapability struct {
|
2020-03-23 17:55:26 +00:00
|
|
|
AccessType VolumeAccessType
|
|
|
|
AccessMode VolumeAccessMode
|
|
|
|
|
|
|
|
// Indicate that the volume will be accessed via the filesystem API.
|
|
|
|
MountVolume *structs.CSIMountOptions
|
2020-01-23 11:11:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-22 15:53:29 +00:00
|
|
|
func VolumeCapabilityFromStructs(sAccessType structs.CSIVolumeAttachmentMode, sAccessMode structs.CSIVolumeAccessMode, sMountOptions *structs.CSIMountOptions) (*VolumeCapability, error) {
|
2020-02-18 16:07:27 +00:00
|
|
|
var accessType VolumeAccessType
|
|
|
|
switch sAccessType {
|
|
|
|
case structs.CSIVolumeAttachmentModeBlockDevice:
|
|
|
|
accessType = VolumeAccessTypeBlock
|
|
|
|
case structs.CSIVolumeAttachmentModeFilesystem:
|
|
|
|
accessType = VolumeAccessTypeMount
|
|
|
|
default:
|
|
|
|
// These fields are validated during job submission, but here we perform a
|
|
|
|
// final check during transformation into the requisite CSI Data type to
|
|
|
|
// defend against development bugs and corrupted state - and incompatible
|
|
|
|
// nomad versions in the future.
|
2021-03-22 13:43:30 +00:00
|
|
|
return nil, fmt.Errorf("unknown volume attachment mode: %s", sAccessType)
|
2020-02-18 16:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var accessMode VolumeAccessMode
|
|
|
|
switch sAccessMode {
|
|
|
|
case structs.CSIVolumeAccessModeSingleNodeReader:
|
|
|
|
accessMode = VolumeAccessModeSingleNodeReaderOnly
|
|
|
|
case structs.CSIVolumeAccessModeSingleNodeWriter:
|
|
|
|
accessMode = VolumeAccessModeSingleNodeWriter
|
|
|
|
case structs.CSIVolumeAccessModeMultiNodeMultiWriter:
|
|
|
|
accessMode = VolumeAccessModeMultiNodeMultiWriter
|
|
|
|
case structs.CSIVolumeAccessModeMultiNodeSingleWriter:
|
|
|
|
accessMode = VolumeAccessModeMultiNodeSingleWriter
|
|
|
|
case structs.CSIVolumeAccessModeMultiNodeReader:
|
|
|
|
accessMode = VolumeAccessModeMultiNodeReaderOnly
|
|
|
|
default:
|
|
|
|
// These fields are validated during job submission, but here we perform a
|
|
|
|
// final check during transformation into the requisite CSI Data type to
|
|
|
|
// defend against development bugs and corrupted state - and incompatible
|
|
|
|
// nomad versions in the future.
|
2021-03-22 13:43:30 +00:00
|
|
|
return nil, fmt.Errorf("unknown volume access mode: %v", sAccessMode)
|
2020-02-18 16:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &VolumeCapability{
|
2021-05-22 15:53:29 +00:00
|
|
|
AccessType: accessType,
|
|
|
|
AccessMode: accessMode,
|
|
|
|
MountVolume: sMountOptions,
|
2020-02-18 16:07:27 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-01-23 11:11:59 +00:00
|
|
|
func (c *VolumeCapability) ToCSIRepresentation() *csipbv1.VolumeCapability {
|
2020-01-25 09:39:21 +00:00
|
|
|
if c == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-23 11:11:59 +00:00
|
|
|
vc := &csipbv1.VolumeCapability{
|
|
|
|
AccessMode: &csipbv1.VolumeCapability_AccessMode{
|
|
|
|
Mode: c.AccessMode.ToCSIRepresentation(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.AccessType == VolumeAccessTypeMount {
|
2020-03-23 17:55:26 +00:00
|
|
|
opts := &csipbv1.VolumeCapability_MountVolume{}
|
|
|
|
if c.MountVolume != nil {
|
|
|
|
opts.FsType = c.MountVolume.FSType
|
|
|
|
opts.MountFlags = c.MountVolume.MountFlags
|
2020-01-23 11:11:59 +00:00
|
|
|
}
|
2020-03-23 17:55:26 +00:00
|
|
|
vc.AccessType = &csipbv1.VolumeCapability_Mount{Mount: opts}
|
2020-01-23 11:11:59 +00:00
|
|
|
} else {
|
|
|
|
vc.AccessType = &csipbv1.VolumeCapability_Block{Block: &csipbv1.VolumeCapability_BlockVolume{}}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vc
|
|
|
|
}
|
2021-03-15 20:07:52 +00:00
|
|
|
|
|
|
|
type CapacityRange struct {
|
|
|
|
RequiredBytes int64
|
|
|
|
LimitBytes int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CapacityRange) ToCSIRepresentation() *csipbv1.CapacityRange {
|
|
|
|
if c == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &csipbv1.CapacityRange{
|
|
|
|
RequiredBytes: c.RequiredBytes,
|
|
|
|
LimitBytes: c.LimitBytes,
|
|
|
|
}
|
|
|
|
}
|