mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-25 15:50:20 +00:00
util: add helper function to strip kube parameters
added helper function to strip the kubernetes specific parameters from the volumeContext as volumeContext is storaged in the PV volumeAttributes Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
f57b7f88b0
commit
772fe8d6c8
39
internal/util/k8s/parameters.go
Normal file
39
internal/util/k8s/parameters.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Ceph-CSI 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 k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CSI Parameters prefixed with csiParameterPrefix are passed through
|
||||||
|
// to the driver on CreateVolumeRequest/CreateSnapshotRequest calls.
|
||||||
|
const (
|
||||||
|
csiParameterPrefix = "csi.storage.k8s.io/"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RemoveCSIPrefixedParameters removes parameters prefixed with csiParameterPrefix.
|
||||||
|
func RemoveCSIPrefixedParameters(param map[string]string) map[string]string {
|
||||||
|
newParam := map[string]string{}
|
||||||
|
for k, v := range param {
|
||||||
|
if !strings.HasPrefix(k, csiParameterPrefix) {
|
||||||
|
// add the parameter to the new map if its not having the prefix
|
||||||
|
newParam[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newParam
|
||||||
|
}
|
62
internal/util/k8s/parameters_test.go
Normal file
62
internal/util/k8s/parameters_test.go
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Ceph-CSI 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 k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRemoveCSIPrefixedParameters(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
param map[string]string
|
||||||
|
want map[string]string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "without csi.storage.k8s.io prefix",
|
||||||
|
param: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
want: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with csi.storage.k8s.io prefix",
|
||||||
|
param: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"csi.storage.k8s.io/pvc/name": "foo",
|
||||||
|
"csi.storage.k8s.io/pvc/namespace": "bar",
|
||||||
|
"csi.storage.k8s.io/pv/name": "baz",
|
||||||
|
},
|
||||||
|
want: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
ts := tt
|
||||||
|
t.Run(ts.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
got := RemoveCSIPrefixedParameters(ts.param)
|
||||||
|
if !reflect.DeepEqual(got, ts.want) {
|
||||||
|
t.Errorf("RemoveCSIPrefixedParameters() = %v, want %v", got, ts.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user