mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 06:10:22 +00:00
util: add helper to get pvcnamespace from input
added helper function to return the pvc namespace name from the input parameters. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
772fe8d6c8
commit
366c2ace31
@ -23,6 +23,7 @@ import (
|
|||||||
// to the driver on CreateVolumeRequest/CreateSnapshotRequest calls.
|
// to the driver on CreateVolumeRequest/CreateSnapshotRequest calls.
|
||||||
const (
|
const (
|
||||||
csiParameterPrefix = "csi.storage.k8s.io/"
|
csiParameterPrefix = "csi.storage.k8s.io/"
|
||||||
|
pvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RemoveCSIPrefixedParameters removes parameters prefixed with csiParameterPrefix.
|
// RemoveCSIPrefixedParameters removes parameters prefixed with csiParameterPrefix.
|
||||||
@ -37,3 +38,8 @@ func RemoveCSIPrefixedParameters(param map[string]string) map[string]string {
|
|||||||
|
|
||||||
return newParam
|
return newParam
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOwner returns the pvc namespace name from the parameter.
|
||||||
|
func GetOwner(param map[string]string) string {
|
||||||
|
return param[pvcNamespaceKey]
|
||||||
|
}
|
||||||
|
@ -60,3 +60,36 @@ func TestRemoveCSIPrefixedParameters(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetOwner(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args map[string]string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "namespace is not present in the parameters",
|
||||||
|
args: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
want: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "namespace is present in the parameters",
|
||||||
|
args: map[string]string{
|
||||||
|
"csi.storage.k8s.io/pvc/namespace": "bar",
|
||||||
|
},
|
||||||
|
want: "bar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
ts := tt
|
||||||
|
t.Run(ts.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
if got := GetOwner(ts.args); got != ts.want {
|
||||||
|
t.Errorf("GetOwner() = %v, want %v", got, ts.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user