forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validation.go
30 lines (26 loc) · 1.29 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
package validation
import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kubernetes/pkg/api/validation"
"github.com/openshift/origin/pkg/build/admission/defaults/api"
buildvalidation "github.com/openshift/origin/pkg/build/api/validation"
)
// ValidateBuildDefaultsConfig tests required fields for a Build.
func ValidateBuildDefaultsConfig(config *api.BuildDefaultsConfig) field.ErrorList {
allErrs := field.ErrorList{}
allErrs = append(allErrs, validateURL(config.GitHTTPProxy, field.NewPath("gitHTTPProxy"))...)
allErrs = append(allErrs, validateURL(config.GitHTTPSProxy, field.NewPath("gitHTTPSProxy"))...)
allErrs = append(allErrs, buildvalidation.ValidateStrategyEnv(config.Env, field.NewPath("env"))...)
allErrs = append(allErrs, buildvalidation.ValidateImageLabels(config.ImageLabels, field.NewPath("imageLabels"))...)
allErrs = append(allErrs, buildvalidation.ValidateNodeSelector(config.NodeSelector, field.NewPath("nodeSelector"))...)
allErrs = append(allErrs, validation.ValidateAnnotations(config.Annotations, field.NewPath("annotations"))...)
return allErrs
}
//
func validateURL(u string, path *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if !buildvalidation.IsValidURL(u) {
allErrs = append(allErrs, field.Invalid(path, u, "invalid URL"))
}
return allErrs
}