From 709c1a294736821d405c093f43e2d7b89b34cd91 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Wed, 6 Oct 2021 16:17:39 +0200 Subject: [PATCH] Fixed creation of ControllerCreateVolumeRequest. (#11238) --- .changelog/11238.txt | 3 +++ client/structs/csi.go | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 .changelog/11238.txt diff --git a/.changelog/11238.txt b/.changelog/11238.txt new file mode 100644 index 000000000..817a27b1f --- /dev/null +++ b/.changelog/11238.txt @@ -0,0 +1,3 @@ +```release-note:bug +csi: Fixed a bug where the client would incorrectly set an empty capacity range for CSI volume creation requests. +``` diff --git a/client/structs/csi.go b/client/structs/csi.go index ca7f88d41..fb6ca6c7a 100644 --- a/client/structs/csi.go +++ b/client/structs/csi.go @@ -229,11 +229,7 @@ type ClientCSIControllerCreateVolumeRequest struct { func (req *ClientCSIControllerCreateVolumeRequest) ToCSIRequest() (*csi.ControllerCreateVolumeRequest, error) { creq := &csi.ControllerCreateVolumeRequest{ - Name: req.Name, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: req.CapacityMin, - LimitBytes: req.CapacityMax, - }, + Name: req.Name, VolumeCapabilities: []*csi.VolumeCapability{}, Parameters: req.Parameters, Secrets: req.Secrets, @@ -244,6 +240,17 @@ func (req *ClientCSIControllerCreateVolumeRequest) ToCSIRequest() (*csi.Controll // TODO: topology is not yet supported AccessibilityRequirements: &csi.TopologyRequirement{}, } + + // The CSI spec requires that at least one of the fields in CapacityRange + // must be defined. Fields set to 0 are considered unspecified and the + // CreateVolumeRequest should not send an invalid value. + if req.CapacityMin != 0 || req.CapacityMax != 0 { + creq.CapacityRange = &csi.CapacityRange{ + RequiredBytes: req.CapacityMin, + LimitBytes: req.CapacityMax, + } + } + for _, cap := range req.VolumeCapabilities { ccap, err := csi.VolumeCapabilityFromStructs(cap.AttachmentMode, cap.AccessMode, req.MountOptions) if err != nil {