/
init.go
69 lines (64 loc) · 2.8 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
package admission
import (
"k8s.io/apiserver/pkg/admission"
restclient "k8s.io/client-go/rest"
quota "k8s.io/kubernetes/pkg/quota/v1"
quotainformer "github.com/openshift/client-go/quota/informers/externalversions/quota/v1"
securityv1informer "github.com/openshift/client-go/security/informers/externalversions/security/v1"
userinformer "github.com/openshift/client-go/user/informers/externalversions"
"github.com/openshift/origin/pkg/image/apiserver/registryhostname"
"github.com/openshift/origin/pkg/project/cache"
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
)
type PluginInitializer struct {
ProjectCache *cache.ProjectCache
DefaultNodeSelector string
OriginQuotaRegistry quota.Registry
RESTClientConfig restclient.Config
ClusterResourceQuotaInformer quotainformer.ClusterResourceQuotaInformer
ClusterQuotaMapper clusterquotamapping.ClusterQuotaMapper
RegistryHostnameRetriever registryhostname.RegistryHostnameRetriever
SecurityInformers securityv1informer.SecurityContextConstraintsInformer
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 wantsProjectCache, ok := plugin.(WantsProjectCache); ok {
wantsProjectCache.SetProjectCache(i.ProjectCache)
}
if castObj, ok := plugin.(WantsDefaultNodeSelector); ok {
castObj.SetDefaultNodeSelector(i.DefaultNodeSelector)
}
if wantsOriginQuotaRegistry, ok := plugin.(WantsOriginQuotaRegistry); ok {
wantsOriginQuotaRegistry.SetOriginQuotaRegistry(i.OriginQuotaRegistry)
}
if wantsRESTClientConfig, ok := plugin.(WantsRESTClientConfig); ok {
wantsRESTClientConfig.SetRESTClientConfig(i.RESTClientConfig)
}
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.InitializationValidator); ok {
err := validater.ValidateInitialization()
if err != nil {
return err
}
}
}
return nil
}