2019-12-16 13:19:59 +00:00
|
|
|
package structs
|
|
|
|
|
2020-01-08 19:52:06 +00:00
|
|
|
import (
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"github.com/hashicorp/nomad/plugins/csi"
|
2019-12-17 11:09:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CSIVolumeMountOptions contains the mount options that should be provided when
|
|
|
|
// attaching and mounting a volume with the CSIVolumeAttachmentModeFilesystem
|
|
|
|
// attachment mode.
|
|
|
|
type CSIVolumeMountOptions struct {
|
|
|
|
// Filesystem is the desired filesystem type that should be used by the volume
|
|
|
|
// (e.g ext4, aufs, zfs). This field is optional.
|
|
|
|
Filesystem string
|
|
|
|
|
|
|
|
// MountFlags contain the mount options that should be used for the volume.
|
|
|
|
// These may contain _sensitive_ data and should not be leaked to logs or
|
|
|
|
// returned in debugging data.
|
|
|
|
// The total size of this field must be under 4KiB.
|
|
|
|
MountFlags []string
|
|
|
|
}
|
|
|
|
|
2021-03-22 13:43:30 +00:00
|
|
|
// CSIControllerRequest interface lets us set embedded CSIControllerQuery
|
|
|
|
// fields in the server
|
|
|
|
type CSIControllerRequest interface {
|
|
|
|
SetControllerNodeID(string)
|
|
|
|
}
|
|
|
|
|
2020-02-21 10:32:10 +00:00
|
|
|
// CSIControllerQuery is used to specify various flags for queries against CSI
|
|
|
|
// Controllers
|
|
|
|
type CSIControllerQuery struct {
|
|
|
|
// ControllerNodeID is the node that should be targeted by the request
|
|
|
|
ControllerNodeID string
|
|
|
|
|
|
|
|
// PluginID is the plugin that should be targeted on the given node.
|
2020-02-18 16:08:38 +00:00
|
|
|
PluginID string
|
2020-02-21 10:32:10 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 13:43:30 +00:00
|
|
|
func (c *CSIControllerQuery) SetControllerNodeID(nodeID string) {
|
|
|
|
c.ControllerNodeID = nodeID
|
|
|
|
}
|
|
|
|
|
2020-02-21 10:32:10 +00:00
|
|
|
type ClientCSIControllerValidateVolumeRequest struct {
|
2020-04-04 15:03:44 +00:00
|
|
|
VolumeID string // note: this is the external ID
|
2020-02-18 16:08:38 +00:00
|
|
|
|
|
|
|
AttachmentMode structs.CSIVolumeAttachmentMode
|
|
|
|
AccessMode structs.CSIVolumeAccessMode
|
2020-05-11 21:12:51 +00:00
|
|
|
Secrets structs.CSISecrets
|
2020-05-15 12:16:01 +00:00
|
|
|
|
|
|
|
// Parameters as returned by storage provider in CreateVolumeResponse.
|
|
|
|
// This field is optional.
|
|
|
|
Parameters map[string]string
|
|
|
|
|
|
|
|
// Volume context as returned by storage provider in CreateVolumeResponse.
|
|
|
|
// This field is optional.
|
|
|
|
Context map[string]string
|
2020-02-21 10:32:10 +00:00
|
|
|
|
|
|
|
CSIControllerQuery
|
2020-02-18 16:08:38 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 12:16:01 +00:00
|
|
|
func (c *ClientCSIControllerValidateVolumeRequest) ToCSIRequest() (*csi.ControllerValidateVolumeRequest, error) {
|
|
|
|
if c == nil {
|
|
|
|
return &csi.ControllerValidateVolumeRequest{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
caps, err := csi.VolumeCapabilityFromStructs(c.AttachmentMode, c.AccessMode)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &csi.ControllerValidateVolumeRequest{
|
|
|
|
ExternalID: c.VolumeID,
|
|
|
|
Secrets: c.Secrets,
|
|
|
|
Capabilities: caps,
|
|
|
|
Parameters: c.Parameters,
|
|
|
|
Context: c.Context,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-02-18 16:08:38 +00:00
|
|
|
type ClientCSIControllerValidateVolumeResponse struct {
|
|
|
|
}
|
|
|
|
|
2019-12-17 11:37:33 +00:00
|
|
|
type ClientCSIControllerAttachVolumeRequest struct {
|
2020-04-04 15:03:44 +00:00
|
|
|
// The external ID of the volume to be used on a node.
|
2019-12-16 13:19:59 +00:00
|
|
|
// This field is REQUIRED.
|
|
|
|
VolumeID string
|
|
|
|
|
|
|
|
// The ID of the node. This field is REQUIRED. This must match the NodeID that
|
|
|
|
// is fingerprinted by the target node for this plugin name.
|
2020-02-21 10:32:10 +00:00
|
|
|
ClientCSINodeID string
|
2019-12-16 13:19:59 +00:00
|
|
|
|
2019-12-17 11:09:57 +00:00
|
|
|
// AttachmentMode indicates how the volume should be attached and mounted into
|
|
|
|
// a task.
|
2020-01-08 19:52:06 +00:00
|
|
|
AttachmentMode structs.CSIVolumeAttachmentMode
|
2019-12-17 11:09:57 +00:00
|
|
|
|
|
|
|
// AccessMode indicates the desired concurrent access model for the volume
|
2020-01-08 19:52:06 +00:00
|
|
|
AccessMode structs.CSIVolumeAccessMode
|
2019-12-16 13:19:59 +00:00
|
|
|
|
2019-12-17 11:09:57 +00:00
|
|
|
// MountOptions is an optional field that contains additional configuration
|
|
|
|
// when providing an AttachmentMode of CSIVolumeAttachmentModeFilesystem
|
|
|
|
MountOptions *CSIVolumeMountOptions
|
2019-12-16 13:19:59 +00:00
|
|
|
|
2019-12-17 11:09:57 +00:00
|
|
|
// ReadOnly indicates that the volume will be used in a readonly fashion. This
|
|
|
|
// only works when the Controller has the PublishReadonly capability.
|
2019-12-16 13:19:59 +00:00
|
|
|
ReadOnly bool
|
2020-02-21 10:32:10 +00:00
|
|
|
|
2020-05-11 21:12:51 +00:00
|
|
|
// Secrets required by plugin to complete the controller publish
|
|
|
|
// volume request. This field is OPTIONAL.
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
|
|
|
|
// Volume context as returned by storage provider in CreateVolumeResponse.
|
|
|
|
// This field is optional.
|
2020-05-15 12:16:01 +00:00
|
|
|
VolumeContext map[string]string
|
2020-05-11 21:12:51 +00:00
|
|
|
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery
|
2019-12-16 13:19:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 10:55:41 +00:00
|
|
|
func (c *ClientCSIControllerAttachVolumeRequest) ToCSIRequest() (*csi.ControllerPublishVolumeRequest, error) {
|
2019-12-16 13:19:59 +00:00
|
|
|
if c == nil {
|
2020-02-21 10:55:41 +00:00
|
|
|
return &csi.ControllerPublishVolumeRequest{}, nil
|
2019-12-16 13:19:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 10:55:41 +00:00
|
|
|
caps, err := csi.VolumeCapabilityFromStructs(c.AttachmentMode, c.AccessMode)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2019-12-16 13:19:59 +00:00
|
|
|
}
|
2020-02-21 10:55:41 +00:00
|
|
|
|
|
|
|
return &csi.ControllerPublishVolumeRequest{
|
2020-05-14 15:56:07 +00:00
|
|
|
ExternalID: c.VolumeID,
|
2020-02-21 10:55:41 +00:00
|
|
|
NodeID: c.ClientCSINodeID,
|
|
|
|
VolumeCapability: caps,
|
2020-05-11 21:12:51 +00:00
|
|
|
ReadOnly: c.ReadOnly,
|
|
|
|
Secrets: c.Secrets,
|
2020-05-15 12:16:01 +00:00
|
|
|
VolumeContext: c.VolumeContext,
|
2020-02-21 10:55:41 +00:00
|
|
|
}, nil
|
2019-12-16 13:19:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-02 20:04:56 +00:00
|
|
|
// ClientCSIControllerDetachVolumeRequest is the RPC made from the server to
|
|
|
|
// a Nomad client to tell a CSI controller plugin on that client to perform
|
|
|
|
// ControllerUnpublish for a volume on a specific client.
|
2019-12-17 11:37:33 +00:00
|
|
|
type ClientCSIControllerAttachVolumeResponse struct {
|
2019-12-16 13:19:59 +00:00
|
|
|
// Opaque static publish properties of the volume. SP MAY use this
|
|
|
|
// field to ensure subsequent `NodeStageVolume` or `NodePublishVolume`
|
|
|
|
// calls calls have contextual information.
|
|
|
|
// The contents of this field SHALL be opaque to nomad.
|
|
|
|
// The contents of this field SHALL NOT be mutable.
|
|
|
|
// The contents of this field SHALL be safe for the nomad to cache.
|
|
|
|
// The contents of this field SHOULD NOT contain sensitive
|
|
|
|
// information.
|
|
|
|
// The contents of this field SHOULD NOT be used for uniquely
|
|
|
|
// identifying a volume. The `volume_id` alone SHOULD be sufficient to
|
|
|
|
// identify the volume.
|
|
|
|
// This field is OPTIONAL and when present MUST be passed to
|
|
|
|
// subsequent `NodeStageVolume` or `NodePublishVolume` calls
|
|
|
|
PublishContext map[string]string
|
|
|
|
}
|
2020-02-10 16:45:06 +00:00
|
|
|
|
|
|
|
type ClientCSIControllerDetachVolumeRequest struct {
|
2020-05-14 15:56:07 +00:00
|
|
|
// The external ID of the volume to be unpublished for the node
|
2020-02-10 16:45:06 +00:00
|
|
|
// This field is REQUIRED.
|
|
|
|
VolumeID string
|
|
|
|
|
2020-02-21 10:32:10 +00:00
|
|
|
// The CSI Node ID for the Node that the volume should be detached from.
|
|
|
|
// This field is REQUIRED. This must match the NodeID that is fingerprinted
|
|
|
|
// by the target node for this plugin name.
|
|
|
|
ClientCSINodeID string
|
|
|
|
|
2020-05-11 21:12:51 +00:00
|
|
|
// Secrets required by plugin to complete the controller unpublish
|
|
|
|
// volume request. This field is OPTIONAL.
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery
|
2020-02-10 16:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientCSIControllerDetachVolumeRequest) ToCSIRequest() *csi.ControllerUnpublishVolumeRequest {
|
|
|
|
if c == nil {
|
|
|
|
return &csi.ControllerUnpublishVolumeRequest{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &csi.ControllerUnpublishVolumeRequest{
|
2020-05-14 15:56:07 +00:00
|
|
|
ExternalID: c.VolumeID,
|
|
|
|
NodeID: c.ClientCSINodeID,
|
2020-02-10 16:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientCSIControllerDetachVolumeResponse struct{}
|
2020-04-02 20:04:56 +00:00
|
|
|
|
2021-03-22 13:43:30 +00:00
|
|
|
// ClientCSIControllerCreateVolumeRequest the RPC made from the server to a
|
|
|
|
// Nomad client to tell a CSI controller plugin on that client to perform
|
|
|
|
// CreateVolume
|
|
|
|
type ClientCSIControllerCreateVolumeRequest struct {
|
|
|
|
Name string
|
|
|
|
VolumeCapabilities []*structs.CSIVolumeCapability
|
|
|
|
Parameters map[string]string
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
CapacityMin int64
|
|
|
|
CapacityMax int64
|
|
|
|
SnapshotID string
|
|
|
|
CloneID string
|
|
|
|
// TODO: topology is not yet supported
|
|
|
|
// TopologyRequirement
|
|
|
|
|
|
|
|
CSIControllerQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (req *ClientCSIControllerCreateVolumeRequest) ToCSIRequest() (*csi.ControllerCreateVolumeRequest, error) {
|
|
|
|
|
|
|
|
creq := &csi.ControllerCreateVolumeRequest{
|
|
|
|
Name: req.Name,
|
|
|
|
CapacityRange: &csi.CapacityRange{
|
|
|
|
RequiredBytes: req.CapacityMin,
|
|
|
|
LimitBytes: req.CapacityMax,
|
|
|
|
},
|
|
|
|
VolumeCapabilities: []*csi.VolumeCapability{},
|
|
|
|
Parameters: req.Parameters,
|
|
|
|
Secrets: req.Secrets,
|
|
|
|
ContentSource: &csi.VolumeContentSource{
|
|
|
|
CloneID: req.CloneID,
|
|
|
|
SnapshotID: req.SnapshotID,
|
|
|
|
},
|
|
|
|
// TODO: topology is not yet supported
|
|
|
|
AccessibilityRequirements: &csi.TopologyRequirement{},
|
|
|
|
}
|
|
|
|
for _, cap := range req.VolumeCapabilities {
|
|
|
|
ccap, err := csi.VolumeCapabilityFromStructs(cap.AttachmentMode, cap.AccessMode)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
creq.VolumeCapabilities = append(creq.VolumeCapabilities, ccap)
|
|
|
|
}
|
|
|
|
return creq, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientCSIControllerCreateVolumeResponse struct {
|
|
|
|
ExternalVolumeID string
|
|
|
|
CapacityBytes int64
|
|
|
|
VolumeContext map[string]string
|
|
|
|
|
|
|
|
// TODO: topology is not yet supported
|
|
|
|
// AccessibleTopology []*Topology
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClientCSIControllerDeleteVolumeRequest the RPC made from the server to a
|
|
|
|
// Nomad client to tell a CSI controller plugin on that client to perform
|
|
|
|
// DeleteVolume
|
|
|
|
type ClientCSIControllerDeleteVolumeRequest struct {
|
|
|
|
ExternalVolumeID string
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
|
|
|
|
CSIControllerQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (req *ClientCSIControllerDeleteVolumeRequest) ToCSIRequest() *csi.ControllerDeleteVolumeRequest {
|
|
|
|
return &csi.ControllerDeleteVolumeRequest{
|
|
|
|
ExternalVolumeID: req.ExternalVolumeID,
|
|
|
|
Secrets: req.Secrets,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientCSIControllerDeleteVolumeResponse struct{}
|
|
|
|
|
|
|
|
// ClientCSIControllerListVolumesVolumeRequest the RPC made from the server to
|
|
|
|
// a Nomad client to tell a CSI controller plugin on that client to perform
|
|
|
|
// ListVolumes
|
|
|
|
type ClientCSIControllerListVolumesRequest struct {
|
2021-03-23 13:45:14 +00:00
|
|
|
// these pagination fields match the pagination fields of the plugins and
|
|
|
|
// not Nomad's own fields, for clarity when mapping between the two RPCs
|
2021-03-22 13:43:30 +00:00
|
|
|
MaxEntries int32
|
|
|
|
StartingToken string
|
|
|
|
|
|
|
|
CSIControllerQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (req *ClientCSIControllerListVolumesRequest) ToCSIRequest() *csi.ControllerListVolumesRequest {
|
|
|
|
return &csi.ControllerListVolumesRequest{
|
|
|
|
MaxEntries: req.MaxEntries,
|
|
|
|
StartingToken: req.StartingToken,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientCSIControllerListVolumesResponse struct {
|
|
|
|
Entries []*structs.CSIVolumeExternalStub
|
|
|
|
NextToken string
|
|
|
|
}
|
|
|
|
|
2021-04-01 15:16:52 +00:00
|
|
|
// ClientCSIControllerCreateSnapshotRequest the RPC made from the server to a
|
|
|
|
// Nomad client to tell a CSI controller plugin on that client to perform
|
|
|
|
// CreateSnapshot
|
|
|
|
type ClientCSIControllerCreateSnapshotRequest struct {
|
|
|
|
ExternalSourceVolumeID string
|
|
|
|
Name string
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
Parameters map[string]string
|
|
|
|
|
|
|
|
CSIControllerQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (req *ClientCSIControllerCreateSnapshotRequest) ToCSIRequest() (*csi.ControllerCreateSnapshotRequest, error) {
|
|
|
|
return &csi.ControllerCreateSnapshotRequest{
|
|
|
|
VolumeID: req.ExternalSourceVolumeID,
|
|
|
|
Name: req.Name,
|
|
|
|
Secrets: req.Secrets,
|
|
|
|
Parameters: req.Parameters,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientCSIControllerCreateSnapshotResponse struct {
|
|
|
|
ID string
|
|
|
|
ExternalSourceVolumeID string
|
|
|
|
SizeBytes int64
|
|
|
|
CreateTime int64
|
|
|
|
IsReady bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClientCSIControllerDeleteSnapshotRequest the RPC made from the server to a
|
|
|
|
// Nomad client to tell a CSI controller plugin on that client to perform
|
|
|
|
// DeleteSnapshot
|
|
|
|
type ClientCSIControllerDeleteSnapshotRequest struct {
|
|
|
|
ID string
|
|
|
|
Secrets structs.CSISecrets
|
|
|
|
|
|
|
|
CSIControllerQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (req *ClientCSIControllerDeleteSnapshotRequest) ToCSIRequest() *csi.ControllerDeleteSnapshotRequest {
|
|
|
|
return &csi.ControllerDeleteSnapshotRequest{
|
|
|
|
SnapshotID: req.ID,
|
|
|
|
Secrets: req.Secrets,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientCSIControllerDeleteSnapshotResponse struct{}
|
|
|
|
|
|
|
|
// ClientCSIControllerListSnapshotsRequest is the RPC made from the server to
|
|
|
|
// a Nomad client to tell a CSI controller plugin on that client to perform
|
|
|
|
// ListSnapshots
|
|
|
|
type ClientCSIControllerListSnapshotsRequest struct {
|
|
|
|
// these pagination fields match the pagination fields of the plugins and
|
|
|
|
// not Nomad's own fields, for clarity when mapping between the two RPCs
|
|
|
|
MaxEntries int32
|
|
|
|
StartingToken string
|
|
|
|
|
|
|
|
CSIControllerQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (req *ClientCSIControllerListSnapshotsRequest) ToCSIRequest() *csi.ControllerListSnapshotsRequest {
|
|
|
|
return &csi.ControllerListSnapshotsRequest{
|
|
|
|
MaxEntries: req.MaxEntries,
|
|
|
|
StartingToken: req.StartingToken,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientCSIControllerListSnapshotsResponse struct {
|
|
|
|
Entries []*structs.CSISnapshot
|
|
|
|
NextToken string
|
|
|
|
}
|
|
|
|
|
2020-04-02 20:04:56 +00:00
|
|
|
// ClientCSINodeDetachVolumeRequest is the RPC made from the server to
|
|
|
|
// a Nomad client to tell a CSI node plugin on that client to perform
|
|
|
|
// NodeUnpublish and NodeUnstage.
|
|
|
|
type ClientCSINodeDetachVolumeRequest struct {
|
2020-04-04 15:03:44 +00:00
|
|
|
PluginID string // ID of the plugin that manages the volume (required)
|
|
|
|
VolumeID string // ID of the volume to be unpublished (required)
|
|
|
|
AllocID string // ID of the allocation we're unpublishing for (required)
|
|
|
|
NodeID string // ID of the Nomad client targeted
|
|
|
|
ExternalID string // External ID of the volume to be unpublished (required)
|
2020-04-02 20:04:56 +00:00
|
|
|
|
|
|
|
// These fields should match the original volume request so that
|
|
|
|
// we can find the mount points on the client
|
|
|
|
AttachmentMode structs.CSIVolumeAttachmentMode
|
|
|
|
AccessMode structs.CSIVolumeAccessMode
|
|
|
|
ReadOnly bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientCSINodeDetachVolumeResponse struct{}
|