forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.go
60 lines (55 loc) · 2 KB
/
init.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
package admission
import (
"k8s.io/kubernetes/pkg/admission"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/quota"
"github.com/openshift/origin/pkg/authorization/authorizer"
"github.com/openshift/origin/pkg/client"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
"github.com/openshift/origin/pkg/project/cache"
)
type PluginInitializer struct {
OpenshiftClient client.Interface
ProjectCache *cache.ProjectCache
OriginQuotaRegistry quota.Registry
Authorizer authorizer.Authorizer
JenkinsPipelineConfig configapi.JenkinsPipelineConfig
RESTClientConfig restclient.Config
}
// Initialize will check the initialization interfaces implemented by each plugin
// and provide the appropriate initialization data
func (i *PluginInitializer) Initialize(plugins []admission.Interface) {
for _, plugin := range plugins {
if wantsOpenshiftClient, ok := plugin.(WantsOpenshiftClient); ok {
wantsOpenshiftClient.SetOpenshiftClient(i.OpenshiftClient)
}
if wantsProjectCache, ok := plugin.(WantsProjectCache); ok {
wantsProjectCache.SetProjectCache(i.ProjectCache)
}
if wantsOriginQuotaRegistry, ok := plugin.(WantsOriginQuotaRegistry); ok {
wantsOriginQuotaRegistry.SetOriginQuotaRegistry(i.OriginQuotaRegistry)
}
if wantsAuthorizer, ok := plugin.(WantsAuthorizer); ok {
wantsAuthorizer.SetAuthorizer(i.Authorizer)
}
if wantsJenkinsPipelineConfig, ok := plugin.(WantsJenkinsPipelineConfig); ok {
wantsJenkinsPipelineConfig.SetJenkinsPipelineConfig(i.JenkinsPipelineConfig)
}
if wantsRESTClientConfig, ok := plugin.(WantsRESTClientConfig); ok {
wantsRESTClientConfig.SetRESTClientConfig(i.RESTClientConfig)
}
}
}
// Validate will call the Validate function in each plugin if they implement
// the Validator interface.
func Validate(plugins []admission.Interface) error {
for _, plugin := range plugins {
if validater, ok := plugin.(Validator); ok {
err := validater.Validate()
if err != nil {
return err
}
}
}
return nil
}