mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Merge pull request #63098 from shubheksha/fix/62916-replace-path-with-filepath-aws-azure
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. aws, azure: replace path with filepath **What this PR does / why we need it**: This PR replaces usage of `path` with `filepath` as it uses OS-specific path separators. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #62916 **Special notes for your reviewer**: This PR addresses the following volume plugins: - `pkg/volume/aws_ebs` - `pkg/volume/azure_dd` - `pkg/volume/azure_file` **Release note**: ```release-note NONE ```
This commit is contained in:
commit
33d85b01fe
@ -19,7 +19,6 @@ package aws_ebs
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -387,12 +386,12 @@ func makeGlobalPDPath(host volume.VolumeHost, volumeID aws.KubernetesVolumeID) s
|
|||||||
// Clean up the URI to be more fs-friendly
|
// Clean up the URI to be more fs-friendly
|
||||||
name := string(volumeID)
|
name := string(volumeID)
|
||||||
name = strings.Replace(name, "://", "/", -1)
|
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
|
// Reverses the mapping done in makeGlobalPDPath
|
||||||
func getVolumeIDFromGlobalMount(host volume.VolumeHost, globalPath string) (string, error) {
|
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)
|
rel, err := filepath.Rel(basePath, globalPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to get volume id from global mount %s - %v", globalPath, err)
|
glog.Errorf("Failed to get volume id from global mount %s - %v", globalPath, err)
|
||||||
|
@ -18,7 +18,6 @@ package aws_ebs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -164,7 +163,7 @@ func (ebs *awsElasticBlockStore) GetGlobalMapPath(spec *volume.Spec) (string, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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
|
// GetPodDeviceMapPath returns pod device map path and volume name
|
||||||
|
@ -18,7 +18,7 @@ package aws_ebs
|
|||||||
|
|
||||||
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{}
|
||||||
|
@ -19,7 +19,7 @@ package aws_ebs
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
@ -129,7 +129,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~aws-ebs/vol1")
|
volPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~aws-ebs/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)
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -210,7 +209,7 @@ func (a *azureDiskAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if volumeSource.Kind == nil { // this spec was constructed from info on the node
|
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
|
return pdPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
libstrings "strings"
|
libstrings "strings"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
|
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
|
||||||
@ -77,7 +77,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 }"
|
// "{m for managed b for blob}{hashed diskUri or DiskId depending on disk kind }"
|
||||||
diskName := fmt.Sprintf(uniqueDiskNameTemplate, prefix, hashedDiskUri)
|
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
|
return pdPath, nil
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ package azure_dd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
libstrings "strings"
|
libstrings "strings"
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (st
|
|||||||
if lun == l {
|
if lun == l {
|
||||||
// find the matching LUN
|
// find the matching LUN
|
||||||
// read vendor and model to ensure it is a VHD disk
|
// 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)
|
vendorBytes, err := io.ReadFile(vendorPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("failed to read device vendor, err: %v", err)
|
glog.Errorf("failed to read device vendor, err: %v", err)
|
||||||
@ -136,7 +136,7 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (st
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
modelPath := path.Join(sys_path, name, "model")
|
modelPath := filepath.Join(sys_path, name, "model")
|
||||||
modelBytes, err := io.ReadFile(modelPath)
|
modelBytes, err := io.ReadFile(modelPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("failed to read device model, err: %v", err)
|
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
|
// 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 {
|
if dev, err := io.ReadDir(dir); err == nil {
|
||||||
found := false
|
found := false
|
||||||
devName := dev[0].Name()
|
devName := dev[0].Name()
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -149,7 +149,7 @@ func testPlugin(t *testing.T, tmpDir string, volumeHost volume.VolumeHost) {
|
|||||||
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~azure-file/vol1")
|
volPath := filepath.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~azure-file/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)
|
||||||
|
Loading…
Reference in New Issue
Block a user