Merge pull request #52662 from xiangpengzhao/volume-const

Automatic merge from submit-queue (batch tested with PRs 52662, 53547, 53588, 53573, 53599). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Use const instead of hard code for volume plugin

**What this PR does / why we need it**:
nits: cleanup hard-coded volume plugin name

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-10-09 12:51:14 -07:00 committed by GitHub
commit 3752a511a4
2 changed files with 10 additions and 5 deletions

View File

@ -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.

View File

@ -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())
}