From 71cfa2f24f16c3e488c7100a9b404145bdba4e5d Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Wed, 29 Sep 2021 18:57:35 +0200 Subject: [PATCH] Fixed creation of ControllerCreateVolumeRequest. `CapacityRange` should only be set if `RequiredBytes` and/or `LimitBytes` are set. --- .changelog/11238.txt | 3 +++ client/structs/csi.go | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changelog/11238.txt diff --git a/.changelog/11238.txt b/.changelog/11238.txt new file mode 100644 index 000000000000..f9b9137e721e --- /dev/null +++ b/.changelog/11238.txt @@ -0,0 +1,3 @@ +```release-note:bug +csi: Fixed a bug where the client would incorrectly set and empty capacity range for CSI volume creation requests. +``` diff --git a/client/structs/csi.go b/client/structs/csi.go index ca7f88d41deb..402a3ae661ae 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,12 @@ func (req *ClientCSIControllerCreateVolumeRequest) ToCSIRequest() (*csi.Controll // TODO: topology is not yet supported AccessibilityRequirements: &csi.TopologyRequirement{}, } + 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 {