From 18a904d187713f5860b3751bafa554f8332d0128 Mon Sep 17 00:00:00 2001 From: yameiwang Date: Wed, 31 Oct 2018 17:20:46 +0800 Subject: [PATCH] fix golint errors in pkg/volume/* --- hack/.golint_failures | 3 -- pkg/volume/cephfs/cephfs.go | 54 ++++++++++----------- pkg/volume/configmap/configmap.go | 4 +- pkg/volume/scaleio/sio_client.go | 26 +++++----- pkg/volume/scaleio/sio_mgr.go | 2 +- pkg/volume/scaleio/sio_mgr_test.go | 2 +- pkg/volume/scaleio/sio_plugin.go | 1 + pkg/volume/scaleio/sio_util.go | 24 ++++----- pkg/volume/scaleio/sio_volume.go | 6 +-- pkg/volume/scaleio/sio_volume_test.go | 14 +++--- pkg/volume/secret/secret.go | 10 ++-- pkg/volume/storageos/storageos_util_test.go | 2 +- 12 files changed, 73 insertions(+), 75 deletions(-) diff --git a/hack/.golint_failures b/hack/.golint_failures index 5709188223..86d247907d 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -403,8 +403,6 @@ pkg/version/verflag pkg/volume pkg/volume/azure_dd pkg/volume/azure_file -pkg/volume/cephfs -pkg/volume/configmap pkg/volume/csi/fake pkg/volume/git_repo pkg/volume/host_path @@ -415,7 +413,6 @@ pkg/volume/photon_pd pkg/volume/portworx pkg/volume/rbd pkg/volume/scaleio -pkg/volume/secret pkg/volume/storageos pkg/volume/testing pkg/volume/util/fs diff --git a/pkg/volume/cephfs/cephfs.go b/pkg/volume/cephfs/cephfs.go index 99697a0de5..c78fbee8c3 100644 --- a/pkg/volume/cephfs/cephfs.go +++ b/pkg/volume/cephfs/cephfs.go @@ -34,7 +34,7 @@ import ( "k8s.io/kubernetes/pkg/volume/util" ) -// This is the primary entrypoint for volume plugins. +// ProbeVolumePlugins is the primary entrypoint for volume plugins. func ProbeVolumePlugins() []volume.VolumePlugin { return []volume.VolumePlugin{&cephfsPlugin{nil}} } @@ -144,7 +144,7 @@ func (plugin *cephfsPlugin) newMounterInternal(spec *volume.Spec, podUID types.U path: path, secret: secret, id: id, - secret_file: secretFile, + secretFile: secretFile, readonly: readOnly, mounter: mounter, plugin: plugin, @@ -182,16 +182,16 @@ func (plugin *cephfsPlugin) ConstructVolumeSpec(volumeName, mountPath string) (* // CephFS volumes represent a bare host file or directory mount of an CephFS export. type cephfs struct { - volName string - podUID types.UID - mon []string - path string - id string - secret string - secret_file string - readonly bool - mounter mount.Interface - plugin *cephfsPlugin + volName string + podUID types.UID + mon []string + path string + id string + secret string + secretFile string + readonly bool + mounter mount.Interface + plugin *cephfsPlugin volume.MetricsNil mountOptions []string } @@ -213,7 +213,7 @@ func (cephfsVolume *cephfsMounter) GetAttributes() volume.Attributes { // Checks prior to mount operations to verify that the required components (binaries, etc.) // to mount the volume are available on the underlying node. // If not, it returns an error -func (cephfsMounter *cephfsMounter) CanMount() error { +func (cephfsVolume *cephfsMounter) CanMount() error { return nil } @@ -250,10 +250,10 @@ func (cephfsVolume *cephfsMounter) SetUpAt(dir string, fsGroup *int64) error { if err == nil { // cephfs fuse mount succeeded. return nil - } else { - // if cephfs fuse mount failed, fallback to kernel mount. - glog.V(2).Infof("CephFS fuse mount failed: %v, fallback to kernel mount.", err) } + // if cephfs fuse mount failed, fallback to kernel mount. + glog.V(2).Infof("CephFS fuse mount failed: %v, fallback to kernel mount.", err) + } glog.V(4).Info("CephFS kernel mount.") @@ -298,19 +298,19 @@ func (cephfsVolume *cephfs) GetKeyringPath() string { func (cephfsVolume *cephfs) execMount(mountpoint string) error { // cephfs mount option - ceph_opt := "" + cephOpt := "" // override secretfile if secret is provided if cephfsVolume.secret != "" { - ceph_opt = "name=" + cephfsVolume.id + ",secret=" + cephfsVolume.secret + cephOpt = "name=" + cephfsVolume.id + ",secret=" + cephfsVolume.secret } else { - ceph_opt = "name=" + cephfsVolume.id + ",secretfile=" + cephfsVolume.secret_file + cephOpt = "name=" + cephfsVolume.id + ",secretfile=" + cephfsVolume.secretFile } // build option array opt := []string{} if cephfsVolume.readonly { opt = append(opt, "ro") } - opt = append(opt, ceph_opt) + opt = append(opt, cephOpt) // build src like mon1:6789,mon2:6789,mon3:6789:/ hosts := cephfsVolume.mon @@ -331,8 +331,8 @@ func (cephfsVolume *cephfs) execMount(mountpoint string) error { return nil } -func (cephfsMounter *cephfsMounter) checkFuseMount() bool { - execute := cephfsMounter.plugin.host.GetExec(cephfsMounter.plugin.GetPluginName()) +func (cephfsVolume *cephfsMounter) checkFuseMount() bool { + execute := cephfsVolume.plugin.host.GetExec(cephfsVolume.plugin.GetPluginName()) switch runtime.GOOS { case "linux": if _, err := execute.Run("/usr/bin/test", "-x", "/sbin/mount.fuse.ceph"); err == nil { @@ -346,7 +346,7 @@ func (cephfsMounter *cephfsMounter) checkFuseMount() bool { func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error { // cephfs keyring file - keyring_file := "" + keyringFile := "" // override secretfile if secret is provided if cephfsVolume.secret != "" { // TODO: cephfs fuse currently doesn't support secret option, @@ -380,10 +380,10 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error { return err } - keyring_file = path.Join(keyringPath, fileName) + keyringFile = path.Join(keyringPath, fileName) } else { - keyring_file = cephfsVolume.secret_file + keyringFile = cephfsVolume.secretFile } // build src like mon1:6789,mon2:6789,mon3:6789:/ @@ -399,7 +399,7 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error { mountArgs := []string{} mountArgs = append(mountArgs, "-k") - mountArgs = append(mountArgs, keyring_file) + mountArgs = append(mountArgs, keyringFile) mountArgs = append(mountArgs, "-m") mountArgs = append(mountArgs, src) mountArgs = append(mountArgs, mountpoint) @@ -423,7 +423,7 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error { command := exec.Command("ceph-fuse", mountArgs...) output, err := command.CombinedOutput() if err != nil || !(strings.Contains(string(output), "starting fuse")) { - return fmt.Errorf("Ceph-fuse failed: %v\narguments: %s\nOutput: %s\n", err, mountArgs, string(output)) + return fmt.Errorf("Ceph-fuse failed: %v\narguments: %s\nOutput: %s", err, mountArgs, string(output)) } return nil diff --git a/pkg/volume/configmap/configmap.go b/pkg/volume/configmap/configmap.go index a1474d2459..4fd1a7332d 100644 --- a/pkg/volume/configmap/configmap.go +++ b/pkg/volume/configmap/configmap.go @@ -30,7 +30,7 @@ import ( volumeutil "k8s.io/kubernetes/pkg/volume/util" ) -// ProbeVolumePlugin is the entry point for plugin detection in a package. +// ProbeVolumePlugins is the entry point for plugin detection in a package. func ProbeVolumePlugins() []volume.VolumePlugin { return []volume.VolumePlugin{&configMapPlugin{}} } @@ -260,7 +260,7 @@ func (b *configMapVolumeMounter) SetUpAt(dir string, fsGroup *int64) error { return nil } -// Note: this function is exported so that it can be called from the projection volume driver +// MakePayload function is exported so that it can be called from the projection volume driver func MakePayload(mappings []v1.KeyToPath, configMap *v1.ConfigMap, defaultMode *int32, optional bool) (map[string]volumeutil.FileProjection, error) { if defaultMode == nil { return nil, fmt.Errorf("No defaultMode used, not even the default value for it") diff --git a/pkg/volume/scaleio/sio_client.go b/pkg/volume/scaleio/sio_client.go index de5b050019..28d8ba79a4 100644 --- a/pkg/volume/scaleio/sio_client.go +++ b/pkg/volume/scaleio/sio_client.go @@ -74,7 +74,7 @@ type sioClient struct { spClient *sio.StoragePool provisionMode string sdcPath string - sdcGuid string + sdcGUID string instanceID string inited bool diskRegex *regexp.Regexp @@ -301,11 +301,11 @@ func (c *sioClient) IID() (string, error) { // if instanceID not set, retrieve it if c.instanceID == "" { - guid, err := c.getGuid() + guid, err := c.getGUID() if err != nil { return "", err } - sdc, err := c.sysClient.FindSdc("SdcGuid", guid) + sdc, err := c.sysClient.FindSdc("SdcGUID", guid) if err != nil { glog.Error(log("failed to retrieve sdc info %s", err)) return "", err @@ -316,10 +316,10 @@ func (c *sioClient) IID() (string, error) { return c.instanceID, nil } -// getGuid returns instance GUID, if not set using resource labels +// getGUID returns instance GUID, if not set using resource labels // it attempts to fallback to using drv_cfg binary -func (c *sioClient) getGuid() (string, error) { - if c.sdcGuid == "" { +func (c *sioClient) getGUID() (string, error) { + if c.sdcGUID == "" { glog.V(4).Info(log("sdc guid label not set, falling back to using drv_cfg")) cmd := c.getSdcCmd() output, err := c.exec.Run(cmd, "--query_guid") @@ -327,9 +327,9 @@ func (c *sioClient) getGuid() (string, error) { glog.Error(log("drv_cfg --query_guid failed: %v", err)) return "", err } - c.sdcGuid = strings.TrimSpace(string(output)) + c.sdcGUID = strings.TrimSpace(string(output)) } - return c.sdcGuid, nil + return c.sdcGUID, nil } // getSioDiskPaths traverse local disk devices to retrieve device path @@ -342,10 +342,10 @@ func (c *sioClient) getSioDiskPaths() ([]os.FileInfo, error) { if os.IsNotExist(err) { // sioDiskIDPath may not exist yet which is fine return []os.FileInfo{}, nil - } else { - glog.Error(log("failed to ReadDir %s: %v", sioDiskIDPath, err)) - return nil, err } + glog.Error(log("failed to ReadDir %s: %v", sioDiskIDPath, err)) + return nil, err + } result := []os.FileInfo{} for _, file := range files { @@ -360,13 +360,13 @@ func (c *sioClient) getSioDiskPaths() ([]os.FileInfo, error) { // GetVolumeRefs counts the number of references an SIO volume has a disk device. // This is useful in preventing premature detach. -func (c *sioClient) GetVolumeRefs(volId sioVolumeID) (refs int, err error) { +func (c *sioClient) GetVolumeRefs(volID sioVolumeID) (refs int, err error) { files, err := c.getSioDiskPaths() if err != nil { return 0, err } for _, file := range files { - if strings.Contains(file.Name(), string(volId)) { + if strings.Contains(file.Name(), string(volID)) { refs++ } } diff --git a/pkg/volume/scaleio/sio_mgr.go b/pkg/volume/scaleio/sio_mgr.go index 711fa7fce5..02fbbee6ee 100644 --- a/pkg/volume/scaleio/sio_mgr.go +++ b/pkg/volume/scaleio/sio_mgr.go @@ -81,7 +81,7 @@ func (m *sioMgr) getClient() (sioInterface, error) { client.spName = configs[confKey.storagePool] client.sdcPath = configs[confKey.sdcRootPath] client.provisionMode = configs[confKey.storageMode] - client.sdcGuid = configs[confKey.sdcGuid] + client.sdcGUID = configs[confKey.sdcGUID] m.client = client diff --git a/pkg/volume/scaleio/sio_mgr_test.go b/pkg/volume/scaleio/sio_mgr_test.go index 49ff5d05a8..b1dff3ca1a 100644 --- a/pkg/volume/scaleio/sio_mgr_test.go +++ b/pkg/volume/scaleio/sio_mgr_test.go @@ -311,7 +311,7 @@ func (f *fakeSio) Devs() (map[string]string, error) { return f.devs, nil } -func (f *fakeSio) GetVolumeRefs(volId sioVolumeID) (int, error) { +func (f *fakeSio) GetVolumeRefs(volID sioVolumeID) (int, error) { if f.volume == nil { return 0, nil } diff --git a/pkg/volume/scaleio/sio_plugin.go b/pkg/volume/scaleio/sio_plugin.go index 367c9b9638..c82b6d0fb1 100644 --- a/pkg/volume/scaleio/sio_plugin.go +++ b/pkg/volume/scaleio/sio_plugin.go @@ -36,6 +36,7 @@ type sioPlugin struct { volumeMtx keymutex.KeyMutex } +// ProbeVolumePlugins is the primary entrypoint for volume plugins. func ProbeVolumePlugins() []volume.VolumePlugin { p := &sioPlugin{ host: nil, diff --git a/pkg/volume/scaleio/sio_util.go b/pkg/volume/scaleio/sio_util.go index de0c581166..d4a1edcd8f 100644 --- a/pkg/volume/scaleio/sio_util.go +++ b/pkg/volume/scaleio/sio_util.go @@ -54,7 +54,7 @@ var ( username, password, secretNamespace, - sdcGuid string + sdcGUID string }{ gateway: "gateway", sslEnabled: "sslEnabled", @@ -71,9 +71,9 @@ var ( readOnly: "readOnly", username: "username", password: "password", - sdcGuid: "sdcGuid", + sdcGUID: "sdcGUID", } - sdcGuidLabelName = "scaleio.sdcGuid" + sdcGUIDLabelName = "scaleio.sdcGUID" sdcRootPath = "/opt/emc/scaleio/sdc/bin" secretNotFoundErr = errors.New("secret not found") @@ -232,30 +232,30 @@ func attachSecret(plug *sioPlugin, namespace string, configData map[string]strin return nil } -// attachSdcGuid injects the sdc guid node label value into config -func attachSdcGuid(plug *sioPlugin, conf map[string]string) error { - guid, err := getSdcGuidLabel(plug) +// attachSdcGUID injects the sdc guid node label value into config +func attachSdcGUID(plug *sioPlugin, conf map[string]string) error { + guid, err := getSdcGUIDLabel(plug) if err != nil { return err } - conf[confKey.sdcGuid] = guid + conf[confKey.sdcGUID] = guid return nil } -// getSdcGuidLabel fetches the scaleio.sdcGuid node label +// getSdcGUIDLabel fetches the scaleio.sdcGuid node label // associated with the node executing this code. -func getSdcGuidLabel(plug *sioPlugin) (string, error) { +func getSdcGUIDLabel(plug *sioPlugin) (string, error) { nodeLabels, err := plug.host.GetNodeLabels() if err != nil { return "", err } - label, ok := nodeLabels[sdcGuidLabelName] + label, ok := nodeLabels[sdcGUIDLabelName] if !ok { - glog.V(4).Info(log("node label %s not found", sdcGuidLabelName)) + glog.V(4).Info(log("node label %s not found", sdcGUIDLabelName)) return "", nil } - glog.V(4).Info(log("found node label %s=%s", sdcGuidLabelName, label)) + glog.V(4).Info(log("found node label %s=%s", sdcGUIDLabelName, label)) return label, nil } diff --git a/pkg/volume/scaleio/sio_volume.go b/pkg/volume/scaleio/sio_volume.go index 0f10dfa1e8..420afb36ba 100644 --- a/pkg/volume/scaleio/sio_volume.go +++ b/pkg/volume/scaleio/sio_volume.go @@ -266,7 +266,7 @@ func (v *sioVolume) Provision(selectedNode *api.Node, allowedTopologies []api.To // setup volume attrributes genName := v.generateName("k8svol", 11) var oneGig int64 = 1024 * 1024 * 1024 - var eightGig int64 = 8 * oneGig + eightGig := 8 * oneGig capacity := v.options.PVC.Spec.Resources.Requests[api.ResourceName(api.ResourceStorage)] volSizeBytes := capacity.Value() @@ -393,7 +393,7 @@ func (v *sioVolume) setSioMgr() error { } // merge in Sdc Guid label value - if err := attachSdcGuid(v.plugin, configData); err != nil { + if err := attachSdcGUID(v.plugin, configData); err != nil { glog.Error(log("failed to retrieve sdc guid: %v", err)) return err } @@ -432,7 +432,7 @@ func (v *sioVolume) resetSioMgr() error { } // merge in Sdc Guid label value - if err := attachSdcGuid(v.plugin, configData); err != nil { + if err := attachSdcGUID(v.plugin, configData); err != nil { glog.Error(log("failed to retrieve sdc guid: %v", err)) return err } diff --git a/pkg/volume/scaleio/sio_volume_test.go b/pkg/volume/scaleio/sio_volume_test.go index 7f122143f5..dbc7b8361e 100644 --- a/pkg/volume/scaleio/sio_volume_test.go +++ b/pkg/volume/scaleio/sio_volume_test.go @@ -56,7 +56,7 @@ func newPluginMgr(t *testing.T, apiObject runtime.Object) (*volume.VolumePluginM tmpDir, fakeClient, nil, - map[string]string{sdcGuidLabelName: "abc-123"}, + map[string]string{sdcGUIDLabelName: "abc-123"}, ) plugMgr := &volume.VolumePluginMgr{} plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, host) @@ -206,9 +206,9 @@ func TestVolumeMounterUnmounter(t *testing.T) { t.Errorf("SetUp() - expecting multiple volume disabled by default") } - // did we read sdcGuid label - if _, ok := sioVol.sioMgr.configData[confKey.sdcGuid]; !ok { - t.Errorf("Expected to find node label scaleio.sdcGuid, but did not find it") + // did we read sdcGUID label + if _, ok := sioVol.sioMgr.configData[confKey.sdcGUID]; !ok { + t.Errorf("Expected to find node label scaleio.sdcGUID, but did not find it") } // rebuild spec @@ -349,9 +349,9 @@ func TestVolumeProvisioner(t *testing.T) { t.Fatalf("Expected success, got: %v", err) } - // did we read sdcGuid label - if _, ok := sioVol.sioMgr.configData[confKey.sdcGuid]; !ok { - t.Errorf("Expected to find node label scaleio.sdcGuid, but did not find it") + // did we read sdcGUID label + if _, ok := sioVol.sioMgr.configData[confKey.sdcGUID]; !ok { + t.Errorf("Expected to find node label scaleio.sdcGUID, but did not find it") } // isMultiMap applied diff --git a/pkg/volume/secret/secret.go b/pkg/volume/secret/secret.go index 065b9bfb5a..92445b8d05 100644 --- a/pkg/volume/secret/secret.go +++ b/pkg/volume/secret/secret.go @@ -30,7 +30,7 @@ import ( volumeutil "k8s.io/kubernetes/pkg/volume/util" ) -// ProbeVolumePlugin is the entry point for plugin detection in a package. +// ProbeVolumePlugins is the entry point for plugin detection in a package. func ProbeVolumePlugins() []volume.VolumePlugin { return []volume.VolumePlugin{&secretPlugin{}} } @@ -259,7 +259,7 @@ func (b *secretVolumeMounter) SetUpAt(dir string, fsGroup *int64) error { return nil } -// Note: this function is exported so that it can be called from the projection volume driver +// MakePayload function is exported so that it can be called from the projection volume driver func MakePayload(mappings []v1.KeyToPath, secret *v1.Secret, defaultMode *int32, optional bool) (map[string]volumeutil.FileProjection, error) { if defaultMode == nil { return nil, fmt.Errorf("No defaultMode used, not even the default value for it") @@ -281,9 +281,9 @@ func MakePayload(mappings []v1.KeyToPath, secret *v1.Secret, defaultMode *int32, if optional { continue } - err_msg := "references non-existent secret key" - glog.Errorf(err_msg) - return nil, fmt.Errorf(err_msg) + errMsg := "references non-existent secret key" + glog.Errorf(errMsg) + return nil, fmt.Errorf(errMsg) } fileProjection.Data = []byte(content) diff --git a/pkg/volume/storageos/storageos_util_test.go b/pkg/volume/storageos/storageos_util_test.go index 598bfd5a21..e4800cbe51 100644 --- a/pkg/volume/storageos/storageos_util_test.go +++ b/pkg/volume/storageos/storageos_util_test.go @@ -30,7 +30,7 @@ import ( "testing" ) -var testApiSecretName = "storageos-api" +var testAPISecretName = "storageos-api" var testVolName = "storageos-test-vol" var testPVName = "storageos-test-pv" var testNamespace = "storageos-test-namespace"