Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2017 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package initializer |
| 18 | |
| 19 | import ( |
| 20 | "k8s.io/apimachinery/pkg/runtime" |
| 21 | "k8s.io/apiserver/pkg/admission" |
| 22 | "k8s.io/apiserver/pkg/authorization/authorizer" |
| 23 | "k8s.io/client-go/informers" |
| 24 | "k8s.io/client-go/kubernetes" |
| 25 | ) |
| 26 | |
| 27 | type pluginInitializer struct { |
| 28 | externalClient kubernetes.Interface |
| 29 | externalInformers informers.SharedInformerFactory |
| 30 | authorizer authorizer.Authorizer |
| 31 | scheme *runtime.Scheme |
| 32 | } |
| 33 | |
| 34 | // New creates an instance of admission plugins initializer. |
| 35 | // TODO(p0lyn0mial): make the parameters public, this construction seems to be redundant. |
| 36 | func New( |
| 37 | extClientset kubernetes.Interface, |
| 38 | extInformers informers.SharedInformerFactory, |
| 39 | authz authorizer.Authorizer, |
| 40 | scheme *runtime.Scheme, |
| 41 | ) pluginInitializer { |
| 42 | return pluginInitializer{ |
| 43 | externalClient: extClientset, |
| 44 | externalInformers: extInformers, |
| 45 | authorizer: authz, |
| 46 | scheme: scheme, |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Initialize checks the initialization interfaces implemented by a plugin |
| 51 | // and provide the appropriate initialization data |
| 52 | func (i pluginInitializer) Initialize(plugin admission.Interface) { |
| 53 | if wants, ok := plugin.(WantsExternalKubeClientSet); ok { |
| 54 | wants.SetExternalKubeClientSet(i.externalClient) |
| 55 | } |
| 56 | |
| 57 | if wants, ok := plugin.(WantsExternalKubeInformerFactory); ok { |
| 58 | wants.SetExternalKubeInformerFactory(i.externalInformers) |
| 59 | } |
| 60 | |
| 61 | if wants, ok := plugin.(WantsAuthorizer); ok { |
| 62 | wants.SetAuthorizer(i.authorizer) |
| 63 | } |
| 64 | |
| 65 | if wants, ok := plugin.(WantsScheme); ok { |
| 66 | wants.SetScheme(i.scheme) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | var _ admission.PluginInitializer = pluginInitializer{} |