Introduce a ResourceQuota object

This commit is contained in:
derekwaynecarr
2015-01-23 12:38:30 -05:00
parent c8f61885df
commit 829fa69527
35 changed files with 1692 additions and 23 deletions

View File

@@ -666,3 +666,28 @@ func ValidateLimitRange(limitRange *api.LimitRange) errs.ValidationErrorList {
}
return allErrs
}
// ValidateResourceQuota tests if required fields in the ResourceQuota are set.
func ValidateResourceQuota(resourceQuota *api.ResourceQuota) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
if len(resourceQuota.Name) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("name", resourceQuota.Name))
} else if !util.IsDNSSubdomain(resourceQuota.Name) {
allErrs = append(allErrs, errs.NewFieldInvalid("name", resourceQuota.Name, ""))
}
if len(resourceQuota.Namespace) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("namespace", resourceQuota.Namespace))
} else if !util.IsDNSSubdomain(resourceQuota.Namespace) {
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", resourceQuota.Namespace, ""))
}
for k := range resourceQuota.Spec.Hard {
allErrs = append(allErrs, ValidateResourceName(string(k))...)
}
for k := range resourceQuota.Status.Hard {
allErrs = append(allErrs, ValidateResourceName(string(k))...)
}
for k := range resourceQuota.Status.Used {
allErrs = append(allErrs, ValidateResourceName(string(k))...)
}
return allErrs
}