From 6820279e588166dfa0e0013f6669b1a090fa1a96 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 5 Dec 2018 14:52:10 +0100 Subject: [PATCH] hostpath: refuse to create block volumes Without this check, the hostpath driver fails one of the E2E storage tests in Kubernetes 1.13: provisioning a block volume is expected to fail in https://github.com/kubernetes/kubernetes/blob/e689d515f77cda51898045d626ec4070e3328194/test/e2e/storage/testsuites/volumemode.go#L329-L330 --- pkg/hostpath/controllerserver.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/hostpath/controllerserver.go b/pkg/hostpath/controllerserver.go index 2bd8d7024..576cb1e24 100644 --- a/pkg/hostpath/controllerserver.go +++ b/pkg/hostpath/controllerserver.go @@ -57,9 +57,21 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol if len(req.GetName()) == 0 { return nil, status.Error(codes.InvalidArgument, "Name missing in request") } - if req.GetVolumeCapabilities() == nil { + caps := req.GetVolumeCapabilities() + if caps == nil { return nil, status.Error(codes.InvalidArgument, "Volume Capabilities missing in request") } + for _, cap := range caps { + if cap.GetBlock() != nil { + return nil, status.Error(codes.Unimplemented, "Block Volume not supported") + } + } + // A real driver would also need to check that the other + // fields in VolumeCapabilities are sane. The check above is + // just enough to pass the "[Testpattern: Dynamic PV (block + // volmode)] volumeMode should fail in binding dynamic + // provisioned PV to PVC" storage E2E test. + // Need to check for already existing volume name, and if found // check for the requested capacity and already allocated capacity if exVol, err := getVolumeByName(req.GetName()); err == nil {