forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.go
91 lines (85 loc) · 3.02 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package validation
import (
"fmt"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
buildapi "github.com/openshift/origin/pkg/build/api"
buildv "github.com/openshift/origin/pkg/build/api/validation"
deployapi "github.com/openshift/origin/pkg/deploy/api"
deployv "github.com/openshift/origin/pkg/deploy/api/validation"
imageapi "github.com/openshift/origin/pkg/image/api"
imagev "github.com/openshift/origin/pkg/image/api/validation"
projectapi "github.com/openshift/origin/pkg/project/api"
projectv "github.com/openshift/origin/pkg/project/api/validation"
routeapi "github.com/openshift/origin/pkg/route/api"
routev "github.com/openshift/origin/pkg/route/api/validation"
templateapi "github.com/openshift/origin/pkg/template/api"
templatev "github.com/openshift/origin/pkg/template/api/validation"
)
// ValidateObject runs all known validations and returns the validation errors
func ValidateObject(obj runtime.Object) (errors []error) {
if m, err := meta.Accessor(obj); err == nil {
if len(m.Namespace()) == 0 {
m.SetNamespace(kapi.NamespaceDefault)
}
}
switch t := obj.(type) {
case *kapi.ReplicationController:
errors = validation.ValidateReplicationController(t)
case *kapi.Service:
errors = validation.ValidateService(t)
case *kapi.Pod:
errors = validation.ValidatePod(t)
case *kapi.Namespace:
errors = validation.ValidateNamespace(t)
case *kapi.Node:
errors = validation.ValidateMinion(t)
case *imageapi.Image:
errors = imagev.ValidateImage(t)
case *imageapi.ImageRepository:
s := &imageapi.ImageStream{}
if err := kapi.Scheme.Convert(&t, &s); err != nil {
return []error{err}
}
return imagev.ValidateImageStream(s)
case *imageapi.ImageStream:
errors = imagev.ValidateImageStream(t)
case *imageapi.ImageRepositoryMapping:
m := &imageapi.ImageStreamMapping{}
if err := kapi.Scheme.Convert(&t, &m); err != nil {
return []error{err}
}
return imagev.ValidateImageStreamMapping(m)
case *imageapi.ImageStreamMapping:
errors = imagev.ValidateImageStreamMapping(t)
case *deployapi.DeploymentConfig:
errors = deployv.ValidateDeploymentConfig(t)
case *deployapi.Deployment:
errors = deployv.ValidateDeployment(t)
case *projectapi.Project:
// this is a global resource that should not have a namespace
t.Namespace = ""
errors = projectv.ValidateProject(t)
case *routeapi.Route:
errors = routev.ValidateRoute(t)
case *buildapi.BuildConfig:
errors = buildv.ValidateBuildConfig(t)
case *buildapi.Build:
errors = buildv.ValidateBuild(t)
case *templateapi.Template:
errors = templatev.ValidateTemplate(t)
default:
if list, err := runtime.ExtractList(obj); err == nil {
for i := range list {
errs := ValidateObject(list[i])
errors = append(errors, errs...)
}
return
}
// TODO: This should not be an error
return []error{fmt.Errorf("no validation defined for %#v", obj)}
}
return errors
}