util: add helper to validate ROX request

added a helper function to validate is create
request for ROX is for volume from source.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
(cherry picked from commit d816df4f42)
This commit is contained in:
Madhu Rajanna 2020-09-09 21:19:01 +05:30 committed by mergify[bot]
parent 90da7961c5
commit c9601189ef

View File

@ -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
}