github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/client/structs/csi.go (about) 1 package structs 2 3 import ( 4 "github.com/hashicorp/nomad/nomad/structs" 5 "github.com/hashicorp/nomad/plugins/csi" 6 ) 7 8 // CSIVolumeMountOptions contains the mount options that should be provided when 9 // attaching and mounting a volume with the CSIVolumeAttachmentModeFilesystem 10 // attachment mode. 11 type CSIVolumeMountOptions struct { 12 // Filesystem is the desired filesystem type that should be used by the volume 13 // (e.g ext4, aufs, zfs). This field is optional. 14 Filesystem string 15 16 // MountFlags contain the mount options that should be used for the volume. 17 // These may contain _sensitive_ data and should not be leaked to logs or 18 // returned in debugging data. 19 // The total size of this field must be under 4KiB. 20 MountFlags []string 21 } 22 23 // CSIControllerQuery is used to specify various flags for queries against CSI 24 // Controllers 25 type CSIControllerQuery struct { 26 // ControllerNodeID is the node that should be targeted by the request 27 ControllerNodeID string 28 29 // PluginID is the plugin that should be targeted on the given node. 30 PluginID string 31 } 32 33 type ClientCSIControllerValidateVolumeRequest struct { 34 VolumeID string // note: this is the external ID 35 36 AttachmentMode structs.CSIVolumeAttachmentMode 37 AccessMode structs.CSIVolumeAccessMode 38 Secrets structs.CSISecrets 39 40 // Parameters as returned by storage provider in CreateVolumeResponse. 41 // This field is optional. 42 Parameters map[string]string 43 44 // Volume context as returned by storage provider in CreateVolumeResponse. 45 // This field is optional. 46 Context map[string]string 47 48 CSIControllerQuery 49 } 50 51 func (c *ClientCSIControllerValidateVolumeRequest) ToCSIRequest() (*csi.ControllerValidateVolumeRequest, error) { 52 if c == nil { 53 return &csi.ControllerValidateVolumeRequest{}, nil 54 } 55 56 caps, err := csi.VolumeCapabilityFromStructs(c.AttachmentMode, c.AccessMode) 57 if err != nil { 58 return nil, err 59 } 60 61 return &csi.ControllerValidateVolumeRequest{ 62 ExternalID: c.VolumeID, 63 Secrets: c.Secrets, 64 Capabilities: caps, 65 Parameters: c.Parameters, 66 Context: c.Context, 67 }, nil 68 } 69 70 type ClientCSIControllerValidateVolumeResponse struct { 71 } 72 73 type ClientCSIControllerAttachVolumeRequest struct { 74 // The external ID of the volume to be used on a node. 75 // This field is REQUIRED. 76 VolumeID string 77 78 // The ID of the node. This field is REQUIRED. This must match the NodeID that 79 // is fingerprinted by the target node for this plugin name. 80 ClientCSINodeID string 81 82 // AttachmentMode indicates how the volume should be attached and mounted into 83 // a task. 84 AttachmentMode structs.CSIVolumeAttachmentMode 85 86 // AccessMode indicates the desired concurrent access model for the volume 87 AccessMode structs.CSIVolumeAccessMode 88 89 // MountOptions is an optional field that contains additional configuration 90 // when providing an AttachmentMode of CSIVolumeAttachmentModeFilesystem 91 MountOptions *CSIVolumeMountOptions 92 93 // ReadOnly indicates that the volume will be used in a readonly fashion. This 94 // only works when the Controller has the PublishReadonly capability. 95 ReadOnly bool 96 97 // Secrets required by plugin to complete the controller publish 98 // volume request. This field is OPTIONAL. 99 Secrets structs.CSISecrets 100 101 // Volume context as returned by storage provider in CreateVolumeResponse. 102 // This field is optional. 103 VolumeContext map[string]string 104 105 CSIControllerQuery 106 } 107 108 func (c *ClientCSIControllerAttachVolumeRequest) ToCSIRequest() (*csi.ControllerPublishVolumeRequest, error) { 109 if c == nil { 110 return &csi.ControllerPublishVolumeRequest{}, nil 111 } 112 113 caps, err := csi.VolumeCapabilityFromStructs(c.AttachmentMode, c.AccessMode) 114 if err != nil { 115 return nil, err 116 } 117 118 return &csi.ControllerPublishVolumeRequest{ 119 ExternalID: c.VolumeID, 120 NodeID: c.ClientCSINodeID, 121 VolumeCapability: caps, 122 ReadOnly: c.ReadOnly, 123 Secrets: c.Secrets, 124 VolumeContext: c.VolumeContext, 125 }, nil 126 } 127 128 // ClientCSIControllerDetachVolumeRequest is the RPC made from the server to 129 // a Nomad client to tell a CSI controller plugin on that client to perform 130 // ControllerUnpublish for a volume on a specific client. 131 type ClientCSIControllerAttachVolumeResponse struct { 132 // Opaque static publish properties of the volume. SP MAY use this 133 // field to ensure subsequent `NodeStageVolume` or `NodePublishVolume` 134 // calls calls have contextual information. 135 // The contents of this field SHALL be opaque to nomad. 136 // The contents of this field SHALL NOT be mutable. 137 // The contents of this field SHALL be safe for the nomad to cache. 138 // The contents of this field SHOULD NOT contain sensitive 139 // information. 140 // The contents of this field SHOULD NOT be used for uniquely 141 // identifying a volume. The `volume_id` alone SHOULD be sufficient to 142 // identify the volume. 143 // This field is OPTIONAL and when present MUST be passed to 144 // subsequent `NodeStageVolume` or `NodePublishVolume` calls 145 PublishContext map[string]string 146 } 147 148 type ClientCSIControllerDetachVolumeRequest struct { 149 // The external ID of the volume to be unpublished for the node 150 // This field is REQUIRED. 151 VolumeID string 152 153 // The CSI Node ID for the Node that the volume should be detached from. 154 // This field is REQUIRED. This must match the NodeID that is fingerprinted 155 // by the target node for this plugin name. 156 ClientCSINodeID string 157 158 // Secrets required by plugin to complete the controller unpublish 159 // volume request. This field is OPTIONAL. 160 Secrets structs.CSISecrets 161 162 CSIControllerQuery 163 } 164 165 func (c *ClientCSIControllerDetachVolumeRequest) ToCSIRequest() *csi.ControllerUnpublishVolumeRequest { 166 if c == nil { 167 return &csi.ControllerUnpublishVolumeRequest{} 168 } 169 170 return &csi.ControllerUnpublishVolumeRequest{ 171 ExternalID: c.VolumeID, 172 NodeID: c.ClientCSINodeID, 173 } 174 } 175 176 type ClientCSIControllerDetachVolumeResponse struct{} 177 178 // ClientCSINodeDetachVolumeRequest is the RPC made from the server to 179 // a Nomad client to tell a CSI node plugin on that client to perform 180 // NodeUnpublish and NodeUnstage. 181 type ClientCSINodeDetachVolumeRequest struct { 182 PluginID string // ID of the plugin that manages the volume (required) 183 VolumeID string // ID of the volume to be unpublished (required) 184 AllocID string // ID of the allocation we're unpublishing for (required) 185 NodeID string // ID of the Nomad client targeted 186 ExternalID string // External ID of the volume to be unpublished (required) 187 188 // These fields should match the original volume request so that 189 // we can find the mount points on the client 190 AttachmentMode structs.CSIVolumeAttachmentMode 191 AccessMode structs.CSIVolumeAccessMode 192 ReadOnly bool 193 } 194 195 type ClientCSINodeDetachVolumeResponse struct{}