forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validation.go
31 lines (27 loc) · 1.44 KB
/
validation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package validation
import (
unversionedvalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"github.com/openshift/origin/pkg/project/admission/requestlimit/api"
)
func ValidateProjectRequestLimitConfig(config *api.ProjectRequestLimitConfig) field.ErrorList {
allErrs := field.ErrorList{}
for i, projectLimit := range config.Limits {
allErrs = append(allErrs, ValidateProjectLimitBySelector(projectLimit, field.NewPath("limits").Index(i))...)
}
if config.MaxProjectsForSystemUsers != nil && *config.MaxProjectsForSystemUsers < 0 {
allErrs = append(allErrs, field.Invalid(field.NewPath("maxProjectsForSystemUsers"), *config.MaxProjectsForSystemUsers, "cannot be a negative number"))
}
if config.MaxProjectsForServiceAccounts != nil && *config.MaxProjectsForServiceAccounts < 0 {
allErrs = append(allErrs, field.Invalid(field.NewPath("maxProjectsForServiceAccounts"), *config.MaxProjectsForServiceAccounts, "cannot be a negative number"))
}
return allErrs
}
func ValidateProjectLimitBySelector(limit api.ProjectLimitBySelector, path *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
allErrs = append(allErrs, unversionedvalidation.ValidateLabels(limit.Selector, path.Child("selector"))...)
if limit.MaxProjects != nil && *limit.MaxProjects < 0 {
allErrs = append(allErrs, field.Invalid(path.Child("maxProjects"), *limit.MaxProjects, "cannot be a negative number"))
}
return allErrs
}