diff --git a/client/pluginmanager/csimanager/volume.go b/client/pluginmanager/csimanager/volume.go index f054416d1..c359f32e3 100644 --- a/client/pluginmanager/csimanager/volume.go +++ b/client/pluginmanager/csimanager/volume.go @@ -127,11 +127,6 @@ func (v *volumeManager) ensureAllocDir(vol *structs.CSIVolume, alloc *structs.Al } func volumeCapability(vol *structs.CSIVolume, usage *UsageOptions) (*csi.VolumeCapability, error) { - capability, err := csi.VolumeCapabilityFromStructs(usage.AttachmentMode, usage.AccessMode) - if err != nil { - return nil, err - } - var opts *structs.CSIMountOptions if vol.MountOptions == nil { opts = usage.MountOptions @@ -140,7 +135,10 @@ func volumeCapability(vol *structs.CSIVolume, usage *UsageOptions) (*csi.VolumeC opts.Merge(usage.MountOptions) } - capability.MountVolume = opts + capability, err := csi.VolumeCapabilityFromStructs(usage.AttachmentMode, usage.AccessMode, opts) + if err != nil { + return nil, err + } return capability, nil } diff --git a/client/structs/csi.go b/client/structs/csi.go index 8ab397cbc..7ad853a87 100644 --- a/client/structs/csi.go +++ b/client/structs/csi.go @@ -20,6 +20,17 @@ type CSIVolumeMountOptions struct { MountFlags []string } +func (c *CSIVolumeMountOptions) ToCSIMountOptions() *structs.CSIMountOptions { + if c == nil { + return nil + } + + return &structs.CSIMountOptions{ + FSType: c.Filesystem, + MountFlags: c.MountFlags, + } +} + // CSIControllerRequest interface lets us set embedded CSIControllerQuery // fields in the server type CSIControllerRequest interface { @@ -45,6 +56,7 @@ type ClientCSIControllerValidateVolumeRequest struct { AttachmentMode structs.CSIVolumeAttachmentMode AccessMode structs.CSIVolumeAccessMode + MountOptions *structs.CSIMountOptions Secrets structs.CSISecrets // Parameters as returned by storage provider in CreateVolumeResponse. @@ -63,7 +75,7 @@ func (c *ClientCSIControllerValidateVolumeRequest) ToCSIRequest() (*csi.Controll return &csi.ControllerValidateVolumeRequest{}, nil } - caps, err := csi.VolumeCapabilityFromStructs(c.AttachmentMode, c.AccessMode) + caps, err := csi.VolumeCapabilityFromStructs(c.AttachmentMode, c.AccessMode, c.MountOptions) if err != nil { return nil, err } @@ -120,7 +132,8 @@ func (c *ClientCSIControllerAttachVolumeRequest) ToCSIRequest() (*csi.Controller return &csi.ControllerPublishVolumeRequest{}, nil } - caps, err := csi.VolumeCapabilityFromStructs(c.AttachmentMode, c.AccessMode) + var opts = c.MountOptions.ToCSIMountOptions() + caps, err := csi.VolumeCapabilityFromStructs(c.AttachmentMode, c.AccessMode, opts) if err != nil { return nil, err } @@ -191,6 +204,7 @@ type ClientCSIControllerDetachVolumeResponse struct{} type ClientCSIControllerCreateVolumeRequest struct { Name string VolumeCapabilities []*structs.CSIVolumeCapability + MountOptions *structs.CSIMountOptions Parameters map[string]string Secrets structs.CSISecrets CapacityMin int64 @@ -222,7 +236,7 @@ func (req *ClientCSIControllerCreateVolumeRequest) ToCSIRequest() (*csi.Controll AccessibilityRequirements: &csi.TopologyRequirement{}, } for _, cap := range req.VolumeCapabilities { - ccap, err := csi.VolumeCapabilityFromStructs(cap.AttachmentMode, cap.AccessMode) + ccap, err := csi.VolumeCapabilityFromStructs(cap.AttachmentMode, cap.AccessMode, req.MountOptions) if err != nil { return nil, err } diff --git a/nomad/csi_endpoint.go b/nomad/csi_endpoint.go index 3626380eb..6a9560a3a 100644 --- a/nomad/csi_endpoint.go +++ b/nomad/csi_endpoint.go @@ -417,6 +417,17 @@ func (v *CSIVolume) Claim(args *structs.CSIVolumeClaimRequest, reply *structs.CS return nil } +func csiVolumeMountOptions(c *structs.CSIMountOptions) *cstructs.CSIVolumeMountOptions { + if c == nil { + return nil + } + + return &cstructs.CSIVolumeMountOptions{ + Filesystem: c.FSType, + MountFlags: c.MountFlags, + } +} + // controllerPublishVolume sends publish request to the CSI controller // plugin associated with a volume, if any. func (v *CSIVolume) controllerPublishVolume(req *structs.CSIVolumeClaimRequest, resp *structs.CSIVolumeClaimResponse) error { @@ -471,6 +482,7 @@ func (v *CSIVolume) controllerPublishVolume(req *structs.CSIVolumeClaimRequest, ClientCSINodeID: externalNodeID, AttachmentMode: req.AttachmentMode, AccessMode: req.AccessMode, + MountOptions: csiVolumeMountOptions(vol.MountOptions), ReadOnly: req.Claim == structs.CSIVolumeClaimRead, Secrets: vol.Secrets, VolumeContext: vol.Context, @@ -901,6 +913,7 @@ func (v *CSIVolume) createVolume(vol *structs.CSIVolume, plugin *structs.CSIPlug cReq := &cstructs.ClientCSIControllerCreateVolumeRequest{ Name: vol.Name, VolumeCapabilities: vol.RequestedCapabilities, + MountOptions: vol.MountOptions, Parameters: vol.Parameters, Secrets: vol.Secrets, CapacityMin: vol.RequestedCapacityMin, diff --git a/plugins/csi/plugin.go b/plugins/csi/plugin.go index 7d896ac19..e211c5a44 100644 --- a/plugins/csi/plugin.go +++ b/plugins/csi/plugin.go @@ -886,7 +886,7 @@ type VolumeCapability struct { MountVolume *structs.CSIMountOptions } -func VolumeCapabilityFromStructs(sAccessType structs.CSIVolumeAttachmentMode, sAccessMode structs.CSIVolumeAccessMode) (*VolumeCapability, error) { +func VolumeCapabilityFromStructs(sAccessType structs.CSIVolumeAttachmentMode, sAccessMode structs.CSIVolumeAccessMode, sMountOptions *structs.CSIMountOptions) (*VolumeCapability, error) { var accessType VolumeAccessType switch sAccessType { case structs.CSIVolumeAttachmentModeBlockDevice: @@ -922,8 +922,9 @@ func VolumeCapabilityFromStructs(sAccessType structs.CSIVolumeAttachmentMode, sA } return &VolumeCapability{ - AccessType: accessType, - AccessMode: accessMode, + AccessType: accessType, + AccessMode: accessMode, + MountVolume: sMountOptions, }, nil }