From 331cd94ccc0cdebced1146d0fdefee3701ff8242 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 30 Jan 2020 14:29:56 -0800 Subject: [PATCH] Ineffassign fixes for pkg/volume Along resolves errors whitelisted in hack/.staticcheck_failures --- hack/.staticcheck_failures | 2 -- pkg/volume/azure_file/azure_file.go | 8 ++++++-- pkg/volume/iscsi/iscsi_util.go | 2 +- pkg/volume/rbd/rbd_util.go | 2 +- pkg/volume/util/fsquota/project.go | 6 +++--- pkg/volume/util/fsquota/quota_linux.go | 11 ++++++++++- .../util/operationexecutor/operation_generator.go | 2 +- pkg/volume/util/subpath/subpath_windows.go | 2 +- 8 files changed, 23 insertions(+), 12 deletions(-) diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index 73c54f7f592..04ffecdf285 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -20,7 +20,6 @@ pkg/registry/core/service/storage pkg/util/coverage pkg/volume pkg/volume/azure_dd -pkg/volume/azure_file pkg/volume/csi pkg/volume/fc pkg/volume/flexvolume @@ -35,7 +34,6 @@ pkg/volume/storageos pkg/volume/util pkg/volume/util/fsquota pkg/volume/util/fsquota/common -pkg/volume/util/operationexecutor pkg/volume/util/subpath pkg/volume/vsphere_volume test/e2e/apps diff --git a/pkg/volume/azure_file/azure_file.go b/pkg/volume/azure_file/azure_file.go index cd1a13ba369..603916a8879 100644 --- a/pkg/volume/azure_file/azure_file.go +++ b/pkg/volume/azure_file/azure_file.go @@ -114,6 +114,11 @@ func (plugin *azureFilePlugin) newMounterInternal(spec *volume.Spec, pod *v1.Pod return nil, err } secretName, secretNamespace, err := getSecretNameAndNamespace(spec, pod.Namespace) + if err != nil { + // Log-and-continue instead of returning an error for now + // due to unspecified backwards compatibility concerns (a subject to revise) + klog.Errorf("get secret name and namespace from pod(%s) return with error: %v", pod.Name, err) + } return &azureFileMounter{ azureFile: &azureFile{ volName: spec.Name(), @@ -257,7 +262,6 @@ func (b *azureFileMounter) SetUpAt(dir string, mounterArgs volume.MounterArgs) e klog.Errorf("azureFile - Unmount directory %s failed with %v", dir, err) return err } - notMnt = true } var accountKey, accountName string @@ -265,7 +269,7 @@ func (b *azureFileMounter) SetUpAt(dir string, mounterArgs volume.MounterArgs) e return err } - mountOptions := []string{} + var mountOptions []string source := "" osSeparator := string(os.PathSeparator) source = fmt.Sprintf("%s%s%s.file.%s%s%s", osSeparator, osSeparator, accountName, getStorageEndpointSuffix(b.plugin.host.GetCloudProvider()), osSeparator, b.shareName) diff --git a/pkg/volume/iscsi/iscsi_util.go b/pkg/volume/iscsi/iscsi_util.go index 9a4744d31ce..d3299bf1f3f 100644 --- a/pkg/volume/iscsi/iscsi_util.go +++ b/pkg/volume/iscsi/iscsi_util.go @@ -362,7 +362,7 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) (string, error) { } // in case of node failure/restart, explicitly set to manual login so it doesn't hang on boot - out, err = execWithLog(b, "iscsiadm", "-m", "node", "-p", tp, "-T", b.Iqn, "-o", "update", "-n", "node.startup", "-v", "manual") + _, err = execWithLog(b, "iscsiadm", "-m", "node", "-p", tp, "-T", b.Iqn, "-o", "update", "-n", "node.startup", "-v", "manual") if err != nil { // don't fail if we can't set startup mode, but log warning so there is a clue klog.Warningf("Warning: Failed to set iSCSI login mode to manual. Error: %v", err) diff --git a/pkg/volume/rbd/rbd_util.go b/pkg/volume/rbd/rbd_util.go index 93b7ff219f0..345751aa145 100644 --- a/pkg/volume/rbd/rbd_util.go +++ b/pkg/volume/rbd/rbd_util.go @@ -355,7 +355,7 @@ func (util *RBDUtil) rbdUnlock(b rbdMounter) error { if len(locker) > 0 { args := []string{"lock", "remove", b.Image, lock_id, locker, "--pool", b.Pool, "--id", b.Id, "-m", mon} args = append(args, secret_opt...) - cmd, err = b.exec.Command("rbd", args...).CombinedOutput() + _, err = b.exec.Command("rbd", args...).CombinedOutput() if err == nil { klog.V(4).Infof("rbd: successfully remove lock (locker_id: %s) on image: %s/%s with id %s mon %s", lock_id, b.Pool, b.Image, b.Id, mon) } else { diff --git a/pkg/volume/util/fsquota/project.go b/pkg/volume/util/fsquota/project.go index 32f04f8decc..9f2b5460bca 100644 --- a/pkg/volume/util/fsquota/project.go +++ b/pkg/volume/util/fsquota/project.go @@ -89,7 +89,7 @@ func openAndLockProjectFiles() (*os.File, *os.File, error) { fProjid, err := os.OpenFile(projidFile, os.O_RDONLY|os.O_CREATE, 0644) if err == nil { // Check once more, to ensure nothing got changed out from under us - if err := projFilesAreOK(); err == nil { + if err = projFilesAreOK(); err == nil { err = lockFile(fProjects) if err == nil { err = lockFile(fProjid) @@ -324,7 +324,7 @@ func createProjectID(path string, ID common.QuotaID) (common.QuotaID, error) { if err == nil { defer closeProjectFiles(fProjects, fProjid) list := readProjectFiles(fProjects, fProjid) - writeProjid := true + var writeProjid bool ID, writeProjid, err = addDirToProject(path, ID, &list) if err == nil && ID != common.BadQuotaID { if err = writeProjectFiles(fProjects, fProjid, writeProjid, list); err == nil { @@ -345,7 +345,7 @@ func removeProjectID(path string, ID common.QuotaID) error { if err == nil { defer closeProjectFiles(fProjects, fProjid) list := readProjectFiles(fProjects, fProjid) - writeProjid := true + var writeProjid bool writeProjid, err = removeDirFromProject(path, ID, &list) if err == nil { if err = writeProjectFiles(fProjects, fProjid, writeProjid, list); err == nil { diff --git a/pkg/volume/util/fsquota/quota_linux.go b/pkg/volume/util/fsquota/quota_linux.go index 70de9c309e6..319ae0e0829 100644 --- a/pkg/volume/util/fsquota/quota_linux.go +++ b/pkg/volume/util/fsquota/quota_linux.go @@ -226,6 +226,11 @@ func clearQuotaOnDir(m mount.Interface, path string) error { // we explicitly have to check in this case. klog.V(4).Infof("clearQuotaOnDir %s", path) supportsQuotas, err := SupportsQuotas(m, path) + if err != nil { + // Log-and-continue instead of returning an error for now + // due to unspecified backwards compatibility concerns (a subject to revise) + klog.V(3).Infof("Attempt to check for quota support failed: %v", err) + } if !supportsQuotas { return nil } @@ -409,8 +414,12 @@ func ClearQuota(m mount.Interface, path string) error { if !ok { return fmt.Errorf("ClearQuota: No quota available for %s", path) } - var err error projid, err := getQuotaOnDir(m, path) + if err != nil { + // Log-and-continue instead of returning an error for now + // due to unspecified backwards compatibility concerns (a subject to revise) + klog.V(3).Infof("Attempt to check quota ID %v on dir %s failed: %v", dirQuotaMap[path], path, err) + } if projid != dirQuotaMap[path] { return fmt.Errorf("Expected quota ID %v on dir %s does not match actual %v", dirQuotaMap[path], path, projid) } diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index d453c049608..8d00bef04d8 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -653,7 +653,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc( // - Volume does not support DeviceMounter interface. // - In case of CSI the volume does not have node stage_unstage capability. if !resizeDone { - resizeDone, resizeError = og.nodeExpandVolume(volumeToMount, resizeOptions) + _, resizeError = og.nodeExpandVolume(volumeToMount, resizeOptions) if resizeError != nil { klog.Errorf("MountVolume.NodeExpandVolume failed with %v", resizeError) return volumeToMount.GenerateError("MountVolume.Setup failed while expanding volume", resizeError) diff --git a/pkg/volume/util/subpath/subpath_windows.go b/pkg/volume/util/subpath/subpath_windows.go index f8987397b63..f8c227e4fc1 100644 --- a/pkg/volume/util/subpath/subpath_windows.go +++ b/pkg/volume/util/subpath/subpath_windows.go @@ -267,7 +267,7 @@ func findExistingPrefix(base, pathname string) (string, []string, error) { dirs := strings.Split(rel, string(filepath.Separator)) - parent := base + var parent string currentPath := base for i, dir := range dirs { parent = currentPath