Skip to content

Commit

Permalink
fixes #143 so that character case in parameters map is irrelevant
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher J. Ruwe <cjr@cruwe.de>
  • Loading branch information
cruwe committed Jun 3, 2020
1 parent dc730bd commit 3e6368a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
15 changes: 10 additions & 5 deletions pkg/common/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ func GetFirstHit(dict map[string]string, keys []string) string {
return res
}

// coerce the map's keys to lower and then lookup against all yaml and json specs
// only works with ASCII
func GetInsensitiveToCase(dict map[string]string, key string) string {
// coerce the map's keys to lower case, only works when unicode char is in ASCII subset
// may overwrite key-value pairs on different permutations of key case as in Key and key
func GetCaseInsensitiveMap(dict *map[string]string) map[string]string {
insensitiveDict := map[string]string{}

for k, v := range dict {
// may overwrite key-value pairs on different permutations of key case
for k, v := range *dict {
insensitiveDict[strings.ToLower(k)] = v
}
return insensitiveDict
}

// special case of GetCaseInsensitiveMap when only on key-value pair is required
func GetInsensitiveParameter(dict *map[string]string, key string) string {
insensitiveDict := GetCaseInsensitiveMap(dict)
return insensitiveDict[strings.ToLower(key)]
}
33 changes: 19 additions & 14 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,21 @@ 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 := helpers.GetFirstHit(
req.GetParameters(), []string{"fstype", "fsType", "FsType", "FStype", "FSTYPE"})
originalParams := req.GetParameters()
// param keys may be mistyped in storageclass wo kubectl CRD validation catching it
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)

Expand Down Expand Up @@ -132,7 +135,8 @@ 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()
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
size := req.GetCapacityRange().RequiredBytes
volsize := strconv.FormatInt(int64(size), 10)

Expand Down Expand Up @@ -190,7 +194,8 @@ func (cs *controller) CreateVolume(
var selected string

volName := req.GetName()
pool := req.GetParameters()["poolname"]
parameters := req.GetParameters()
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
size := req.GetCapacityRange().RequiredBytes
contentSource := req.GetVolumeContentSource()

Expand Down

0 comments on commit 3e6368a

Please sign in to comment.