| ... | ... |
@@ -2,49 +2,52 @@ package validation |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"regexp" |
| 5 |
+ "strings" |
|
| 5 | 6 |
|
| 6 | 7 |
kubeapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 7 |
- . "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" |
|
| 8 |
- . "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation" |
|
| 8 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" |
|
| 9 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation" |
|
| 9 | 10 |
|
| 10 |
- . "github.com/openshift/origin/pkg/template/api" |
|
| 11 | 11 |
routeapi "github.com/openshift/origin/pkg/route/api" |
| 12 |
- . "github.com/openshift/origin/pkg/route/api/validation" |
|
| 12 |
+ routevalidation "github.com/openshift/origin/pkg/route/api/validation" |
|
| 13 |
+ "github.com/openshift/origin/pkg/template/api" |
|
| 13 | 14 |
) |
| 14 | 15 |
|
| 15 | 16 |
var parameterNameExp = regexp.MustCompile(`^[a-zA-Z0-9\_]+$`) |
| 16 | 17 |
|
| 17 | 18 |
// ValidateParameter tests if required fields in the Parameter are set. |
| 18 |
-func ValidateParameter(param *Parameter) (errs ErrorList) {
|
|
| 19 |
+func ValidateParameter(param *api.Parameter) (errs errors.ErrorList) {
|
|
| 19 | 20 |
if len(param.Name) == 0 {
|
| 20 |
- errs = append(errs, NewFieldRequired("name", ""))
|
|
| 21 |
+ errs = append(errs, errors.NewFieldRequired("name", ""))
|
|
| 21 | 22 |
return |
| 22 | 23 |
} |
| 23 | 24 |
if !parameterNameExp.MatchString(param.Name) {
|
| 24 |
- errs = append(errs, NewFieldInvalid("name", param.Name))
|
|
| 25 |
+ errs = append(errs, errors.NewFieldInvalid("name", param.Name))
|
|
| 25 | 26 |
} |
| 26 | 27 |
return |
| 27 | 28 |
} |
| 28 | 29 |
|
| 29 | 30 |
// ValidateTemplate tests if required fields in the Template are set. |
| 30 |
-func ValidateTemplate(template *Template) (errs ErrorList) {
|
|
| 31 |
+func ValidateTemplate(template *api.Template) (errs errors.ErrorList) {
|
|
| 31 | 32 |
if len(template.ID) == 0 {
|
| 32 |
- errs = append(errs, NewFieldRequired("id", template.ID))
|
|
| 33 |
+ errs = append(errs, errors.NewFieldRequired("id", template.ID))
|
|
| 33 | 34 |
} |
| 34 | 35 |
for i, item := range template.Items {
|
| 35 |
- err := ErrorList{}
|
|
| 36 |
+ err := errors.ErrorList{}
|
|
| 36 | 37 |
switch obj := item.Object.(type) {
|
| 37 | 38 |
case *kubeapi.ReplicationController: |
| 38 |
- err = ValidateReplicationController(obj) |
|
| 39 |
+ err = validation.ValidateReplicationController(obj) |
|
| 39 | 40 |
case *kubeapi.Pod: |
| 40 |
- err = ValidatePod(obj) |
|
| 41 |
+ err = validation.ValidatePod(obj) |
|
| 41 | 42 |
case *kubeapi.Service: |
| 42 |
- err = ValidateService(obj) |
|
| 43 |
- case *routeapi.Route: |
|
| 44 |
- err = ValidateRoute(obj) |
|
| 43 |
+ err = validation.ValidateService(obj) |
|
| 44 |
+ case *routeapi.Route: |
|
| 45 |
+ err = routevalidation.ValidateRoute(obj) |
|
| 45 | 46 |
default: |
| 46 | 47 |
// Pass-through unknown types. |
| 47 | 48 |
} |
| 49 |
+ // ignore namespace validation errors in templates |
|
| 50 |
+ err = filter(err, "namespace") |
|
| 48 | 51 |
errs = append(errs, err.PrefixIndex(i).Prefix("items")...)
|
| 49 | 52 |
} |
| 50 | 53 |
for i := range template.Parameters {
|
| ... | ... |
@@ -53,3 +56,18 @@ func ValidateTemplate(template *Template) (errs ErrorList) {
|
| 53 | 53 |
} |
| 54 | 54 |
return |
| 55 | 55 |
} |
| 56 |
+ |
|
| 57 |
+func filter(errs errors.ErrorList, prefix string) errors.ErrorList {
|
|
| 58 |
+ if errs == nil {
|
|
| 59 |
+ return errs |
|
| 60 |
+ } |
|
| 61 |
+ next := errors.ErrorList{}
|
|
| 62 |
+ for _, err := range errs {
|
|
| 63 |
+ ve, ok := err.(errors.ValidationError) |
|
| 64 |
+ if ok && strings.HasPrefix(ve.Field, prefix) {
|
|
| 65 |
+ continue |
|
| 66 |
+ } |
|
| 67 |
+ next = append(next, err) |
|
| 68 |
+ } |
|
| 69 |
+ return next |
|
| 70 |
+} |