diff --git a/internal/util/validate.go b/internal/util/validate.go index 0a21390e8..81404249b 100644 --- a/internal/util/validate.go +++ b/internal/util/validate.go @@ -78,3 +78,16 @@ func ValidateNodeUnpublishVolumeRequest(req *csi.NodeUnpublishVolumeRequest) err return nil } + +// CheckReadOnlyManyIsSupported checks the request is to create ReadOnlyMany +// volume is from source as empty ReadOnlyMany is not supported. +func CheckReadOnlyManyIsSupported(req *csi.CreateVolumeRequest) error { + for _, cap := range req.GetVolumeCapabilities() { + if m := cap.GetAccessMode().Mode; m == csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY || m == csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY { + if req.GetVolumeContentSource() == nil { + return status.Error(codes.InvalidArgument, "readOnly accessMode is supported only with content source") + } + } + } + return nil +}