From 1578a574b2753a51aeb5e8c2328d798a37db17c6 Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:22:49 +0100 Subject: [PATCH] fix gocritic linter Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- .golangci.yaml | 1 - examples/simple/main.go | 35 ++++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 4e56d52..63058c7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,7 +3,6 @@ issues: - linters: - gosec - errorlint - - gocritic - goimports text: ".*" linters: diff --git a/examples/simple/main.go b/examples/simple/main.go index 6f8005e..1305750 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -112,6 +112,23 @@ func main() { klog.SetLogger(logr) ctrl.SetLogger(logr) + if err := run( + clusterResourceNamespace, + metricsAddr, + enableLeaderElection, + probeAddr, + ); err != nil { + logr.Error(err, "error running manager") + os.Exit(1) + } +} + +func run( + clusterResourceNamespace string, + metricsAddr string, + enableLeaderElection bool, + probeAddr string, +) error { setupLog := ctrl.Log.WithName("setup") setupLog.Info("versionInfo", "Version", Version) @@ -123,7 +140,6 @@ func main() { } else { setupLog.Error(err, "unexpected error while getting in-cluster Namespace") } - os.Exit(1) } scheme := runtime.NewScheme() @@ -159,30 +175,27 @@ func main() { mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options) if err != nil { - setupLog.Error(err, "unable to start manager") - os.Exit(1) + return fmt.Errorf("unable to start manager: %w", err) } if err = (&controller.Signer{}).SetupWithManager(ctx, mgr); err != nil { - setupLog.Error(err, "unable to create controller") - os.Exit(1) + return fmt.Errorf("unable to create controller: %w", err) } // +kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { - setupLog.Error(err, "unable to set up health check") - os.Exit(1) + return fmt.Errorf("unable to set up health check: %w", err) } if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { - setupLog.Error(err, "unable to set up ready check") - os.Exit(1) + return fmt.Errorf("unable to set up ready check: %w", err) } setupLog.Info("starting manager") if err := mgr.Start(ctx); err != nil { - setupLog.Error(err, "problem running manager") - os.Exit(1) + return fmt.Errorf("problem running manager: %w", err) } + + return nil } var errNotInCluster = errors.New("not running in-cluster")