From 68f115d64c3837b6274afb5c2b7227fd979481bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20J=C3=BCttner?= Date: Tue, 10 Sep 2024 11:47:30 +0200 Subject: [PATCH] Disable logger development mode to avoid panicking, use zap as logger --- CHANGELOG.md | 4 ++++ main.go | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37d012b..d7f2a35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Disable logger development mode to avoid panicking, use zap as logger. + ## [0.2.3] - 2024-07-18 ## [0.2.2] - 2024-04-22 diff --git a/main.go b/main.go index a009de8..e58f0f7 100644 --- a/main.go +++ b/main.go @@ -30,8 +30,11 @@ import ( capz "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" capi "sigs.k8s.io/cluster-api/api/v1beta1" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/log/zap" + metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" + "sigs.k8s.io/controller-runtime/pkg/webhook" "github.com/giantswarm/azure-private-endpoint-operator/controllers" "github.com/giantswarm/azure-private-endpoint-operator/pkg/azure" @@ -74,7 +77,7 @@ func main() { flag.DurationVar(&syncPeriod, "sync-period", 5*time.Minute, "The minimum interval at which watched resources are reconciled (e.g. 15m)") opts := zap.Options{ - Development: true, + Development: false, TimeEncoder: zapcore.ISO8601TimeEncoder, } opts.BindFlags(flag.CommandLine) @@ -83,13 +86,19 @@ func main() { ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ - Scheme: scheme, - MetricsBindAddress: metricsAddr, - Port: 9443, + Scheme: scheme, + Metrics: metricsserver.Options{ + BindAddress: metricsAddr, + }, + WebhookServer: webhook.NewServer( + webhook.Options{ + Port: 9443, + }, + ), HealthProbeBindAddress: probeAddr, LeaderElection: enableLeaderElection, LeaderElectionID: "0934d11a.giantswarm.io", - SyncPeriod: &syncPeriod, + Cache: cache.Options{SyncPeriod: &syncPeriod}, // LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily // when the Manager ends. This requires the binary to immediately end when the // Manager is stopped, otherwise, this setting is unsafe. Setting this significantly