Always use filepath.Join instead of path.Join

This patch cleans up pkg/util/mount/* and pkg/util/volume/* to always
use filepath.Join instead of path.Join. filepath.Join is preferred
because path.Join can have issues on Windows.
This commit is contained in:
Travis Rhoden 2019-03-29 17:23:31 -06:00
parent 12b7f1450c
commit 78d109e201
62 changed files with 210 additions and 221 deletions

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"path" "path/filepath"
"runtime" "runtime"
"strings" "strings"
@ -384,7 +384,7 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
return err return err
} }
keyringFile = path.Join(keyringPath, fileName) keyringFile = filepath.Join(keyringPath, fileName)
} else { } else {
keyringFile = cephfsVolume.secretFile keyringFile = cephfsVolume.secretFile

View File

@ -18,7 +18,7 @@ package cephfs
import ( import (
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -83,7 +83,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Got a nil Mounter") t.Errorf("Got a nil Mounter")
} }
volumePath := mounter.GetPath() volumePath := mounter.GetPath()
volpath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~cephfs/vol1") volpath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~cephfs/vol1")
if volumePath != volpath { if volumePath != volpath {
t.Errorf("Got unexpected path: %s", volumePath) t.Errorf("Got unexpected path: %s", volumePath)
} }

View File

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"path/filepath"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
@ -449,7 +450,7 @@ func (b *cinderVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
} }
func makeGlobalPDName(host volume.VolumeHost, devName string) string { func makeGlobalPDName(host volume.VolumeHost, devName string) string {
return path.Join(host.GetPluginDir(cinderVolumePluginName), util.MountsInGlobalPDPath, devName) return filepath.Join(host.GetPluginDir(cinderVolumePluginName), util.MountsInGlobalPDPath, devName)
} }
func (cd *cinderVolume) GetPath() string { func (cd *cinderVolume) GetPath() string {

View File

@ -18,7 +18,7 @@ package cinder
import ( import (
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -47,7 +47,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {
//deferred clean up //deferred clean up
defer os.RemoveAll(tmpVDir) defer os.RemoveAll(tmpVDir)
expectedGlobalPath := path.Join(tmpVDir, testGlobalPath) expectedGlobalPath := filepath.Join(tmpVDir, testGlobalPath)
//Bad Path //Bad Path
badspec, err := getVolumeSpecFromGlobalMapPath("") badspec, err := getVolumeSpecFromGlobalMapPath("")
@ -102,8 +102,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) {
//deferred clean up //deferred clean up
defer os.RemoveAll(tmpVDir) defer os.RemoveAll(tmpVDir)
expectedGlobalPath := path.Join(tmpVDir, testGlobalPath) expectedGlobalPath := filepath.Join(tmpVDir, testGlobalPath)
expectedPodPath := path.Join(tmpVDir, testPodPath) expectedPodPath := filepath.Join(tmpVDir, testPodPath)
spec := getTestVolume(false, true /*isBlock*/) spec := getTestVolume(false, true /*isBlock*/)
plugMgr := volume.VolumePluginMgr{} plugMgr := volume.VolumePluginMgr{}

View File

@ -19,7 +19,7 @@ package cinder
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"testing" "testing"
"time" "time"
@ -64,7 +64,7 @@ type fakePDManager struct {
} }
func getFakeDeviceName(host volume.VolumeHost, pdName string) string { func getFakeDeviceName(host volume.VolumeHost, pdName string) string {
return path.Join(host.GetPluginDir(cinderVolumePluginName), "device", pdName) return filepath.Join(host.GetPluginDir(cinderVolumePluginName), "device", pdName)
} }
// Real Cinder AttachDisk attaches a cinder volume. If it is not yet mounted, // Real Cinder AttachDisk attaches a cinder volume. If it is not yet mounted,
@ -160,7 +160,7 @@ func TestPlugin(t *testing.T) {
if mounter == nil { if mounter == nil {
t.Errorf("Got a nil Mounter") t.Errorf("Got a nil Mounter")
} }
volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~cinder/vol1") volPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~cinder/vol1")
path := mounter.GetPath() path := mounter.GetPath()
if path != volPath { if path != volPath {
t.Errorf("Got unexpected path: %s", path) t.Errorf("Got unexpected path: %s", path)

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -498,14 +498,14 @@ func TestPluginOptional(t *testing.T) {
} }
} }
datadirSymlink := path.Join(volumePath, "..data") datadirSymlink := filepath.Join(volumePath, "..data")
datadir, err := os.Readlink(datadirSymlink) datadir, err := os.Readlink(datadirSymlink)
if err != nil && os.IsNotExist(err) { if err != nil && os.IsNotExist(err) {
t.Fatalf("couldn't find volume path's data dir, %s", datadirSymlink) t.Fatalf("couldn't find volume path's data dir, %s", datadirSymlink)
} else if err != nil { } else if err != nil {
t.Fatalf("couldn't read symlink, %s", datadirSymlink) t.Fatalf("couldn't read symlink, %s", datadirSymlink)
} }
datadirPath := path.Join(volumePath, datadir) datadirPath := filepath.Join(volumePath, datadir)
infos, err := ioutil.ReadDir(volumePath) infos, err := ioutil.ReadDir(volumePath)
if err != nil { if err != nil {
@ -689,7 +689,7 @@ func configMap(namespace, name string) v1.ConfigMap {
func doTestConfigMapDataInVolume(volumePath string, configMap v1.ConfigMap, t *testing.T) { func doTestConfigMapDataInVolume(volumePath string, configMap v1.ConfigMap, t *testing.T) {
for key, value := range configMap.Data { for key, value := range configMap.Data {
configMapDataHostPath := path.Join(volumePath, key) configMapDataHostPath := filepath.Join(volumePath, key)
if _, err := os.Stat(configMapDataHostPath); err != nil { if _, err := os.Stat(configMapDataHostPath); err != nil {
t.Fatalf("SetUp() failed, couldn't find configMap data on disk: %v", configMapDataHostPath) t.Fatalf("SetUp() failed, couldn't find configMap data on disk: %v", configMapDataHostPath)
} else { } else {

View File

@ -22,7 +22,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
@ -598,7 +597,7 @@ func makeDeviceMountPath(plugin *csiPlugin, spec *volume.Spec) (string, error) {
return "", fmt.Errorf("makeDeviceMountPath failed, pv name empty") return "", fmt.Errorf("makeDeviceMountPath failed, pv name empty")
} }
return path.Join(plugin.host.GetPluginDir(plugin.GetPluginName()), persistentVolumeInGlobalPath, pvName, globalMountInGlobalPath), nil return filepath.Join(plugin.host.GetPluginDir(plugin.GetPluginName()), persistentVolumeInGlobalPath, pvName, globalMountInGlobalPath), nil
} }
func getDriverAndVolNameFromDeviceMountPath(k8s kubernetes.Interface, deviceMountPath string) (string, string, error) { func getDriverAndVolNameFromDeviceMountPath(k8s kubernetes.Interface, deviceMountPath string) (string, string, error) {

View File

@ -21,7 +21,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"k8s.io/klog" "k8s.io/klog"
@ -63,14 +62,14 @@ func (m *csiBlockMapper) GetGlobalMapPath(spec *volume.Spec) (string, error) {
// Example: plugins/kubernetes.io/csi/volumeDevices/staging/{pvname} // Example: plugins/kubernetes.io/csi/volumeDevices/staging/{pvname}
func (m *csiBlockMapper) getStagingPath() string { func (m *csiBlockMapper) getStagingPath() string {
sanitizedSpecVolID := utilstrings.EscapeQualifiedName(m.specName) sanitizedSpecVolID := utilstrings.EscapeQualifiedName(m.specName)
return path.Join(m.plugin.host.GetVolumeDevicePluginDir(CSIPluginName), "staging", sanitizedSpecVolID) return filepath.Join(m.plugin.host.GetVolumeDevicePluginDir(CSIPluginName), "staging", sanitizedSpecVolID)
} }
// getPublishPath returns a publish path for a file (on the node) that should be used on NodePublishVolume/NodeUnpublishVolume // getPublishPath returns a publish path for a file (on the node) that should be used on NodePublishVolume/NodeUnpublishVolume
// Example: plugins/kubernetes.io/csi/volumeDevices/publish/{pvname} // Example: plugins/kubernetes.io/csi/volumeDevices/publish/{pvname}
func (m *csiBlockMapper) getPublishPath() string { func (m *csiBlockMapper) getPublishPath() string {
sanitizedSpecVolID := utilstrings.EscapeQualifiedName(m.specName) sanitizedSpecVolID := utilstrings.EscapeQualifiedName(m.specName)
return path.Join(m.plugin.host.GetVolumeDevicePluginDir(CSIPluginName), "publish", sanitizedSpecVolID) return filepath.Join(m.plugin.host.GetVolumeDevicePluginDir(CSIPluginName), "publish", sanitizedSpecVolID)
} }
// GetPodDeviceMapPath returns pod's device file which will be mapped to a volume // GetPodDeviceMapPath returns pod's device file which will be mapped to a volume

View File

@ -19,7 +19,6 @@ package csi
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"testing" "testing"
@ -64,12 +63,12 @@ func TestBlockMapperGetGlobalMapPath(t *testing.T) {
{ {
name: "simple specName", name: "simple specName",
specVolumeName: "spec-0", specVolumeName: "spec-0",
path: path.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/%s/%s", "spec-0", "dev")), path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/%s/%s", "spec-0", "dev")),
}, },
{ {
name: "specName with dots", name: "specName with dots",
specVolumeName: "test.spec.1", specVolumeName: "test.spec.1",
path: path.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/%s/%s", "test.spec.1", "dev")), path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/%s/%s", "test.spec.1", "dev")),
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
@ -104,12 +103,12 @@ func TestBlockMapperGetStagingPath(t *testing.T) {
{ {
name: "simple specName", name: "simple specName",
specVolumeName: "spec-0", specVolumeName: "spec-0",
path: path.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/staging/%s", "spec-0")), path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/staging/%s", "spec-0")),
}, },
{ {
name: "specName with dots", name: "specName with dots",
specVolumeName: "test.spec.1", specVolumeName: "test.spec.1",
path: path.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/staging/%s", "test.spec.1")), path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/staging/%s", "test.spec.1")),
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
@ -141,12 +140,12 @@ func TestBlockMapperGetPublishPath(t *testing.T) {
{ {
name: "simple specName", name: "simple specName",
specVolumeName: "spec-0", specVolumeName: "spec-0",
path: path.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/publish/%s", "spec-0")), path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/publish/%s", "spec-0")),
}, },
{ {
name: "specName with dots", name: "specName with dots",
specVolumeName: "test.spec.1", specVolumeName: "test.spec.1",
path: path.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/publish/%s", "test.spec.1")), path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/publish/%s", "test.spec.1")),
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
@ -178,12 +177,12 @@ func TestBlockMapperGetDeviceMapPath(t *testing.T) {
{ {
name: "simple specName", name: "simple specName",
specVolumeName: "spec-0", specVolumeName: "spec-0",
path: path.Join(tmpDir, fmt.Sprintf("pods/%s/volumeDevices/kubernetes.io~csi", testPodUID)), path: filepath.Join(tmpDir, fmt.Sprintf("pods/%s/volumeDevices/kubernetes.io~csi", testPodUID)),
}, },
{ {
name: "specName with dots", name: "specName with dots",
specVolumeName: "test.spec.1", specVolumeName: "test.spec.1",
path: path.Join(tmpDir, fmt.Sprintf("pods/%s/volumeDevices/kubernetes.io~csi", testPodUID)), path: filepath.Join(tmpDir, fmt.Sprintf("pods/%s/volumeDevices/kubernetes.io~csi", testPodUID)),
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {

View File

@ -22,6 +22,7 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"path/filepath"
"k8s.io/klog" "k8s.io/klog"
@ -75,7 +76,7 @@ type csiMountMgr struct {
var _ volume.Volume = &csiMountMgr{} var _ volume.Volume = &csiMountMgr{}
func (c *csiMountMgr) GetPath() string { func (c *csiMountMgr) GetPath() string {
dir := path.Join(getTargetPath(c.podUID, c.specVolumeID, c.plugin.host), "/mount") dir := filepath.Join(getTargetPath(c.podUID, c.specVolumeID, c.plugin.host), "/mount")
klog.V(4).Info(log("mounter.GetPath generated [%s]", dir)) klog.V(4).Info(log("mounter.GetPath generated [%s]", dir))
return dir return dir
} }
@ -440,7 +441,7 @@ func removeMountDir(plug *csiPlugin, mountPath string) error {
} }
// remove volume data file as well // remove volume data file as well
volPath := path.Dir(mountPath) volPath := path.Dir(mountPath)
dataFile := path.Join(volPath, volDataFileName) dataFile := filepath.Join(volPath, volDataFileName)
klog.V(4).Info(log("also deleting volume info data file [%s]", dataFile)) klog.V(4).Info(log("also deleting volume info data file [%s]", dataFile))
if err := os.Remove(dataFile); err != nil && !os.IsNotExist(err) { if err := os.Remove(dataFile); err != nil && !os.IsNotExist(err) {
klog.Error(log("failed to delete volume data file [%s]: %v", dataFile, err)) klog.Error(log("failed to delete volume data file [%s]: %v", dataFile, err))

View File

@ -21,6 +21,7 @@ import (
"math/rand" "math/rand"
"os" "os"
"path" "path"
"path/filepath"
"testing" "testing"
"reflect" "reflect"
@ -60,12 +61,12 @@ func TestMounterGetPath(t *testing.T) {
{ {
name: "simple specName", name: "simple specName",
specVolumeName: "spec-0", specVolumeName: "spec-0",
path: path.Join(tmpDir, fmt.Sprintf("pods/%s/volumes/kubernetes.io~csi/%s/%s", testPodUID, "spec-0", "/mount")), path: filepath.Join(tmpDir, fmt.Sprintf("pods/%s/volumes/kubernetes.io~csi/%s/%s", testPodUID, "spec-0", "/mount")),
}, },
{ {
name: "specName with dots", name: "specName with dots",
specVolumeName: "test.spec.1", specVolumeName: "test.spec.1",
path: path.Join(tmpDir, fmt.Sprintf("pods/%s/volumes/kubernetes.io~csi/%s/%s", testPodUID, "test.spec.1", "/mount")), path: filepath.Join(tmpDir, fmt.Sprintf("pods/%s/volumes/kubernetes.io~csi/%s/%s", testPodUID, "test.spec.1", "/mount")),
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
@ -649,7 +650,7 @@ func TestUnmounterTeardown(t *testing.T) {
pv := makeTestPV("test-pv", 10, testDriver, testVol) pv := makeTestPV("test-pv", 10, testDriver, testVol)
// save the data file prior to unmount // save the data file prior to unmount
dir := path.Join(getTargetPath(testPodUID, pv.ObjectMeta.Name, plug.host), "/mount") dir := filepath.Join(getTargetPath(testPodUID, pv.ObjectMeta.Name, plug.host), "/mount")
if err := os.MkdirAll(dir, 0755); err != nil && !os.IsNotExist(err) { if err := os.MkdirAll(dir, 0755); err != nil && !os.IsNotExist(err) {
t.Errorf("failed to create dir [%s]: %v", dir, err) t.Errorf("failed to create dir [%s]: %v", dir, err)
} }

View File

@ -756,7 +756,7 @@ func TestPluginNewUnmounter(t *testing.T) {
pv := makeTestPV("test-pv", 10, testDriver, testVol) pv := makeTestPV("test-pv", 10, testDriver, testVol)
// save the data file to re-create client // save the data file to re-create client
dir := path.Join(getTargetPath(testPodUID, pv.ObjectMeta.Name, plug.host), "/mount") dir := filepath.Join(getTargetPath(testPodUID, pv.ObjectMeta.Name, plug.host), "/mount")
if err := os.MkdirAll(dir, 0755); err != nil && !os.IsNotExist(err) { if err := os.MkdirAll(dir, 0755); err != nil && !os.IsNotExist(err) {
t.Errorf("failed to create dir [%s]: %v", dir, err) t.Errorf("failed to create dir [%s]: %v", dir, err)
} }

View File

@ -20,7 +20,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"time" "time"
api "k8s.io/api/core/v1" api "k8s.io/api/core/v1"
@ -54,7 +54,7 @@ func getCredentialsFromSecret(k8s kubernetes.Interface, secretRef *api.SecretRef
// saveVolumeData persists parameter data as json file at the provided location // saveVolumeData persists parameter data as json file at the provided location
func saveVolumeData(dir string, fileName string, data map[string]string) error { func saveVolumeData(dir string, fileName string, data map[string]string) error {
dataFilePath := path.Join(dir, fileName) dataFilePath := filepath.Join(dir, fileName)
klog.V(4).Info(log("saving volume data file [%s]", dataFilePath)) klog.V(4).Info(log("saving volume data file [%s]", dataFilePath))
file, err := os.Create(dataFilePath) file, err := os.Create(dataFilePath)
if err != nil { if err != nil {
@ -73,7 +73,7 @@ func saveVolumeData(dir string, fileName string, data map[string]string) error {
// loadVolumeData loads volume info from specified json file/location // loadVolumeData loads volume info from specified json file/location
func loadVolumeData(dir string, fileName string) (map[string]string, error) { func loadVolumeData(dir string, fileName string) (map[string]string, error) {
// remove /mount at the end // remove /mount at the end
dataFileName := path.Join(dir, fileName) dataFileName := filepath.Join(dir, fileName)
klog.V(4).Info(log("loading volume data file [%s]", dataFileName)) klog.V(4).Info(log("loading volume data file [%s]", dataFileName))
file, err := os.Open(dataFileName) file, err := os.Open(dataFileName)
@ -114,7 +114,7 @@ func log(msg string, parts ...interface{}) string {
// path: plugins/kubernetes.io/csi/volumeDevices/{specVolumeID}/dev // path: plugins/kubernetes.io/csi/volumeDevices/{specVolumeID}/dev
func getVolumeDevicePluginDir(specVolID string, host volume.VolumeHost) string { func getVolumeDevicePluginDir(specVolID string, host volume.VolumeHost) string {
sanitizedSpecVolID := utilstrings.EscapeQualifiedName(specVolID) sanitizedSpecVolID := utilstrings.EscapeQualifiedName(specVolID)
return path.Join(host.GetVolumeDevicePluginDir(CSIPluginName), sanitizedSpecVolID, "dev") return filepath.Join(host.GetVolumeDevicePluginDir(CSIPluginName), sanitizedSpecVolID, "dev")
} }
// getVolumeDeviceDataDir returns the path where the CSI plugin keeps the // getVolumeDeviceDataDir returns the path where the CSI plugin keeps the
@ -122,7 +122,7 @@ func getVolumeDevicePluginDir(specVolID string, host volume.VolumeHost) string {
// path: plugins/kubernetes.io/csi/volumeDevices/{specVolumeID}/data // path: plugins/kubernetes.io/csi/volumeDevices/{specVolumeID}/data
func getVolumeDeviceDataDir(specVolID string, host volume.VolumeHost) string { func getVolumeDeviceDataDir(specVolID string, host volume.VolumeHost) string {
sanitizedSpecVolID := utilstrings.EscapeQualifiedName(specVolID) sanitizedSpecVolID := utilstrings.EscapeQualifiedName(specVolID)
return path.Join(host.GetVolumeDevicePluginDir(CSIPluginName), sanitizedSpecVolID, "data") return filepath.Join(host.GetVolumeDevicePluginDir(CSIPluginName), sanitizedSpecVolID, "data")
} }
// hasReadWriteOnce returns true if modes contains v1.ReadWriteOnce // hasReadWriteOnce returns true if modes contains v1.ReadWriteOnce

View File

@ -24,6 +24,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"path/filepath"
"testing" "testing"
api "k8s.io/api/core/v1" api "k8s.io/api/core/v1"
@ -104,7 +105,7 @@ func TestSaveVolumeData(t *testing.T) {
for i, tc := range testCases { for i, tc := range testCases {
t.Logf("test case: %s", tc.name) t.Logf("test case: %s", tc.name)
specVolID := fmt.Sprintf("spec-volid-%d", i) specVolID := fmt.Sprintf("spec-volid-%d", i)
mountDir := path.Join(getTargetPath(testPodUID, specVolID, plug.host), "/mount") mountDir := filepath.Join(getTargetPath(testPodUID, specVolID, plug.host), "/mount")
if err := os.MkdirAll(mountDir, 0755); err != nil && !os.IsNotExist(err) { if err := os.MkdirAll(mountDir, 0755); err != nil && !os.IsNotExist(err) {
t.Errorf("failed to create dir [%s]: %v", mountDir, err) t.Errorf("failed to create dir [%s]: %v", mountDir, err)
} }
@ -116,7 +117,7 @@ func TestSaveVolumeData(t *testing.T) {
} }
// did file get created // did file get created
dataDir := getTargetPath(testPodUID, specVolID, plug.host) dataDir := getTargetPath(testPodUID, specVolID, plug.host)
file := path.Join(dataDir, volDataFileName) file := filepath.Join(dataDir, volDataFileName)
if _, err := os.Stat(file); err != nil { if _, err := os.Stat(file); err != nil {
t.Errorf("failed to create data dir: %v", err) t.Errorf("failed to create data dir: %v", err)
} }

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -314,7 +314,7 @@ type stepName struct {
func (step stepName) getName() string { return step.name } func (step stepName) getName() string { return step.name }
func doVerifyLinesInFile(t *testing.T, volumePath, filename string, expected string) { func doVerifyLinesInFile(t *testing.T, volumePath, filename string, expected string) {
data, err := ioutil.ReadFile(path.Join(volumePath, filename)) data, err := ioutil.ReadFile(filepath.Join(volumePath, filename))
if err != nil { if err != nil {
t.Errorf(err.Error()) t.Errorf(err.Error())
return return
@ -350,7 +350,7 @@ type verifyMode struct {
} }
func (step verifyMode) run(test *downwardAPITest) { func (step verifyMode) run(test *downwardAPITest) {
fileInfo, err := os.Stat(path.Join(test.volumePath, step.name)) fileInfo, err := os.Stat(filepath.Join(test.volumePath, step.name))
if err != nil { if err != nil {
test.t.Errorf(err.Error()) test.t.Errorf(err.Error())
return return
@ -374,7 +374,7 @@ func (step reSetUp) run(test *downwardAPITest) {
test.pod.ObjectMeta.Labels = step.newLabels test.pod.ObjectMeta.Labels = step.newLabels
} }
currentTarget, err := os.Readlink(path.Join(test.volumePath, downwardAPIDir)) currentTarget, err := os.Readlink(filepath.Join(test.volumePath, downwardAPIDir))
if err != nil { if err != nil {
test.t.Errorf("labels file should be a link... %s\n", err.Error()) test.t.Errorf("labels file should be a link... %s\n", err.Error())
} }
@ -385,7 +385,7 @@ func (step reSetUp) run(test *downwardAPITest) {
} }
// get the link of the link // get the link of the link
currentTarget2, err := os.Readlink(path.Join(test.volumePath, downwardAPIDir)) currentTarget2, err := os.Readlink(filepath.Join(test.volumePath, downwardAPIDir))
if err != nil { if err != nil {
test.t.Errorf(".current should be a link... %s\n", err.Error()) test.t.Errorf(".current should be a link... %s\n", err.Error())
} }

View File

@ -19,7 +19,7 @@ package emptydir
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
@ -420,7 +420,7 @@ func (ed *emptyDir) teardownTmpfsOrHugetlbfs(dir string) error {
} }
func (ed *emptyDir) getMetaDir() string { func (ed *emptyDir) getMetaDir() string {
return path.Join(ed.plugin.host.GetPodPluginDir(ed.pod.UID, utilstrings.EscapeQualifiedName(emptyDirPluginName)), ed.volName) return filepath.Join(ed.plugin.host.GetPodPluginDir(ed.pod.UID, utilstrings.EscapeQualifiedName(emptyDirPluginName)), ed.volName)
} }
func getVolumeSource(spec *volume.Spec) (*v1.EmptyDirVolumeSource, bool) { func getVolumeSource(spec *volume.Spec) (*v1.EmptyDirVolumeSource, bool) {

View File

@ -20,7 +20,7 @@ package emptydir
import ( import (
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -107,8 +107,8 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
defer os.RemoveAll(basePath) defer os.RemoveAll(basePath)
var ( var (
volumePath = path.Join(basePath, "pods/poduid/volumes/kubernetes.io~empty-dir/test-volume") volumePath = filepath.Join(basePath, "pods/poduid/volumes/kubernetes.io~empty-dir/test-volume")
metadataDir = path.Join(basePath, "pods/poduid/plugins/kubernetes.io~empty-dir/test-volume") metadataDir = filepath.Join(basePath, "pods/poduid/plugins/kubernetes.io~empty-dir/test-volume")
plug = makePluginUnderTest(t, "kubernetes.io/empty-dir", basePath) plug = makePluginUnderTest(t, "kubernetes.io/empty-dir", basePath)
volumeName = "test-volume" volumeName = "test-volume"
@ -250,7 +250,7 @@ func TestPluginBackCompat(t *testing.T) {
} }
volPath := mounter.GetPath() volPath := mounter.GetPath()
if volPath != path.Join(basePath, "pods/poduid/volumes/kubernetes.io~empty-dir/vol1") { if volPath != filepath.Join(basePath, "pods/poduid/volumes/kubernetes.io~empty-dir/vol1") {
t.Errorf("Got unexpected path: %s", volPath) t.Errorf("Got unexpected path: %s", volPath)
} }
} }

View File

@ -20,7 +20,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -136,18 +135,18 @@ func scsiHostRescan(io ioHandler) {
func makePDNameInternal(host volume.VolumeHost, wwns []string, lun string, wwids []string) string { func makePDNameInternal(host volume.VolumeHost, wwns []string, lun string, wwids []string) string {
if len(wwns) != 0 { if len(wwns) != 0 {
w := strings.Join(wwns, "-") w := strings.Join(wwns, "-")
return path.Join(host.GetPluginDir(fcPluginName), w+"-lun-"+lun) return filepath.Join(host.GetPluginDir(fcPluginName), w+"-lun-"+lun)
} }
return path.Join(host.GetPluginDir(fcPluginName), strings.Join(wwids, "-")) return filepath.Join(host.GetPluginDir(fcPluginName), strings.Join(wwids, "-"))
} }
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/fc/volumeDevices/target-lun-0 // make a directory like /var/lib/kubelet/plugins/kubernetes.io/fc/volumeDevices/target-lun-0
func makeVDPDNameInternal(host volume.VolumeHost, wwns []string, lun string, wwids []string) string { func makeVDPDNameInternal(host volume.VolumeHost, wwns []string, lun string, wwids []string) string {
if len(wwns) != 0 { if len(wwns) != 0 {
w := strings.Join(wwns, "-") w := strings.Join(wwns, "-")
return path.Join(host.GetVolumeDevicePluginDir(fcPluginName), w+"-lun-"+lun) return filepath.Join(host.GetVolumeDevicePluginDir(fcPluginName), w+"-lun-"+lun)
} }
return path.Join(host.GetVolumeDevicePluginDir(fcPluginName), strings.Join(wwids, "-")) return filepath.Join(host.GetVolumeDevicePluginDir(fcPluginName), strings.Join(wwids, "-"))
} }
func parsePDName(path string) (wwns []string, lun int32, wwids []string, err error) { func parsePDName(path string) (wwns []string, lun int32, wwids []string, err error) {
@ -360,7 +359,7 @@ func (util *fcUtil) DetachBlockFCDisk(c fcDiskUnmapper, mapPath, devicePath stri
} }
for _, fi := range fis { for _, fi := range fis {
if strings.Contains(fi.Name(), volumeInfo) { if strings.Contains(fi.Name(), volumeInfo) {
devicePath = path.Join(searchPath, fi.Name()) devicePath = filepath.Join(searchPath, fi.Name())
klog.V(5).Infof("fc: updated devicePath: %s", devicePath) klog.V(5).Infof("fc: updated devicePath: %s", devicePath)
break break
} }

View File

@ -20,7 +20,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"testing" "testing"
"text/template" "text/template"
@ -132,12 +132,12 @@ func installPluginUnderTest(t *testing.T, vendorName, plugName, tmpDir string, e
if vendorName != "" { if vendorName != "" {
vendoredName = fmt.Sprintf("%s~%s", vendorName, plugName) vendoredName = fmt.Sprintf("%s~%s", vendorName, plugName)
} }
pluginDir := path.Join(tmpDir, vendoredName) pluginDir := filepath.Join(tmpDir, vendoredName)
err := os.MkdirAll(pluginDir, 0777) err := os.MkdirAll(pluginDir, 0777)
if err != nil { if err != nil {
t.Errorf("Failed to create plugin: %v", err) t.Errorf("Failed to create plugin: %v", err)
} }
pluginExec := path.Join(pluginDir, plugName) pluginExec := filepath.Join(pluginDir, plugName)
f, err := os.Create(pluginExec) f, err := os.Create(pluginExec)
if err != nil { if err != nil {
t.Errorf("Failed to install plugin") t.Errorf("Failed to install plugin")
@ -149,7 +149,7 @@ func installPluginUnderTest(t *testing.T, vendorName, plugName, tmpDir string, e
if execTemplateData == nil { if execTemplateData == nil {
execTemplateData = &map[string]interface{}{ execTemplateData = &map[string]interface{}{
"DevicePath": "/dev/sdx", "DevicePath": "/dev/sdx",
"OutputFile": path.Join(pluginDir, plugName+".out"), "OutputFile": filepath.Join(pluginDir, plugName+".out"),
} }
} }

View File

@ -18,7 +18,7 @@ package flexvolume
import ( import (
"fmt" "fmt"
"path" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"sync" "sync"
@ -69,7 +69,7 @@ type PluginFactory interface {
type pluginFactory struct{} type pluginFactory struct{}
func (pluginFactory) NewFlexVolumePlugin(pluginDir, name string, runner exec.Interface) (volume.VolumePlugin, error) { func (pluginFactory) NewFlexVolumePlugin(pluginDir, name string, runner exec.Interface) (volume.VolumePlugin, error) {
execPath := path.Join(pluginDir, name) execPath := filepath.Join(pluginDir, name)
driverName := utilstrings.UnescapeQualifiedName(name) driverName := utilstrings.UnescapeQualifiedName(name)
@ -105,7 +105,7 @@ func (plugin *flexVolumePlugin) Init(host volume.VolumeHost) error {
func (plugin *flexVolumePlugin) getExecutable() string { func (plugin *flexVolumePlugin) getExecutable() string {
parts := strings.Split(plugin.driverName, "/") parts := strings.Split(plugin.driverName, "/")
execName := parts[len(parts)-1] execName := parts[len(parts)-1]
execPath := path.Join(plugin.execPath, execName) execPath := filepath.Join(plugin.execPath, execName)
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
execPath = util.GetWindowsPath(execPath) execPath = util.GetWindowsPath(execPath)
} }
@ -315,8 +315,8 @@ func (plugin *flexVolumePlugin) getDeviceMountPath(spec *volume.Spec) (string, e
return "", fmt.Errorf("GetVolumeName failed from getDeviceMountPath: %s", err) return "", fmt.Errorf("GetVolumeName failed from getDeviceMountPath: %s", err)
} }
mountsDir := path.Join(plugin.host.GetPluginDir(flexVolumePluginName), plugin.driverName, "mounts") mountsDir := filepath.Join(plugin.host.GetPluginDir(flexVolumePluginName), plugin.driverName, "mounts")
return path.Join(mountsDir, volumeName), nil return filepath.Join(mountsDir, volumeName), nil
} }
func (plugin *flexVolumePlugin) RequiresFSResize() bool { func (plugin *flexVolumePlugin) RequiresFSResize() bool {

View File

@ -18,7 +18,7 @@ package flexvolume
import ( import (
"fmt" "fmt"
"path" "path/filepath"
"testing" "testing"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@ -71,8 +71,8 @@ func TestProberAddRemoveDriver(t *testing.T) {
// add driver // add driver
const driverName2 = "fake-driver2" const driverName2 = "fake-driver2"
driverPath := path.Join(pluginDir, driverName2) driverPath := filepath.Join(pluginDir, driverName2)
executablePath := path.Join(driverPath, driverName2) executablePath := filepath.Join(driverPath, driverName2)
installDriver(driverName2, fs) installDriver(driverName2, fs)
watcher.TriggerEvent(fsnotify.Create, driverPath) watcher.TriggerEvent(fsnotify.Create, driverPath)
watcher.TriggerEvent(fsnotify.Create, executablePath) watcher.TriggerEvent(fsnotify.Create, executablePath)
@ -95,7 +95,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// Call probe after a non-driver file is added in a subdirectory. should return 1 event. // Call probe after a non-driver file is added in a subdirectory. should return 1 event.
fp := path.Join(driverPath, "dummyfile") fp := filepath.Join(driverPath, "dummyfile")
fs.Create(fp) fs.Create(fp)
watcher.TriggerEvent(fsnotify.Create, fp) watcher.TriggerEvent(fsnotify.Create, fp)
@ -115,7 +115,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// Call probe after a subdirectory is added in a driver directory. should return 1 event. // Call probe after a subdirectory is added in a driver directory. should return 1 event.
subdirPath := path.Join(driverPath, "subdir") subdirPath := filepath.Join(driverPath, "subdir")
fs.Create(subdirPath) fs.Create(subdirPath)
watcher.TriggerEvent(fsnotify.Create, subdirPath) watcher.TriggerEvent(fsnotify.Create, subdirPath)
@ -196,7 +196,7 @@ func TestRemovePluginDir(t *testing.T) {
// Arrange // Arrange
driverPath, fs, watcher, _ := initTestEnvironment(t) driverPath, fs, watcher, _ := initTestEnvironment(t)
fs.RemoveAll(pluginDir) fs.RemoveAll(pluginDir)
watcher.TriggerEvent(fsnotify.Remove, path.Join(driverPath, driverName)) watcher.TriggerEvent(fsnotify.Remove, filepath.Join(driverPath, driverName))
watcher.TriggerEvent(fsnotify.Remove, driverPath) watcher.TriggerEvent(fsnotify.Remove, driverPath)
watcher.TriggerEvent(fsnotify.Remove, pluginDir) watcher.TriggerEvent(fsnotify.Remove, pluginDir)
@ -216,7 +216,7 @@ func TestNestedDriverDir(t *testing.T) {
// test add testDriverName // test add testDriverName
testDriverName := "testDriverName" testDriverName := "testDriverName"
testDriverPath := path.Join(pluginDir, testDriverName) testDriverPath := filepath.Join(pluginDir, testDriverName)
fs.MkdirAll(testDriverPath, 0666) fs.MkdirAll(testDriverPath, 0666)
watcher.TriggerEvent(fsnotify.Create, testDriverPath) watcher.TriggerEvent(fsnotify.Create, testDriverPath)
// Assert // Assert
@ -227,7 +227,7 @@ func TestNestedDriverDir(t *testing.T) {
basePath := testDriverPath basePath := testDriverPath
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
subdirName := "subdirName" subdirName := "subdirName"
subdirPath := path.Join(basePath, subdirName) subdirPath := filepath.Join(basePath, subdirName)
fs.MkdirAll(subdirPath, 0666) fs.MkdirAll(subdirPath, 0666)
watcher.TriggerEvent(fsnotify.Create, subdirPath) watcher.TriggerEvent(fsnotify.Create, subdirPath)
// Assert // Assert
@ -246,9 +246,9 @@ func TestProberMultipleEvents(t *testing.T) {
for i := 0; i < iterations; i++ { for i := 0; i < iterations; i++ {
newDriver := fmt.Sprintf("multi-event-driver%d", 1) newDriver := fmt.Sprintf("multi-event-driver%d", 1)
installDriver(newDriver, fs) installDriver(newDriver, fs)
driverPath := path.Join(pluginDir, newDriver) driverPath := filepath.Join(pluginDir, newDriver)
watcher.TriggerEvent(fsnotify.Create, driverPath) watcher.TriggerEvent(fsnotify.Create, driverPath)
watcher.TriggerEvent(fsnotify.Create, path.Join(driverPath, newDriver)) watcher.TriggerEvent(fsnotify.Create, filepath.Join(driverPath, newDriver))
} }
// Act // Act
@ -284,9 +284,9 @@ func TestProberError(t *testing.T) {
// Installs a mock driver (an empty file) in the mock fs. // Installs a mock driver (an empty file) in the mock fs.
func installDriver(driverName string, fs utilfs.Filesystem) { func installDriver(driverName string, fs utilfs.Filesystem) {
driverPath := path.Join(pluginDir, driverName) driverPath := filepath.Join(pluginDir, driverName)
fs.MkdirAll(driverPath, 0666) fs.MkdirAll(driverPath, 0666)
fs.Create(path.Join(driverPath, driverName)) fs.Create(filepath.Join(driverPath, driverName))
} }
// Initializes mocks, installs a single driver in the mock fs, then initializes prober. // Initializes mocks, installs a single driver in the mock fs, then initializes prober.
@ -303,7 +303,7 @@ func initTestEnvironment(t *testing.T) (
fs: fs, fs: fs,
factory: fakePluginFactory{error: false}, factory: fakePluginFactory{error: false},
} }
driverPath = path.Join(pluginDir, driverName) driverPath = filepath.Join(pluginDir, driverName)
installDriver(driverName, fs) installDriver(driverName, fs)
prober.Init() prober.Init()

View File

@ -19,7 +19,7 @@ package flocker
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"time" "time"
flockerapi "github.com/clusterhq/flocker-go" flockerapi "github.com/clusterhq/flocker-go"
@ -81,7 +81,7 @@ func getPath(uid types.UID, volName string, host volume.VolumeHost) string {
} }
func makeGlobalFlockerPath(datasetUUID string) string { func makeGlobalFlockerPath(datasetUUID string) string {
return path.Join(defaultMountPath, datasetUUID) return filepath.Join(defaultMountPath, datasetUUID)
} }
func (p *flockerPlugin) Init(host volume.VolumeHost) error { func (p *flockerPlugin) Init(host volume.VolumeHost) error {

View File

@ -104,7 +104,7 @@ func (attacher *gcePersistentDiskAttacher) Attach(spec *volume.Spec, nodeName ty
} }
} }
return path.Join(diskByIDPath, diskGooglePrefix+pdName), nil return filepath.Join(diskByIDPath, diskGooglePrefix+pdName), nil
} }
func (attacher *gcePersistentDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) { func (attacher *gcePersistentDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) {

View File

@ -20,7 +20,7 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
@ -441,7 +441,7 @@ func (b *gcePersistentDiskMounter) SetUpAt(dir string, fsGroup *int64) error {
} }
func makeGlobalPDName(host volume.VolumeHost, devName string) string { func makeGlobalPDName(host volume.VolumeHost, devName string) string {
return path.Join(host.GetPluginDir(gcePersistentDiskPluginName), util.MountsInGlobalPDPath, devName) return filepath.Join(host.GetPluginDir(gcePersistentDiskPluginName), util.MountsInGlobalPDPath, devName)
} }
func (b *gcePersistentDiskMounter) GetPath() string { func (b *gcePersistentDiskMounter) GetPath() string {

View File

@ -18,7 +18,6 @@ package gcepd
import ( import (
"fmt" "fmt"
"path"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -163,7 +162,7 @@ func (pd *gcePersistentDisk) GetGlobalMapPath(spec *volume.Spec) (string, error)
if err != nil { if err != nil {
return "", err return "", err
} }
return path.Join(pd.plugin.host.GetVolumeDevicePluginDir(gcePersistentDiskPluginName), string(volumeSource.PDName)), nil return filepath.Join(pd.plugin.host.GetVolumeDevicePluginDir(gcePersistentDiskPluginName), string(volumeSource.PDName)), nil
} }
// GetPodDeviceMapPath returns pod device map path and volume name // GetPodDeviceMapPath returns pod device map path and volume name

View File

@ -18,7 +18,7 @@ package gcepd
import ( import (
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -47,7 +47,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {
//deferred clean up //deferred clean up
defer os.RemoveAll(tmpVDir) defer os.RemoveAll(tmpVDir)
expectedGlobalPath := path.Join(tmpVDir, testGlobalPath) expectedGlobalPath := filepath.Join(tmpVDir, testGlobalPath)
//Bad Path //Bad Path
badspec, err := getVolumeSpecFromGlobalMapPath("") badspec, err := getVolumeSpecFromGlobalMapPath("")
@ -102,8 +102,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) {
//deferred clean up //deferred clean up
defer os.RemoveAll(tmpVDir) defer os.RemoveAll(tmpVDir)
expectedGlobalPath := path.Join(tmpVDir, testGlobalPath) expectedGlobalPath := filepath.Join(tmpVDir, testGlobalPath)
expectedPodPath := path.Join(tmpVDir, testPodPath) expectedPodPath := filepath.Join(tmpVDir, testPodPath)
spec := getTestVolume(false, tmpVDir, true /*isBlock*/) spec := getTestVolume(false, tmpVDir, true /*isBlock*/)
plugMgr := volume.VolumePluginMgr{} plugMgr := volume.VolumePluginMgr{}

View File

@ -19,7 +19,7 @@ package gcepd
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"sort" "sort"
"testing" "testing"
@ -135,7 +135,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Got a nil Mounter") t.Errorf("Got a nil Mounter")
} }
volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~gce-pd/vol1") volPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~gce-pd/vol1")
path := mounter.GetPath() path := mounter.GetPath()
if path != volPath { if path != volPath {
t.Errorf("Got unexpected path: %s", path) t.Errorf("Got unexpected path: %s", path)

View File

@ -18,7 +18,6 @@ package gcepd
import ( import (
"fmt" "fmt"
"path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
@ -272,8 +271,8 @@ func parseScsiSerial(output string) (string, error) {
// Returns list of all /dev/disk/by-id/* paths for given PD. // Returns list of all /dev/disk/by-id/* paths for given PD.
func getDiskByIDPaths(pdName string, partition string) []string { func getDiskByIDPaths(pdName string, partition string) []string {
devicePaths := []string{ devicePaths := []string{
path.Join(diskByIDPath, diskGooglePrefix+pdName), filepath.Join(diskByIDPath, diskGooglePrefix+pdName),
path.Join(diskByIDPath, diskScsiGooglePrefix+pdName), filepath.Join(diskByIDPath, diskScsiGooglePrefix+pdName),
} }
if partition != "" { if partition != "" {

View File

@ -19,7 +19,6 @@ package git_repo
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -225,10 +224,10 @@ func (b *gitRepoVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
switch { switch {
case len(b.target) != 0 && filepath.Clean(b.target) == ".": case len(b.target) != 0 && filepath.Clean(b.target) == ".":
// if target dir is '.', use the current dir // if target dir is '.', use the current dir
subdir = path.Join(dir) subdir = filepath.Join(dir)
case len(files) == 1: case len(files) == 1:
// if target is not '.', use the generated folder // if target is not '.', use the generated folder
subdir = path.Join(dir, files[0].Name()) subdir = filepath.Join(dir, files[0].Name())
default: default:
// if target is not '.', but generated many files, it's wrong // if target is not '.', but generated many files, it's wrong
return fmt.Errorf("unexpected directory contents: %v", files) return fmt.Errorf("unexpected directory contents: %v", files)
@ -248,7 +247,7 @@ func (b *gitRepoVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
} }
func (b *gitRepoVolumeMounter) getMetaDir() string { func (b *gitRepoVolumeMounter) getMetaDir() string {
return path.Join(b.plugin.host.GetPodPluginDir(b.podUID, utilstrings.EscapeQualifiedName(gitRepoPluginName)), b.volName) return filepath.Join(b.plugin.host.GetPodPluginDir(b.podUID, utilstrings.EscapeQualifiedName(gitRepoPluginName)), b.volName)
} }
func (b *gitRepoVolumeMounter) execCommand(command string, args []string, dir string) ([]byte, error) { func (b *gitRepoVolumeMounter) execCommand(command string, args []string, dir string) ([]byte, error) {

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -393,7 +393,7 @@ func doTestSetUp(scenario struct {
if expected.cmd[1] == "clone" { if expected.cmd[1] == "clone" {
fakeOutputs = append(fakeOutputs, func() ([]byte, error) { fakeOutputs = append(fakeOutputs, func() ([]byte, error) {
// git clone, it creates new dir/files // git clone, it creates new dir/files
os.MkdirAll(path.Join(fcmd.Dirs[0], expected.dir), 0750) os.MkdirAll(filepath.Join(fcmd.Dirs[0], expected.dir), 0750)
return []byte{}, nil return []byte{}, nil
}) })
} else { } else {

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"math" "math"
"os" "os"
"path" "path/filepath"
"runtime" "runtime"
"strconv" "strconv"
dstrings "strings" dstrings "strings"
@ -347,7 +347,7 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
// If logfile has not been provided, create driver specific log file. // If logfile has not been provided, create driver specific log file.
if !hasLogFile { if !hasLogFile {
p := path.Join(b.glusterfs.plugin.host.GetPluginDir(glusterfsPluginName), b.glusterfs.volName) p := filepath.Join(b.glusterfs.plugin.host.GetPluginDir(glusterfsPluginName), b.glusterfs.volName)
if err := os.MkdirAll(p, 0750); err != nil { if err := os.MkdirAll(p, 0750); err != nil {
return fmt.Errorf("failed to create directory %v: %v", p, err) return fmt.Errorf("failed to create directory %v: %v", p, err)
} }
@ -355,7 +355,7 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
// adding log-level ERROR to remove noise // adding log-level ERROR to remove noise
// and more specific log path so each pod has // and more specific log path so each pod has
// its own log based on PV + Pod // its own log based on PV + Pod
log = path.Join(p, b.pod.Name+"-glusterfs.log") log = filepath.Join(p, b.pod.Name+"-glusterfs.log")
// Use derived log file in gluster fuse mount // Use derived log file in gluster fuse mount
options = append(options, "log-file="+log) options = append(options, "log-file="+log)

View File

@ -20,7 +20,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv" "strconv"
@ -186,12 +185,12 @@ func getDevicePrefixRefCount(mounter mount.Interface, deviceNamePrefix string) (
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/iscsi/iface_name/portal-some_iqn-lun-lun_id // make a directory like /var/lib/kubelet/plugins/kubernetes.io/iscsi/iface_name/portal-some_iqn-lun-lun_id
func makePDNameInternal(host volume.VolumeHost, portal string, iqn string, lun string, iface string) string { func makePDNameInternal(host volume.VolumeHost, portal string, iqn string, lun string, iface string) string {
return path.Join(host.GetPluginDir(iscsiPluginName), "iface-"+iface, portal+"-"+iqn+"-lun-"+lun) return filepath.Join(host.GetPluginDir(iscsiPluginName), "iface-"+iface, portal+"-"+iqn+"-lun-"+lun)
} }
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/iscsi/volumeDevices/iface_name/portal-some_iqn-lun-lun_id // make a directory like /var/lib/kubelet/plugins/kubernetes.io/iscsi/volumeDevices/iface_name/portal-some_iqn-lun-lun_id
func makeVDPDNameInternal(host volume.VolumeHost, portal string, iqn string, lun string, iface string) string { func makeVDPDNameInternal(host volume.VolumeHost, portal string, iqn string, lun string, iface string) string {
return path.Join(host.GetVolumeDevicePluginDir(iscsiPluginName), "iface-"+iface, portal+"-"+iqn+"-lun-"+lun) return filepath.Join(host.GetVolumeDevicePluginDir(iscsiPluginName), "iface-"+iface, portal+"-"+iqn+"-lun-"+lun)
} }
type ISCSIUtil struct{} type ISCSIUtil struct{}
@ -207,7 +206,7 @@ func (util *ISCSIUtil) MakeGlobalVDPDName(iscsi iscsiDisk) string {
} }
func (util *ISCSIUtil) persistISCSI(conf iscsiDisk, mnt string) error { func (util *ISCSIUtil) persistISCSI(conf iscsiDisk, mnt string) error {
file := path.Join(mnt, "iscsi.json") file := filepath.Join(mnt, "iscsi.json")
fp, err := os.Create(file) fp, err := os.Create(file)
if err != nil { if err != nil {
return fmt.Errorf("iscsi: create %s err %s", file, err) return fmt.Errorf("iscsi: create %s err %s", file, err)
@ -221,7 +220,7 @@ func (util *ISCSIUtil) persistISCSI(conf iscsiDisk, mnt string) error {
} }
func (util *ISCSIUtil) loadISCSI(conf *iscsiDisk, mnt string) error { func (util *ISCSIUtil) loadISCSI(conf *iscsiDisk, mnt string) error {
file := path.Join(mnt, "iscsi.json") file := filepath.Join(mnt, "iscsi.json")
fp, err := os.Open(file) fp, err := os.Open(file)
if err != nil { if err != nil {
return fmt.Errorf("iscsi: open %s err %s", file, err) return fmt.Errorf("iscsi: open %s err %s", file, err)

View File

@ -21,7 +21,6 @@ package local
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime" "runtime"
@ -302,7 +301,7 @@ func TestMountUnmount(t *testing.T) {
t.Fatalf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
volPath := path.Join(tmpDir, testMountPath) volPath := filepath.Join(tmpDir, testMountPath)
path := mounter.GetPath() path := mounter.GetPath()
if path != volPath { if path != volPath {
t.Errorf("Got unexpected path: %s", path) t.Errorf("Got unexpected path: %s", path)
@ -356,7 +355,7 @@ func TestMapUnmap(t *testing.T) {
t.Fatalf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
expectedGlobalPath := path.Join(tmpDir, testGlobalPath) expectedGlobalPath := filepath.Join(tmpDir, testGlobalPath)
globalPath, err := mapper.GetGlobalMapPath(volSpec) globalPath, err := mapper.GetGlobalMapPath(volSpec)
if err != nil { if err != nil {
t.Errorf("Failed to get global path: %v", err) t.Errorf("Failed to get global path: %v", err)
@ -364,7 +363,7 @@ func TestMapUnmap(t *testing.T) {
if globalPath != expectedGlobalPath { if globalPath != expectedGlobalPath {
t.Errorf("Got unexpected path: %s, expected %s", globalPath, expectedGlobalPath) t.Errorf("Got unexpected path: %s, expected %s", globalPath, expectedGlobalPath)
} }
expectedPodPath := path.Join(tmpDir, testPodPath) expectedPodPath := filepath.Join(tmpDir, testPodPath)
podPath, volName := mapper.GetPodDeviceMapPath() podPath, volName := mapper.GetPodDeviceMapPath()
if podPath != expectedPodPath { if podPath != expectedPodPath {
t.Errorf("Got unexpected pod path: %s, expected %s", podPath, expectedPodPath) t.Errorf("Got unexpected pod path: %s, expected %s", podPath, expectedPodPath)
@ -407,7 +406,7 @@ func testFSGroupMount(plug volume.VolumePlugin, pod *v1.Pod, tmpDir string, fsGr
return fmt.Errorf("Got a nil Mounter") return fmt.Errorf("Got a nil Mounter")
} }
volPath := path.Join(tmpDir, testMountPath) volPath := filepath.Join(tmpDir, testMountPath)
path := mounter.GetPath() path := mounter.GetPath()
if path != volPath { if path != volPath {
return fmt.Errorf("Got unexpected path: %s", path) return fmt.Errorf("Got unexpected path: %s", path)
@ -423,7 +422,7 @@ func TestConstructVolumeSpec(t *testing.T) {
tmpDir, plug := getPlugin(t) tmpDir, plug := getPlugin(t)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
volPath := path.Join(tmpDir, testMountPath) volPath := filepath.Join(tmpDir, testMountPath)
spec, err := plug.ConstructVolumeSpec(testPVName, volPath) spec, err := plug.ConstructVolumeSpec(testPVName, volPath)
if err != nil { if err != nil {
t.Errorf("ConstructVolumeSpec() failed: %v", err) t.Errorf("ConstructVolumeSpec() failed: %v", err)
@ -464,7 +463,7 @@ func TestConstructBlockVolumeSpec(t *testing.T) {
tmpDir, plug := getBlockPlugin(t) tmpDir, plug := getBlockPlugin(t)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
podPath := path.Join(tmpDir, testPodPath) podPath := filepath.Join(tmpDir, testPodPath)
spec, err := plug.ConstructBlockVolumeSpec(types.UID("poduid"), testPVName, podPath) spec, err := plug.ConstructBlockVolumeSpec(types.UID("poduid"), testPVName, podPath)
if err != nil { if err != nil {
t.Errorf("ConstructBlockVolumeSpec() failed: %v", err) t.Errorf("ConstructBlockVolumeSpec() failed: %v", err)

View File

@ -95,7 +95,7 @@ func (attacher *photonPersistentDiskAttacher) Attach(spec *volume.Spec, nodeName
} }
PdidWithNoHypens := strings.Replace(volumeSource.PdID, "-", "", -1) PdidWithNoHypens := strings.Replace(volumeSource.PdID, "-", "", -1)
return path.Join(diskByIDPath, diskPhotonPrefix+PdidWithNoHypens), nil return filepath.Join(diskByIDPath, diskPhotonPrefix+PdidWithNoHypens), nil
} }
func (attacher *photonPersistentDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) { func (attacher *photonPersistentDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) {

View File

@ -19,7 +19,7 @@ package photon_pd
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
@ -285,7 +285,7 @@ func (c *photonPersistentDiskUnmounter) TearDownAt(dir string) error {
} }
func makeGlobalPDPath(host volume.VolumeHost, devName string) string { func makeGlobalPDPath(host volume.VolumeHost, devName string) string {
return path.Join(host.GetPluginDir(photonPersistentDiskPluginName), util.MountsInGlobalPDPath, devName) return filepath.Join(host.GetPluginDir(photonPersistentDiskPluginName), util.MountsInGlobalPDPath, devName)
} }
func (ppd *photonPersistentDisk) GetPath() string { func (ppd *photonPersistentDisk) GetPath() string {

View File

@ -19,7 +19,7 @@ package photon_pd
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -122,7 +122,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Got a nil Mounter") t.Errorf("Got a nil Mounter")
} }
volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~photon-pd/vol1") volPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~photon-pd/vol1")
path := mounter.GetPath() path := mounter.GetPath()
if path != volPath { if path != volPath {
t.Errorf("Got unexpected path: %s", path) t.Errorf("Got unexpected path: %s", path)

View File

@ -19,7 +19,7 @@ package portworx
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -157,7 +157,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Got a nil Mounter") t.Errorf("Got a nil Mounter")
} }
volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~portworx-volume/vol1") volPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~portworx-volume/vol1")
path := mounter.GetPath() path := mounter.GetPath()
if path != volPath { if path != volPath {
t.Errorf("Got unexpected path: %s", path) t.Errorf("Got unexpected path: %s", path)

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -1069,14 +1069,14 @@ func TestPluginOptional(t *testing.T) {
} }
} }
datadirSymlink := path.Join(volumePath, "..data") datadirSymlink := filepath.Join(volumePath, "..data")
datadir, err := os.Readlink(datadirSymlink) datadir, err := os.Readlink(datadirSymlink)
if err != nil && os.IsNotExist(err) { if err != nil && os.IsNotExist(err) {
t.Fatalf("couldn't find volume path's data dir, %s", datadirSymlink) t.Fatalf("couldn't find volume path's data dir, %s", datadirSymlink)
} else if err != nil { } else if err != nil {
t.Fatalf("couldn't read symlink, %s", datadirSymlink) t.Fatalf("couldn't read symlink, %s", datadirSymlink)
} }
datadirPath := path.Join(volumePath, datadir) datadirPath := filepath.Join(volumePath, datadir)
infos, err := ioutil.ReadDir(volumePath) infos, err := ioutil.ReadDir(volumePath)
if err != nil { if err != nil {
@ -1227,7 +1227,7 @@ func makeProjection(name string, defaultMode int32, kind string) *v1.ProjectedVo
func doTestSecretDataInVolume(volumePath string, secret v1.Secret, t *testing.T) { func doTestSecretDataInVolume(volumePath string, secret v1.Secret, t *testing.T) {
for key, value := range secret.Data { for key, value := range secret.Data {
secretDataHostPath := path.Join(volumePath, key) secretDataHostPath := filepath.Join(volumePath, key)
if _, err := os.Stat(secretDataHostPath); err != nil { if _, err := os.Stat(secretDataHostPath); err != nil {
t.Fatalf("SetUp() failed, couldn't find secret data on disk: %v", secretDataHostPath) t.Fatalf("SetUp() failed, couldn't find secret data on disk: %v", secretDataHostPath)
} else { } else {

View File

@ -19,7 +19,7 @@ package quobyte
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
gostrings "strings" gostrings "strings"
"github.com/pborman/uuid" "github.com/pborman/uuid"
@ -286,7 +286,7 @@ func (quobyteVolume *quobyte) GetPath() string {
// Quobyte has only one mount in the PluginDir where all Volumes are mounted // Quobyte has only one mount in the PluginDir where all Volumes are mounted
// The Quobyte client does a fixed-user mapping // The Quobyte client does a fixed-user mapping
pluginDir := quobyteVolume.plugin.host.GetPluginDir(utilstrings.EscapeQualifiedName(quobytePluginName)) pluginDir := quobyteVolume.plugin.host.GetPluginDir(utilstrings.EscapeQualifiedName(quobytePluginName))
return path.Join(pluginDir, fmt.Sprintf("%s#%s@%s", user, group, quobyteVolume.volume)) return filepath.Join(pluginDir, fmt.Sprintf("%s#%s@%s", user, group, quobyteVolume.volume))
} }
type quobyteUnmounter struct { type quobyteUnmounter struct {

View File

@ -27,7 +27,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -80,7 +80,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
// https://github.com/torvalds/linux/blob/master/drivers/block/rbd.c // https://github.com/torvalds/linux/blob/master/drivers/block/rbd.c
name := f.Name() name := f.Name()
// First match pool, then match name. // First match pool, then match name.
poolFile := path.Join(sys_path, name, "pool") poolFile := filepath.Join(sys_path, name, "pool")
poolBytes, err := ioutil.ReadFile(poolFile) poolBytes, err := ioutil.ReadFile(poolFile)
if err != nil { if err != nil {
klog.V(4).Infof("error reading %s: %v", poolFile, err) klog.V(4).Infof("error reading %s: %v", poolFile, err)
@ -90,7 +90,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
klog.V(4).Infof("device %s is not %q: %q", name, pool, string(poolBytes)) klog.V(4).Infof("device %s is not %q: %q", name, pool, string(poolBytes))
continue continue
} }
imgFile := path.Join(sys_path, name, "name") imgFile := filepath.Join(sys_path, name, "name")
imgBytes, err := ioutil.ReadFile(imgFile) imgBytes, err := ioutil.ReadFile(imgFile)
if err != nil { if err != nil {
klog.V(4).Infof("error reading %s: %v", imgFile, err) klog.V(4).Infof("error reading %s: %v", imgFile, err)
@ -160,12 +160,12 @@ func getNbdDevFromImageAndPool(pool string, image string) (string, bool) {
klog.V(4).Infof("error reading nbd info directory %s: %v", nbdPath, err) klog.V(4).Infof("error reading nbd info directory %s: %v", nbdPath, err)
continue continue
} }
pidBytes, err := ioutil.ReadFile(path.Join(nbdPath, "pid")) pidBytes, err := ioutil.ReadFile(filepath.Join(nbdPath, "pid"))
if err != nil { if err != nil {
klog.V(5).Infof("did not find valid pid file in dir %s: %v", nbdPath, err) klog.V(5).Infof("did not find valid pid file in dir %s: %v", nbdPath, err)
continue continue
} }
cmdlineFileName := path.Join("/proc", strings.TrimSpace(string(pidBytes)), "cmdline") cmdlineFileName := filepath.Join("/proc", strings.TrimSpace(string(pidBytes)), "cmdline")
rawCmdline, err := ioutil.ReadFile(cmdlineFileName) rawCmdline, err := ioutil.ReadFile(cmdlineFileName)
if err != nil { if err != nil {
klog.V(4).Infof("failed to read cmdline file %s: %v", cmdlineFileName, err) klog.V(4).Infof("failed to read cmdline file %s: %v", cmdlineFileName, err)
@ -186,7 +186,7 @@ func getNbdDevFromImageAndPool(pool string, image string) (string, bool) {
nbdPath, imgPath, cmdlineArgs[2]) nbdPath, imgPath, cmdlineArgs[2])
continue continue
} }
devicePath := path.Join("/dev", "nbd"+strconv.Itoa(i)) devicePath := filepath.Join("/dev", "nbd"+strconv.Itoa(i))
if _, err := os.Lstat(devicePath); err != nil { if _, err := os.Lstat(devicePath); err != nil {
klog.Warningf("Stat device %s for imgpath %s failed %v", devicePath, imgPath, err) klog.Warningf("Stat device %s for imgpath %s failed %v", devicePath, imgPath, err)
continue continue
@ -248,7 +248,7 @@ func checkRbdNbdTools(e mount.Exec) bool {
// Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/mounts/pool-image-image. // Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/mounts/pool-image-image.
func makePDNameInternal(host volume.VolumeHost, pool string, image string) string { func makePDNameInternal(host volume.VolumeHost, pool string, image string) string {
// Backward compatibility for the deprecated format: /var/lib/kubelet/plugins/kubernetes.io/rbd/rbd/pool-image-image. // Backward compatibility for the deprecated format: /var/lib/kubelet/plugins/kubernetes.io/rbd/rbd/pool-image-image.
deprecatedDir := path.Join(host.GetPluginDir(rbdPluginName), "rbd", pool+"-image-"+image) deprecatedDir := filepath.Join(host.GetPluginDir(rbdPluginName), "rbd", pool+"-image-"+image)
info, err := os.Stat(deprecatedDir) info, err := os.Stat(deprecatedDir)
if err == nil && info.IsDir() { if err == nil && info.IsDir() {
// The device mount path has already been created with the deprecated format, return it. // The device mount path has already been created with the deprecated format, return it.
@ -256,12 +256,12 @@ func makePDNameInternal(host volume.VolumeHost, pool string, image string) strin
return deprecatedDir return deprecatedDir
} }
// Return the canonical format path. // Return the canonical format path.
return path.Join(host.GetPluginDir(rbdPluginName), volutil.MountsInGlobalPDPath, pool+"-image-"+image) return filepath.Join(host.GetPluginDir(rbdPluginName), volutil.MountsInGlobalPDPath, pool+"-image-"+image)
} }
// Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/volumeDevices/pool-image-image. // Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/volumeDevices/pool-image-image.
func makeVDPDNameInternal(host volume.VolumeHost, pool string, image string) string { func makeVDPDNameInternal(host volume.VolumeHost, pool string, image string) string {
return path.Join(host.GetVolumeDevicePluginDir(rbdPluginName), pool+"-image-"+image) return filepath.Join(host.GetVolumeDevicePluginDir(rbdPluginName), pool+"-image-"+image)
} }
// RBDUtil implements diskManager interface. // RBDUtil implements diskManager interface.
@ -486,7 +486,7 @@ func (util *RBDUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, devic
// Currently, we don't persist rbd info on the disk, but for backward // Currently, we don't persist rbd info on the disk, but for backward
// compatbility, we need to clean it if found. // compatbility, we need to clean it if found.
rbdFile := path.Join(deviceMountPath, "rbd.json") rbdFile := filepath.Join(deviceMountPath, "rbd.json")
exists, err := utilpath.Exists(utilpath.CheckFollowSymlink, rbdFile) exists, err := utilpath.Exists(utilpath.CheckFollowSymlink, rbdFile)
if err != nil { if err != nil {
return err return err

View File

@ -21,7 +21,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv" "strconv"
@ -535,5 +534,5 @@ func (c *sioClient) getSdcPath() string {
} }
func (c *sioClient) getSdcCmd() string { func (c *sioClient) getSdcCmd() string {
return path.Join(c.getSdcPath(), "drv_cfg") return filepath.Join(c.getSdcPath(), "drv_cfg")
} }

View File

@ -19,7 +19,7 @@ package scaleio
import ( import (
"encoding/gob" "encoding/gob"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"testing" "testing"
@ -152,7 +152,7 @@ func TestUtilSaveConfig(t *testing.T) {
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
config := path.Join(tmpDir, testConfigFile) config := filepath.Join(tmpDir, testConfigFile)
data := map[string]string{ data := map[string]string{
confKey.gateway: "https://test-gateway/", confKey.gateway: "https://test-gateway/",
confKey.secretName: "sio-secret", confKey.secretName: "sio-secret",
@ -207,7 +207,7 @@ func TestUtilLoadConfig(t *testing.T) {
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
configFile := path.Join(tmpDir, sioConfigFileName) configFile := filepath.Join(tmpDir, sioConfigFileName)
if err := saveConfig(configFile, config); err != nil { if err := saveConfig(configFile, config); err != nil {
t.Fatalf("failed to save configFile %s error:%v", configFile, err) t.Fatalf("failed to save configFile %s error:%v", configFile, err)

View File

@ -19,7 +19,7 @@ package scaleio
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -359,7 +359,7 @@ func (v *sioVolume) Provision(selectedNode *api.Node, allowedTopologies []api.To
func (v *sioVolume) setSioMgr() error { func (v *sioVolume) setSioMgr() error {
klog.V(4).Info(log("setting up sio mgr for spec %s", v.volSpecName)) klog.V(4).Info(log("setting up sio mgr for spec %s", v.volSpecName))
podDir := v.plugin.host.GetPodPluginDir(v.podUID, sioPluginName) podDir := v.plugin.host.GetPodPluginDir(v.podUID, sioPluginName)
configName := path.Join(podDir, sioConfigFileName) configName := filepath.Join(podDir, sioConfigFileName)
if v.sioMgr == nil { if v.sioMgr == nil {
configData, err := loadConfig(configName) // try to load config if exist configData, err := loadConfig(configName) // try to load config if exist
if err != nil { if err != nil {
@ -414,7 +414,7 @@ func (v *sioVolume) setSioMgr() error {
// resetSioMgr creates scaleio manager from existing (cached) config data // resetSioMgr creates scaleio manager from existing (cached) config data
func (v *sioVolume) resetSioMgr() error { func (v *sioVolume) resetSioMgr() error {
podDir := v.plugin.host.GetPodPluginDir(v.podUID, sioPluginName) podDir := v.plugin.host.GetPodPluginDir(v.podUID, sioPluginName)
configName := path.Join(podDir, sioConfigFileName) configName := filepath.Join(podDir, sioConfigFileName)
if v.sioMgr == nil { if v.sioMgr == nil {
// load config data from disk // load config data from disk
configData, err := loadConfig(configName) configData, err := loadConfig(configName)

View File

@ -19,7 +19,7 @@ package scaleio
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"strings" "strings"
"testing" "testing"
@ -185,7 +185,7 @@ func TestVolumeMounterUnmounter(t *testing.T) {
sioVol.sioMgr.client = sio sioVol.sioMgr.client = sio
sioVol.sioMgr.CreateVolume(testSioVol, 8) //create vol ahead of time sioVol.sioMgr.CreateVolume(testSioVol, 8) //create vol ahead of time
volPath := path.Join(tmpDir, fmt.Sprintf("pods/%s/volumes/kubernetes.io~scaleio/%s", podUID, testSioVolName)) volPath := filepath.Join(tmpDir, fmt.Sprintf("pods/%s/volumes/kubernetes.io~scaleio/%s", podUID, testSioVolName))
path := sioMounter.GetPath() path := sioMounter.GetPath()
if path != volPath { if path != volPath {
t.Errorf("Got unexpected path: %s", path) t.Errorf("Got unexpected path: %s", path)

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"runtime" "runtime"
"strings" "strings"
@ -527,14 +527,14 @@ func TestPluginOptional(t *testing.T) {
} }
} }
datadirSymlink := path.Join(volumePath, "..data") datadirSymlink := filepath.Join(volumePath, "..data")
datadir, err := os.Readlink(datadirSymlink) datadir, err := os.Readlink(datadirSymlink)
if err != nil && os.IsNotExist(err) { if err != nil && os.IsNotExist(err) {
t.Fatalf("couldn't find volume path's data dir, %s", datadirSymlink) t.Fatalf("couldn't find volume path's data dir, %s", datadirSymlink)
} else if err != nil { } else if err != nil {
t.Fatalf("couldn't read symlink, %s", datadirSymlink) t.Fatalf("couldn't read symlink, %s", datadirSymlink)
} }
datadirPath := path.Join(volumePath, datadir) datadirPath := filepath.Join(volumePath, datadir)
infos, err := ioutil.ReadDir(volumePath) infos, err := ioutil.ReadDir(volumePath)
if err != nil { if err != nil {
@ -665,7 +665,7 @@ func secret(namespace, name string) v1.Secret {
func doTestSecretDataInVolume(volumePath string, secret v1.Secret, t *testing.T) { func doTestSecretDataInVolume(volumePath string, secret v1.Secret, t *testing.T) {
for key, value := range secret.Data { for key, value := range secret.Data {
secretDataHostPath := path.Join(volumePath, key) secretDataHostPath := filepath.Join(volumePath, key)
if _, err := os.Stat(secretDataHostPath); err != nil { if _, err := os.Stat(secretDataHostPath); err != nil {
t.Fatalf("SetUp() failed, couldn't find secret data on disk: %v", secretDataHostPath) t.Fatalf("SetUp() failed, couldn't find secret data on disk: %v", secretDataHostPath)
} else { } else {

View File

@ -20,7 +20,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -441,7 +440,7 @@ func (b *storageosMounter) SetUpAt(dir string, fsGroup *int64) error {
} }
func makeGlobalPDName(host volume.VolumeHost, pvName, volNamespace, volName string) string { func makeGlobalPDName(host volume.VolumeHost, pvName, volNamespace, volName string) string {
return path.Join(host.GetPluginDir(utilstrings.EscapeQualifiedName(storageosPluginName)), util.MountsInGlobalPDPath, pvName+"."+volNamespace+"."+volName) return filepath.Join(host.GetPluginDir(utilstrings.EscapeQualifiedName(storageosPluginName)), util.MountsInGlobalPDPath, pvName+"."+volNamespace+"."+volName)
} }
// Given the pod id and PV name, finds the volume's namespace and name from the // Given the pod id and PV name, finds the volume's namespace and name from the

View File

@ -19,7 +19,7 @@ package storageos
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -202,7 +202,7 @@ func TestPlugin(t *testing.T) {
t.Fatalf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
expectedPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~storageos/vol1-pvname.ns1.vol1") expectedPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~storageos/vol1-pvname.ns1.vol1")
volPath := mounter.GetPath() volPath := mounter.GetPath()
if volPath != expectedPath { if volPath != expectedPath {
t.Errorf("Expected path: '%s' got: '%s'", expectedPath, volPath) t.Errorf("Expected path: '%s' got: '%s'", expectedPath, volPath)

View File

@ -20,7 +20,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"strings" "strings"
"k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/mount"
@ -174,7 +174,7 @@ func (u *storageosUtil) AttachVolume(b *storageosMounter) (string, error) {
} }
} }
srcPath := path.Join(b.deviceDir, vol.ID) srcPath := filepath.Join(b.deviceDir, vol.ID)
dt, err := pathDeviceType(srcPath) dt, err := pathDeviceType(srcPath)
if err != nil { if err != nil {
klog.Warningf("volume source path %q for volume %q not ready (%v)", srcPath, b.volName, err) klog.Warningf("volume source path %q for volume %q not ready (%v)", srcPath, b.volName, err)

View File

@ -21,7 +21,7 @@ import (
"net" "net"
"os" "os"
"os/exec" "os/exec"
"path" "path/filepath"
"strings" "strings"
"sync" "sync"
"testing" "testing"
@ -118,27 +118,27 @@ func NewFakeVolumeHostWithMounterFSType(rootDir string, kubeClient clientset.Int
} }
func (f *fakeVolumeHost) GetPluginDir(podUID string) string { func (f *fakeVolumeHost) GetPluginDir(podUID string) string {
return path.Join(f.rootDir, "plugins", podUID) return filepath.Join(f.rootDir, "plugins", podUID)
} }
func (f *fakeVolumeHost) GetVolumeDevicePluginDir(pluginName string) string { func (f *fakeVolumeHost) GetVolumeDevicePluginDir(pluginName string) string {
return path.Join(f.rootDir, "plugins", pluginName, "volumeDevices") return filepath.Join(f.rootDir, "plugins", pluginName, "volumeDevices")
} }
func (f *fakeVolumeHost) GetPodsDir() string { func (f *fakeVolumeHost) GetPodsDir() string {
return path.Join(f.rootDir, "pods") return filepath.Join(f.rootDir, "pods")
} }
func (f *fakeVolumeHost) GetPodVolumeDir(podUID types.UID, pluginName, volumeName string) string { func (f *fakeVolumeHost) GetPodVolumeDir(podUID types.UID, pluginName, volumeName string) string {
return path.Join(f.rootDir, "pods", string(podUID), "volumes", pluginName, volumeName) return filepath.Join(f.rootDir, "pods", string(podUID), "volumes", pluginName, volumeName)
} }
func (f *fakeVolumeHost) GetPodVolumeDeviceDir(podUID types.UID, pluginName string) string { func (f *fakeVolumeHost) GetPodVolumeDeviceDir(podUID types.UID, pluginName string) string {
return path.Join(f.rootDir, "pods", string(podUID), "volumeDevices", pluginName) return filepath.Join(f.rootDir, "pods", string(podUID), "volumeDevices", pluginName)
} }
func (f *fakeVolumeHost) GetPodPluginDir(podUID types.UID, pluginName string) string { func (f *fakeVolumeHost) GetPodPluginDir(podUID types.UID, pluginName string) string {
return path.Join(f.rootDir, "pods", string(podUID), "plugins", pluginName) return filepath.Join(f.rootDir, "pods", string(podUID), "plugins", pluginName)
} }
func (f *fakeVolumeHost) GetKubeClient() clientset.Interface { func (f *fakeVolumeHost) GetKubeClient() clientset.Interface {
@ -789,7 +789,7 @@ func (fv *FakeVolume) GetPath() string {
} }
func (fv *FakeVolume) getPath() string { func (fv *FakeVolume) getPath() string {
return path.Join(fv.Plugin.Host.GetPodVolumeDir(fv.PodUID, utilstrings.EscapeQualifiedName(fv.Plugin.PluginName), fv.VolName)) return filepath.Join(fv.Plugin.Host.GetPodVolumeDir(fv.PodUID, utilstrings.EscapeQualifiedName(fv.Plugin.PluginName), fv.VolName))
} }
func (fv *FakeVolume) TearDown() error { func (fv *FakeVolume) TearDown() error {
@ -834,7 +834,7 @@ func (fv *FakeVolume) GetGlobalMapPath(spec *Spec) (string, error) {
// Block volume support // Block volume support
func (fv *FakeVolume) getGlobalMapPath() (string, error) { func (fv *FakeVolume) getGlobalMapPath() (string, error) {
return path.Join(fv.Plugin.Host.GetVolumeDevicePluginDir(utilstrings.EscapeQualifiedName(fv.Plugin.PluginName)), "pluginDependentPath"), nil return filepath.Join(fv.Plugin.Host.GetVolumeDevicePluginDir(utilstrings.EscapeQualifiedName(fv.Plugin.PluginName)), "pluginDependentPath"), nil
} }
// Block volume support // Block volume support
@ -854,7 +854,7 @@ func (fv *FakeVolume) GetPodDeviceMapPath() (string, string) {
// Block volume support // Block volume support
func (fv *FakeVolume) getPodDeviceMapPath() (string, string) { func (fv *FakeVolume) getPodDeviceMapPath() (string, string) {
return path.Join(fv.Plugin.Host.GetPodVolumeDeviceDir(fv.PodUID, utilstrings.EscapeQualifiedName(fv.Plugin.PluginName))), fv.VolName return filepath.Join(fv.Plugin.Host.GetPodVolumeDeviceDir(fv.PodUID, utilstrings.EscapeQualifiedName(fv.Plugin.PluginName))), fv.VolName
} }
// Block volume support // Block volume support

View File

@ -126,7 +126,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
} }
// (2) // (2)
dataDirPath := path.Join(w.targetDir, dataDirName) dataDirPath := filepath.Join(w.targetDir, dataDirName)
oldTsDir, err := os.Readlink(dataDirPath) oldTsDir, err := os.Readlink(dataDirPath)
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
@ -137,7 +137,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
// empty oldTsDir indicates that it didn't exist // empty oldTsDir indicates that it didn't exist
oldTsDir = "" oldTsDir = ""
} }
oldTsPath := path.Join(w.targetDir, oldTsDir) oldTsPath := filepath.Join(w.targetDir, oldTsDir)
var pathsToRemove sets.String var pathsToRemove sets.String
// if there was no old version, there's nothing to remove // if there was no old version, there's nothing to remove
@ -183,7 +183,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
} }
// (8) // (8)
newDataDirPath := path.Join(w.targetDir, newDataDirName) newDataDirPath := filepath.Join(w.targetDir, newDataDirName)
if err = os.Symlink(tsDirName, newDataDirPath); err != nil { if err = os.Symlink(tsDirName, newDataDirPath); err != nil {
os.RemoveAll(tsDir) os.RemoveAll(tsDir)
klog.Errorf("%s: error creating symbolic link for atomic update: %v", w.logContext, err) klog.Errorf("%s: error creating symbolic link for atomic update: %v", w.logContext, err)
@ -279,7 +279,7 @@ func validatePath(targetPath string) error {
// shouldWritePayload returns whether the payload should be written to disk. // shouldWritePayload returns whether the payload should be written to disk.
func shouldWritePayload(payload map[string]FileProjection, oldTsDir string) (bool, error) { func shouldWritePayload(payload map[string]FileProjection, oldTsDir string) (bool, error) {
for userVisiblePath, fileProjection := range payload { for userVisiblePath, fileProjection := range payload {
shouldWrite, err := shouldWriteFile(path.Join(oldTsDir, userVisiblePath), fileProjection.Data) shouldWrite, err := shouldWriteFile(filepath.Join(oldTsDir, userVisiblePath), fileProjection.Data)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -375,7 +375,7 @@ func (w *AtomicWriter) writePayloadToDir(payload map[string]FileProjection, dir
for userVisiblePath, fileProjection := range payload { for userVisiblePath, fileProjection := range payload {
content := fileProjection.Data content := fileProjection.Data
mode := os.FileMode(fileProjection.Mode) mode := os.FileMode(fileProjection.Mode)
fullPath := path.Join(dir, userVisiblePath) fullPath := filepath.Join(dir, userVisiblePath)
baseDir, _ := filepath.Split(fullPath) baseDir, _ := filepath.Split(fullPath)
err := os.MkdirAll(baseDir, os.ModePerm) err := os.MkdirAll(baseDir, os.ModePerm)
@ -419,11 +419,11 @@ func (w *AtomicWriter) createUserVisibleFiles(payload map[string]FileProjection)
slashpos = len(userVisiblePath) slashpos = len(userVisiblePath)
} }
linkname := userVisiblePath[:slashpos] linkname := userVisiblePath[:slashpos]
_, err := os.Readlink(path.Join(w.targetDir, linkname)) _, err := os.Readlink(filepath.Join(w.targetDir, linkname))
if err != nil && os.IsNotExist(err) { if err != nil && os.IsNotExist(err) {
// The link into the data directory for this path doesn't exist; create it // The link into the data directory for this path doesn't exist; create it
visibleFile := path.Join(w.targetDir, linkname) visibleFile := filepath.Join(w.targetDir, linkname)
dataDirFile := path.Join(dataDirName, linkname) dataDirFile := filepath.Join(dataDirName, linkname)
err = os.Symlink(dataDirFile, visibleFile) err = os.Symlink(dataDirFile, visibleFile)
if err != nil { if err != nil {
@ -444,7 +444,7 @@ func (w *AtomicWriter) removeUserVisiblePaths(paths sets.String) error {
if strings.Contains(p, ps) { if strings.Contains(p, ps) {
continue continue
} }
if err := os.Remove(path.Join(w.targetDir, p)); err != nil { if err := os.Remove(filepath.Join(w.targetDir, p)); err != nil {
klog.Errorf("%s: error pruning old user-visible path %s: %v", w.logContext, p, err) klog.Errorf("%s: error pruning old user-visible path %s: %v", w.logContext, p, err)
lasterr = err lasterr = err
} }

View File

@ -22,7 +22,6 @@ import (
"encoding/base64" "encoding/base64"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"reflect" "reflect"
"strings" "strings"
@ -235,7 +234,7 @@ func TestPathsToRemove(t *testing.T) {
continue continue
} }
dataDirPath := path.Join(targetDir, dataDirName) dataDirPath := filepath.Join(targetDir, dataDirName)
oldTsDir, err := os.Readlink(dataDirPath) oldTsDir, err := os.Readlink(dataDirPath)
if err != nil && os.IsNotExist(err) { if err != nil && os.IsNotExist(err) {
t.Errorf("Data symlink does not exist: %v", dataDirPath) t.Errorf("Data symlink does not exist: %v", dataDirPath)
@ -245,7 +244,7 @@ func TestPathsToRemove(t *testing.T) {
continue continue
} }
actual, err := writer.pathsToRemove(tc.payload2, path.Join(targetDir, oldTsDir)) actual, err := writer.pathsToRemove(tc.payload2, filepath.Join(targetDir, oldTsDir))
if err != nil { if err != nil {
t.Errorf("%v: unexpected error determining paths to remove: %v", tc.name, err) t.Errorf("%v: unexpected error determining paths to remove: %v", tc.name, err)
continue continue
@ -751,7 +750,7 @@ func TestMultipleUpdates(t *testing.T) {
} }
func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjection, t *testing.T) { func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjection, t *testing.T) {
dataDirPath := path.Join(targetDir, dataDirName) dataDirPath := filepath.Join(targetDir, dataDirName)
// use filepath.Walk to reconstruct the payload, then deep equal // use filepath.Walk to reconstruct the payload, then deep equal
observedPayload := make(map[string]FileProjection) observedPayload := make(map[string]FileProjection)
visitor := func(path string, info os.FileInfo, err error) error { visitor := func(path string, info os.FileInfo, err error) error {
@ -790,13 +789,13 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec
continue continue
} }
if info.Mode()&os.ModeSymlink != 0 { if info.Mode()&os.ModeSymlink != 0 {
p := path.Join(targetDir, info.Name()) p := filepath.Join(targetDir, info.Name())
actual, err := os.Readlink(p) actual, err := os.Readlink(p)
if err != nil { if err != nil {
t.Errorf("Unable to read symlink %v: %v", p, err) t.Errorf("Unable to read symlink %v: %v", p, err)
continue continue
} }
if err := filepath.Walk(path.Join(targetDir, actual), visitor); err != nil { if err := filepath.Walk(filepath.Join(targetDir, actual), visitor); err != nil {
t.Errorf("%v: unexpected error walking directory: %v", tcName, err) t.Errorf("%v: unexpected error walking directory: %v", tcName, err)
} }
} }
@ -953,7 +952,7 @@ func TestCreateUserVisibleFiles(t *testing.T) {
} }
defer os.RemoveAll(targetDir) defer os.RemoveAll(targetDir)
dataDirPath := path.Join(targetDir, dataDirName) dataDirPath := filepath.Join(targetDir, dataDirName)
err = os.MkdirAll(dataDirPath, 0755) err = os.MkdirAll(dataDirPath, 0755)
if err != nil { if err != nil {
t.Fatalf("%v: unexpected error creating data path: %v", tc.name, err) t.Fatalf("%v: unexpected error creating data path: %v", tc.name, err)
@ -970,7 +969,7 @@ func TestCreateUserVisibleFiles(t *testing.T) {
} }
for subpath, expectedDest := range tc.expected { for subpath, expectedDest := range tc.expected {
visiblePath := path.Join(targetDir, subpath) visiblePath := filepath.Join(targetDir, subpath)
destination, err := os.Readlink(visiblePath) destination, err := os.Readlink(visiblePath)
if err != nil && os.IsNotExist(err) { if err != nil && os.IsNotExist(err) {
t.Fatalf("%v: visible symlink does not exist: %v", tc.name, visiblePath) t.Fatalf("%v: visible symlink does not exist: %v", tc.name, visiblePath)

View File

@ -22,7 +22,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -77,10 +77,10 @@ func (handler *deviceHandler) FindSlaveDevicesOnMultipath(dm string) []string {
return devices return devices
} }
disk := parts[2] disk := parts[2]
slavesPath := path.Join("/sys/block/", disk, "/slaves/") slavesPath := filepath.Join("/sys/block/", disk, "/slaves/")
if files, err := io.ReadDir(slavesPath); err == nil { if files, err := io.ReadDir(slavesPath); err == nil {
for _, f := range files { for _, f := range files {
devices = append(devices, path.Join("/dev/", f.Name())) devices = append(devices, filepath.Join("/dev/", f.Name()))
} }
} }
return devices return devices

View File

@ -18,12 +18,12 @@ package util
import ( import (
"fmt" "fmt"
"k8s.io/api/core/v1"
"os" "os"
"path"
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"k8s.io/api/core/v1"
) )
// getNestedMountpoints returns a list of mountpoint directories that should be created // getNestedMountpoints returns a list of mountpoint directories that should be created
@ -90,7 +90,7 @@ func MakeNestedMountpoints(name, baseDir string, pod v1.Pod) error {
return err return err
} }
for _, dir := range dirs { for _, dir := range dirs {
err := os.MkdirAll(path.Join(baseDir, dir), 0755) err := os.MkdirAll(filepath.Join(baseDir, dir), 0755)
if err != nil { if err != nil {
return fmt.Errorf("Unable to create nested volume mountpoints: %v", err) return fmt.Errorf("Unable to create nested volume mountpoints: %v", err)
} }

View File

@ -19,7 +19,7 @@ package util
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -206,7 +206,7 @@ func TestGetNestedMountpoints(t *testing.T) {
} }
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
rootdir := path.Join(dir, "vol") rootdir := filepath.Join(dir, "vol")
err = os.Mkdir(rootdir, 0755) err = os.Mkdir(rootdir, 0755)
if err != nil { if err != nil {
t.Errorf("Unexpected error trying to create temp root directory: %v", err) t.Errorf("Unexpected error trying to create temp root directory: %v", err)

View File

@ -19,7 +19,7 @@ package operationexecutor
import ( import (
goerrors "errors" goerrors "errors"
"fmt" "fmt"
"path" "path/filepath"
"strings" "strings"
"time" "time"
@ -810,7 +810,7 @@ func (og *operationGenerator) GenerateUnmountVolumeFunc(
subpather := og.volumePluginMgr.Host.GetSubpather() subpather := og.volumePluginMgr.Host.GetSubpather()
// Remove all bind-mounts for subPaths // Remove all bind-mounts for subPaths
podDir := path.Join(podsDir, string(volumeToUnmount.PodUID)) podDir := filepath.Join(podsDir, string(volumeToUnmount.PodUID))
if err := subpather.CleanSubPaths(podDir, volumeToUnmount.InnerVolumeSpecName); err != nil { if err := subpather.CleanSubPaths(podDir, volumeToUnmount.InnerVolumeSpecName); err != nil {
return volumeToUnmount.GenerateError("error cleaning subPath mounts", err) return volumeToUnmount.GenerateError("error cleaning subPath mounts", err)
} }

View File

@ -20,7 +20,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"reflect" "reflect"
"strings" "strings"
@ -75,7 +74,7 @@ const (
// called 'ready' in the given directory and returns // called 'ready' in the given directory and returns
// true if that file exists. // true if that file exists.
func IsReady(dir string) bool { func IsReady(dir string) bool {
readyFile := path.Join(dir, readyFileName) readyFile := filepath.Join(dir, readyFileName)
s, err := os.Stat(readyFile) s, err := os.Stat(readyFile)
if err != nil { if err != nil {
return false return false
@ -98,7 +97,7 @@ func SetReady(dir string) {
return return
} }
readyFile := path.Join(dir, readyFileName) readyFile := filepath.Join(dir, readyFileName)
file, err := os.Create(readyFile) file, err := os.Create(readyFile)
if err != nil { if err != nil {
klog.Errorf("Can't touch %s: %v", readyFile, err) klog.Errorf("Can't touch %s: %v", readyFile, err)

View File

@ -20,7 +20,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"k8s.io/klog" "k8s.io/klog"
@ -102,7 +101,7 @@ func (v VolumePathHandler) MapDevice(devicePath string, mapPath string, linkName
// Remove old symbolic link(or file) then create new one. // Remove old symbolic link(or file) then create new one.
// This should be done because current symbolic link is // This should be done because current symbolic link is
// stale across node reboot. // stale across node reboot.
linkPath := path.Join(mapPath, string(linkName)) linkPath := filepath.Join(mapPath, string(linkName))
if err = os.Remove(linkPath); err != nil && !os.IsNotExist(err) { if err = os.Remove(linkPath); err != nil && !os.IsNotExist(err) {
return err return err
} }
@ -119,7 +118,7 @@ func (v VolumePathHandler) UnmapDevice(mapPath string, linkName string) error {
klog.V(5).Infof("UnmapDevice: linkName %s", linkName) klog.V(5).Infof("UnmapDevice: linkName %s", linkName)
// Check symbolic link exists // Check symbolic link exists
linkPath := path.Join(mapPath, string(linkName)) linkPath := filepath.Join(mapPath, string(linkName))
if islinkExist, checkErr := v.IsSymlinkExist(linkPath); checkErr != nil { if islinkExist, checkErr := v.IsSymlinkExist(linkPath); checkErr != nil {
return checkErr return checkErr
} else if !islinkExist { } else if !islinkExist {
@ -176,13 +175,13 @@ func (v VolumePathHandler) GetDeviceSymlinkRefs(devPath string, mapPath string)
continue continue
} }
filename := file.Name() filename := file.Name()
filepath, err := os.Readlink(path.Join(mapPath, filename)) fp, err := os.Readlink(filepath.Join(mapPath, filename))
if err != nil { if err != nil {
return nil, fmt.Errorf("Symbolic link cannot be retrieved %v", err) return nil, fmt.Errorf("Symbolic link cannot be retrieved %v", err)
} }
klog.V(5).Infof("GetDeviceSymlinkRefs: filepath: %v, devPath: %v", filepath, devPath) klog.V(5).Infof("GetDeviceSymlinkRefs: filepath: %v, devPath: %v", fp, devPath)
if filepath == devPath { if fp == devPath {
refs = append(refs, path.Join(mapPath, filename)) refs = append(refs, filepath.Join(mapPath, filename))
} }
} }
klog.V(5).Infof("GetDeviceSymlinkRefs: refs %v", refs) klog.V(5).Infof("GetDeviceSymlinkRefs: refs %v", refs)

View File

@ -19,7 +19,7 @@ package vsphere_volume
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"time" "time"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -90,7 +90,7 @@ func (attacher *vsphereVMDKAttacher) Attach(spec *volume.Spec, nodeName types.No
return "", err return "", err
} }
return path.Join(diskByIDPath, diskSCSIPrefix+diskUUID), nil return filepath.Join(diskByIDPath, diskSCSIPrefix+diskUUID), nil
} }
func (attacher *vsphereVMDKAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) { func (attacher *vsphereVMDKAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) {

View File

@ -19,7 +19,7 @@ package vsphere_volume
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"strings" "strings"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -294,7 +294,7 @@ func (v *vsphereVolumeUnmounter) TearDownAt(dir string) error {
} }
func makeGlobalPDPath(host volume.VolumeHost, devName string) string { func makeGlobalPDPath(host volume.VolumeHost, devName string) string {
return path.Join(host.GetPluginDir(vsphereVolumePluginName), util.MountsInGlobalPDPath, devName) return filepath.Join(host.GetPluginDir(vsphereVolumePluginName), util.MountsInGlobalPDPath, devName)
} }
func (vv *vsphereVolume) GetPath() string { func (vv *vsphereVolume) GetPath() string {

View File

@ -18,7 +18,6 @@ package vsphere_volume
import ( import (
"fmt" "fmt"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -153,7 +152,7 @@ func (v *vsphereVolume) GetGlobalMapPath(spec *volume.Spec) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
return path.Join(v.plugin.host.GetVolumeDevicePluginDir(vsphereVolumePluginName), string(volumeSource.VolumePath)), nil return filepath.Join(v.plugin.host.GetVolumeDevicePluginDir(vsphereVolumePluginName), string(volumeSource.VolumePath)), nil
} }
func (v *vsphereVolume) GetPodDeviceMapPath() (string, string) { func (v *vsphereVolume) GetPodDeviceMapPath() (string, string) {

View File

@ -18,7 +18,7 @@ package vsphere_volume
import ( import (
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -46,7 +46,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {
// deferred clean up // deferred clean up
defer os.RemoveAll(tmpVDir) defer os.RemoveAll(tmpVDir)
expectedGlobalPath := path.Join(tmpVDir, testGlobalPath) expectedGlobalPath := filepath.Join(tmpVDir, testGlobalPath)
// Bad Path // Bad Path
badspec, err := getVolumeSpecFromGlobalMapPath("") badspec, err := getVolumeSpecFromGlobalMapPath("")
@ -80,8 +80,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) {
// deferred clean up // deferred clean up
defer os.RemoveAll(tmpVDir) defer os.RemoveAll(tmpVDir)
expectedGlobalPath := path.Join(tmpVDir, testGlobalPath) expectedGlobalPath := filepath.Join(tmpVDir, testGlobalPath)
expectedPodPath := path.Join(tmpVDir, testPodPath) expectedPodPath := filepath.Join(tmpVDir, testPodPath)
spec := getTestVolume(true) // block volume spec := getTestVolume(true) // block volume
pluginMgr := volume.VolumePluginMgr{} pluginMgr := volume.VolumePluginMgr{}

View File

@ -19,7 +19,7 @@ package vsphere_volume
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -117,7 +117,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Got a nil Mounter") t.Errorf("Got a nil Mounter")
} }
mntPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~vsphere-volume/vol1") mntPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~vsphere-volume/vol1")
path := mounter.GetPath() path := mounter.GetPath()
if path != mntPath { if path != mntPath {
t.Errorf("Got unexpected path: %s", path) t.Errorf("Got unexpected path: %s", path)