2019-07-03 10:02:36 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// ValidateNodeStageVolumeRequest validates the node stage request.
|
2019-07-03 10:02:36 +00:00
|
|
|
func ValidateNodeStageVolumeRequest(req *csi.NodeStageVolumeRequest) error {
|
|
|
|
if req.GetVolumeCapability() == nil {
|
|
|
|
return status.Error(codes.InvalidArgument, "volume capability missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.GetVolumeId() == "" {
|
|
|
|
return status.Error(codes.InvalidArgument, "volume ID missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.GetStagingTargetPath() == "" {
|
|
|
|
return status.Error(codes.InvalidArgument, "staging target path missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.GetSecrets() == nil || len(req.GetSecrets()) == 0 {
|
|
|
|
return status.Error(codes.InvalidArgument, "stage secrets cannot be nil or empty")
|
|
|
|
}
|
|
|
|
|
2019-07-25 09:01:10 +00:00
|
|
|
// validate stagingpath exists
|
|
|
|
ok := checkDirExists(req.GetStagingTargetPath())
|
|
|
|
if !ok {
|
2021-06-25 12:15:08 +00:00
|
|
|
return status.Errorf(
|
|
|
|
codes.InvalidArgument,
|
|
|
|
"staging path %s does not exist on node",
|
|
|
|
req.GetStagingTargetPath())
|
2019-07-25 09:01:10 +00:00
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2019-07-03 10:02:36 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// ValidateNodeUnstageVolumeRequest validates the node unstage request.
|
2019-07-03 10:02:36 +00:00
|
|
|
func ValidateNodeUnstageVolumeRequest(req *csi.NodeUnstageVolumeRequest) error {
|
|
|
|
if req.GetVolumeId() == "" {
|
|
|
|
return status.Error(codes.InvalidArgument, "volume ID missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.GetStagingTargetPath() == "" {
|
|
|
|
return status.Error(codes.InvalidArgument, "staging target path missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// ValidateNodePublishVolumeRequest validates the node publish request.
|
2019-07-03 10:02:36 +00:00
|
|
|
func ValidateNodePublishVolumeRequest(req *csi.NodePublishVolumeRequest) error {
|
|
|
|
if req.GetVolumeCapability() == nil {
|
|
|
|
return status.Error(codes.InvalidArgument, "volume capability missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.GetVolumeId() == "" {
|
|
|
|
return status.Error(codes.InvalidArgument, "volume ID missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.GetTargetPath() == "" {
|
|
|
|
return status.Error(codes.InvalidArgument, "target path missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.GetStagingTargetPath() == "" {
|
|
|
|
return status.Error(codes.InvalidArgument, "staging target path missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// ValidateNodeUnpublishVolumeRequest validates the node unpublish request.
|
2019-07-03 10:02:36 +00:00
|
|
|
func ValidateNodeUnpublishVolumeRequest(req *csi.NodeUnpublishVolumeRequest) error {
|
|
|
|
if req.GetVolumeId() == "" {
|
|
|
|
return status.Error(codes.InvalidArgument, "volume ID missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.GetTargetPath() == "" {
|
|
|
|
return status.Error(codes.InvalidArgument, "target path missing in request")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-09-09 15:49:01 +00:00
|
|
|
|
|
|
|
// CheckReadOnlyManyIsSupported checks the request is to create ReadOnlyMany
|
|
|
|
// volume is from source as empty ReadOnlyMany is not supported.
|
|
|
|
func CheckReadOnlyManyIsSupported(req *csi.CreateVolumeRequest) error {
|
2020-10-21 07:00:55 +00:00
|
|
|
for _, capability := range req.GetVolumeCapabilities() {
|
2024-04-04 08:53:45 +00:00
|
|
|
if m := capability.GetAccessMode().GetMode(); m == csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY ||
|
2021-06-25 12:15:08 +00:00
|
|
|
m == csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY {
|
2020-09-09 15:49:01 +00:00
|
|
|
if req.GetVolumeContentSource() == nil {
|
|
|
|
return status.Error(codes.InvalidArgument, "readOnly accessMode is supported only with content source")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2020-09-09 15:49:01 +00:00
|
|
|
return nil
|
|
|
|
}
|