Add Validators for Scale Objects

This commit introduces a validator for use with Scale updates.
The validator checks that we have > 0 replica count, as well
as the normal ObjectMeta checks (some of which have to be
faked since they don't exist on the Scale object).
This commit is contained in:
Solly Ross
2015-11-02 13:50:43 -05:00
parent fd03c2c1d7
commit e5ef9e1406
4 changed files with 89 additions and 0 deletions

View File

@@ -564,3 +564,14 @@ func ValidatePodSelectorRequirement(sr extensions.PodSelectorRequirement) errs.V
allErrs = append(allErrs, apivalidation.ValidateLabelName(sr.Key, "key")...)
return allErrs
}
func ValidateScale(scale *extensions.Scale) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&scale.ObjectMeta, true, apivalidation.NameIsDNSSubdomain).Prefix("metadata")...)
if scale.Spec.Replicas < 0 {
allErrs = append(allErrs, errs.NewFieldInvalid("spec.replicas", scale.Spec.Replicas, "must be non-negative"))
}
return allErrs
}