Skip to content

Commit 25df4e6

Browse files
committed
Clean up pkg/apis.
These are based on recommendation from [staticcheck](http://staticcheck.io/).
1 parent 524169f commit 25df4e6

File tree

6 files changed

+47
-54
lines changed

6 files changed

+47
-54
lines changed

pkg/apis/apps/v1/conversion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func Convert_v1_Deployment_To_apps_Deployment(in *appsv1.Deployment, out *apps.D
174174

175175
// Copy annotation to deprecated rollbackTo field for roundtrip
176176
// TODO: remove this conversion after we delete extensions/v1beta1 and apps/v1beta1 Deployment
177-
if revision, _ := in.Annotations[appsv1.DeprecatedRollbackTo]; revision != "" {
177+
if revision := in.Annotations[appsv1.DeprecatedRollbackTo]; revision != "" {
178178
if revision64, err := strconv.ParseInt(revision, 10, 64); err != nil {
179179
return fmt.Errorf("failed to parse annotation[%s]=%s as int64: %v", appsv1.DeprecatedRollbackTo, revision, err)
180180
} else {

pkg/apis/apps/v1beta2/conversion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func Convert_v1beta2_Deployment_To_apps_Deployment(in *appsv1beta2.Deployment, o
407407

408408
// Copy annotation to deprecated rollbackTo field for roundtrip
409409
// TODO: remove this conversion after we delete extensions/v1beta1 and apps/v1beta1 Deployment
410-
if revision, _ := in.Annotations[appsv1beta2.DeprecatedRollbackTo]; revision != "" {
410+
if revision := in.Annotations[appsv1beta2.DeprecatedRollbackTo]; revision != "" {
411411
if revision64, err := strconv.ParseInt(revision, 10, 64); err != nil {
412412
return fmt.Errorf("failed to parse annotation[%s]=%s as int64: %v", appsv1beta2.DeprecatedRollbackTo, revision, err)
413413
} else {

pkg/apis/autoscaling/v1/conversion.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ func Convert_autoscaling_PodsMetricSource_To_v1_PodsMetricSource(in *autoscaling
150150
}
151151

152152
func Convert_v1_PodsMetricSource_To_autoscaling_PodsMetricSource(in *autoscalingv1.PodsMetricSource, out *autoscaling.PodsMetricSource, s conversion.Scope) error {
153-
var metricType autoscaling.MetricTargetType
154-
metricType = autoscaling.AverageValueMetricType
153+
metricType := autoscaling.AverageValueMetricType
155154

156155
out.Target = autoscaling.MetricTarget{
157156
Type: metricType,
@@ -327,10 +326,8 @@ func Convert_autoscaling_HorizontalPodAutoscaler_To_v1_HorizontalPodAutoscaler(i
327326
if len(otherMetrics) > 0 || len(in.Status.CurrentMetrics) > 0 || len(currentConditions) > 0 {
328327
old := out.Annotations
329328
out.Annotations = make(map[string]string, len(old)+3)
330-
if old != nil {
331-
for k, v := range old {
332-
out.Annotations[k] = v
333-
}
329+
for k, v := range old {
330+
out.Annotations[k] = v
334331
}
335332
}
336333

pkg/apis/autoscaling/v2beta1/conversion.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ func Convert_autoscaling_PodsMetricSource_To_v2beta1_PodsMetricSource(in *autosc
198198

199199
func Convert_v2beta1_PodsMetricSource_To_autoscaling_PodsMetricSource(in *autoscalingv2beta1.PodsMetricSource, out *autoscaling.PodsMetricSource, s conversion.Scope) error {
200200
targetAverageValue := &in.TargetAverageValue
201-
var metricType autoscaling.MetricTargetType
202-
metricType = autoscaling.AverageValueMetricType
201+
metricType := autoscaling.AverageValueMetricType
203202

204203
out.Target = autoscaling.MetricTarget{
205204
Type: metricType,

pkg/apis/core/validation/validation.go

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,8 +1770,7 @@ func ValidatePersistentVolume(pv *core.PersistentVolume) field.ErrorList {
17701770
// ValidatePersistentVolumeUpdate tests to see if the update is legal for an end user to make.
17711771
// newPv is updated with fields that cannot be changed.
17721772
func ValidatePersistentVolumeUpdate(newPv, oldPv *core.PersistentVolume) field.ErrorList {
1773-
allErrs := field.ErrorList{}
1774-
allErrs = ValidatePersistentVolume(newPv)
1773+
allErrs := ValidatePersistentVolume(newPv)
17751774

17761775
// PersistentVolumeSource should be immutable after creation.
17771776
if !apiequality.Semantic.DeepEqual(newPv.Spec.PersistentVolumeSource, oldPv.Spec.PersistentVolumeSource) {
@@ -2293,46 +2292,44 @@ func ValidateVolumeDevices(devices []core.VolumeDevice, volmounts map[string]str
22932292
devicepath := sets.NewString()
22942293
devicename := sets.NewString()
22952294

2296-
if devices != nil {
2297-
for i, dev := range devices {
2298-
idxPath := fldPath.Index(i)
2299-
devName := dev.Name
2300-
devPath := dev.DevicePath
2301-
didMatch, isPVC := isMatchedDevice(devName, volumes)
2302-
if len(devName) == 0 {
2303-
allErrs = append(allErrs, field.Required(idxPath.Child("name"), ""))
2304-
}
2305-
if devicename.Has(devName) {
2306-
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must be unique"))
2307-
}
2308-
// Must be PersistentVolumeClaim volume source
2309-
if didMatch && !isPVC {
2310-
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "can only use volume source type of PersistentVolumeClaim for block mode"))
2311-
}
2312-
if !didMatch {
2313-
allErrs = append(allErrs, field.NotFound(idxPath.Child("name"), devName))
2314-
}
2315-
if len(devPath) == 0 {
2316-
allErrs = append(allErrs, field.Required(idxPath.Child("devicePath"), ""))
2317-
}
2318-
if devicepath.Has(devPath) {
2319-
allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must be unique"))
2320-
}
2321-
if len(devPath) > 0 && len(validatePathNoBacksteps(devPath, fldPath.Child("devicePath"))) > 0 {
2322-
allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "can not contain backsteps ('..')"))
2323-
} else {
2324-
devicepath.Insert(devPath)
2325-
}
2326-
// check for overlap with VolumeMount
2327-
if deviceNameAlreadyExists(devName, volmounts) {
2328-
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must not already exist in volumeMounts"))
2329-
}
2330-
if devicePathAlreadyExists(devPath, volmounts) {
2331-
allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must not already exist as a path in volumeMounts"))
2332-
}
2333-
if len(devName) > 0 {
2334-
devicename.Insert(devName)
2335-
}
2295+
for i, dev := range devices {
2296+
idxPath := fldPath.Index(i)
2297+
devName := dev.Name
2298+
devPath := dev.DevicePath
2299+
didMatch, isPVC := isMatchedDevice(devName, volumes)
2300+
if len(devName) == 0 {
2301+
allErrs = append(allErrs, field.Required(idxPath.Child("name"), ""))
2302+
}
2303+
if devicename.Has(devName) {
2304+
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must be unique"))
2305+
}
2306+
// Must be PersistentVolumeClaim volume source
2307+
if didMatch && !isPVC {
2308+
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "can only use volume source type of PersistentVolumeClaim for block mode"))
2309+
}
2310+
if !didMatch {
2311+
allErrs = append(allErrs, field.NotFound(idxPath.Child("name"), devName))
2312+
}
2313+
if len(devPath) == 0 {
2314+
allErrs = append(allErrs, field.Required(idxPath.Child("devicePath"), ""))
2315+
}
2316+
if devicepath.Has(devPath) {
2317+
allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must be unique"))
2318+
}
2319+
if len(devPath) > 0 && len(validatePathNoBacksteps(devPath, fldPath.Child("devicePath"))) > 0 {
2320+
allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "can not contain backsteps ('..')"))
2321+
} else {
2322+
devicepath.Insert(devPath)
2323+
}
2324+
// check for overlap with VolumeMount
2325+
if deviceNameAlreadyExists(devName, volmounts) {
2326+
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must not already exist in volumeMounts"))
2327+
}
2328+
if devicePathAlreadyExists(devPath, volmounts) {
2329+
allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must not already exist as a path in volumeMounts"))
2330+
}
2331+
if len(devName) > 0 {
2332+
devicename.Insert(devName)
23362333
}
23372334
}
23382335
return allErrs
@@ -3186,7 +3183,7 @@ func validatePreferAvoidPodsEntry(avoidPodEntry core.PreferAvoidPodsEntry, fldPa
31863183
if avoidPodEntry.PodSignature.PodController == nil {
31873184
allErrors = append(allErrors, field.Required(fldPath.Child("PodSignature"), ""))
31883185
} else {
3189-
if *(avoidPodEntry.PodSignature.PodController.Controller) != true {
3186+
if !*(avoidPodEntry.PodSignature.PodController.Controller) {
31903187
allErrors = append(allErrors,
31913188
field.Invalid(fldPath.Child("PodSignature").Child("PodController").Child("Controller"),
31923189
*(avoidPodEntry.PodSignature.PodController.Controller), "must point to a controller"))

pkg/apis/storage/validation/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func validateVolumeBindingMode(mode *storage.VolumeBindingMode, fldPath *field.P
247247
func validateAllowedTopologies(topologies []api.TopologySelectorTerm, fldPath *field.Path) field.ErrorList {
248248
allErrs := field.ErrorList{}
249249

250-
if topologies == nil || len(topologies) == 0 {
250+
if len(topologies) == 0 {
251251
return allErrs
252252
}
253253

0 commit comments

Comments
 (0)