Skip to content

Commit

Permalink
Add logic for webhooks in main.go
Browse files Browse the repository at this point in the history
Signed-off-by: Chandan Kumar <[email protected]>
  • Loading branch information
raukadah committed Nov 27, 2024
1 parent efacf51 commit feb8447
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/tls"
"flag"
"os"
"strings"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand Down Expand Up @@ -143,12 +144,32 @@ func main() {
if err != nil {
os.Exit(1)
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
checker := healthz.Ping
// Setup webhooks if requested
if strings.ToLower(os.Getenv("ENABLE_WEBHOOKS")) != "false" {

if err = (&watcherv1beta1.Watcher{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Watcher")
os.Exit(1)
}
if err = (&watcherv1beta1.WatcherAPI{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "WatcherAPI")
os.Exit(1)
}
if err = (&watcherv1beta1.WatcherApplier{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "WatcherApplier")
os.Exit(1)
}
if err = (&watcherv1beta1.WatcherDecisionEngine{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "WatcherDecisionEngine")
os.Exit(1)
}
}
if err := mgr.AddHealthzCheck("healthz", checker); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
if err := mgr.AddReadyzCheck("readyz", checker); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
Expand All @@ -158,4 +179,4 @@ func main() {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}
}

0 comments on commit feb8447

Please sign in to comment.