2019-12-18 18:14:42 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-07-01 16:17:51 +00:00
|
|
|
"fmt"
|
|
|
|
"net/url"
|
2019-12-18 18:14:42 +00:00
|
|
|
"sort"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSIVolumes is used to access Container Storage Interface (CSI) endpoints.
|
2019-12-18 18:14:42 +00:00
|
|
|
type CSIVolumes struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSIVolumes returns a handle on the CSIVolumes endpoint.
|
2019-12-18 18:14:42 +00:00
|
|
|
func (c *Client) CSIVolumes() *CSIVolumes {
|
|
|
|
return &CSIVolumes{client: c}
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// List returns all CSI volumes.
|
2019-12-18 18:14:42 +00:00
|
|
|
func (v *CSIVolumes) List(q *QueryOptions) ([]*CSIVolumeListStub, *QueryMeta, error) {
|
|
|
|
var resp []*CSIVolumeListStub
|
2020-03-12 18:20:40 +00:00
|
|
|
qm, err := v.client.query("/v1/volumes?type=csi", &resp, q)
|
2019-12-18 18:14:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
sort.Sort(CSIVolumeIndexSort(resp))
|
|
|
|
return resp, qm, nil
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// ListExternal returns all CSI volumes, as understood by the external storage
|
|
|
|
// provider. These volumes may or may not be currently registered with Nomad.
|
|
|
|
// The response is paginated by the plugin and accepts the
|
|
|
|
// QueryOptions.PerPage and QueryOptions.NextToken fields.
|
2021-03-23 13:45:14 +00:00
|
|
|
func (v *CSIVolumes) ListExternal(pluginID string, q *QueryOptions) (*CSIVolumeListExternalResponse, *QueryMeta, error) {
|
|
|
|
var resp *CSIVolumeListExternalResponse
|
|
|
|
|
|
|
|
qp := url.Values{}
|
|
|
|
qp.Set("plugin_id", pluginID)
|
|
|
|
if q.NextToken != "" {
|
|
|
|
qp.Set("next_token", q.NextToken)
|
|
|
|
}
|
|
|
|
if q.PerPage != 0 {
|
|
|
|
qp.Set("per_page", fmt.Sprint(q.PerPage))
|
|
|
|
}
|
|
|
|
|
|
|
|
qm, err := v.client.query("/v1/volumes/external?"+qp.Encode(), &resp, q)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Sort(CSIVolumeExternalStubSort(resp.Volumes))
|
|
|
|
return resp, qm, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginList returns all CSI volumes for the specified plugin id
|
|
|
|
func (v *CSIVolumes) PluginList(pluginID string) ([]*CSIVolumeListStub, *QueryMeta, error) {
|
|
|
|
return v.List(&QueryOptions{Prefix: pluginID})
|
|
|
|
}
|
|
|
|
|
2020-01-28 15:28:34 +00:00
|
|
|
// Info is used to retrieve a single CSIVolume
|
2019-12-18 18:14:42 +00:00
|
|
|
func (v *CSIVolumes) Info(id string, q *QueryOptions) (*CSIVolume, *QueryMeta, error) {
|
|
|
|
var resp CSIVolume
|
2020-03-12 18:20:40 +00:00
|
|
|
qm, err := v.client.query("/v1/volume/csi/"+id, &resp, q)
|
2019-12-18 18:14:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2020-03-06 15:09:10 +00:00
|
|
|
|
2019-12-18 18:14:42 +00:00
|
|
|
return &resp, qm, nil
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// Register registers a single CSIVolume with Nomad. The volume must already
|
|
|
|
// exist in the external storage provider.
|
2020-01-28 15:28:34 +00:00
|
|
|
func (v *CSIVolumes) Register(vol *CSIVolume, w *WriteOptions) (*WriteMeta, error) {
|
2019-12-18 18:14:42 +00:00
|
|
|
req := CSIVolumeRegisterRequest{
|
|
|
|
Volumes: []*CSIVolume{vol},
|
|
|
|
}
|
2020-03-12 18:20:40 +00:00
|
|
|
meta, err := v.client.write("/v1/volume/csi/"+vol.ID, req, nil, w)
|
2020-01-28 15:28:34 +00:00
|
|
|
return meta, err
|
2019-12-18 18:14:42 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// Deregister deregisters a single CSIVolume from Nomad. The volume will not be deleted from the external storage provider.
|
2020-07-01 16:17:51 +00:00
|
|
|
func (v *CSIVolumes) Deregister(id string, force bool, w *WriteOptions) error {
|
2020-07-08 14:08:22 +00:00
|
|
|
_, err := v.client.delete(fmt.Sprintf("/v1/volume/csi/%v?force=%t", url.PathEscape(id), force), nil, w)
|
2019-12-18 18:14:42 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// Create creates a single CSIVolume in an external storage provider and
|
|
|
|
// registers it with Nomad. You do not need to call Register if this call is
|
|
|
|
// successful.
|
2021-03-23 13:45:14 +00:00
|
|
|
func (v *CSIVolumes) Create(vol *CSIVolume, w *WriteOptions) ([]*CSIVolume, *WriteMeta, error) {
|
|
|
|
req := CSIVolumeCreateRequest{
|
|
|
|
Volumes: []*CSIVolume{vol},
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := &CSIVolumeCreateResponse{}
|
|
|
|
meta, err := v.client.write(fmt.Sprintf("/v1/volume/csi/%v/create", vol.ID), req, resp, w)
|
|
|
|
return resp.Volumes, meta, err
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// Delete deletes a CSI volume from an external storage provider. The ID
|
|
|
|
// passed as an argument here is for the storage provider's ID, so a volume
|
|
|
|
// that's already been deregistered can be deleted.
|
2021-03-23 13:45:14 +00:00
|
|
|
func (v *CSIVolumes) Delete(externalVolID string, w *WriteOptions) error {
|
|
|
|
_, err := v.client.delete(fmt.Sprintf("/v1/volume/csi/%v/delete", url.PathEscape(externalVolID)), nil, w)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// Detach causes Nomad to attempt to detach a CSI volume from a client
|
|
|
|
// node. This is used in the case that the node is temporarily lost and the
|
|
|
|
// allocations are unable to drop their claims automatically.
|
2020-08-11 14:18:54 +00:00
|
|
|
func (v *CSIVolumes) Detach(volID, nodeID string, w *WriteOptions) error {
|
|
|
|
_, err := v.client.delete(fmt.Sprintf("/v1/volume/csi/%v/detach?node=%v", url.PathEscape(volID), nodeID), nil, w)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-01 15:16:52 +00:00
|
|
|
// CreateSnapshot snapshots an external storage volume.
|
2021-04-07 12:44:12 +00:00
|
|
|
func (v *CSIVolumes) CreateSnapshot(snap *CSISnapshot, w *WriteOptions) (*CSISnapshotCreateResponse, *WriteMeta, error) {
|
2021-04-01 15:16:52 +00:00
|
|
|
req := &CSISnapshotCreateRequest{
|
|
|
|
Snapshots: []*CSISnapshot{snap},
|
|
|
|
}
|
|
|
|
resp := &CSISnapshotCreateResponse{}
|
2021-04-03 07:50:23 +00:00
|
|
|
meta, err := v.client.write("/v1/volumes/snapshot", req, resp, w)
|
2021-04-07 12:44:12 +00:00
|
|
|
return resp, meta, err
|
2021-04-01 15:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteSnapshot deletes an external storage volume snapshot.
|
|
|
|
func (v *CSIVolumes) DeleteSnapshot(snap *CSISnapshot, w *WriteOptions) error {
|
|
|
|
req := &CSISnapshotDeleteRequest{
|
|
|
|
Snapshots: []*CSISnapshot{snap},
|
|
|
|
}
|
2021-04-03 07:50:23 +00:00
|
|
|
_, err := v.client.delete("/v1/volumes/snapshot", req, w)
|
2021-04-01 15:16:52 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListSnapshots lists external storage volume snapshots.
|
|
|
|
func (v *CSIVolumes) ListSnapshots(pluginID string, q *QueryOptions) (*CSISnapshotListResponse, *QueryMeta, error) {
|
|
|
|
var resp *CSISnapshotListResponse
|
|
|
|
|
|
|
|
qp := url.Values{}
|
|
|
|
if pluginID != "" {
|
|
|
|
qp.Set("plugin_id", pluginID)
|
|
|
|
}
|
|
|
|
if q.NextToken != "" {
|
|
|
|
qp.Set("next_token", q.NextToken)
|
|
|
|
}
|
|
|
|
if q.PerPage != 0 {
|
|
|
|
qp.Set("per_page", fmt.Sprint(q.PerPage))
|
|
|
|
}
|
|
|
|
|
|
|
|
qm, err := v.client.query("/v1/volumes/snapshots?"+qp.Encode(), &resp, q)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Sort(CSISnapshotSort(resp.Snapshots))
|
|
|
|
return resp, qm, nil
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSIVolumeAttachmentMode chooses the type of storage api that will be used to
|
|
|
|
// interact with the device. (Duplicated in nomad/structs/csi.go)
|
2019-12-18 18:14:42 +00:00
|
|
|
type CSIVolumeAttachmentMode string
|
|
|
|
|
|
|
|
const (
|
|
|
|
CSIVolumeAttachmentModeUnknown CSIVolumeAttachmentMode = ""
|
|
|
|
CSIVolumeAttachmentModeBlockDevice CSIVolumeAttachmentMode = "block-device"
|
|
|
|
CSIVolumeAttachmentModeFilesystem CSIVolumeAttachmentMode = "file-system"
|
|
|
|
)
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSIVolumeAccessMode indicates how a volume should be used in a storage topology
|
|
|
|
// e.g whether the provider should make the volume available concurrently. (Duplicated in nomad/structs/csi.go)
|
2019-12-18 18:14:42 +00:00
|
|
|
type CSIVolumeAccessMode string
|
|
|
|
|
|
|
|
const (
|
2021-04-01 13:50:07 +00:00
|
|
|
CSIVolumeAccessModeUnknown CSIVolumeAccessMode = ""
|
|
|
|
CSIVolumeAccessModeSingleNodeReader CSIVolumeAccessMode = "single-node-reader-only"
|
|
|
|
CSIVolumeAccessModeSingleNodeWriter CSIVolumeAccessMode = "single-node-writer"
|
2019-12-18 18:14:42 +00:00
|
|
|
CSIVolumeAccessModeMultiNodeReader CSIVolumeAccessMode = "multi-node-reader-only"
|
|
|
|
CSIVolumeAccessModeMultiNodeSingleWriter CSIVolumeAccessMode = "multi-node-single-writer"
|
|
|
|
CSIVolumeAccessModeMultiNodeMultiWriter CSIVolumeAccessMode = "multi-node-multi-writer"
|
|
|
|
)
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSIMountOptions contain optional additional configuration that can be used
|
|
|
|
// when specifying that a Volume should be used with VolumeAccessTypeMount.
|
2020-03-23 17:55:26 +00:00
|
|
|
type CSIMountOptions struct {
|
2021-04-01 13:50:07 +00:00
|
|
|
// FSType is an optional field that allows an operator to specify the type
|
|
|
|
// of the filesystem.
|
|
|
|
FSType string `hcl:"fs_type,optional"`
|
|
|
|
|
|
|
|
// MountFlags contains additional options that may be used when mounting the
|
|
|
|
// volume by the plugin. This may contain sensitive data and should not be
|
|
|
|
// leaked.
|
|
|
|
MountFlags []string `hcl:"mount_flags,optional"`
|
|
|
|
|
2020-10-21 13:58:45 +00:00
|
|
|
ExtraKeysHCL []string `hcl1:",unusedKeys" json:"-"` // report unexpected keys
|
2020-03-23 17:55:26 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSISecrets contain optional additional credentials that may be needed by
|
|
|
|
// the storage provider. These values will be redacted when reported in the
|
|
|
|
// API or in Nomad's logs.
|
2020-05-11 21:12:51 +00:00
|
|
|
type CSISecrets map[string]string
|
|
|
|
|
2019-12-18 18:14:42 +00:00
|
|
|
// CSIVolume is used for serialization, see also nomad/structs/csi.go
|
|
|
|
type CSIVolume struct {
|
2020-03-23 17:55:26 +00:00
|
|
|
ID string
|
|
|
|
Name string
|
2021-03-23 13:11:18 +00:00
|
|
|
ExternalID string `mapstructure:"external_id" hcl:"external_id"`
|
2020-03-23 17:55:26 +00:00
|
|
|
Namespace string
|
|
|
|
Topologies []*CSITopology
|
2020-03-06 15:09:10 +00:00
|
|
|
AccessMode CSIVolumeAccessMode `hcl:"access_mode"`
|
|
|
|
AttachmentMode CSIVolumeAttachmentMode `hcl:"attachment_mode"`
|
2020-03-23 17:55:26 +00:00
|
|
|
MountOptions *CSIMountOptions `hcl:"mount_options"`
|
2021-03-23 13:11:18 +00:00
|
|
|
Secrets CSISecrets `mapstructure:"secrets" hcl:"secrets"`
|
|
|
|
Parameters map[string]string `mapstructure:"parameters" hcl:"parameters"`
|
|
|
|
Context map[string]string `mapstructure:"context" hcl:"context"`
|
2021-03-23 13:45:14 +00:00
|
|
|
Capacity int64 `hcl:"-"`
|
|
|
|
|
|
|
|
// These fields are used as part of the volume creation request
|
|
|
|
RequestedCapacityMin int64 `hcl:"capacity_min"`
|
|
|
|
RequestedCapacityMax int64 `hcl:"capacity_max"`
|
|
|
|
RequestedCapabilities []*CSIVolumeCapability `hcl:"capability"`
|
2021-03-23 13:11:18 +00:00
|
|
|
CloneID string `mapstructure:"clone_id" hcl:"clone_id"`
|
|
|
|
SnapshotID string `mapstructure:"snapshot_id" hcl:"snapshot_id"`
|
2020-03-06 15:09:10 +00:00
|
|
|
|
2020-11-25 21:44:06 +00:00
|
|
|
// ReadAllocs is a map of allocation IDs for tracking reader claim status.
|
|
|
|
// The Allocation value will always be nil; clients can populate this data
|
|
|
|
// by iterating over the Allocations field.
|
|
|
|
ReadAllocs map[string]*Allocation
|
|
|
|
|
|
|
|
// WriteAllocs is a map of allocation IDs for tracking writer claim
|
|
|
|
// status. The Allocation value will always be nil; clients can populate
|
|
|
|
// this data by iterating over the Allocations field.
|
2020-03-06 15:09:10 +00:00
|
|
|
WriteAllocs map[string]*Allocation
|
|
|
|
|
2020-11-25 21:44:06 +00:00
|
|
|
// Allocations is a combined list of readers and writers
|
2019-12-18 18:14:42 +00:00
|
|
|
Allocations []*AllocationListStub
|
|
|
|
|
2020-03-06 15:09:10 +00:00
|
|
|
// Schedulable is true if all the denormalized plugin health fields are true
|
2020-03-03 15:59:58 +00:00
|
|
|
Schedulable bool
|
2021-03-23 13:11:18 +00:00
|
|
|
PluginID string `mapstructure:"plugin_id" hcl:"plugin_id"`
|
2020-03-09 13:57:59 +00:00
|
|
|
Provider string
|
|
|
|
ProviderVersion string
|
2020-03-03 15:59:58 +00:00
|
|
|
ControllerRequired bool
|
2020-01-28 15:28:34 +00:00
|
|
|
ControllersHealthy int
|
|
|
|
ControllersExpected int
|
|
|
|
NodesHealthy int
|
|
|
|
NodesExpected int
|
|
|
|
ResourceExhausted time.Time
|
|
|
|
|
|
|
|
CreateIndex uint64
|
|
|
|
ModifyIndex uint64
|
2020-03-06 15:09:10 +00:00
|
|
|
|
|
|
|
// ExtraKeysHCL is used by the hcl parser to report unexpected keys
|
2020-10-21 13:58:45 +00:00
|
|
|
ExtraKeysHCL []string `hcl1:",unusedKeys" json:"-"`
|
2020-03-06 15:09:10 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 13:45:14 +00:00
|
|
|
// CSIVolumeCapability is a requested attachment and access mode for a
|
|
|
|
// volume
|
|
|
|
type CSIVolumeCapability struct {
|
2021-03-23 13:11:18 +00:00
|
|
|
AccessMode CSIVolumeAccessMode `mapstructure:"access_mode" hcl:"access_mode"`
|
|
|
|
AttachmentMode CSIVolumeAttachmentMode `mapstructure:"attachment_mode" hcl:"attachment_mode"`
|
2021-03-23 13:45:14 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSIVolumeIndexSort is a helper used for sorting volume stubs by creation
|
|
|
|
// time.
|
2019-12-18 18:14:42 +00:00
|
|
|
type CSIVolumeIndexSort []*CSIVolumeListStub
|
|
|
|
|
|
|
|
func (v CSIVolumeIndexSort) Len() int {
|
|
|
|
return len(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v CSIVolumeIndexSort) Less(i, j int) bool {
|
2020-01-28 15:28:34 +00:00
|
|
|
return v[i].CreateIndex > v[j].CreateIndex
|
2019-12-18 18:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v CSIVolumeIndexSort) Swap(i, j int) {
|
|
|
|
v[i], v[j] = v[j], v[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSIVolumeListStub omits allocations. See also nomad/structs/csi.go
|
|
|
|
type CSIVolumeListStub struct {
|
2020-03-03 15:59:58 +00:00
|
|
|
ID string
|
|
|
|
Namespace string
|
|
|
|
Name string
|
|
|
|
ExternalID string
|
|
|
|
Topologies []*CSITopology
|
|
|
|
AccessMode CSIVolumeAccessMode
|
|
|
|
AttachmentMode CSIVolumeAttachmentMode
|
|
|
|
Schedulable bool
|
2020-01-28 15:28:34 +00:00
|
|
|
PluginID string
|
2020-03-09 13:57:59 +00:00
|
|
|
Provider string
|
2020-03-03 15:59:58 +00:00
|
|
|
ControllerRequired bool
|
2020-01-28 15:28:34 +00:00
|
|
|
ControllersHealthy int
|
|
|
|
ControllersExpected int
|
|
|
|
NodesHealthy int
|
|
|
|
NodesExpected int
|
|
|
|
ResourceExhausted time.Time
|
|
|
|
|
|
|
|
CreateIndex uint64
|
|
|
|
ModifyIndex uint64
|
2019-12-18 18:14:42 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 13:45:14 +00:00
|
|
|
type CSIVolumeListExternalResponse struct {
|
|
|
|
Volumes []*CSIVolumeExternalStub
|
|
|
|
NextToken string
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSIVolumeExternalStub is the storage provider's view of a volume, as
|
|
|
|
// returned from the controller plugin; all IDs are for external resources
|
|
|
|
type CSIVolumeExternalStub struct {
|
|
|
|
ExternalID string
|
|
|
|
CapacityBytes int64
|
|
|
|
VolumeContext map[string]string
|
|
|
|
CloneID string
|
|
|
|
SnapshotID string
|
|
|
|
PublishedExternalNodeIDs []string
|
|
|
|
IsAbnormal bool
|
|
|
|
Status string
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSIVolumeExternalStubSort is a sorting helper for external volumes. We
|
|
|
|
// can't sort these by creation time because we don't get that data back from
|
|
|
|
// the storage provider. Sort by External ID within this page.
|
2021-03-23 13:45:14 +00:00
|
|
|
type CSIVolumeExternalStubSort []*CSIVolumeExternalStub
|
|
|
|
|
|
|
|
func (v CSIVolumeExternalStubSort) Len() int {
|
|
|
|
return len(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v CSIVolumeExternalStubSort) Less(i, j int) bool {
|
|
|
|
return v[i].ExternalID > v[j].ExternalID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v CSIVolumeExternalStubSort) Swap(i, j int) {
|
|
|
|
v[i], v[j] = v[j], v[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
type CSIVolumeCreateRequest struct {
|
|
|
|
Volumes []*CSIVolume
|
|
|
|
WriteRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
type CSIVolumeCreateResponse struct {
|
|
|
|
Volumes []*CSIVolume
|
|
|
|
QueryMeta
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:14:42 +00:00
|
|
|
type CSIVolumeRegisterRequest struct {
|
|
|
|
Volumes []*CSIVolume
|
|
|
|
WriteRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
type CSIVolumeDeregisterRequest struct {
|
|
|
|
VolumeIDs []string
|
|
|
|
WriteRequest
|
|
|
|
}
|
2020-01-28 15:28:34 +00:00
|
|
|
|
2021-04-01 15:16:52 +00:00
|
|
|
// CSISnapshot is the storage provider's view of a volume snapshot
|
|
|
|
type CSISnapshot struct {
|
|
|
|
ID string // storage provider's ID
|
|
|
|
ExternalSourceVolumeID string // storage provider's ID for volume
|
|
|
|
SizeBytes int64 // value from storage provider
|
|
|
|
CreateTime int64 // value from storage provider
|
|
|
|
IsReady bool // value from storage provider
|
|
|
|
SourceVolumeID string // Nomad volume ID
|
|
|
|
PluginID string // CSI plugin ID
|
|
|
|
|
|
|
|
// These field are only used during snapshot creation and will not be
|
|
|
|
// populated when the snapshot is returned
|
|
|
|
Name string // suggested name of the snapshot, used for creation
|
|
|
|
Secrets CSISecrets // secrets needed to create snapshot
|
|
|
|
Parameters map[string]string // secrets needed to create snapshot
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSISnapshotSort is a helper used for sorting snapshots by creation time.
|
|
|
|
type CSISnapshotSort []*CSISnapshot
|
|
|
|
|
|
|
|
func (v CSISnapshotSort) Len() int {
|
|
|
|
return len(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v CSISnapshotSort) Less(i, j int) bool {
|
|
|
|
return v[i].CreateTime > v[j].CreateTime
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v CSISnapshotSort) Swap(i, j int) {
|
|
|
|
v[i], v[j] = v[j], v[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
type CSISnapshotCreateRequest struct {
|
|
|
|
Snapshots []*CSISnapshot
|
|
|
|
WriteRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
type CSISnapshotCreateResponse struct {
|
|
|
|
Snapshots []*CSISnapshot
|
|
|
|
QueryMeta
|
|
|
|
}
|
|
|
|
|
|
|
|
type CSISnapshotDeleteRequest struct {
|
|
|
|
Snapshots []*CSISnapshot
|
|
|
|
WriteRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSISnapshotListRequest is a request to a controller plugin to list all the
|
|
|
|
// snapshot known to the the storage provider. This request is paginated by
|
|
|
|
// the plugin and accepts the QueryOptions.PerPage and QueryOptions.NextToken
|
|
|
|
// fields
|
|
|
|
type CSISnapshotListRequest struct {
|
|
|
|
PluginID string
|
|
|
|
QueryOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
type CSISnapshotListResponse struct {
|
|
|
|
Snapshots []*CSISnapshot
|
|
|
|
NextToken string
|
|
|
|
QueryMeta
|
|
|
|
}
|
|
|
|
|
2020-01-28 15:28:34 +00:00
|
|
|
// CSI Plugins are jobs with plugin specific data
|
|
|
|
type CSIPlugins struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSIPlugin is used for serialization, see also nomad/structs/csi.go
|
2020-01-28 15:28:34 +00:00
|
|
|
type CSIPlugin struct {
|
2020-03-03 15:59:58 +00:00
|
|
|
ID string
|
2020-03-09 13:57:59 +00:00
|
|
|
Provider string
|
|
|
|
Version string
|
2020-03-03 15:59:58 +00:00
|
|
|
ControllerRequired bool
|
2020-02-21 19:48:16 +00:00
|
|
|
// Map Node.ID to CSIInfo fingerprint results
|
2020-05-07 16:37:51 +00:00
|
|
|
Controllers map[string]*CSIInfo
|
|
|
|
Nodes map[string]*CSIInfo
|
|
|
|
Allocations []*AllocationListStub
|
|
|
|
ControllersHealthy int
|
|
|
|
ControllersExpected int
|
|
|
|
NodesHealthy int
|
|
|
|
NodesExpected int
|
|
|
|
CreateIndex uint64
|
|
|
|
ModifyIndex uint64
|
2020-01-28 15:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type CSIPluginListStub struct {
|
|
|
|
ID string
|
2020-03-09 13:57:59 +00:00
|
|
|
Provider string
|
2020-03-03 15:59:58 +00:00
|
|
|
ControllerRequired bool
|
2020-01-28 15:28:34 +00:00
|
|
|
ControllersHealthy int
|
|
|
|
ControllersExpected int
|
|
|
|
NodesHealthy int
|
|
|
|
NodesExpected int
|
|
|
|
CreateIndex uint64
|
|
|
|
ModifyIndex uint64
|
|
|
|
}
|
|
|
|
|
2021-04-01 13:50:07 +00:00
|
|
|
// CSIPluginIndexSort is a helper used for sorting plugin stubs by creation
|
|
|
|
// time.
|
2020-01-28 15:28:34 +00:00
|
|
|
type CSIPluginIndexSort []*CSIPluginListStub
|
|
|
|
|
|
|
|
func (v CSIPluginIndexSort) Len() int {
|
|
|
|
return len(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v CSIPluginIndexSort) Less(i, j int) bool {
|
|
|
|
return v[i].CreateIndex > v[j].CreateIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v CSIPluginIndexSort) Swap(i, j int) {
|
|
|
|
v[i], v[j] = v[j], v[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSIPlugins returns a handle on the CSIPlugins endpoint
|
|
|
|
func (c *Client) CSIPlugins() *CSIPlugins {
|
|
|
|
return &CSIPlugins{client: c}
|
|
|
|
}
|
|
|
|
|
|
|
|
// List returns all CSI plugins
|
|
|
|
func (v *CSIPlugins) List(q *QueryOptions) ([]*CSIPluginListStub, *QueryMeta, error) {
|
|
|
|
var resp []*CSIPluginListStub
|
2020-03-12 18:20:40 +00:00
|
|
|
qm, err := v.client.query("/v1/plugins?type=csi", &resp, q)
|
2020-01-28 15:28:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
sort.Sort(CSIPluginIndexSort(resp))
|
|
|
|
return resp, qm, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Info is used to retrieve a single CSI Plugin Job
|
|
|
|
func (v *CSIPlugins) Info(id string, q *QueryOptions) (*CSIPlugin, *QueryMeta, error) {
|
|
|
|
var resp *CSIPlugin
|
2020-03-12 18:20:40 +00:00
|
|
|
qm, err := v.client.query("/v1/plugin/csi/"+id, &resp, q)
|
2020-01-28 15:28:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return resp, qm, nil
|
|
|
|
}
|