From 8fe98fb845f8996db01f3708787529e9d2b52aac Mon Sep 17 00:00:00 2001 From: Niclas Schad Date: Wed, 20 Nov 2024 16:12:49 +0100 Subject: [PATCH] Validate volume capabilities in RPC call `CreateVolume` Signed-off-by: Niclas Schad --- pkg/csi/cinder/controllerserver.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/csi/cinder/controllerserver.go b/pkg/csi/cinder/controllerserver.go index 43b2ba1941..0ece8468da 100644 --- a/pkg/csi/cinder/controllerserver.go +++ b/pkg/csi/cinder/controllerserver.go @@ -51,6 +51,15 @@ const ( antiAffinityKey = "cinder.csi.openstack.org/anti-affinity" ) +func (cs *controllerServer) validateVolumeCapabilities(req []*csi.VolumeCapability) error { + for _, volCap := range req { + if volCap.GetAccessMode().GetMode() != cs.Driver.vcap[0].GetMode() { + return fmt.Errorf("volume access mode %s not supported", volCap.GetAccessMode().GetMode().String()) + } + } + return nil +} + func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { klog.V(4).Infof("CreateVolume: called with args %+v", protosanitizer.StripSecrets(*req)) @@ -74,6 +83,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol return nil, status.Error(codes.InvalidArgument, "[CreateVolume] missing Volume capability") } + if err := cs.validateVolumeCapabilities(volCapabilities); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + // Volume Size - Default is 1 GiB volSizeBytes := int64(1 * 1024 * 1024 * 1024) if req.GetCapacityRange() != nil {