make character case for keys in parameters map irrelevant, fixing #143

More specifically,
- introduce helper function to get maps with all keys set to lowercase,
- introduce lookup helper based on such maps and
- change lookups for CreateVolumeRequest()s and CreateVolume()s so that
  parameter keys are processed as lowercase irrespective of actual
  spelling.

Signed-off-by: Christopher J. Ruwe <cjr@cruwe.de>
This commit is contained in:
Christopher J. Ruwe 2020-06-01 14:21:24 +02:00 committed by Pawan Prakash Sharma
parent 1e23607d8a
commit 377b881653
3 changed files with 70 additions and 13 deletions

View file

@ -27,6 +27,7 @@ import (
"github.com/openebs/zfs-localpv/pkg/builder/snapbuilder"
"github.com/openebs/zfs-localpv/pkg/builder/volbuilder"
errors "github.com/openebs/zfs-localpv/pkg/common/errors"
"github.com/openebs/zfs-localpv/pkg/common/helpers"
csipayload "github.com/openebs/zfs-localpv/pkg/response"
analytics "github.com/openebs/zfs-localpv/pkg/usage"
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
@ -75,17 +76,25 @@ func sendEventOrIgnore(pvName, capacity, stgType, method string) {
func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) {
volName := req.GetName()
size := req.GetCapacityRange().RequiredBytes
rs := req.GetParameters()["recordsize"]
bs := req.GetParameters()["volblocksize"]
compression := req.GetParameters()["compression"]
dedup := req.GetParameters()["dedup"]
encr := req.GetParameters()["encryption"]
kf := req.GetParameters()["keyformat"]
kl := req.GetParameters()["keylocation"]
pool := req.GetParameters()["poolname"]
tp := req.GetParameters()["thinprovision"]
schld := req.GetParameters()["scheduler"]
fstype := req.GetParameters()["fstype"]
// parameter keys may be mistyped from the CRD specification when declaring
// the storageclass, which kubectl validation will not catch. Because ZFS
// parameter keys (not values!) are all lowercase, keys may safely be forced
// to the lower case.
originalParams := req.GetParameters()
parameters := helpers.GetCaseInsensitiveMap(&originalParams)
rs := parameters["recordsize"]
bs := parameters["volblocksize"]
compression := parameters["compression"]
dedup := parameters["dedup"]
encr := parameters["encryption"]
kf := parameters["keyformat"]
kl := parameters["keylocation"]
pool := parameters["poolname"]
tp := parameters["thinprovision"]
schld := parameters["scheduler"]
fstype := parameters["fstype"]
vtype := zfs.GetVolumeType(fstype)
@ -130,7 +139,9 @@ func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) {
func CreateZFSClone(req *csi.CreateVolumeRequest, snapshot string) (string, error) {
volName := req.GetName()
pool := req.GetParameters()["poolname"]
parameters := req.GetParameters()
// lower case keys, cf CreateZFSVolume()
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
size := req.GetCapacityRange().RequiredBytes
volsize := strconv.FormatInt(int64(size), 10)
@ -188,7 +199,9 @@ func (cs *controller) CreateVolume(
var selected string
volName := req.GetName()
pool := req.GetParameters()["poolname"]
parameters := req.GetParameters()
// lower case keys, cf CreateZFSVolume()
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
size := req.GetCapacityRange().RequiredBytes
contentSource := req.GetVolumeContentSource()