forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.go
85 lines (80 loc) · 3.28 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
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
package admission
import (
"k8s.io/apiserver/pkg/admission"
kauthorizer "k8s.io/apiserver/pkg/authorization/authorizer"
restclient "k8s.io/client-go/rest"
kubeapiserveradmission "k8s.io/kubernetes/pkg/kubeapiserver/admission"
"k8s.io/kubernetes/pkg/quota"
"github.com/openshift/origin/pkg/client"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
"github.com/openshift/origin/pkg/controller/shared"
imageapi "github.com/openshift/origin/pkg/image/api"
"github.com/openshift/origin/pkg/project/cache"
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
usercache "github.com/openshift/origin/pkg/user/cache"
)
type PluginInitializer struct {
OpenshiftClient client.Interface
ProjectCache *cache.ProjectCache
OriginQuotaRegistry quota.Registry
Authorizer kauthorizer.Authorizer
JenkinsPipelineConfig configapi.JenkinsPipelineConfig
RESTClientConfig restclient.Config
Informers shared.InformerFactory
ClusterQuotaMapper clusterquotamapping.ClusterQuotaMapper
DefaultRegistryFn imageapi.DefaultRegistryFunc
GroupCache *usercache.GroupCache
}
// Initialize will check the initialization interfaces implemented by each plugin
// and provide the appropriate initialization data
func (i *PluginInitializer) Initialize(plugin admission.Interface) {
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 kubeWantsAuthorizer, ok := plugin.(kubeapiserveradmission.WantsAuthorizer); ok {
kubeWantsAuthorizer.SetAuthorizer(i.Authorizer)
}
if wantsJenkinsPipelineConfig, ok := plugin.(WantsJenkinsPipelineConfig); ok {
wantsJenkinsPipelineConfig.SetJenkinsPipelineConfig(i.JenkinsPipelineConfig)
}
if wantsRESTClientConfig, ok := plugin.(WantsRESTClientConfig); ok {
wantsRESTClientConfig.SetRESTClientConfig(i.RESTClientConfig)
}
if wantsInformers, ok := plugin.(WantsInformers); ok {
wantsInformers.SetInformers(i.Informers)
}
if wantsInformerFactory, ok := plugin.(kubeapiserveradmission.WantsInternalKubeInformerFactory); ok {
wantsInformerFactory.SetInternalKubeInformerFactory(i.Informers.InternalKubernetesInformers())
}
if wantsClusterQuotaMapper, ok := plugin.(WantsClusterQuotaMapper); ok {
wantsClusterQuotaMapper.SetClusterQuotaMapper(i.ClusterQuotaMapper)
}
if wantsDefaultRegistryFunc, ok := plugin.(WantsDefaultRegistryFunc); ok {
wantsDefaultRegistryFunc.SetDefaultRegistryFunc(i.DefaultRegistryFn)
}
if wantsGroupCache, ok := plugin.(WantsGroupCache); ok {
wantsGroupCache.SetGroupCache(i.GroupCache)
}
}
// 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.(admission.Validator); ok {
err := validater.Validate()
if err != nil {
return err
}
}
}
return nil
}