@@ -118,11 +118,13 @@ func (r *cniDetectRunnable) Start(ctx context.Context) error {
118118func main () {
119119 var metricsAddr string
120120 var enableLeaderElection bool
121+ var enableWebhooks bool
121122 var probeAddr string
122123
123124 flag .StringVar (& metricsAddr , "metrics-bind-address" , ":8080" , "The address the metrics endpoint binds to." )
124125 flag .StringVar (& probeAddr , "health-probe-bind-address" , ":8081" , "The address the probe endpoint binds to." )
125126 flag .BoolVar (& enableLeaderElection , "leader-elect" , false , "Enable leader election for controller manager." )
127+ flag .BoolVar (& enableWebhooks , "enable-webhooks" , true , "Enable admission webhooks." )
126128
127129 opts := zap.Options {Development : true }
128130 opts .BindFlags (flag .CommandLine )
@@ -218,26 +220,30 @@ func main() {
218220 os .Exit (1 )
219221 }
220222
221- if err = builder .WebhookManagedBy (mgr , & impv1alpha1.ImpVM {}).
222- WithDefaulter (& webhookv1alpha1.ImpVMWebhook {}).
223- WithValidator (& webhookv1alpha1.ImpVMWebhook {}).
224- Complete (); err != nil {
225- setupLog .Error (err , "unable to register webhook" , "webhook" , "ImpVM" )
226- os .Exit (1 )
227- }
223+ if enableWebhooks {
224+ if err = builder .WebhookManagedBy (mgr , & impv1alpha1.ImpVM {}).
225+ WithDefaulter (& webhookv1alpha1.ImpVMWebhook {}).
226+ WithValidator (& webhookv1alpha1.ImpVMWebhook {}).
227+ Complete (); err != nil {
228+ setupLog .Error (err , "unable to register webhook" , "webhook" , "ImpVM" )
229+ os .Exit (1 )
230+ }
228231
229- if err = builder .WebhookManagedBy (mgr , & impv1alpha1.ImpVMClass {}).
230- WithValidator (& webhookv1alpha1.ImpVMClassWebhook {}).
231- Complete (); err != nil {
232- setupLog .Error (err , "unable to register webhook" , "webhook" , "ImpVMClass" )
233- os .Exit (1 )
234- }
232+ if err = builder .WebhookManagedBy (mgr , & impv1alpha1.ImpVMClass {}).
233+ WithValidator (& webhookv1alpha1.ImpVMClassWebhook {}).
234+ Complete (); err != nil {
235+ setupLog .Error (err , "unable to register webhook" , "webhook" , "ImpVMClass" )
236+ os .Exit (1 )
237+ }
235238
236- if err = builder .WebhookManagedBy (mgr , & impv1alpha1.ImpVMTemplate {}).
237- WithValidator (& webhookv1alpha1.ImpVMTemplateWebhook {}).
238- Complete (); err != nil {
239- setupLog .Error (err , "unable to register webhook" , "webhook" , "ImpVMTemplate" )
240- os .Exit (1 )
239+ if err = builder .WebhookManagedBy (mgr , & impv1alpha1.ImpVMTemplate {}).
240+ WithValidator (& webhookv1alpha1.ImpVMTemplateWebhook {}).
241+ Complete (); err != nil {
242+ setupLog .Error (err , "unable to register webhook" , "webhook" , "ImpVMTemplate" )
243+ os .Exit (1 )
244+ }
245+ } else {
246+ setupLog .Info ("admission webhooks disabled" )
241247 }
242248
243249 if err := mgr .AddHealthzCheck ("healthz" , healthz .Ping ); err != nil {
0 commit comments