From 39a996ea985ee9a200a4fdc70c0a3222c7d81227 Mon Sep 17 00:00:00 2001 From: xiangpengzhao Date: Mon, 18 Sep 2017 20:09:07 +0800 Subject: [PATCH] Use const instead of hard code for volume plugin --- pkg/volume/flexvolume/plugin.go | 7 +++++-- pkg/volume/plugins_test.go | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/volume/flexvolume/plugin.go b/pkg/volume/flexvolume/plugin.go index ed351e05ea..ba46e2c52d 100644 --- a/pkg/volume/flexvolume/plugin.go +++ b/pkg/volume/flexvolume/plugin.go @@ -32,7 +32,10 @@ import ( "k8s.io/utils/exec" ) -const flexVolumePluginName = "kubernetes.io/flexvolume" +const ( + flexVolumePluginName = "kubernetes.io/flexvolume" + flexVolumePluginNamePrefix = "flexvolume-" +) // FlexVolumePlugin object. type flexVolumePlugin struct { @@ -102,7 +105,7 @@ func (plugin *flexVolumePlugin) getExecutable() string { // Name is part of the volume.VolumePlugin interface. func (plugin *flexVolumePlugin) GetPluginName() string { - return "flexvolume-" + plugin.driverName + return flexVolumePluginNamePrefix + plugin.driverName } // GetVolumeName is part of the volume.VolumePlugin interface. diff --git a/pkg/volume/plugins_test.go b/pkg/volume/plugins_test.go index b8d74a26fa..fc780d6a2e 100644 --- a/pkg/volume/plugins_test.go +++ b/pkg/volume/plugins_test.go @@ -24,6 +24,8 @@ import ( "k8s.io/apimachinery/pkg/types" ) +const testPluginName = "kubernetes.io/testPlugin" + func TestSpecSourceConverters(t *testing.T) { v := &v1.Volume{ Name: "foo", @@ -62,7 +64,7 @@ func (plugin *testPlugins) Init(host VolumeHost) error { } func (plugin *testPlugins) GetPluginName() string { - return "testPlugin" + return testPluginName } func (plugin *testPlugins) GetVolumeName(spec *Spec) (string, error) { @@ -106,11 +108,11 @@ func TestVolumePluginMgrFunc(t *testing.T) { var prober DynamicPluginProber = nil // TODO (#51147) inject mock vpm.InitPlugins(newTestPlugin(), prober, nil) - plug, err := vpm.FindPluginByName("testPlugin") + plug, err := vpm.FindPluginByName(testPluginName) if err != nil { t.Errorf("Can't find the plugin by name") } - if plug.GetPluginName() != "testPlugin" { + if plug.GetPluginName() != testPluginName { t.Errorf("Wrong name: %s", plug.GetPluginName()) }