Merge pull request #89435 from humblec/correct

Clean some code paths and correct static errors
This commit is contained in:
Kubernetes Prow Robot 2020-03-31 05:14:40 -07:00 committed by GitHub
commit 2590f6cc77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 42 deletions

View File

@ -202,8 +202,8 @@ func (a *azureDiskAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error
return makeGlobalPDPath(a.plugin.host, volumeSource.DataDiskURI, isManagedDisk)
}
func (attacher *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error {
mounter := attacher.plugin.host.GetMounter(azureDataDiskPluginName)
func (a *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error {
mounter := a.plugin.host.GetMounter(azureDataDiskPluginName)
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
if err != nil {
@ -242,7 +242,7 @@ func (attacher *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath str
options := []string{}
if notMnt {
diskMounter := util.NewSafeFormatAndMountFromHost(azureDataDiskPluginName, attacher.plugin.host)
diskMounter := util.NewSafeFormatAndMountFromHost(azureDataDiskPluginName, a.plugin.host)
mountOptions := util.MountOptionFromSpec(spec, options...)
if runtime.GOOS == "windows" {
// only parse devicePath on Windows node
@ -284,8 +284,8 @@ func (d *azureDiskDetacher) Detach(diskURI string, nodeName types.NodeName) erro
}
// UnmountDevice unmounts the volume on the node
func (detacher *azureDiskDetacher) UnmountDevice(deviceMountPath string) error {
err := mount.CleanupMountPoint(deviceMountPath, detacher.plugin.host.GetMounter(detacher.plugin.GetPluginName()), false)
func (d *azureDiskDetacher) UnmountDevice(deviceMountPath string) error {
err := mount.CleanupMountPoint(deviceMountPath, d.plugin.host.GetMounter(d.plugin.GetPluginName()), false)
if err == nil {
klog.V(2).Infof("azureDisk - Device %s was unmounted", deviceMountPath)
} else {

View File

@ -73,16 +73,16 @@ func getPath(uid types.UID, volName string, host volume.VolumeHost) string {
}
// creates a unique path for disks (even if they share the same *.vhd name)
func makeGlobalPDPath(host volume.VolumeHost, diskUri string, isManaged bool) (string, error) {
diskUri = libstrings.ToLower(diskUri) // always lower uri because users may enter it in caps.
func makeGlobalPDPath(host volume.VolumeHost, diskURI string, isManaged bool) (string, error) {
diskURI = libstrings.ToLower(diskURI) // always lower uri because users may enter it in caps.
uniqueDiskNameTemplate := "%s%s"
hashedDiskUri := azure.MakeCRC32(diskUri)
hashedDiskURI := azure.MakeCRC32(diskURI)
prefix := "b"
if isManaged {
prefix = "m"
}
// "{m for managed b for blob}{hashed diskUri or DiskId depending on disk kind }"
diskName := fmt.Sprintf(uniqueDiskNameTemplate, prefix, hashedDiskUri)
// "{m for managed b for blob}{hashed diskURI or DiskId depending on disk kind }"
diskName := fmt.Sprintf(uniqueDiskNameTemplate, prefix, hashedDiskURI)
pdPath := filepath.Join(host.GetPluginDir(azureDataDiskPluginName), util.MountsInGlobalPDPath, diskName)
return pdPath, nil

View File

@ -73,17 +73,17 @@ func getDiskLinkByDevName(io ioHandler, devLinkPath, devName string) (string, er
}
func scsiHostRescan(io ioHandler, exec utilexec.Interface) {
scsi_path := "/sys/class/scsi_host/"
if dirs, err := io.ReadDir(scsi_path); err == nil {
scsiPath := "/sys/class/scsi_host/"
if dirs, err := io.ReadDir(scsiPath); err == nil {
for _, f := range dirs {
name := scsi_path + f.Name() + "/scan"
name := scsiPath + f.Name() + "/scan"
data := []byte("- - -")
if err = io.WriteFile(name, data, 0666); err != nil {
klog.Warningf("failed to rescan scsi host %s", name)
}
}
} else {
klog.Warningf("failed to read %s, err %v", scsi_path, err)
klog.Warningf("failed to read %s, err %v", scsiPath, err)
}
}
@ -95,8 +95,8 @@ func findDiskByLun(lun int, io ioHandler, exec utilexec.Interface) (string, erro
// finds a device mounted to "current" node
func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (string, error) {
var err error
sys_path := "/sys/bus/scsi/devices"
if dirs, err := io.ReadDir(sys_path); err == nil {
sysPath := "/sys/bus/scsi/devices"
if dirs, err := io.ReadDir(sysPath); err == nil {
for _, f := range dirs {
name := f.Name()
// look for path like /sys/bus/scsi/devices/3:0:0:1
@ -128,7 +128,7 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (st
if lun == l {
// find the matching LUN
// read vendor and model to ensure it is a VHD disk
vendorPath := filepath.Join(sys_path, name, "vendor")
vendorPath := filepath.Join(sysPath, name, "vendor")
vendorBytes, err := io.ReadFile(vendorPath)
if err != nil {
klog.Errorf("failed to read device vendor, err: %v", err)
@ -140,7 +140,7 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (st
continue
}
modelPath := filepath.Join(sys_path, name, "model")
modelPath := filepath.Join(sysPath, name, "model")
modelBytes, err := io.ReadFile(modelPath)
if err != nil {
klog.Errorf("failed to read device model, err: %v", err)
@ -153,7 +153,7 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (st
}
// find a disk, validate name
dir := filepath.Join(sys_path, name, "block")
dir := filepath.Join(sysPath, name, "block")
if dev, err := io.ReadDir(dir); err == nil {
found := false
devName := dev[0].Name()

View File

@ -36,7 +36,7 @@ import (
"k8s.io/legacy-cloud-providers/azure"
)
// interface exposed by the cloud provider implementing Disk functionality
// DiskController interface exposed by the cloud provider implementing Disk functionality
type DiskController interface {
CreateBlobDisk(dataDiskName string, storageAccountType storage.SkuName, sizeGB int) (string, error)
DeleteBlobDisk(diskUri string) error

View File

@ -31,8 +31,9 @@ import (
)
const (
// NodePublishTimeout_VolumeID is volume id that will result in NodePublish operation to timeout
// NodePublishTimeOut_VolumeID is volume id that will result in NodePublish operation to timeout
NodePublishTimeOut_VolumeID = "node-publish-timeout"
// NodeStageTimeOut_VolumeID is a volume id that will result in NodeStage operation to timeout
NodeStageTimeOut_VolumeID = "node-stage-timeout"
)

View File

@ -70,7 +70,7 @@ type expectedCommand struct {
}
func TestPlugin(t *testing.T) {
gitUrl := "https://github.com/kubernetes/kubernetes.git"
gitURL := "https://github.com/kubernetes/kubernetes.git"
revision := "2a30ce65c5ab586b98916d83385c5983edd353a1"
scenarios := []struct {
@ -85,7 +85,7 @@ func TestPlugin(t *testing.T) {
Name: "vol1",
VolumeSource: v1.VolumeSource{
GitRepo: &v1.GitRepoVolumeSource{
Repository: gitUrl,
Repository: gitURL,
Revision: revision,
Directory: "target_dir",
},
@ -93,7 +93,7 @@ func TestPlugin(t *testing.T) {
},
expecteds: []expectedCommand{
{
cmd: []string{"git", "clone", "--", gitUrl, "target_dir"},
cmd: []string{"git", "clone", "--", gitURL, "target_dir"},
dir: "",
},
{
@ -113,14 +113,14 @@ func TestPlugin(t *testing.T) {
Name: "vol1",
VolumeSource: v1.VolumeSource{
GitRepo: &v1.GitRepoVolumeSource{
Repository: gitUrl,
Repository: gitURL,
Directory: "target_dir",
},
},
},
expecteds: []expectedCommand{
{
cmd: []string{"git", "clone", "--", gitUrl, "target_dir"},
cmd: []string{"git", "clone", "--", gitURL, "target_dir"},
dir: "",
},
},
@ -132,13 +132,13 @@ func TestPlugin(t *testing.T) {
Name: "vol1",
VolumeSource: v1.VolumeSource{
GitRepo: &v1.GitRepoVolumeSource{
Repository: gitUrl,
Repository: gitURL,
},
},
},
expecteds: []expectedCommand{
{
cmd: []string{"git", "clone", "--", gitUrl},
cmd: []string{"git", "clone", "--", gitURL},
dir: "",
},
},
@ -150,7 +150,7 @@ func TestPlugin(t *testing.T) {
Name: "vol1",
VolumeSource: v1.VolumeSource{
GitRepo: &v1.GitRepoVolumeSource{
Repository: gitUrl,
Repository: gitURL,
Revision: revision,
Directory: "",
},
@ -158,7 +158,7 @@ func TestPlugin(t *testing.T) {
},
expecteds: []expectedCommand{
{
cmd: []string{"git", "clone", "--", gitUrl},
cmd: []string{"git", "clone", "--", gitURL},
dir: "",
},
{
@ -178,7 +178,7 @@ func TestPlugin(t *testing.T) {
Name: "vol1",
VolumeSource: v1.VolumeSource{
GitRepo: &v1.GitRepoVolumeSource{
Repository: gitUrl,
Repository: gitURL,
Revision: revision,
Directory: ".",
},
@ -186,7 +186,7 @@ func TestPlugin(t *testing.T) {
},
expecteds: []expectedCommand{
{
cmd: []string{"git", "clone", "--", gitUrl, "."},
cmd: []string{"git", "clone", "--", gitURL, "."},
dir: "",
},
{
@ -206,7 +206,7 @@ func TestPlugin(t *testing.T) {
Name: "vol1",
VolumeSource: v1.VolumeSource{
GitRepo: &v1.GitRepoVolumeSource{
Repository: gitUrl,
Repository: gitURL,
Revision: revision,
Directory: "./.",
},
@ -214,7 +214,7 @@ func TestPlugin(t *testing.T) {
},
expecteds: []expectedCommand{
{
cmd: []string{"git", "clone", "--", gitUrl, "./."},
cmd: []string{"git", "clone", "--", gitURL, "./."},
dir: "",
},
{
@ -246,7 +246,7 @@ func TestPlugin(t *testing.T) {
Name: "vol1",
VolumeSource: v1.VolumeSource{
GitRepo: &v1.GitRepoVolumeSource{
Repository: gitUrl,
Repository: gitURL,
Revision: "--bar",
},
},
@ -259,7 +259,7 @@ func TestPlugin(t *testing.T) {
Name: "vol1",
VolumeSource: v1.VolumeSource{
GitRepo: &v1.GitRepoVolumeSource{
Repository: gitUrl,
Repository: gitURL,
Directory: "-b",
},
},
@ -330,11 +330,11 @@ func doTestPlugin(scenario struct {
allErrs = append(allErrs,
fmt.Errorf("SetUp() failed, volume path not created: %s", path))
return allErrs
} else {
allErrs = append(allErrs,
fmt.Errorf("SetUp() failed: %v", err))
return allErrs
}
allErrs = append(allErrs,
fmt.Errorf("SetUp() failed: %v", err))
return allErrs
}
// gitRepo volume should create its own empty wrapper path

View File

@ -38,7 +38,7 @@ import (
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
)
// This is the primary entrypoint for volume plugins.
// ProbeVolumePlugins is the primary entrypoint for volume plugins.
func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.VolumePlugin{&iscsiPlugin{}}
}

View File

@ -30,7 +30,7 @@ import (
"k8s.io/kubernetes/pkg/volume/util/fsquota"
)
// FSInfo linux returns (available bytes, byte capacity, byte usage, total inodes, inodes free, inode usage, error)
// FsInfo linux returns (available bytes, byte capacity, byte usage, total inodes, inodes free, inode usage, error)
// for the filesystem that path resides upon.
func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) {
statfs := &unix.Statfs_t{}