mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Clean up pkg/apis.
These are based on recommendation from [staticcheck](http://staticcheck.io/).
This commit is contained in:
parent
524169fe1c
commit
25df4e69a5
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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,12 +326,10 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(otherMetrics) > 0 {
|
||||
otherMetricsEnc, err := json.Marshal(otherMetrics)
|
||||
|
@ -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,
|
||||
|
@ -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,7 +2292,6 @@ 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
|
||||
@ -2334,7 +2332,6 @@ func ValidateVolumeDevices(devices []core.VolumeDevice, volmounts map[string]str
|
||||
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"))
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user