From 71ef65b5546f7beb08bae78bebb0ff59b6fa67a7 Mon Sep 17 00:00:00 2001 From: yangw Date: Mon, 11 Sep 2023 16:07:08 +0800 Subject: [PATCH] Support ENABLE_WEBHOOKS env which cloud disable webhook server locally (#617) * Support ENABLE_WEBHOOKS env which cloud disable webhook server on locally Signed-off-by: drivebyer * Add related flag Signed-off-by: drivebyer --------- Signed-off-by: drivebyer --- main.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) 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