Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hostpath: Implement ValidateVolumeCapabilities #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions hack/e2e-hostpath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ CSI_MOUNTPOINT="/mnt"
APP=hostpathplugin

SKIP="WithCapacity"
if [ x${TRAVIS} = x"true" ] ; then
SKIP="ValidateVolumeCapabilities"
fi

# Get csi-sanity
./hack/get-sanity.sh
Expand Down
30 changes: 29 additions & 1 deletion pkg/hostpath/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,35 @@ func (cs *controllerServer) ControllerGetCapabilities(ctx context.Context, req *
}

func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
return nil, status.Error(codes.Unimplemented, "")

// Check arguments
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID cannot be empty")
}
if len(req.VolumeCapabilities) == 0 {
return nil, status.Error(codes.InvalidArgument, req.VolumeId)
}

if _, err := getVolumeByID(req.GetVolumeId()); err != nil {
return nil, status.Error(codes.NotFound, req.GetVolumeId())
}

for _, cap := range req.GetVolumeCapabilities() {
if cap.GetMount() == nil && cap.GetBlock() == nil {
return nil, status.Error(codes.InvalidArgument, "cannot have both mount and block access type be undefined")
}

// A real driver would check the capabilities of the given volume with
// the set of requested capabilities.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether any "real" driver properly implements this? I was trying to do it recently in my own CSI driver when adapting it to CSI 1.0 (sadly, still not public). It was far from trivial, so it might be good to have a correct example.

gcepd doesn't implement it:
kubernetes-sigs/gcp-compute-persistent-disk-csi-driver#162

This is just an observation, it shouldn't hold back merging this PR.

Copy link
Contributor Author

@darkowlzz darkowlzz Jan 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My driver does something like this:

	mode := cap.GetAccessMode().GetMode()
	switch mode {
	case csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER:
		// Supported capability. Continue checking other capabilities.
	case csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY:
		message = "Volume is not singlenode read only volume"
		break
	case csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
		csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY,
		csi.VolumeCapability_AccessMode_MULTI_NODE_SINGLE_WRITER:
		message = "Volume is not multinode volume"
		break
	default:
		return nil, status.Errorf(codes.InvalidArgument, "AccessMode %s is not allowed", mode)
	}

I'm not sure if that's how it should be done.
Maybe we can have a commented example in this driver if there's no other sample drivers that have different capabilities.

}

return &csi.ValidateVolumeCapabilitiesResponse{
Confirmed: &csi.ValidateVolumeCapabilitiesResponse_Confirmed{
VolumeContext: req.GetVolumeContext(),
VolumeCapabilities: req.GetVolumeCapabilities(),
Parameters: req.GetParameters(),
},
}, nil
}

func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
Expand Down