From 84b046d73680e32d6d1b46a2c7cc9625fa5a66f7 Mon Sep 17 00:00:00 2001 From: Rakshith R Date: Mon, 7 Jun 2021 13:01:38 +0530 Subject: [PATCH] rbd: add check for imageFeatures parameter This commit adds checks for missing `imageFeatures` parameter in createvolumerequest and nodestagerequest(only for static PVs). Missing `imageFeatures` parameter is ignored in case of non-static PVs to ensure backwards compatibility with older versions which did not have `imageFeatures` as required parameter. Signed-off-by: Rakshith R --- internal/rbd/controllerserver.go | 4 ++++ internal/rbd/nodeserver.go | 6 ++++++ internal/rbd/rbd_util.go | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index b977c4d49..b7d1e87c7 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -111,6 +111,10 @@ func (cs *ControllerServer) parseVolCreateRequest(ctx context.Context, req *csi. return nil, status.Error(codes.InvalidArgument, "multi node access modes are only supported on rbd `block` type volumes") } + if imageFeatures, ok := req.GetParameters()["imageFeatures"]; checkImageFeatures(imageFeatures, ok, true) { + return nil, status.Error(codes.InvalidArgument, "missing required parameter imageFeatures") + } + // if it's NOT SINGLE_NODE_WRITER and it's BLOCK we'll set the parameter to ignore the in-use checks rbdVol, err := genVolFromVolumeOptions(ctx, req.GetParameters(), req.GetSecrets(), (isMultiNode && isBlock)) if err != nil { diff --git a/internal/rbd/nodeserver.go b/internal/rbd/nodeserver.go index 1f1ce673b..fbabe370f 100644 --- a/internal/rbd/nodeserver.go +++ b/internal/rbd/nodeserver.go @@ -166,6 +166,12 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol return &csi.NodeStageVolumeResponse{}, nil } + // throw error when imageFeatures parameter is missing or empty + // for backward compatibility, ignore error for non-static volumes from older cephcsi version + if imageFeatures, ok := req.GetVolumeContext()["imageFeatures"]; checkImageFeatures(imageFeatures, ok, staticVol) { + return nil, status.Error(codes.InvalidArgument, "missing required parameter imageFeatures") + } + volOptions, err := genVolFromVolumeOptions(ctx, req.GetVolumeContext(), req.GetSecrets(), disableInUseChecks) if err != nil { return nil, status.Error(codes.Internal, err.Error()) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index a6cb3658a..60f52c59e 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -448,6 +448,13 @@ func (rv *rbdVolume) isInUse() (bool, error) { return len(watchers) > defaultWatchers, nil } +// checkImageFeatures check presence of imageFeatures parameter. It returns true when +// there imageFeatures is missing or empty, skips missing parameter for non-static volumes +// for backward compatibility. +func checkImageFeatures(imageFeatures string, ok, static bool) bool { + return static && (!ok || imageFeatures == "") +} + // addRbdManagerTask adds a ceph manager task to execute command // asynchronously. If command is not found returns a bool set to false // example arg ["trash", "remove","pool/image"].