mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
csi: VolumeCapabilities for ControllerPublishVolume
This commit introduces support for providing VolumeCapabilities during requests to `ControllerPublishVolumes` as this is a required field.
This commit is contained in:
committed by
Tim Gross
parent
fab252ce5d
commit
20ec9a2115
@@ -9,7 +9,6 @@ import (
|
||||
metrics "github.com/armon/go-metrics"
|
||||
"github.com/hashicorp/nomad/client/dynamicplugins"
|
||||
"github.com/hashicorp/nomad/client/structs"
|
||||
nstructs "github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/plugins/csi"
|
||||
)
|
||||
|
||||
@@ -89,18 +88,15 @@ func (c *CSIController) AttachVolume(req *structs.ClientCSIControllerAttachVolum
|
||||
return errors.New("ClientCSINodeID is required")
|
||||
}
|
||||
|
||||
if !nstructs.ValidCSIVolumeAccessMode(req.AccessMode) {
|
||||
return fmt.Errorf("Unknown access mode: %v", req.AccessMode)
|
||||
}
|
||||
|
||||
if !nstructs.ValidCSIVolumeAttachmentMode(req.AttachmentMode) {
|
||||
return fmt.Errorf("Unknown attachment mode: %v", req.AttachmentMode)
|
||||
csiReq, err := req.ToCSIRequest()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Submit the request for a volume to the CSI Plugin.
|
||||
ctx, cancelFn := c.requestContext()
|
||||
defer cancelFn()
|
||||
cresp, err := plugin.ControllerPublishVolume(ctx, req.ToCSIRequest())
|
||||
cresp, err := plugin.ControllerPublishVolume(ctx, csiReq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -64,9 +64,10 @@ func TestCSIController_AttachVolume(t *testing.T) {
|
||||
},
|
||||
VolumeID: "1234-4321-1234-4321",
|
||||
ClientCSINodeID: "abcde",
|
||||
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
||||
AccessMode: nstructs.CSIVolumeAccessMode("foo"),
|
||||
},
|
||||
ExpectedErr: errors.New("Unknown access mode: foo"),
|
||||
ExpectedErr: errors.New("Unknown volume access mode: foo"),
|
||||
},
|
||||
{
|
||||
Name: "validates attachmentmode is not empty",
|
||||
@@ -79,7 +80,7 @@ func TestCSIController_AttachVolume(t *testing.T) {
|
||||
AccessMode: nstructs.CSIVolumeAccessModeMultiNodeReader,
|
||||
AttachmentMode: nstructs.CSIVolumeAttachmentMode("bar"),
|
||||
},
|
||||
ExpectedErr: errors.New("Unknown attachment mode: bar"),
|
||||
ExpectedErr: errors.New("Unknown volume attachment mode: bar"),
|
||||
},
|
||||
{
|
||||
Name: "returns transitive errors",
|
||||
|
||||
@@ -69,16 +69,22 @@ type ClientCSIControllerAttachVolumeRequest struct {
|
||||
CSIControllerQuery
|
||||
}
|
||||
|
||||
func (c *ClientCSIControllerAttachVolumeRequest) ToCSIRequest() *csi.ControllerPublishVolumeRequest {
|
||||
func (c *ClientCSIControllerAttachVolumeRequest) ToCSIRequest() (*csi.ControllerPublishVolumeRequest, error) {
|
||||
if c == nil {
|
||||
return &csi.ControllerPublishVolumeRequest{}
|
||||
return &csi.ControllerPublishVolumeRequest{}, nil
|
||||
}
|
||||
|
||||
caps, err := csi.VolumeCapabilityFromStructs(c.AttachmentMode, c.AccessMode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &csi.ControllerPublishVolumeRequest{
|
||||
VolumeID: c.VolumeID,
|
||||
NodeID: c.ClientCSINodeID,
|
||||
ReadOnly: c.ReadOnly,
|
||||
}
|
||||
VolumeID: c.VolumeID,
|
||||
NodeID: c.ClientCSINodeID,
|
||||
ReadOnly: c.ReadOnly,
|
||||
VolumeCapability: caps,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type ClientCSIControllerAttachVolumeResponse struct {
|
||||
|
||||
@@ -228,10 +228,10 @@ func NewControllerCapabilitySet(resp *csipbv1.ControllerGetCapabilitiesResponse)
|
||||
}
|
||||
|
||||
type ControllerPublishVolumeRequest struct {
|
||||
VolumeID string
|
||||
NodeID string
|
||||
ReadOnly bool
|
||||
//TODO: Add Capabilities
|
||||
VolumeID string
|
||||
NodeID string
|
||||
ReadOnly bool
|
||||
VolumeCapability *VolumeCapability
|
||||
}
|
||||
|
||||
func (r *ControllerPublishVolumeRequest) ToCSIRepresentation() *csipbv1.ControllerPublishVolumeRequest {
|
||||
@@ -240,10 +240,10 @@ func (r *ControllerPublishVolumeRequest) ToCSIRepresentation() *csipbv1.Controll
|
||||
}
|
||||
|
||||
return &csipbv1.ControllerPublishVolumeRequest{
|
||||
VolumeId: r.VolumeID,
|
||||
NodeId: r.NodeID,
|
||||
Readonly: r.ReadOnly,
|
||||
// TODO: add capabilities
|
||||
VolumeId: r.VolumeID,
|
||||
NodeId: r.NodeID,
|
||||
Readonly: r.ReadOnly,
|
||||
VolumeCapability: r.VolumeCapability.ToCSIRepresentation(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user