Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix golint issue for pkg/volume/flexvolume package #68813

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion hack/.golint_failures
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ pkg/volume/configmap
pkg/volume/csi/fake
pkg/volume/empty_dir
pkg/volume/fc
pkg/volume/flexvolume
pkg/volume/flocker
pkg/volume/gce_pd
pkg/volume/git_repo
Expand Down
3 changes: 1 addition & 2 deletions pkg/volume/flexvolume/attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ func (a *flexVolumeAttacher) MountDevice(spec *volume.Spec, devicePath string, d
// plugin does not implement attach interface.
if devicePath != "" {
return (*attacherDefaults)(a).MountDevice(spec, devicePath, deviceMountPath, a.plugin.host.GetMounter(a.plugin.GetPluginName()))
} else {
return nil
}
return nil
}
return err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/volume/flexvolume/attacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAttach(t *testing.T) {
plugin, _ := testPlugin()
plugin.runner = fakeRunner(
assertDriverCall(t, notSupportedOutput(), attachCmd,
specJson(plugin, spec, nil), "localhost"),
specJSON(plugin, spec, nil), "localhost"),
)

a, _ := plugin.NewAttacher()
Expand All @@ -43,7 +43,7 @@ func TestWaitForAttach(t *testing.T) {
plugin, _ := testPlugin()
plugin.runner = fakeRunner(
assertDriverCall(t, notSupportedOutput(), waitForAttachCmd, "/dev/sdx",
specJson(plugin, spec, nil)),
specJSON(plugin, spec, nil)),
)

a, _ := plugin.NewAttacher()
Expand All @@ -56,7 +56,7 @@ func TestMountDevice(t *testing.T) {
plugin, rootDir := testPlugin()
plugin.runner = fakeRunner(
assertDriverCall(t, notSupportedOutput(), mountDeviceCmd, rootDir+"/mount-dir", "/dev/sdx",
specJson(plugin, spec, nil)),
specJSON(plugin, spec, nil)),
)

a, _ := plugin.NewAttacher()
Expand All @@ -68,7 +68,7 @@ func TestIsVolumeAttached(t *testing.T) {

plugin, _ := testPlugin()
plugin.runner = fakeRunner(
assertDriverCall(t, notSupportedOutput(), isAttached, specJson(plugin, spec, nil), "localhost"),
assertDriverCall(t, notSupportedOutput(), isAttached, specJSON(plugin, spec, nil), "localhost"),
)
a, _ := plugin.NewAttacher()
specs := []*volume.Spec{spec}
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/flexvolume/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func fakePersistentVolumeSpec() *volume.Spec {
return volume.NewSpecFromPersistentVolume(vol, false)
}

func specJson(plugin *flexVolumeAttachablePlugin, spec *volume.Spec, extraOptions map[string]string) string {
func specJSON(plugin *flexVolumeAttachablePlugin, spec *volume.Spec, extraOptions map[string]string) string {
o, err := NewOptionsForDriver(spec, plugin.host, extraOptions)
if err != nil {
panic("Failed to convert spec: " + err.Error())
Expand Down
9 changes: 7 additions & 2 deletions pkg/volume/flexvolume/driver-call.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const (
)

var (
TimeoutError = fmt.Errorf("Timeout")
errTimeout = fmt.Errorf("Timeout")
)

// DriverCall implements the basic contract between FlexVolume and its driver.
Expand All @@ -92,10 +92,12 @@ func (plugin *flexVolumePlugin) NewDriverCallWithTimeout(command string, timeout
}
}

// Append appends arg into driver call argument list
func (dc *DriverCall) Append(arg string) {
dc.args = append(dc.args, arg)
}

// AppendSpec appends volume spec to driver call argument list
func (dc *DriverCall) AppendSpec(spec *volume.Spec, host volume.VolumeHost, extraOptions map[string]string) error {
optionsForDriver, err := NewOptionsForDriver(spec, host, extraOptions)
if err != nil {
Expand All @@ -111,6 +113,7 @@ func (dc *DriverCall) AppendSpec(spec *volume.Spec, host volume.VolumeHost, extr
return nil
}

// Run executes the driver call
func (dc *DriverCall) Run() (*DriverStatus, error) {
if dc.plugin.isUnsupported(dc.Command) {
return nil, errors.New(StatusNotSupported)
Expand All @@ -131,7 +134,7 @@ func (dc *DriverCall) Run() (*DriverStatus, error) {
output, execErr := cmd.CombinedOutput()
if execErr != nil {
if timeout {
return nil, TimeoutError
return nil, errTimeout
}
_, err := handleCmdResponse(dc.Command, output)
if err == nil {
Expand Down Expand Up @@ -160,6 +163,7 @@ func (dc *DriverCall) Run() (*DriverStatus, error) {
// OptionsForDriver represents the spec given to the driver.
type OptionsForDriver map[string]string

// NewOptionsForDriver create driver options given volume spec
func NewOptionsForDriver(spec *volume.Spec, host volume.VolumeHost, extraOptions map[string]string) (OptionsForDriver, error) {

volSourceFSType, err := getFSType(spec)
Expand Down Expand Up @@ -219,6 +223,7 @@ type DriverStatus struct {
Capabilities *DriverCapabilities `json:",omitempty"`
}

// DriverCapabilities represents what driver can do
type DriverCapabilities struct {
Attach bool `json:"attach"`
SELinuxRelabel bool `json:"selinuxRelabel"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/flexvolume/fake_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type fakeWatcher struct {

var _ utilfs.FSWatcher = &fakeWatcher{}

func NewFakeWatcher() *fakeWatcher {
func newFakeWatcher() *fakeWatcher {
return &fakeWatcher{
watches: nil,
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/volume/flexvolume/mounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestSetUpAt(t *testing.T) {
plugin.runner = fakeRunner(
// first call without fsGroup
assertDriverCall(t, successOutput(), mountCmd, rootDir+"/mount-dir",
specJson(plugin, spec, map[string]string{
specJSON(plugin, spec, map[string]string{
optionKeyPodName: "my-pod",
optionKeyPodNamespace: "my-ns",
optionKeyPodUID: "my-uid",
Expand All @@ -53,15 +53,15 @@ func TestSetUpAt(t *testing.T) {

// second test has fsGroup
assertDriverCall(t, notSupportedOutput(), mountCmd, rootDir+"/mount-dir",
specJson(plugin, spec, map[string]string{
specJSON(plugin, spec, map[string]string{
optionFSGroup: "42",
optionKeyPodName: "my-pod",
optionKeyPodNamespace: "my-ns",
optionKeyPodUID: "my-uid",
optionKeyServiceAccountName: "my-sa",
})),
assertDriverCall(t, fakeVolumeNameOutput("sdx"), getVolumeNameCmd,
specJson(plugin, spec, nil)),
specJSON(plugin, spec, nil)),
)

m, _ := plugin.newMounterInternal(spec, pod, mounter, plugin.runner)
Expand Down
4 changes: 2 additions & 2 deletions pkg/volume/flexvolume/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var _ volume.PersistentVolumePlugin = &flexVolumePlugin{}

var _ volume.DeviceMountableVolumePlugin = &flexVolumeAttachablePlugin{}

// PluginFactory create flex volume plugin
type PluginFactory interface {
NewFlexVolumePlugin(pluginDir, driverName string, runner exec.Interface) (volume.VolumePlugin, error)
}
Expand Down Expand Up @@ -89,9 +90,8 @@ func (pluginFactory) NewFlexVolumePlugin(pluginDir, name string, runner exec.Int
if flexPlugin.capabilities.Attach {
// Plugin supports attach/detach, so return flexVolumeAttachablePlugin
return &flexVolumeAttachablePlugin{flexVolumePlugin: flexPlugin}, nil
} else {
return flexPlugin, nil
}
return flexPlugin, nil
}

// Init is part of the volume.VolumePlugin interface.
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/flexvolume/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestGetVolumeName(t *testing.T) {
plugin, _ := testPlugin()
plugin.runner = fakeRunner(
assertDriverCall(t, fakeVolumeNameOutput(spec.Name()), getVolumeNameCmd,
specJson(plugin, spec, nil)),
specJSON(plugin, spec, nil)),
)

name, err := plugin.GetVolumeName(spec)
Expand Down
1 change: 1 addition & 0 deletions pkg/volume/flexvolume/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type flexVolumeProber struct {
eventsMap map[string]volume.ProbeOperation // the key is the driver directory path, the value is the coresponding operation
}

// GetDynamicPluginProber creates dynamic plugin prober
func GetDynamicPluginProber(pluginDir string, runner exec.Interface) volume.DynamicPluginProber {
return &flexVolumeProber{
pluginDir: pluginDir,
Expand Down
6 changes: 3 additions & 3 deletions pkg/volume/flexvolume/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
func TestEmptyPluginDir(t *testing.T) {
// Arrange
fs := utilfs.NewFakeFs()
watcher := NewFakeWatcher()
watcher := newFakeWatcher()
prober := &flexVolumeProber{
pluginDir: pluginDir,
watcher: watcher,
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestProberMultipleEvents(t *testing.T) {

func TestProberError(t *testing.T) {
fs := utilfs.NewFakeFs()
watcher := NewFakeWatcher()
watcher := newFakeWatcher()
prober := &flexVolumeProber{
pluginDir: pluginDir,
watcher: watcher,
Expand Down Expand Up @@ -296,7 +296,7 @@ func initTestEnvironment(t *testing.T) (
watcher *fakeWatcher,
prober volume.DynamicPluginProber) {
fs = utilfs.NewFakeFs()
watcher = NewFakeWatcher()
watcher = newFakeWatcher()
prober = &flexVolumeProber{
pluginDir: pluginDir,
watcher: watcher,
Expand Down
12 changes: 6 additions & 6 deletions pkg/volume/flexvolume/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func addSecretsToOptions(options map[string]string, spec *volume.Spec, namespace
return nil
}

var notFlexVolume = fmt.Errorf("not a flex volume")
var errNotFlexVolume = fmt.Errorf("not a flex volume")

func getDriver(spec *volume.Spec) (string, error) {
if spec.Volume != nil && spec.Volume.FlexVolume != nil {
Expand All @@ -64,7 +64,7 @@ func getDriver(spec *volume.Spec) (string, error) {
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FlexVolume != nil {
return spec.PersistentVolume.Spec.FlexVolume.Driver, nil
}
return "", notFlexVolume
return "", errNotFlexVolume
}

func getFSType(spec *volume.Spec) (string, error) {
Expand All @@ -74,7 +74,7 @@ func getFSType(spec *volume.Spec) (string, error) {
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FlexVolume != nil {
return spec.PersistentVolume.Spec.FlexVolume.FSType, nil
}
return "", notFlexVolume
return "", errNotFlexVolume
}

func getSecretNameAndNamespace(spec *volume.Spec, podNamespace string) (string, string, error) {
Expand All @@ -95,7 +95,7 @@ func getSecretNameAndNamespace(spec *volume.Spec, podNamespace string) (string,
}
return secretName, secretNamespace, nil
}
return "", "", notFlexVolume
return "", "", errNotFlexVolume
}

func getReadOnly(spec *volume.Spec) (bool, error) {
Expand All @@ -106,7 +106,7 @@ func getReadOnly(spec *volume.Spec) (bool, error) {
// ReadOnly is specified at the PV level
return spec.ReadOnly, nil
}
return false, notFlexVolume
return false, errNotFlexVolume
}

func getOptions(spec *volume.Spec) (map[string]string, error) {
Expand All @@ -116,7 +116,7 @@ func getOptions(spec *volume.Spec) (map[string]string, error) {
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FlexVolume != nil {
return spec.PersistentVolume.Spec.FlexVolume.Options, nil
}
return nil, notFlexVolume
return nil, errNotFlexVolume
}

func prepareForMount(mounter mount.Interface, deviceMountPath string) (bool, error) {
Expand Down