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 {