Skip to content

Commit

Permalink
fix: merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rkettelerij committed Jun 13, 2024
1 parent 3a6d44c commit 0641c5c
Showing 1 changed file with 68 additions and 39 deletions.
107 changes: 68 additions & 39 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import (
"os"

"github.com/PDOK/uptime-operator/internal/service"
"github.com/PDOK/uptime-operator/internal/service/providers"
"github.com/PDOK/uptime-operator/internal/util"
"github.com/peterbourgon/ff"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/manager"

// 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 @@ -69,8 +71,13 @@ func main() {
var slackChannel string
var slackWebhookURL string
var uptimeProvider string
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.")
var pingdomApiToken string

Check failure on line 74 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var pingdomApiToken should be pingdomAPIToken (revive)
var pingdomAlertUserIds util.SliceFlag

Check failure on line 75 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var pingdomAlertUserIds should be pingdomAlertUserIDs (revive)
var pingdomAlertIntegrationIds util.SliceFlag

Check failure on line 76 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var pingdomAlertIntegrationIds should be pingdomAlertIntegrationIDs (revive)
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,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -80,22 +87,76 @@ func main() {
"If set, HTTP/2 will be enabled for the metrics and webhook servers.")
flag.Var(&namespaces, "namespace", "Namespace(s) to watch for changes. "+
"Specify this flag multiple times for each namespace to watch. When not provided all namespaces will be watched.")
flag.StringVar(&slackChannel, "slack-channel", "", "The Slack Channel ID for posting updates when uptime checks are mutated.")
flag.StringVar(&slackWebhookURL, "slack-webhook-url", "", "The webhook URL required to post messages to the given Slack channel.")
flag.StringVar(&uptimeProvider, "uptime-provider", "mock", "Name of the (SaaS) uptime monitoring provider to use.")
flag.StringVar(&slackChannel, "slack-channel", "",
"The Slack Channel ID for posting updates when uptime checks are mutated.")
flag.StringVar(&slackWebhookURL, "slack-webhook-url", "",
"The webhook URL required to post messages to the given Slack channel.")
flag.StringVar(&uptimeProvider, "uptime-provider", "mock",
"Name of the (SaaS) uptime monitoring provider to use.")
flag.StringVar(&pingdomApiToken, "pingdom-api-token", "",
"The API token to authenticate with Pingdom. Only applies when 'uptime-provider' is 'pingdom'")
flag.Var(&pingdomAlertUserIds, "pingdom-alert-user-ids",
"One or more IDs of Pingdom users to alert. Only applies when 'uptime-provider' is 'pingdom'")
flag.Var(&pingdomAlertIntegrationIds, "pingdom-alert-integration-ids",
"One or more IDs of Pingdom integrations (like slack channels) to alert. Only applies when 'uptime-provider' is 'pingdom'")

opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

if err := ff.Parse(flag.CommandLine, os.Args[1:], ff.WithEnvVarNoPrefix()); err != nil {
setupLog.Error(err, "unable to parse flags")
os.Exit(1)
}

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
mgr, err := createManager(enableHTTP2, metricsAddr, secureMetrics, probeAddr, enableLeaderElection, namespaces)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

var uptimeProviderSettings any
if uptimeProvider == "pingdom" {
uptimeProviderSettings = providers.PingdomSettings{
ApiToken: pingdomApiToken,
AlertUserIds: pingdomAlertUserIds,
AlertIntegrationIds: pingdomAlertIntegrationIds,
}
}

if err = (&controller.IngressRouteReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
UptimeCheckService: service.New(
service.WithProviderAndSettings(uptimeProvider, uptimeProviderSettings),
service.WithSlack(slackWebhookURL, slackChannel),
),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IngressRoute")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}

func createManager(enableHTTP2 bool, metricsAddr string, secureMetrics bool, probeAddr string,
enableLeaderElection bool, namespaces util.SliceFlag) (manager.Manager, error) {
// if the enable-http2 flag is false (the default), http/2 should be disabled
// due to its vulnerabilities. More specifically, disabling http/2 will
// prevent from being vulnerable to the HTTP/2 Stream Cancelation and
Expand Down Expand Up @@ -148,37 +209,5 @@ func main() {
managerOpts.Cache.DefaultNamespaces = namespacesToWatch
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), managerOpts)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

if err = (&controller.IngressRouteReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
UptimeCheckService: service.New(
service.WithProviderName(uptimeProvider),
service.WithSlack(slackWebhookURL, slackChannel),
),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IngressRoute")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
return ctrl.NewManager(ctrl.GetConfigOrDie(), managerOpts)
}

0 comments on commit 0641c5c

Please sign in to comment.