Skip to content

Commit

Permalink
csi: support for VolumeContext and VolumeParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed May 14, 2020
1 parent b672c50 commit 2a65dad
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 11 deletions.
2 changes: 2 additions & 0 deletions api/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ type CSIVolume struct {
AttachmentMode CSIVolumeAttachmentMode `hcl:"attachment_mode"`
MountOptions *CSIMountOptions `hcl:"mount_options"`
Secrets CSISecrets `hcl:"secrets"`
Parameters map[string]string `hcl:"parameters"`
Context map[string]string `hcl:"context"`

// Allocations, tracking claim status
ReadAllocs map[string]*Allocation
Expand Down
18 changes: 13 additions & 5 deletions client/structs/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ type ClientCSIControllerValidateVolumeRequest struct {
AttachmentMode structs.CSIVolumeAttachmentMode
AccessMode structs.CSIVolumeAccessMode
Secrets structs.CSISecrets
// Parameters map[string]string // TODO: https://github.com/hashicorp/nomad/issues/7670

// 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

CSIControllerQuery
}
Expand All @@ -55,6 +62,8 @@ func (c *ClientCSIControllerValidateVolumeRequest) ToCSIRequest() (*csi.Controll
VolumeID: c.VolumeID,
Secrets: c.Secrets,
Capabilities: caps,
Parameters: c.Parameters,
Context: c.Context,
}, nil
}

Expand Down Expand Up @@ -89,10 +98,9 @@ type ClientCSIControllerAttachVolumeRequest struct {
// volume request. This field is OPTIONAL.
Secrets structs.CSISecrets

// TODO https://github.com/hashicorp/nomad/issues/7771
// Volume context as returned by storage provider in CreateVolumeResponse.
// This field is optional.
// VolumeContext map[string]string
VolumeContext map[string]string

CSIControllerQuery
}
Expand All @@ -113,7 +121,7 @@ func (c *ClientCSIControllerAttachVolumeRequest) ToCSIRequest() (*csi.Controller
VolumeCapability: caps,
ReadOnly: c.ReadOnly,
Secrets: c.Secrets,
// VolumeContext: c.VolumeContext, TODO: https://github.com/hashicorp/nomad/issues/7771
VolumeContext: c.VolumeContext,
}, nil
}

Expand All @@ -138,7 +146,7 @@ type ClientCSIControllerAttachVolumeResponse struct {
}

type ClientCSIControllerDetachVolumeRequest struct {
// The ID of the volume to be unpublished for the node
// The external ID of the volume to be unpublished for the node
// This field is REQUIRED.
VolumeID string

Expand Down
5 changes: 3 additions & 2 deletions nomad/csi_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ func (v *CSIVolume) controllerValidateVolume(req *structs.CSIVolumeRegisterReque
AttachmentMode: vol.AttachmentMode,
AccessMode: vol.AccessMode,
Secrets: vol.Secrets,
// Parameters: TODO: https://github.com/hashicorp/nomad/issues/7670
Parameters: vol.Parameters,
Context: vol.Context,
}
cReq.PluginID = plugin.ID
cResp := &cstructs.ClientCSIControllerValidateVolumeResponse{}
Expand Down Expand Up @@ -443,7 +444,7 @@ func (v *CSIVolume) controllerPublishVolume(req *structs.CSIVolumeClaimRequest,
AccessMode: vol.AccessMode,
ReadOnly: req.Claim == structs.CSIVolumeClaimRead,
Secrets: vol.Secrets,
// VolumeContext: TODO https://github.com/hashicorp/nomad/issues/7771
VolumeContext: vol.Context,
}
cReq.PluginID = plug.ID
cResp := &cstructs.ClientCSIControllerAttachVolumeResponse{}
Expand Down
2 changes: 2 additions & 0 deletions nomad/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,8 @@ func CSIVolume(plugin *structs.CSIPlugin) *structs.CSIVolume {
AttachmentMode: structs.CSIVolumeAttachmentModeFilesystem,
MountOptions: &structs.CSIMountOptions{},
Secrets: structs.CSISecrets{},
Parameters: map[string]string{},
Context: map[string]string{},
ReadAllocs: map[string]*structs.Allocation{},
WriteAllocs: map[string]*structs.Allocation{},
ReadClaims: map[string]*structs.CSIVolumeClaim{},
Expand Down
14 changes: 14 additions & 0 deletions nomad/structs/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ type CSIVolume struct {
AttachmentMode CSIVolumeAttachmentMode
MountOptions *CSIMountOptions
Secrets CSISecrets
Parameters map[string]string
Context map[string]string

// Allocations, tracking claim status
ReadAllocs map[string]*Allocation // AllocID -> Allocation
Expand Down Expand Up @@ -300,6 +302,12 @@ func (v *CSIVolume) newStructs() {
if v.Topologies == nil {
v.Topologies = []*CSITopology{}
}
if v.Context == nil {
v.Context = map[string]string{}
}
if v.Parameters == nil {
v.Parameters = map[string]string{}
}
if v.Secrets == nil {
v.Secrets = CSISecrets{}
}
Expand Down Expand Up @@ -388,6 +396,12 @@ func (v *CSIVolume) Copy() *CSIVolume {
copy := *v
out := &copy
out.newStructs()
for k, v := range v.Parameters {
out.Parameters[k] = v
}
for k, v := range v.Context {
out.Context[k] = v
}
for k, v := range v.Secrets {
out.Secrets[k] = v
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/csi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ func TestClient_RPC_ControllerValidateVolume(t *testing.T) {
VolumeID: "volumeID",
Secrets: structs.CSISecrets{},
Capabilities: requestedCaps,
Parameters: map[string]string{},
Context: map[string]string{},
}

cc.NextValidateVolumeCapabilitiesResponse = c.Response
Expand Down
12 changes: 8 additions & 4 deletions plugins/csi/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ type ControllerValidateVolumeRequest struct {
VolumeID string // note: this is the external ID
Secrets structs.CSISecrets
Capabilities *VolumeCapability
Parameters map[string]string
Context map[string]string
}

func (r *ControllerValidateVolumeRequest) ToCSIRepresentation() *csipbv1.ValidateVolumeCapabilitiesRequest {
Expand All @@ -241,11 +243,13 @@ func (r *ControllerValidateVolumeRequest) ToCSIRepresentation() *csipbv1.Validat
}

return &csipbv1.ValidateVolumeCapabilitiesRequest{
VolumeId: r.VolumeID,
VolumeId: r.VolumeID,
VolumeContext: r.Context,
VolumeCapabilities: []*csipbv1.VolumeCapability{
r.Capabilities.ToCSIRepresentation(),
},
Secrets: r.Secrets,
Parameters: r.Parameters,
Secrets: r.Secrets,
}
}

Expand All @@ -255,7 +259,7 @@ type ControllerPublishVolumeRequest struct {
ReadOnly bool
VolumeCapability *VolumeCapability
Secrets structs.CSISecrets
// VolumeContext map[string]string // TODO: https://github.com/hashicorp/nomad/issues/7771
VolumeContext map[string]string
}

func (r *ControllerPublishVolumeRequest) ToCSIRepresentation() *csipbv1.ControllerPublishVolumeRequest {
Expand All @@ -269,7 +273,7 @@ func (r *ControllerPublishVolumeRequest) ToCSIRepresentation() *csipbv1.Controll
Readonly: r.ReadOnly,
VolumeCapability: r.VolumeCapability.ToCSIRepresentation(),
Secrets: r.Secrets,
// VolumeContext: r.VolumeContext, https://github.com/hashicorp/nomad/issues/7771
VolumeContext: r.VolumeContext,
}
}

Expand Down

0 comments on commit 2a65dad

Please sign in to comment.