Skip to content

Commit

Permalink
fix static check failed from pkg/volume/vspherevolume
Browse files Browse the repository at this point in the history
remove field from staticcheck_failures
  • Loading branch information
haleygo committed Jun 26, 2020
1 parent c90427d commit a5b7ce1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
1 change: 0 additions & 1 deletion hack/.staticcheck_failures
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/volume/vsphere_volume/attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/vsphere_volume/vsphere_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/volume/vsphere_volume/vsphere_volume_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 17 additions & 17 deletions pkg/volume/vsphere_volume/vsphere_volume_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down Expand Up @@ -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 + ")"
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit a5b7ce1

Please sign in to comment.