Merge pull request #77671 from bjhaid/cleanup_pkg_apis

Clean up pkg/apis.
This commit is contained in:
Kubernetes Prow Robot 2019-05-09 15:48:35 -07:00 committed by GitHub
commit 88eea7e2ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 54 deletions

View File

@ -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 // Copy annotation to deprecated rollbackTo field for roundtrip
// TODO: remove this conversion after we delete extensions/v1beta1 and apps/v1beta1 Deployment // 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 { 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) return fmt.Errorf("failed to parse annotation[%s]=%s as int64: %v", appsv1.DeprecatedRollbackTo, revision, err)
} else { } else {

View File

@ -407,7 +407,7 @@ func Convert_v1beta2_Deployment_To_apps_Deployment(in *appsv1beta2.Deployment, o
// Copy annotation to deprecated rollbackTo field for roundtrip // Copy annotation to deprecated rollbackTo field for roundtrip
// TODO: remove this conversion after we delete extensions/v1beta1 and apps/v1beta1 Deployment // 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 { 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) return fmt.Errorf("failed to parse annotation[%s]=%s as int64: %v", appsv1beta2.DeprecatedRollbackTo, revision, err)
} else { } else {

View File

@ -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 { 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{ out.Target = autoscaling.MetricTarget{
Type: metricType, 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 { if len(otherMetrics) > 0 || len(in.Status.CurrentMetrics) > 0 || len(currentConditions) > 0 {
old := out.Annotations old := out.Annotations
out.Annotations = make(map[string]string, len(old)+3) out.Annotations = make(map[string]string, len(old)+3)
if old != nil { for k, v := range old {
for k, v := range old { out.Annotations[k] = v
out.Annotations[k] = v
}
} }
} }

View File

@ -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 { func Convert_v2beta1_PodsMetricSource_To_autoscaling_PodsMetricSource(in *autoscalingv2beta1.PodsMetricSource, out *autoscaling.PodsMetricSource, s conversion.Scope) error {
targetAverageValue := &in.TargetAverageValue targetAverageValue := &in.TargetAverageValue
var metricType autoscaling.MetricTargetType metricType := autoscaling.AverageValueMetricType
metricType = autoscaling.AverageValueMetricType
out.Target = autoscaling.MetricTarget{ out.Target = autoscaling.MetricTarget{
Type: metricType, Type: metricType,

View File

@ -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. // ValidatePersistentVolumeUpdate tests to see if the update is legal for an end user to make.
// newPv is updated with fields that cannot be changed. // newPv is updated with fields that cannot be changed.
func ValidatePersistentVolumeUpdate(newPv, oldPv *core.PersistentVolume) field.ErrorList { func ValidatePersistentVolumeUpdate(newPv, oldPv *core.PersistentVolume) field.ErrorList {
allErrs := field.ErrorList{} allErrs := ValidatePersistentVolume(newPv)
allErrs = ValidatePersistentVolume(newPv)
// PersistentVolumeSource should be immutable after creation. // PersistentVolumeSource should be immutable after creation.
if !apiequality.Semantic.DeepEqual(newPv.Spec.PersistentVolumeSource, oldPv.Spec.PersistentVolumeSource) { 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() devicepath := sets.NewString()
devicename := sets.NewString() devicename := sets.NewString()
if devices != nil { for i, dev := range devices {
for i, dev := range devices { idxPath := fldPath.Index(i)
idxPath := fldPath.Index(i) devName := dev.Name
devName := dev.Name devPath := dev.DevicePath
devPath := dev.DevicePath didMatch, isPVC := isMatchedDevice(devName, volumes)
didMatch, isPVC := isMatchedDevice(devName, volumes) if len(devName) == 0 {
if len(devName) == 0 { allErrs = append(allErrs, field.Required(idxPath.Child("name"), ""))
allErrs = append(allErrs, field.Required(idxPath.Child("name"), "")) }
} if devicename.Has(devName) {
if devicename.Has(devName) { allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must be unique"))
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must be unique")) }
} // Must be PersistentVolumeClaim volume source
// Must be PersistentVolumeClaim volume source if didMatch && !isPVC {
if didMatch && !isPVC { allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "can only use volume source type of PersistentVolumeClaim for block mode"))
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "can only use volume source type of PersistentVolumeClaim for block mode")) }
} if !didMatch {
if !didMatch { allErrs = append(allErrs, field.NotFound(idxPath.Child("name"), devName))
allErrs = append(allErrs, field.NotFound(idxPath.Child("name"), devName)) }
} if len(devPath) == 0 {
if len(devPath) == 0 { allErrs = append(allErrs, field.Required(idxPath.Child("devicePath"), ""))
allErrs = append(allErrs, field.Required(idxPath.Child("devicePath"), "")) }
} if devicepath.Has(devPath) {
if devicepath.Has(devPath) { allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must be unique"))
allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must be unique")) }
} if len(devPath) > 0 && len(validatePathNoBacksteps(devPath, fldPath.Child("devicePath"))) > 0 {
if len(devPath) > 0 && len(validatePathNoBacksteps(devPath, fldPath.Child("devicePath"))) > 0 { allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "can not contain backsteps ('..')"))
allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "can not contain backsteps ('..')")) } else {
} else { devicepath.Insert(devPath)
devicepath.Insert(devPath) }
} // check for overlap with VolumeMount
// check for overlap with VolumeMount if deviceNameAlreadyExists(devName, volmounts) {
if deviceNameAlreadyExists(devName, volmounts) { allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must not already exist in volumeMounts"))
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), devName, "must not already exist in volumeMounts")) }
} if devicePathAlreadyExists(devPath, volmounts) {
if devicePathAlreadyExists(devPath, volmounts) { allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must not already exist as a path in volumeMounts"))
allErrs = append(allErrs, field.Invalid(idxPath.Child("devicePath"), devPath, "must not already exist as a path in volumeMounts")) }
} if len(devName) > 0 {
if len(devName) > 0 { devicename.Insert(devName)
devicename.Insert(devName)
}
} }
} }
return allErrs return allErrs
@ -3186,7 +3183,7 @@ func validatePreferAvoidPodsEntry(avoidPodEntry core.PreferAvoidPodsEntry, fldPa
if avoidPodEntry.PodSignature.PodController == nil { if avoidPodEntry.PodSignature.PodController == nil {
allErrors = append(allErrors, field.Required(fldPath.Child("PodSignature"), "")) allErrors = append(allErrors, field.Required(fldPath.Child("PodSignature"), ""))
} else { } else {
if *(avoidPodEntry.PodSignature.PodController.Controller) != true { if !*(avoidPodEntry.PodSignature.PodController.Controller) {
allErrors = append(allErrors, allErrors = append(allErrors,
field.Invalid(fldPath.Child("PodSignature").Child("PodController").Child("Controller"), field.Invalid(fldPath.Child("PodSignature").Child("PodController").Child("Controller"),
*(avoidPodEntry.PodSignature.PodController.Controller), "must point to a controller")) *(avoidPodEntry.PodSignature.PodController.Controller), "must point to a controller"))

View File

@ -247,7 +247,7 @@ func validateVolumeBindingMode(mode *storage.VolumeBindingMode, fldPath *field.P
func validateAllowedTopologies(topologies []api.TopologySelectorTerm, fldPath *field.Path) field.ErrorList { func validateAllowedTopologies(topologies []api.TopologySelectorTerm, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
if topologies == nil || len(topologies) == 0 { if len(topologies) == 0 {
return allErrs return allErrs
} }