forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.go
117 lines (112 loc) · 5.86 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package admission
import (
"k8s.io/apiserver/pkg/admission"
kauthorizer "k8s.io/apiserver/pkg/authorization/authorizer"
restclient "k8s.io/client-go/rest"
kinternalinformers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
kubeapiserveradmission "k8s.io/kubernetes/pkg/kubeapiserver/admission"
"k8s.io/kubernetes/pkg/quota"
authorizationclient "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
imageapi "github.com/openshift/origin/pkg/image/apis/image"
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset"
"github.com/openshift/origin/pkg/project/cache"
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
quotainformer "github.com/openshift/origin/pkg/quota/generated/informers/internalversion/quota/internalversion"
quotaclient "github.com/openshift/origin/pkg/quota/generated/internalclientset"
securityinformer "github.com/openshift/origin/pkg/security/generated/informers/internalversion"
templateclient "github.com/openshift/origin/pkg/template/generated/internalclientset"
userinformer "github.com/openshift/origin/pkg/user/generated/informers/internalversion"
userclient "github.com/openshift/origin/pkg/user/generated/internalclientset"
)
type PluginInitializer struct {
OpenshiftInternalAuthorizationClient authorizationclient.Interface
OpenshiftInternalBuildClient buildclient.Interface
OpenshiftInternalImageClient imageclient.Interface
OpenshiftInternalQuotaClient quotaclient.Interface
OpenshiftInternalTemplateClient templateclient.Interface
OpenshiftInternalUserClient userclient.Interface
ProjectCache *cache.ProjectCache
OriginQuotaRegistry quota.Registry
Authorizer kauthorizer.Authorizer
JenkinsPipelineConfig configapi.JenkinsPipelineConfig
RESTClientConfig restclient.Config
Informers kinternalinformers.SharedInformerFactory
ClusterResourceQuotaInformer quotainformer.ClusterResourceQuotaInformer
ClusterQuotaMapper clusterquotamapping.ClusterQuotaMapper
RegistryHostnameRetriever imageapi.RegistryHostnameRetriever
SecurityInformers securityinformer.SharedInformerFactory
UserInformers userinformer.SharedInformerFactory
}
// Initialize will check the initialization interfaces implemented by each plugin
// and provide the appropriate initialization data
func (i *PluginInitializer) Initialize(plugin admission.Interface) {
if wantsOpenshiftAuthorizationClient, ok := plugin.(WantsOpenshiftInternalAuthorizationClient); ok {
wantsOpenshiftAuthorizationClient.SetOpenshiftInternalAuthorizationClient(i.OpenshiftInternalAuthorizationClient)
}
if wantsOpenshiftBuildClient, ok := plugin.(WantsOpenshiftInternalBuildClient); ok {
wantsOpenshiftBuildClient.SetOpenshiftInternalBuildClient(i.OpenshiftInternalBuildClient)
}
if wantsOpenshiftImageClient, ok := plugin.(WantsOpenshiftInternalImageClient); ok {
wantsOpenshiftImageClient.SetOpenshiftInternalImageClient(i.OpenshiftInternalImageClient)
}
if wantsOpenshiftQuotaClient, ok := plugin.(WantsOpenshiftInternalQuotaClient); ok {
wantsOpenshiftQuotaClient.SetOpenshiftInternalQuotaClient(i.OpenshiftInternalQuotaClient)
}
if WantsOpenshiftInternalTemplateClient, ok := plugin.(WantsOpenshiftInternalTemplateClient); ok {
WantsOpenshiftInternalTemplateClient.SetOpenshiftInternalTemplateClient(i.OpenshiftInternalTemplateClient)
}
if WantsOpenshiftInternalUserClient, ok := plugin.(WantsOpenshiftInternalUserClient); ok {
WantsOpenshiftInternalUserClient.SetOpenshiftInternalUserClient(i.OpenshiftInternalUserClient)
}
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.(WantsInternalKubernetesInformers); ok {
wantsInformers.SetInternalKubernetesInformers(i.Informers)
}
if wantsInformerFactory, ok := plugin.(kubeapiserveradmission.WantsInternalKubeInformerFactory); ok {
wantsInformerFactory.SetInternalKubeInformerFactory(i.Informers)
}
if wantsClusterQuota, ok := plugin.(WantsClusterQuota); ok {
wantsClusterQuota.SetClusterQuota(i.ClusterQuotaMapper, i.ClusterResourceQuotaInformer)
}
if wantsSecurityInformer, ok := plugin.(WantsSecurityInformer); ok {
wantsSecurityInformer.SetSecurityInformers(i.SecurityInformers)
}
if wantsDefaultRegistryFunc, ok := plugin.(WantsDefaultRegistryFunc); ok {
wantsDefaultRegistryFunc.SetDefaultRegistryFunc(i.RegistryHostnameRetriever.InternalRegistryHostname)
}
if wantsUserInformer, ok := plugin.(WantsUserInformer); ok {
wantsUserInformer.SetUserInformer(i.UserInformers)
}
}
// 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
}