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) return makeGlobalPDPath(a.plugin.host, volumeSource.DataDiskURI, isManagedDisk)
} }
func (attacher *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { func (a *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error {
mounter := attacher.plugin.host.GetMounter(azureDataDiskPluginName) mounter := a.plugin.host.GetMounter(azureDataDiskPluginName)
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath) notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
if err != nil { if err != nil {
@ -242,7 +242,7 @@ func (attacher *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath str
options := []string{} options := []string{}
if notMnt { if notMnt {
diskMounter := util.NewSafeFormatAndMountFromHost(azureDataDiskPluginName, attacher.plugin.host) diskMounter := util.NewSafeFormatAndMountFromHost(azureDataDiskPluginName, a.plugin.host)
mountOptions := util.MountOptionFromSpec(spec, options...) mountOptions := util.MountOptionFromSpec(spec, options...)
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
// only parse devicePath on Windows node // 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 // UnmountDevice unmounts the volume on the node
func (detacher *azureDiskDetacher) UnmountDevice(deviceMountPath string) error { func (d *azureDiskDetacher) UnmountDevice(deviceMountPath string) error {
err := mount.CleanupMountPoint(deviceMountPath, detacher.plugin.host.GetMounter(detacher.plugin.GetPluginName()), false) err := mount.CleanupMountPoint(deviceMountPath, d.plugin.host.GetMounter(d.plugin.GetPluginName()), false)
if err == nil { if err == nil {
klog.V(2).Infof("azureDisk - Device %s was unmounted", deviceMountPath) klog.V(2).Infof("azureDisk - Device %s was unmounted", deviceMountPath)
} else { } 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) // 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) { 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. diskURI = libstrings.ToLower(diskURI) // always lower uri because users may enter it in caps.
uniqueDiskNameTemplate := "%s%s" uniqueDiskNameTemplate := "%s%s"
hashedDiskUri := azure.MakeCRC32(diskUri) hashedDiskURI := azure.MakeCRC32(diskURI)
prefix := "b" prefix := "b"
if isManaged { if isManaged {
prefix = "m" prefix = "m"
} }
// "{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 := filepath.Join(host.GetPluginDir(azureDataDiskPluginName), util.MountsInGlobalPDPath, diskName) pdPath := filepath.Join(host.GetPluginDir(azureDataDiskPluginName), util.MountsInGlobalPDPath, diskName)
return pdPath, nil 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) { func scsiHostRescan(io ioHandler, exec utilexec.Interface) {
scsi_path := "/sys/class/scsi_host/" scsiPath := "/sys/class/scsi_host/"
if dirs, err := io.ReadDir(scsi_path); err == nil { if dirs, err := io.ReadDir(scsiPath); err == nil {
for _, f := range dirs { for _, f := range dirs {
name := scsi_path + f.Name() + "/scan" name := scsiPath + f.Name() + "/scan"
data := []byte("- - -") data := []byte("- - -")
if err = io.WriteFile(name, data, 0666); err != nil { if err = io.WriteFile(name, data, 0666); err != nil {
klog.Warningf("failed to rescan scsi host %s", name) klog.Warningf("failed to rescan scsi host %s", name)
} }
} }
} else { } 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 // finds a device mounted to "current" node
func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (string, error) { func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (string, error) {
var err error var err error
sys_path := "/sys/bus/scsi/devices" sysPath := "/sys/bus/scsi/devices"
if dirs, err := io.ReadDir(sys_path); err == nil { if dirs, err := io.ReadDir(sysPath); err == nil {
for _, f := range dirs { for _, f := range dirs {
name := f.Name() name := f.Name()
// look for path like /sys/bus/scsi/devices/3:0:0:1 // 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 { 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 := filepath.Join(sys_path, name, "vendor") vendorPath := filepath.Join(sysPath, name, "vendor")
vendorBytes, err := io.ReadFile(vendorPath) vendorBytes, err := io.ReadFile(vendorPath)
if err != nil { if err != nil {
klog.Errorf("failed to read device vendor, err: %v", err) klog.Errorf("failed to read device vendor, err: %v", err)
@ -140,7 +140,7 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, azureDisks []string) (st
continue continue
} }
modelPath := filepath.Join(sys_path, name, "model") modelPath := filepath.Join(sysPath, name, "model")
modelBytes, err := io.ReadFile(modelPath) modelBytes, err := io.ReadFile(modelPath)
if err != nil { if err != nil {
klog.Errorf("failed to read device model, err: %v", err) 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 // 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 { if dev, err := io.ReadDir(dir); err == nil {
found := false found := false
devName := dev[0].Name() devName := dev[0].Name()

View File

@ -36,7 +36,7 @@ import (
"k8s.io/legacy-cloud-providers/azure" "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 { type DiskController interface {
CreateBlobDisk(dataDiskName string, storageAccountType storage.SkuName, sizeGB int) (string, error) CreateBlobDisk(dataDiskName string, storageAccountType storage.SkuName, sizeGB int) (string, error)
DeleteBlobDisk(diskUri string) error DeleteBlobDisk(diskUri string) error

View File

@ -31,8 +31,9 @@ import (
) )
const ( 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" NodePublishTimeOut_VolumeID = "node-publish-timeout"
// NodeStageTimeOut_VolumeID is a volume id that will result in NodeStage operation to timeout // NodeStageTimeOut_VolumeID is a volume id that will result in NodeStage operation to timeout
NodeStageTimeOut_VolumeID = "node-stage-timeout" NodeStageTimeOut_VolumeID = "node-stage-timeout"
) )

View File

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

View File

@ -38,7 +38,7 @@ import (
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler" "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 { func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.VolumePlugin{&iscsiPlugin{}} return []volume.VolumePlugin{&iscsiPlugin{}}
} }

View File

@ -30,7 +30,7 @@ import (
"k8s.io/kubernetes/pkg/volume/util/fsquota" "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. // for the filesystem that path resides upon.
func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) { func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) {
statfs := &unix.Statfs_t{} statfs := &unix.Statfs_t{}