Skip to content

Commit

Permalink
fixes #143 differently changing the CRD spec to "fstype"
Browse files Browse the repository at this point in the history
More specifically,
- introduce helper functions to lookup values based on a sequence of
  possible keys and ignore case all together and
- lookup the fstype based on a sequence of possible spellings.

Signed-off-by: Christopher J. Ruwe <[email protected]>
  • Loading branch information
cruwe committed Jun 3, 2020
1 parent 8279592 commit b52200d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
47 changes: 47 additions & 0 deletions pkg/common/helpers/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2019 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package helpers

import (
"strings"
)

// iterate over []possibleKeys and return the first non-nil result on lookup
func GetFirstHit(dict map[string]string, keys []string) string {
var res string

for _, key := range keys {
res = dict[key]
println("key is %s, result is %v", key, res)
if len(res) > 0 {
break
}
}
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 {
insensitiveDict := map[string]string{}

for k, v := range dict {
// may overwrite key-value pairs on different permutations of key case
insensitiveDict[strings.ToLower(k)] = v
}
return insensitiveDict[strings.ToLower(key)]
}
4 changes: 3 additions & 1 deletion pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -85,7 +86,8 @@ func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) {
pool := req.GetParameters()["poolname"]
tp := req.GetParameters()["thinprovision"]
schld := req.GetParameters()["scheduler"]
fstype := req.GetParameters()["fsType"]
fstype := helpers.GetFirstHit(
req.GetParameters(), []string{"fstype", "fsType", "FsType", "FStype", "FSTYPE"})

vtype := zfs.GetVolumeType(fstype)

Expand Down

0 comments on commit b52200d

Please sign in to comment.