From a5b7ce1bfdf06de4a20e80b9cbc6756ff05db410 Mon Sep 17 00:00:00 2001 From: haleygo Date: Wed, 24 Jun 2020 17:47:28 +0800 Subject: [PATCH] fix static check failed from pkg/volume/vspherevolume remove field from staticcheck_failures --- hack/.staticcheck_failures | 1 - pkg/volume/vsphere_volume/attacher.go | 4 +-- pkg/volume/vsphere_volume/vsphere_volume.go | 2 +- .../vsphere_volume_block_test.go | 4 +-- .../vsphere_volume/vsphere_volume_util.go | 34 +++++++++---------- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index 410350c7991..2292639c85a 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -10,7 +10,6 @@ pkg/volume/azure_dd pkg/volume/gcepd pkg/volume/rbd pkg/volume/testing -pkg/volume/vsphere_volume test/e2e/apps test/e2e/autoscaling test/e2e_node diff --git a/pkg/volume/vsphere_volume/attacher.go b/pkg/volume/vsphere_volume/attacher.go index 50b2f1a3cbb..7dd0a042c8e 100644 --- a/pkg/volume/vsphere_volume/attacher.go +++ b/pkg/volume/vsphere_volume/attacher.go @@ -161,7 +161,7 @@ func (attacher *vsphereVMDKAttacher) WaitForAttach(spec *volume.Spec, devicePath } if devicePath == "" { - return "", fmt.Errorf("WaitForAttach failed for VMDK %q: devicePath is empty.", volumeSource.VolumePath) + return "", fmt.Errorf("WaitForAttach failed for VMDK %q: devicePath is empty", volumeSource.VolumePath) } ticker := time.NewTicker(checkSleepDuration) @@ -184,7 +184,7 @@ func (attacher *vsphereVMDKAttacher) WaitForAttach(spec *volume.Spec, devicePath return path, nil } case <-timer.C: - return "", fmt.Errorf("Could not find attached VMDK %q. Timeout waiting for mount paths to be created.", volumeSource.VolumePath) + return "", fmt.Errorf("could not find attached VMDK %q. Timeout waiting for mount paths to be created", volumeSource.VolumePath) } } } diff --git a/pkg/volume/vsphere_volume/vsphere_volume.go b/pkg/volume/vsphere_volume/vsphere_volume.go index f38295952f5..10f146baf6e 100644 --- a/pkg/volume/vsphere_volume/vsphere_volume.go +++ b/pkg/volume/vsphere_volume/vsphere_volume.go @@ -464,7 +464,7 @@ func getVolumeSource( return spec.PersistentVolume.Spec.VsphereVolume, spec.ReadOnly, nil } - return nil, false, fmt.Errorf("Spec does not reference a VSphere volume type") + return nil, false, fmt.Errorf("spec does not reference a VSphere volume type") } func getNodeName(node *v1.Node) string { diff --git a/pkg/volume/vsphere_volume/vsphere_volume_block_test.go b/pkg/volume/vsphere_volume/vsphere_volume_block_test.go index 0f980d1eda7..1b46ab3f519 100644 --- a/pkg/volume/vsphere_volume/vsphere_volume_block_test.go +++ b/pkg/volume/vsphere_volume/vsphere_volume_block_test.go @@ -69,8 +69,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 expected: %v", &specMode, block) + if specMode == nil { + t.Errorf("Invalid volumeMode from GlobalMapPath spec: %v expected: %v", specMode, block) } if *specMode != block { t.Errorf("Invalid volumeMode from GlobalMapPath spec: %v expected: %v", *specMode, block) diff --git a/pkg/volume/vsphere_volume/vsphere_volume_util.go b/pkg/volume/vsphere_volume/vsphere_volume_util.go index e16c6c246c8..b42eede1aa8 100644 --- a/pkg/volume/vsphere_volume/vsphere_volume_util.go +++ b/pkg/volume/vsphere_volume/vsphere_volume_util.go @@ -63,7 +63,7 @@ const ( IopsLimitCapabilityMin = 0 ) -var ErrProbeVolume = errors.New("Error scanning attached volumes") +var ErrProbeVolume = errors.New("error scanning attached volumes") type VsphereDiskUtil struct{} @@ -129,7 +129,7 @@ func (util *VsphereDiskUtil) CreateVolume(v *vsphereVolumeProvisioner, selectedN if volumeOptions.VSANStorageProfileData != "" { if volumeOptions.StoragePolicyName != "" { - return nil, fmt.Errorf("Cannot specify storage policy capabilities along with storage policy name. Please specify only one") + return nil, fmt.Errorf("cannot specify storage policy capabilities along with storage policy name. Please specify only one") } volumeOptions.VSANStorageProfileData = "(" + volumeOptions.VSANStorageProfileData + ")" } @@ -186,12 +186,12 @@ func getVolPathfromVolumeName(deviceMountPath string) string { func getCloudProvider(cloud cloudprovider.Interface) (*vsphere.VSphere, error) { if cloud == nil { klog.Errorf("Cloud provider not initialized properly") - return nil, errors.New("Cloud provider not initialized properly") + return nil, errors.New("cloud provider not initialized properly") } vs, ok := cloud.(*vsphere.VSphere) if !ok || vs == nil { - return nil, errors.New("Invalid cloud provider: expected vSphere") + return nil, errors.New("invalid cloud provider: expected vSphere") } return vs, nil } @@ -201,55 +201,55 @@ func validateVSANCapability(capabilityName string, capabilityValue string) (stri var capabilityData string capabilityIntVal, ok := verifyCapabilityValueIsInteger(capabilityValue) if !ok { - return "", fmt.Errorf("Invalid value for %s. The capabilityValue: %s must be a valid integer value", capabilityName, capabilityValue) + return "", fmt.Errorf("invalid value for %s. The capabilityValue: %s must be a valid integer value", capabilityName, capabilityValue) } switch strings.ToLower(capabilityName) { case HostFailuresToTolerateCapability: if capabilityIntVal >= HostFailuresToTolerateCapabilityMin && capabilityIntVal <= HostFailuresToTolerateCapabilityMax { capabilityData = " (\"hostFailuresToTolerate\" i" + capabilityValue + ")" } else { - return "", fmt.Errorf(`Invalid value for hostFailuresToTolerate. - The default value is %d, minimum value is %d and maximum value is %d.`, + return "", fmt.Errorf(`invalid value for hostFailuresToTolerate. + The default value is %d, minimum value is %d and maximum value is %d`, 1, HostFailuresToTolerateCapabilityMin, HostFailuresToTolerateCapabilityMax) } case ForceProvisioningCapability: if capabilityIntVal >= ForceProvisioningCapabilityMin && capabilityIntVal <= ForceProvisioningCapabilityMax { capabilityData = " (\"forceProvisioning\" i" + capabilityValue + ")" } else { - return "", fmt.Errorf(`Invalid value for forceProvisioning. - The value can be either %d or %d.`, + return "", fmt.Errorf(`invalid value for forceProvisioning. + The value can be either %d or %d`, ForceProvisioningCapabilityMin, ForceProvisioningCapabilityMax) } case CacheReservationCapability: if capabilityIntVal >= CacheReservationCapabilityMin && capabilityIntVal <= CacheReservationCapabilityMax { capabilityData = " (\"cacheReservation\" i" + strconv.Itoa(capabilityIntVal*10000) + ")" } else { - return "", fmt.Errorf(`Invalid value for cacheReservation. - The minimum percentage is %d and maximum percentage is %d.`, + return "", fmt.Errorf(`invalid value for cacheReservation. + The minimum percentage is %d and maximum percentage is %d`, CacheReservationCapabilityMin, CacheReservationCapabilityMax) } case DiskStripesCapability: if capabilityIntVal >= DiskStripesCapabilityMin && capabilityIntVal <= DiskStripesCapabilityMax { capabilityData = " (\"stripeWidth\" i" + capabilityValue + ")" } else { - return "", fmt.Errorf(`Invalid value for diskStripes. - The minimum value is %d and maximum value is %d.`, + return "", fmt.Errorf(`invalid value for diskStripes. + The minimum value is %d and maximum value is %d`, DiskStripesCapabilityMin, DiskStripesCapabilityMax) } case ObjectSpaceReservationCapability: if capabilityIntVal >= ObjectSpaceReservationCapabilityMin && capabilityIntVal <= ObjectSpaceReservationCapabilityMax { capabilityData = " (\"proportionalCapacity\" i" + capabilityValue + ")" } else { - return "", fmt.Errorf(`Invalid value for ObjectSpaceReservation. - The minimum percentage is %d and maximum percentage is %d.`, + return "", fmt.Errorf(`invalid value for ObjectSpaceReservation. + The minimum percentage is %d and maximum percentage is %d`, ObjectSpaceReservationCapabilityMin, ObjectSpaceReservationCapabilityMax) } case IopsLimitCapability: if capabilityIntVal >= IopsLimitCapabilityMin { capabilityData = " (\"iopsLimit\" i" + capabilityValue + ")" } else { - return "", fmt.Errorf(`Invalid value for iopsLimit. - The value should be greater than %d.`, IopsLimitCapabilityMin) + return "", fmt.Errorf(`invalid value for iopsLimit. + The value should be greater than %d`, IopsLimitCapabilityMin) } } return capabilityData, nil