@@ -50,13 +50,13 @@ import (
50
50
51
51
const (
52
52
// Name of admission plug-in
53
- PluginName = "GenericAdmissionWebhook "
53
+ PluginName = "ValidatingAdmissionWebhook "
54
54
)
55
55
56
56
// Register registers a plugin
57
57
func Register (plugins * admission.Plugins ) {
58
58
plugins .Register (PluginName , func (configFile io.Reader ) (admission.Interface , error ) {
59
- plugin , err := NewGenericAdmissionWebhook (configFile )
59
+ plugin , err := NewValidatingAdmissionWebhook (configFile )
60
60
if err != nil {
61
61
return nil , err
62
62
}
@@ -71,8 +71,8 @@ type WebhookSource interface {
71
71
Webhooks () (* v1alpha1.ValidatingWebhookConfiguration , error )
72
72
}
73
73
74
- // NewGenericAdmissionWebhook returns a generic admission webhook plugin.
75
- func NewGenericAdmissionWebhook (configFile io.Reader ) (* GenericAdmissionWebhook , error ) {
74
+ // NewValidatingAdmissionWebhook returns a generic admission webhook plugin.
75
+ func NewValidatingAdmissionWebhook (configFile io.Reader ) (* ValidatingAdmissionWebhook , error ) {
76
76
kubeconfigFile , err := config .LoadConfig (configFile )
77
77
if err != nil {
78
78
return nil , err
@@ -90,7 +90,7 @@ func NewGenericAdmissionWebhook(configFile io.Reader) (*GenericAdmissionWebhook,
90
90
cm .SetAuthenticationInfoResolver (authInfoResolver )
91
91
cm .SetServiceResolver (config .NewDefaultServiceResolver ())
92
92
93
- return & GenericAdmissionWebhook {
93
+ return & ValidatingAdmissionWebhook {
94
94
Handler : admission .NewHandler (
95
95
admission .Connect ,
96
96
admission .Create ,
@@ -101,8 +101,8 @@ func NewGenericAdmissionWebhook(configFile io.Reader) (*GenericAdmissionWebhook,
101
101
}, nil
102
102
}
103
103
104
- // GenericAdmissionWebhook is an implementation of admission.Interface.
105
- type GenericAdmissionWebhook struct {
104
+ // ValidatingAdmissionWebhook is an implementation of admission.Interface.
105
+ type ValidatingAdmissionWebhook struct {
106
106
* admission.Handler
107
107
hookSource WebhookSource
108
108
namespaceMatcher namespace.Matcher
@@ -111,22 +111,22 @@ type GenericAdmissionWebhook struct {
111
111
}
112
112
113
113
var (
114
- _ = genericadmissioninit .WantsExternalKubeClientSet (& GenericAdmissionWebhook {})
114
+ _ = genericadmissioninit .WantsExternalKubeClientSet (& ValidatingAdmissionWebhook {})
115
115
)
116
116
117
117
// TODO find a better way wire this, but keep this pull small for now.
118
- func (a * GenericAdmissionWebhook ) SetAuthenticationInfoResolverWrapper (wrapper config.AuthenticationInfoResolverWrapper ) {
118
+ func (a * ValidatingAdmissionWebhook ) SetAuthenticationInfoResolverWrapper (wrapper config.AuthenticationInfoResolverWrapper ) {
119
119
a .clientManager .SetAuthenticationInfoResolverWrapper (wrapper )
120
120
}
121
121
122
122
// SetServiceResolver sets a service resolver for the webhook admission plugin.
123
123
// Passing a nil resolver does not have an effect, instead a default one will be used.
124
- func (a * GenericAdmissionWebhook ) SetServiceResolver (sr config.ServiceResolver ) {
124
+ func (a * ValidatingAdmissionWebhook ) SetServiceResolver (sr config.ServiceResolver ) {
125
125
a .clientManager .SetServiceResolver (sr )
126
126
}
127
127
128
128
// SetScheme sets a serializer(NegotiatedSerializer) which is derived from the scheme
129
- func (a * GenericAdmissionWebhook ) SetScheme (scheme * runtime.Scheme ) {
129
+ func (a * ValidatingAdmissionWebhook ) SetScheme (scheme * runtime.Scheme ) {
130
130
if scheme != nil {
131
131
a .clientManager .SetNegotiatedSerializer (serializer .NegotiatedSerializerWrapper (runtime.SerializerInfo {
132
132
Serializer : serializer .NewCodecFactory (scheme ).LegacyCodec (admissionv1alpha1 .SchemeGroupVersion ),
@@ -136,37 +136,37 @@ func (a *GenericAdmissionWebhook) SetScheme(scheme *runtime.Scheme) {
136
136
}
137
137
138
138
// WantsExternalKubeClientSet defines a function which sets external ClientSet for admission plugins that need it
139
- func (a * GenericAdmissionWebhook ) SetExternalKubeClientSet (client clientset.Interface ) {
139
+ func (a * ValidatingAdmissionWebhook ) SetExternalKubeClientSet (client clientset.Interface ) {
140
140
a .namespaceMatcher .Client = client
141
141
a .hookSource = configuration .NewValidatingWebhookConfigurationManager (client .AdmissionregistrationV1alpha1 ().ValidatingWebhookConfigurations ())
142
142
}
143
143
144
144
// SetExternalKubeInformerFactory implements the WantsExternalKubeInformerFactory interface.
145
- func (a * GenericAdmissionWebhook ) SetExternalKubeInformerFactory (f informers.SharedInformerFactory ) {
145
+ func (a * ValidatingAdmissionWebhook ) SetExternalKubeInformerFactory (f informers.SharedInformerFactory ) {
146
146
namespaceInformer := f .Core ().V1 ().Namespaces ()
147
147
a .namespaceMatcher .NamespaceLister = namespaceInformer .Lister ()
148
148
a .SetReadyFunc (namespaceInformer .Informer ().HasSynced )
149
149
}
150
150
151
151
// ValidateInitialization implements the InitializationValidator interface.
152
- func (a * GenericAdmissionWebhook ) ValidateInitialization () error {
152
+ func (a * ValidatingAdmissionWebhook ) ValidateInitialization () error {
153
153
if a .hookSource == nil {
154
- return fmt .Errorf ("GenericAdmissionWebhook admission plugin requires a Kubernetes client to be provided" )
154
+ return fmt .Errorf ("ValidatingAdmissionWebhook admission plugin requires a Kubernetes client to be provided" )
155
155
}
156
156
if err := a .namespaceMatcher .Validate (); err != nil {
157
- return fmt .Errorf ("GenericAdmissionWebhook .namespaceMatcher is not properly setup: %v" , err )
157
+ return fmt .Errorf ("ValidatingAdmissionWebhook .namespaceMatcher is not properly setup: %v" , err )
158
158
}
159
159
if err := a .clientManager .Validate (); err != nil {
160
- return fmt .Errorf ("GenericAdmissionWebhook .clientManager is not properly setup: %v" , err )
160
+ return fmt .Errorf ("ValidatingAdmissionWebhook .clientManager is not properly setup: %v" , err )
161
161
}
162
162
if err := a .convertor .Validate (); err != nil {
163
- return fmt .Errorf ("GenericAdmissionWebhook .convertor is not properly setup: %v" , err )
163
+ return fmt .Errorf ("ValidatingAdmissionWebhook .convertor is not properly setup: %v" , err )
164
164
}
165
165
go a .hookSource .Run (wait .NeverStop )
166
166
return nil
167
167
}
168
168
169
- func (a * GenericAdmissionWebhook ) loadConfiguration (attr admission.Attributes ) (* v1alpha1.ValidatingWebhookConfiguration , error ) {
169
+ func (a * ValidatingAdmissionWebhook ) loadConfiguration (attr admission.Attributes ) (* v1alpha1.ValidatingWebhookConfiguration , error ) {
170
170
hookConfig , err := a .hookSource .Webhooks ()
171
171
// if Webhook configuration is disabled, fail open
172
172
if err == configuration .ErrDisabled {
@@ -186,7 +186,7 @@ func (a *GenericAdmissionWebhook) loadConfiguration(attr admission.Attributes) (
186
186
}
187
187
188
188
// Admit makes an admission decision based on the request attributes.
189
- func (a * GenericAdmissionWebhook ) Admit (attr admission.Attributes ) error {
189
+ func (a * ValidatingAdmissionWebhook ) Admit (attr admission.Attributes ) error {
190
190
hookConfig , err := a .loadConfiguration (attr )
191
191
if err != nil {
192
192
return err
@@ -280,7 +280,7 @@ func (a *GenericAdmissionWebhook) Admit(attr admission.Attributes) error {
280
280
}
281
281
282
282
// TODO: factor into a common place along with the validating webhook version.
283
- func (a * GenericAdmissionWebhook ) shouldCallHook (h * v1alpha1.Webhook , attr admission.Attributes ) (bool , * apierrors.StatusError ) {
283
+ func (a * ValidatingAdmissionWebhook ) shouldCallHook (h * v1alpha1.Webhook , attr admission.Attributes ) (bool , * apierrors.StatusError ) {
284
284
var matches bool
285
285
for _ , r := range h .Rules {
286
286
m := rules.Matcher {Rule : r , Attr : attr }
@@ -296,7 +296,7 @@ func (a *GenericAdmissionWebhook) shouldCallHook(h *v1alpha1.Webhook, attr admis
296
296
return a .namespaceMatcher .MatchNamespaceSelector (h , attr )
297
297
}
298
298
299
- func (a * GenericAdmissionWebhook ) callHook (ctx context.Context , h * v1alpha1.Webhook , attr admission.Attributes ) error {
299
+ func (a * ValidatingAdmissionWebhook ) callHook (ctx context.Context , h * v1alpha1.Webhook , attr admission.Attributes ) error {
300
300
// Make the webhook request
301
301
request := request .CreateAdmissionReview (attr )
302
302
client , err := a .clientManager .HookClient (h )
0 commit comments