From 6f82f40760da40eed47717a2432832dc3df6566c Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Tue, 24 Apr 2018 19:08:38 +0530 Subject: [PATCH 1/2] replace path with filepath --- pkg/volume/aws_ebs/attacher.go | 4 ++-- pkg/volume/aws_ebs/aws_ebs.go | 5 ++--- pkg/volume/aws_ebs/aws_ebs_block.go | 3 +-- pkg/volume/aws_ebs/aws_ebs_block_test.go | 8 ++++---- pkg/volume/aws_ebs/aws_ebs_test.go | 4 ++-- pkg/volume/azure_dd/attacher.go | 3 +-- pkg/volume/azure_dd/azure_common.go | 4 ++-- pkg/volume/azure_dd/azure_common_linux.go | 8 ++++---- pkg/volume/azure_file/azure_file_test.go | 4 ++-- 9 files changed, 20 insertions(+), 23 deletions(-) diff --git a/pkg/volume/aws_ebs/attacher.go b/pkg/volume/aws_ebs/attacher.go index 059431e1661..9b7d732b3cb 100644 --- a/pkg/volume/aws_ebs/attacher.go +++ b/pkg/volume/aws_ebs/attacher.go @@ -19,7 +19,7 @@ package aws_ebs import ( "fmt" "os" - "path" + "path/filepath" "strconv" "time" @@ -249,7 +249,7 @@ func (plugin *awsElasticBlockStorePlugin) NewDetacher() (volume.Detacher, error) } func (detacher *awsElasticBlockStoreDetacher) Detach(volumeName string, nodeName types.NodeName) error { - volumeID := aws.KubernetesVolumeID(path.Base(volumeName)) + volumeID := aws.KubernetesVolumeID(filepath.Base(volumeName)) if _, err := detacher.awsVolumes.DetachDisk(volumeID, nodeName); err != nil { glog.Errorf("Error detaching volumeID %q: %v", volumeID, err) diff --git a/pkg/volume/aws_ebs/aws_ebs.go b/pkg/volume/aws_ebs/aws_ebs.go index 869d06773c1..71531245371 100644 --- a/pkg/volume/aws_ebs/aws_ebs.go +++ b/pkg/volume/aws_ebs/aws_ebs.go @@ -19,7 +19,6 @@ package aws_ebs import ( "fmt" "os" - "path" "path/filepath" "strconv" "strings" @@ -387,12 +386,12 @@ func makeGlobalPDPath(host volume.VolumeHost, volumeID aws.KubernetesVolumeID) s // Clean up the URI to be more fs-friendly name := string(volumeID) name = strings.Replace(name, "://", "/", -1) - return path.Join(host.GetPluginDir(awsElasticBlockStorePluginName), mount.MountsInGlobalPDPath, name) + return filepath.Join(host.GetPluginDir(awsElasticBlockStorePluginName), mount.MountsInGlobalPDPath, name) } // Reverses the mapping done in makeGlobalPDPath func getVolumeIDFromGlobalMount(host volume.VolumeHost, globalPath string) (string, error) { - basePath := path.Join(host.GetPluginDir(awsElasticBlockStorePluginName), mount.MountsInGlobalPDPath) + basePath := filepath.Join(host.GetPluginDir(awsElasticBlockStorePluginName), mount.MountsInGlobalPDPath) rel, err := filepath.Rel(basePath, globalPath) if err != nil { glog.Errorf("Failed to get volume id from global mount %s - %v", globalPath, err) diff --git a/pkg/volume/aws_ebs/aws_ebs_block.go b/pkg/volume/aws_ebs/aws_ebs_block.go index d104bafa5e9..37e748707c6 100644 --- a/pkg/volume/aws_ebs/aws_ebs_block.go +++ b/pkg/volume/aws_ebs/aws_ebs_block.go @@ -18,7 +18,6 @@ package aws_ebs import ( "fmt" - "path" "path/filepath" "strconv" "strings" @@ -164,7 +163,7 @@ func (ebs *awsElasticBlockStore) GetGlobalMapPath(spec *volume.Spec) (string, er if err != nil { return "", err } - return path.Join(ebs.plugin.host.GetVolumeDevicePluginDir(awsElasticBlockStorePluginName), string(volumeSource.VolumeID)), nil + return filepath.Join(ebs.plugin.host.GetVolumeDevicePluginDir(awsElasticBlockStorePluginName), string(volumeSource.VolumeID)), nil } // GetPodDeviceMapPath returns pod device map path and volume name diff --git a/pkg/volume/aws_ebs/aws_ebs_block_test.go b/pkg/volume/aws_ebs/aws_ebs_block_test.go index a1a4ba37d8c..5181492d6c0 100644 --- a/pkg/volume/aws_ebs/aws_ebs_block_test.go +++ b/pkg/volume/aws_ebs/aws_ebs_block_test.go @@ -18,7 +18,7 @@ package aws_ebs import ( "os" - "path" + "path/filepath" "testing" "k8s.io/api/core/v1" @@ -47,7 +47,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) { //deferred clean up defer os.RemoveAll(tmpVDir) - expectedGlobalPath := path.Join(tmpVDir, testGlobalPath) + expectedGlobalPath := filepath.Join(tmpVDir, testGlobalPath) //Bad Path badspec, err := getVolumeSpecFromGlobalMapPath("") @@ -102,8 +102,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) { //deferred clean up defer os.RemoveAll(tmpVDir) - expectedGlobalPath := path.Join(tmpVDir, testGlobalPath) - expectedPodPath := path.Join(tmpVDir, testPodPath) + expectedGlobalPath := filepath.Join(tmpVDir, testGlobalPath) + expectedPodPath := filepath.Join(tmpVDir, testPodPath) spec := getTestVolume(false, true /*isBlock*/) plugMgr := volume.VolumePluginMgr{} diff --git a/pkg/volume/aws_ebs/aws_ebs_test.go b/pkg/volume/aws_ebs/aws_ebs_test.go index 95d81c049ef..72438e379b7 100644 --- a/pkg/volume/aws_ebs/aws_ebs_test.go +++ b/pkg/volume/aws_ebs/aws_ebs_test.go @@ -19,7 +19,7 @@ package aws_ebs import ( "fmt" "os" - "path" + "path/filepath" "testing" "k8s.io/api/core/v1" @@ -129,7 +129,7 @@ func TestPlugin(t *testing.T) { t.Errorf("Got a nil Mounter") } - volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~aws-ebs/vol1") + volPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~aws-ebs/vol1") path := mounter.GetPath() if path != volPath { t.Errorf("Got unexpected path: %s", path) diff --git a/pkg/volume/azure_dd/attacher.go b/pkg/volume/azure_dd/attacher.go index 3a00b86d214..da9d92ac297 100644 --- a/pkg/volume/azure_dd/attacher.go +++ b/pkg/volume/azure_dd/attacher.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "os" - "path" "path/filepath" "runtime" "strconv" @@ -209,7 +208,7 @@ func (a *azureDiskAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error } if volumeSource.Kind == nil { // this spec was constructed from info on the node - pdPath := path.Join(a.plugin.host.GetPluginDir(azureDataDiskPluginName), mount.MountsInGlobalPDPath, volumeSource.DataDiskURI) + pdPath := filepath.Join(a.plugin.host.GetPluginDir(azureDataDiskPluginName), mount.MountsInGlobalPDPath, volumeSource.DataDiskURI) return pdPath, nil } diff --git a/pkg/volume/azure_dd/azure_common.go b/pkg/volume/azure_dd/azure_common.go index 61a71354463..ab31ab2a975 100644 --- a/pkg/volume/azure_dd/azure_common.go +++ b/pkg/volume/azure_dd/azure_common.go @@ -20,7 +20,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" libstrings "strings" storage "github.com/Azure/azure-sdk-for-go/arm/storage" @@ -76,7 +76,7 @@ func makeGlobalPDPath(host volume.VolumeHost, diskUri string, isManaged bool) (s } // "{m for managed b for blob}{hashed diskUri or DiskId depending on disk kind }" diskName := fmt.Sprintf(uniqueDiskNameTemplate, prefix, hashedDiskUri) - pdPath := path.Join(host.GetPluginDir(azureDataDiskPluginName), mount.MountsInGlobalPDPath, diskName) + pdPath := filepath.Join(host.GetPluginDir(azureDataDiskPluginName), mount.MountsInGlobalPDPath, diskName) return pdPath, nil } diff --git a/pkg/volume/azure_dd/azure_common_linux.go b/pkg/volume/azure_dd/azure_common_linux.go index 3c19b9244b5..806e27e0e94 100644 --- a/pkg/volume/azure_dd/azure_common_linux.go +++ b/pkg/volume/azure_dd/azure_common_linux.go @@ -20,7 +20,7 @@ package azure_dd import ( "fmt" - "path" + "path/filepath" "strconv" libstrings "strings" @@ -124,7 +124,7 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (st if lun == l { // find the matching LUN // read vendor and model to ensure it is a VHD disk - vendorPath := path.Join(sys_path, name, "vendor") + vendorPath := filepath.Join(sys_path, name, "vendor") vendorBytes, err := io.ReadFile(vendorPath) if err != nil { glog.Errorf("failed to read device vendor, err: %v", err) @@ -136,7 +136,7 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (st continue } - modelPath := path.Join(sys_path, name, "model") + modelPath := filepath.Join(sys_path, name, "model") modelBytes, err := io.ReadFile(modelPath) if err != nil { glog.Errorf("failed to read device model, err: %v", err) @@ -149,7 +149,7 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (st } // find a disk, validate name - dir := path.Join(sys_path, name, "block") + dir := filepath.Join(sys_path, name, "block") if dev, err := io.ReadDir(dir); err == nil { found := false devName := dev[0].Name() diff --git a/pkg/volume/azure_file/azure_file_test.go b/pkg/volume/azure_file/azure_file_test.go index 1f394d69cef..43dcd208186 100644 --- a/pkg/volume/azure_file/azure_file_test.go +++ b/pkg/volume/azure_file/azure_file_test.go @@ -20,7 +20,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "reflect" "strings" "testing" @@ -149,7 +149,7 @@ func testPlugin(t *testing.T, tmpDir string, volumeHost volume.VolumeHost) { if mounter == nil { t.Errorf("Got a nil Mounter") } - volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~azure-file/vol1") + volPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~azure-file/vol1") path := mounter.GetPath() if path != volPath { t.Errorf("Got unexpected path: %s", path) From 7a14b14bf49bd96b8757b79aa6bd9395f5a1e512 Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Fri, 27 Apr 2018 21:22:55 +0530 Subject: [PATCH 2/2] replace filepath with path due to pre-formatted volumeName --- pkg/volume/aws_ebs/attacher.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/volume/aws_ebs/attacher.go b/pkg/volume/aws_ebs/attacher.go index 9b7d732b3cb..059431e1661 100644 --- a/pkg/volume/aws_ebs/attacher.go +++ b/pkg/volume/aws_ebs/attacher.go @@ -19,7 +19,7 @@ package aws_ebs import ( "fmt" "os" - "path/filepath" + "path" "strconv" "time" @@ -249,7 +249,7 @@ func (plugin *awsElasticBlockStorePlugin) NewDetacher() (volume.Detacher, error) } func (detacher *awsElasticBlockStoreDetacher) Detach(volumeName string, nodeName types.NodeName) error { - volumeID := aws.KubernetesVolumeID(filepath.Base(volumeName)) + volumeID := aws.KubernetesVolumeID(path.Base(volumeName)) if _, err := detacher.awsVolumes.DetachDisk(volumeID, nodeName); err != nil { glog.Errorf("Error detaching volumeID %q: %v", volumeID, err)