Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update static check failed from pkg/volume/rbd #92461

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion hack/.staticcheck_failures
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pkg/controller/resourcequota
pkg/controller/statefulset
pkg/volume/azure_dd
pkg/volume/gcepd
pkg/volume/rbd
pkg/volume/testing
pkg/volume/vsphere_volume
test/e2e/apps
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/rbd/attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ var _ volume.DeviceUnmounter = &rbdDetacher{}
// This method is idempotent, callers are responsible for retrying on failure.
func (detacher *rbdDetacher) UnmountDevice(deviceMountPath string) error {
if pathExists, pathErr := mount.PathExists(deviceMountPath); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
return fmt.Errorf("error checking if path exists: %v", pathErr)
} else if !pathExists {
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", deviceMountPath)
return nil
Expand Down
35 changes: 17 additions & 18 deletions pkg/volume/rbd/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
volutil "k8s.io/kubernetes/pkg/volume/util"
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
)
Expand Down Expand Up @@ -199,7 +198,7 @@ func (plugin *rbdPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resource.
}

func (plugin *rbdPlugin) NodeExpand(resizeOptions volume.NodeResizeOptions) (bool, error) {
fsVolume, err := util.CheckVolumeModeFilesystem(resizeOptions.VolumeSpec)
fsVolume, err := volutil.CheckVolumeModeFilesystem(resizeOptions.VolumeSpec)
if err != nil {
return false, fmt.Errorf("error checking VolumeMode: %v", err)
}
Expand Down Expand Up @@ -268,11 +267,11 @@ func (plugin *rbdPlugin) createMounterFromVolumeSpecAndPod(spec *volume.Spec, po
// if secret is provideded, retrieve it
kubeClient := plugin.host.GetKubeClient()
if kubeClient == nil {
return nil, fmt.Errorf("Cannot get kube client")
return nil, fmt.Errorf("cannot get kube client")
}
secrets, err := kubeClient.CoreV1().Secrets(secretNs).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
err = fmt.Errorf("Couldn't get secret %v/%v err: %v", secretNs, secretName, err)
err = fmt.Errorf("couldn't get secret %v/%v err: %v", secretNs, secretName, err)
return nil, err
}
for _, data := range secrets.Data {
Expand Down Expand Up @@ -301,11 +300,11 @@ func (plugin *rbdPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volume.Vol
// if secret is provideded, retrieve it
kubeClient := plugin.host.GetKubeClient()
if kubeClient == nil {
return nil, fmt.Errorf("Cannot get kube client")
return nil, fmt.Errorf("cannot get kube client")
}
secrets, err := kubeClient.CoreV1().Secrets(secretNs).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
err = fmt.Errorf("Couldn't get secret %v/%v err: %v", secretNs, secretName, err)
err = fmt.Errorf("couldn't get secret %v/%v err: %v", secretNs, secretName, err)
return nil, err
}
for _, data := range secrets.Data {
Expand Down Expand Up @@ -483,11 +482,11 @@ func (plugin *rbdPlugin) NewBlockVolumeMapper(spec *volume.Spec, pod *v1.Pod, _
// if secret is provideded, retrieve it
kubeClient := plugin.host.GetKubeClient()
if kubeClient == nil {
return nil, fmt.Errorf("Cannot get kube client")
return nil, fmt.Errorf("cannot get kube client")
}
secrets, err := kubeClient.CoreV1().Secrets(secretNs).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
err = fmt.Errorf("Couldn't get secret %v/%v err: %v", secretNs, secretName, err)
err = fmt.Errorf("couldn't get secret %v/%v err: %v", secretNs, secretName, err)
return nil, err
}
for _, data := range secrets.Data {
Expand Down Expand Up @@ -862,7 +861,7 @@ func (c *rbdUnmounter) TearDown() error {
func (c *rbdUnmounter) TearDownAt(dir string) error {
klog.V(4).Infof("rbd: attempting to teardown at %s", dir)
if pathExists, pathErr := mount.PathExists(dir); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
return fmt.Errorf("error checking if path exists: %v", pathErr)
} else if !pathExists {
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
Expand Down Expand Up @@ -996,7 +995,7 @@ func getVolumeSourceMonitors(spec *volume.Spec) ([]string, error) {
return spec.PersistentVolume.Spec.RBD.CephMonitors, nil
}

return nil, fmt.Errorf("Spec does not reference a RBD volume type")
return nil, fmt.Errorf("spec does not reference a RBD volume type")
}

func getVolumeSourceImage(spec *volume.Spec) (string, error) {
Expand All @@ -1007,7 +1006,7 @@ func getVolumeSourceImage(spec *volume.Spec) (string, error) {
return spec.PersistentVolume.Spec.RBD.RBDImage, nil
}

return "", fmt.Errorf("Spec does not reference a RBD volume type")
return "", fmt.Errorf("spec does not reference a RBD volume type")
}

func getVolumeSourceFSType(spec *volume.Spec) (string, error) {
Expand All @@ -1018,7 +1017,7 @@ func getVolumeSourceFSType(spec *volume.Spec) (string, error) {
return spec.PersistentVolume.Spec.RBD.FSType, nil
}

return "", fmt.Errorf("Spec does not reference a RBD volume type")
return "", fmt.Errorf("spec does not reference a RBD volume type")
}

func getVolumeSourcePool(spec *volume.Spec) (string, error) {
Expand All @@ -1029,7 +1028,7 @@ func getVolumeSourcePool(spec *volume.Spec) (string, error) {
return spec.PersistentVolume.Spec.RBD.RBDPool, nil
}

return "", fmt.Errorf("Spec does not reference a RBD volume type")
return "", fmt.Errorf("spec does not reference a RBD volume type")
}

func getVolumeSourceUser(spec *volume.Spec) (string, error) {
Expand All @@ -1040,7 +1039,7 @@ func getVolumeSourceUser(spec *volume.Spec) (string, error) {
return spec.PersistentVolume.Spec.RBD.RadosUser, nil
}

return "", fmt.Errorf("Spec does not reference a RBD volume type")
return "", fmt.Errorf("spec does not reference a RBD volume type")
}

func getVolumeSourceKeyRing(spec *volume.Spec) (string, error) {
Expand All @@ -1051,7 +1050,7 @@ func getVolumeSourceKeyRing(spec *volume.Spec) (string, error) {
return spec.PersistentVolume.Spec.RBD.Keyring, nil
}

return "", fmt.Errorf("Spec does not reference a RBD volume type")
return "", fmt.Errorf("spec does not reference a RBD volume type")
}

func getVolumeSourceReadOnly(spec *volume.Spec) (bool, error) {
Expand All @@ -1064,7 +1063,7 @@ func getVolumeSourceReadOnly(spec *volume.Spec) (bool, error) {
return spec.ReadOnly, nil
}

return false, fmt.Errorf("Spec does not reference a RBD volume type")
return false, fmt.Errorf("spec does not reference a RBD volume type")
}

func getVolumeAccessModes(spec *volume.Spec) ([]v1.PersistentVolumeAccessMode, error) {
Expand All @@ -1073,7 +1072,7 @@ func getVolumeAccessModes(spec *volume.Spec) ([]v1.PersistentVolumeAccessMode, e
if spec.PersistentVolume.Spec.RBD != nil {
return spec.PersistentVolume.Spec.AccessModes, nil
}
return nil, fmt.Errorf("Spec does not reference a RBD volume type")
return nil, fmt.Errorf("spec does not reference a RBD volume type")
}

return nil, nil
Expand Down Expand Up @@ -1124,5 +1123,5 @@ func getSecretNameAndNamespace(spec *volume.Spec, defaultNamespace string) (stri
}
return "", "", nil
}
return "", "", fmt.Errorf("Spec does not reference an RBD volume type")
return "", "", fmt.Errorf("spec does not reference an RBD volume type")
}
4 changes: 2 additions & 2 deletions pkg/volume/rbd/rbd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {

block := v1.PersistentVolumeBlock
specMode := spec.PersistentVolume.Spec.VolumeMode
if &specMode == nil {
t.Errorf("Invalid volumeMode from GlobalMapPath spec: %v - %v", &specMode, block)
if specMode == nil {
t.Errorf("Invalid volumeMode from GlobalMapPath spec: %v - %v", specMode, block)
}
if *specMode != block {
t.Errorf("Invalid volumeMode from GlobalMapPath spec: %v - %v", *specMode, block)
Expand Down
8 changes: 4 additions & 4 deletions pkg/volume/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (util *rbdUtil) AttachDisk(b rbdMounter) (string, error) {

globalPDPath := util.MakeGlobalPDName(*b.rbd)
if pathExists, pathErr := mount.PathExists(globalPDPath); pathErr != nil {
return "", fmt.Errorf("Error checking if path exists: %v", pathErr)
return "", fmt.Errorf("error checking if path exists: %v", pathErr)
} else if !pathExists {
if err := os.MkdirAll(globalPDPath, 0750); err != nil {
return "", err
Expand Down Expand Up @@ -459,7 +459,7 @@ func (util *rbdUtil) AttachDisk(b rbdMounter) (string, error) {
devicePath, mapped = waitForPath(b.Pool, b.Image, 10 /*maxRetries*/, false /*useNbdDriver*/)
}
if !mapped {
return "", fmt.Errorf("Could not map image %s/%s, Timeout after 10s", b.Pool, b.Image)
return "", fmt.Errorf("could not map image %s/%s, Timeout after 10s", b.Pool, b.Image)
}
}
return devicePath, nil
Expand Down Expand Up @@ -515,7 +515,7 @@ func (util *rbdUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, devic
func (util *rbdUtil) DetachBlockDisk(disk rbdDiskUnmapper, mapPath string) error {

if pathExists, pathErr := mount.PathExists(mapPath); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
return fmt.Errorf("error checking if path exists: %v", pathErr)
} else if !pathExists {
klog.Warningf("Warning: Unmap skipped because path does not exist: %v", mapPath)
return nil
Expand Down Expand Up @@ -803,7 +803,7 @@ func (util *rbdUtil) rbdStatus(b *rbdMounter) (bool, string, error) {
func getRbdImageInfo(deviceMountPath string) (*rbdImageInfo, error) {
deviceMountedPathSeps := strings.Split(filepath.Base(deviceMountPath), "-image-")
if len(deviceMountedPathSeps) != 2 {
return nil, fmt.Errorf("Can't found devicePath for %s ", deviceMountPath)
return nil, fmt.Errorf("can't found devicePath for %s ", deviceMountPath)
}
return &rbdImageInfo{
pool: deviceMountedPathSeps[0],
Expand Down