Commit 39a996ea authored by xiangpengzhao's avatar xiangpengzhao

Use const instead of hard code for volume plugin

parent 93ddb7be
...@@ -32,7 +32,10 @@ import ( ...@@ -32,7 +32,10 @@ import (
"k8s.io/utils/exec" "k8s.io/utils/exec"
) )
const flexVolumePluginName = "kubernetes.io/flexvolume" const (
flexVolumePluginName = "kubernetes.io/flexvolume"
flexVolumePluginNamePrefix = "flexvolume-"
)
// FlexVolumePlugin object. // FlexVolumePlugin object.
type flexVolumePlugin struct { type flexVolumePlugin struct {
...@@ -102,7 +105,7 @@ func (plugin *flexVolumePlugin) getExecutable() string { ...@@ -102,7 +105,7 @@ func (plugin *flexVolumePlugin) getExecutable() string {
// Name is part of the volume.VolumePlugin interface. // Name is part of the volume.VolumePlugin interface.
func (plugin *flexVolumePlugin) GetPluginName() string { func (plugin *flexVolumePlugin) GetPluginName() string {
return "flexvolume-" + plugin.driverName return flexVolumePluginNamePrefix + plugin.driverName
} }
// GetVolumeName is part of the volume.VolumePlugin interface. // GetVolumeName is part of the volume.VolumePlugin interface.
......
...@@ -24,6 +24,8 @@ import ( ...@@ -24,6 +24,8 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
) )
const testPluginName = "kubernetes.io/testPlugin"
func TestSpecSourceConverters(t *testing.T) { func TestSpecSourceConverters(t *testing.T) {
v := &v1.Volume{ v := &v1.Volume{
Name: "foo", Name: "foo",
...@@ -62,7 +64,7 @@ func (plugin *testPlugins) Init(host VolumeHost) error { ...@@ -62,7 +64,7 @@ func (plugin *testPlugins) Init(host VolumeHost) error {
} }
func (plugin *testPlugins) GetPluginName() string { func (plugin *testPlugins) GetPluginName() string {
return "testPlugin" return testPluginName
} }
func (plugin *testPlugins) GetVolumeName(spec *Spec) (string, error) { func (plugin *testPlugins) GetVolumeName(spec *Spec) (string, error) {
...@@ -106,11 +108,11 @@ func TestVolumePluginMgrFunc(t *testing.T) { ...@@ -106,11 +108,11 @@ func TestVolumePluginMgrFunc(t *testing.T) {
var prober DynamicPluginProber = nil // TODO (#51147) inject mock var prober DynamicPluginProber = nil // TODO (#51147) inject mock
vpm.InitPlugins(newTestPlugin(), prober, nil) vpm.InitPlugins(newTestPlugin(), prober, nil)
plug, err := vpm.FindPluginByName("testPlugin") plug, err := vpm.FindPluginByName(testPluginName)
if err != nil { if err != nil {
t.Errorf("Can't find the plugin by name") t.Errorf("Can't find the plugin by name")
} }
if plug.GetPluginName() != "testPlugin" { if plug.GetPluginName() != testPluginName {
t.Errorf("Wrong name: %s", plug.GetPluginName()) t.Errorf("Wrong name: %s", plug.GetPluginName())
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment