diff --git a/main.go b/main.go index 1ee4ec28a..d6b1cb761 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,8 @@ func main() { var metricsAddr string var enableLeaderElection bool var probeAddr string + var enableWebhooks bool + flag.BoolVar(&enableWebhooks, "enable-webhooks", os.Getenv("ENABLE_WEBHOOKS") != "false", "Enable webhooks") flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") flag.BoolVar(&enableLeaderElection, "leader-elect", false, @@ -122,21 +124,24 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "RedisSentinel") os.Exit(1) } - if err = (&redisv1beta2.Redis{}).SetupWebhookWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create webhook", "webhook", "Redis") - os.Exit(1) - } - if err = (&redisv1beta2.RedisCluster{}).SetupWebhookWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create webhook", "webhook", "RedisCluster") - os.Exit(1) - } - if err = (&redisv1beta2.RedisReplication{}).SetupWebhookWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create webhook", "webhook", "RedisReplication") - os.Exit(1) - } - if err = (&redisv1beta2.RedisSentinel{}).SetupWebhookWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create webhook", "webhook", "RedisSentinel") - os.Exit(1) + + if enableWebhooks { + if err = (&redisv1beta2.Redis{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "Redis") + os.Exit(1) + } + if err = (&redisv1beta2.RedisCluster{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "RedisCluster") + os.Exit(1) + } + if err = (&redisv1beta2.RedisReplication{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "RedisReplication") + os.Exit(1) + } + if err = (&redisv1beta2.RedisSentinel{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "RedisSentinel") + os.Exit(1) + } } // +kubebuilder:scaffold:builder