forked from openshift/origin
/
init.go
45 lines (40 loc) · 1.27 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
package admission
import (
"k8s.io/kubernetes/pkg/admission"
"github.com/openshift/origin/pkg/authorization/authorizer"
"github.com/openshift/origin/pkg/client"
"github.com/openshift/origin/pkg/project/cache"
)
type PluginInitializer struct {
OpenshiftClient client.Interface
ProjectCache *cache.ProjectCache
Authorizer authorizer.Authorizer
}
// 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 wantsAuthorizer, ok := plugin.(WantsAuthorizer); ok {
wantsAuthorizer.SetAuthorizer(i.Authorizer)
}
}
}
// 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
}