diff --git a/pkg/apis/apps/v1/conversion.go b/pkg/apis/apps/v1/conversion.go index 34f6078b467..8aa43f9f490 100644 --- a/pkg/apis/apps/v1/conversion.go +++ b/pkg/apis/apps/v1/conversion.go @@ -174,7 +174,7 @@ func Convert_v1_Deployment_To_apps_Deployment(in *appsv1.Deployment, out *apps.D // Copy annotation to deprecated rollbackTo field for roundtrip // TODO: remove this conversion after we delete extensions/v1beta1 and apps/v1beta1 Deployment - if revision, _ := in.Annotations[appsv1.DeprecatedRollbackTo]; revision != "" { + if revision := in.Annotations[appsv1.DeprecatedRollbackTo]; revision != "" { if revision64, err := strconv.ParseInt(revision, 10, 64); err != nil { return fmt.Errorf("failed to parse annotation[%s]=%s as int64: %v", appsv1.DeprecatedRollbackTo, revision, err) } else { diff --git a/pkg/apis/apps/v1beta2/conversion.go b/pkg/apis/apps/v1beta2/conversion.go index 8d0e753a35c..327b61292e0 100644 --- a/pkg/apis/apps/v1beta2/conversion.go +++ b/pkg/apis/apps/v1beta2/conversion.go @@ -407,7 +407,7 @@ func Convert_v1beta2_Deployment_To_apps_Deployment(in *appsv1beta2.Deployment, o // Copy annotation to deprecated rollbackTo field for roundtrip // TODO: remove this conversion after we delete extensions/v1beta1 and apps/v1beta1 Deployment - if revision, _ := in.Annotations[appsv1beta2.DeprecatedRollbackTo]; revision != "" { + if revision := in.Annotations[appsv1beta2.DeprecatedRollbackTo]; revision != "" { if revision64, err := strconv.ParseInt(revision, 10, 64); err != nil { return fmt.Errorf("failed to parse annotation[%s]=%s as int64: %v", appsv1beta2.DeprecatedRollbackTo, revision, err) } else { diff --git a/pkg/apis/autoscaling/v1/conversion.go b/pkg/apis/autoscaling/v1/conversion.go index f68ac8c286b..a62a3339475 100644 --- a/pkg/apis/autoscaling/v1/conversion.go +++ b/pkg/apis/autoscaling/v1/conversion.go @@ -150,8 +150,7 @@ func Convert_autoscaling_PodsMetricSource_To_v1_PodsMetricSource(in *autoscaling } func Convert_v1_PodsMetricSource_To_autoscaling_PodsMetricSource(in *autoscalingv1.PodsMetricSource, out *autoscaling.PodsMetricSource, s conversion.Scope) error { - var metricType autoscaling.MetricTargetType - metricType = autoscaling.AverageValueMetricType + metricType := autoscaling.AverageValueMetricType out.Target = autoscaling.MetricTarget{ Type: metricType, @@ -327,10 +326,8 @@ func Convert_autoscaling_HorizontalPodAutoscaler_To_v1_HorizontalPodAutoscaler(i if len(otherMetrics) > 0 || len(in.Status.CurrentMetrics) > 0 || len(currentConditions) > 0 { old := out.Annotations out.Annotations = make(map[string]string, len(old)+3) - if old != nil { - for k, v := range old { - out.Annotations[k] = v - } + for k, v := range old { + out.Annotations[k] = v } } diff --git a/pkg/apis/autoscaling/v2beta1/conversion.go b/pkg/apis/autoscaling/v2beta1/conversion.go index 142cf726493..1f6378670dc 100644 --- a/pkg/apis/autoscaling/v2beta1/conversion.go +++ b/pkg/apis/autoscaling/v2beta1/conversion.go @@ -198,8 +198,7 @@ func Convert_autoscaling_PodsMetricSource_To_v2beta1_PodsMetricSource(in *autosc func Convert_v2beta1_PodsMetricSource_To_autoscaling_PodsMetricSource(in *autoscalingv2beta1.PodsMetricSource, out *autoscaling.PodsMetricSource, s conversion.Scope) error { targetAverageValue := &in.TargetAverageValue - var metricType autoscaling.MetricTargetType - metricType = autoscaling.AverageValueMetricType + metricType := autoscaling.AverageValueMetricType out.Target = autoscaling.MetricTarget{ Type: metricType, diff --git a/pkg/apis/core/validation/validation.go b/pkg/apis/core/validation/validation.go index 89940c52a3a..d2e08d0cd01 100644 --- a/pkg/apis/core/validation/validation.go +++ b/pkg/apis/core/validation/validation.go @@ -1770,8 +1770,7 @@ func ValidatePersistentVolume(pv *core.PersistentVolume) field.ErrorList { // ValidatePersistentVolumeUpdate tests to see if the update is legal for an end user to make. // newPv is updated with fields that cannot be changed. func ValidatePersistentVolumeUpdate(newPv, oldPv *core.PersistentVolume) field.ErrorList { - allErrs := field.ErrorList{} - allErrs = ValidatePersistentVolume(newPv) + allErrs := ValidatePersistentVolume(newPv) // PersistentVolumeSource should be immutable after creation. if !apiequality.Semantic.DeepEqual(newPv.Spec.PersistentVolumeSource, oldPv.Spec.PersistentVolumeSource) { @@ -2293,46 +2292,44 @@ func ValidateVolumeDevices(devices []core.VolumeDevice, volmounts map[string]str devicepath := sets.NewString() devicename := sets.NewString() - if devices != nil { - for i, dev := range devices { - idxPath := fldPath.Index(i) - devName := dev.Name - devPath := dev.DevicePath - didMatch, isPVC := isMatchedDevice(devName, volumes) - if len(devName) == 0 { - allErrs = append(allErrs, field.Required(idxPath.Child("name"), "")) - } - if devicename.Has(devName) { - allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must be unique")) - } - // Must be PersistentVolumeClaim volume source - if didMatch && !isPVC { - allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "can only use volume source type of PersistentVolumeClaim for block mode")) - } - if !didMatch { - allErrs = append(allErrs, field.NotFound(idxPath.Child("name"), devName)) - } - if len(devPath) == 0 { - allErrs = append(allErrs, field.Required(idxPath.Child("devicePath"), "")) - } - if devicepath.Has(devPath) { - allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must be unique")) - } - if len(devPath) > 0 && len(validatePathNoBacksteps(devPath, fldPath.Child("devicePath"))) > 0 { - allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "can not contain backsteps ('..')")) - } else { - devicepath.Insert(devPath) - } - // check for overlap with VolumeMount - if deviceNameAlreadyExists(devName, volmounts) { - allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must not already exist in volumeMounts")) - } - if devicePathAlreadyExists(devPath, volmounts) { - allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must not already exist as a path in volumeMounts")) - } - if len(devName) > 0 { - devicename.Insert(devName) - } + for i, dev := range devices { + idxPath := fldPath.Index(i) + devName := dev.Name + devPath := dev.DevicePath + didMatch, isPVC := isMatchedDevice(devName, volumes) + if len(devName) == 0 { + allErrs = append(allErrs, field.Required(idxPath.Child("name"), "")) + } + if devicename.Has(devName) { + allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must be unique")) + } + // Must be PersistentVolumeClaim volume source + if didMatch && !isPVC { + allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "can only use volume source type of PersistentVolumeClaim for block mode")) + } + if !didMatch { + allErrs = append(allErrs, field.NotFound(idxPath.Child("name"), devName)) + } + if len(devPath) == 0 { + allErrs = append(allErrs, field.Required(idxPath.Child("devicePath"), "")) + } + if devicepath.Has(devPath) { + allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must be unique")) + } + if len(devPath) > 0 && len(validatePathNoBacksteps(devPath, fldPath.Child("devicePath"))) > 0 { + allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "can not contain backsteps ('..')")) + } else { + devicepath.Insert(devPath) + } + // check for overlap with VolumeMount + if deviceNameAlreadyExists(devName, volmounts) { + allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must not already exist in volumeMounts")) + } + if devicePathAlreadyExists(devPath, volmounts) { + allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must not already exist as a path in volumeMounts")) + } + if len(devName) > 0 { + devicename.Insert(devName) } } return allErrs @@ -3186,7 +3183,7 @@ func validatePreferAvoidPodsEntry(avoidPodEntry core.PreferAvoidPodsEntry, fldPa if avoidPodEntry.PodSignature.PodController == nil { allErrors = append(allErrors, field.Required(fldPath.Child("PodSignature"), "")) } else { - if *(avoidPodEntry.PodSignature.PodController.Controller) != true { + if !*(avoidPodEntry.PodSignature.PodController.Controller) { allErrors = append(allErrors, field.Invalid(fldPath.Child("PodSignature").Child("PodController").Child("Controller"), *(avoidPodEntry.PodSignature.PodController.Controller), "must point to a controller")) diff --git a/pkg/apis/storage/validation/validation.go b/pkg/apis/storage/validation/validation.go index 518e04a9de3..4100627d4a5 100644 --- a/pkg/apis/storage/validation/validation.go +++ b/pkg/apis/storage/validation/validation.go @@ -247,7 +247,7 @@ func validateVolumeBindingMode(mode *storage.VolumeBindingMode, fldPath *field.P func validateAllowedTopologies(topologies []api.TopologySelectorTerm, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} - if topologies == nil || len(topologies) == 0 { + if len(topologies) == 0 { return allErrs }