-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.go
77 lines (69 loc) · 2.49 KB
/
validate.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
package util
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"
)
type fakeServiceLister struct{}
func (f *fakeServiceLister) ListServices(kapi.Context) (*kapi.ServiceList, error) {
return &kapi.ServiceList{}, nil
}
// ValidateObject validates the runtime.Object 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 *imageapi.Image:
errors = imagev.ValidateImage(t)
case *imageapi.ImageRepository:
errors = imagev.ValidateImageRepository(t)
case *imageapi.ImageRepositoryMapping:
errors = imagev.ValidateImageRepositoryMapping(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)
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
}