Merge pull request #92462 from Haleygo/vspherevolume-staticcheck

fix pkg/volume/vspherevolume static check
This commit is contained in:
Kubernetes Prow Robot 2020-06-29 18:34:49 -07:00 committed by GitHub
commit c664611f5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 23 deletions

View File

@ -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

View File

@ -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)
}
}
}

View File

@ -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 {

View File

@ -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)

View File

@ -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