diff --git a/cmd/manager/main.go b/cmd/manager/main.go index c916b69..6f37745 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -1,11 +1,14 @@ package main import ( + "context" + "errors" "fmt" "os" "github.com/cloudnative-pg/machinery/pkg/log" "github.com/spf13/cobra" + ctrl "sigs.k8s.io/controller-runtime" "github.com/cloudnative-pg/plugin-barman-cloud/internal/cmd/instance" "github.com/cloudnative-pg/plugin-barman-cloud/internal/cmd/operator" @@ -30,8 +33,10 @@ func main() { rootCmd.AddCommand(operator.NewCmd()) rootCmd.AddCommand(restore.NewCmd()) - if err := rootCmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(1) + if err := rootCmd.ExecuteContext(ctrl.SetupSignalHandler()); err != nil { + if !errors.Is(err, context.Canceled) { + fmt.Println(err) + os.Exit(1) + } } } diff --git a/go.mod b/go.mod index e393e51..2c16033 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/cloudnative-pg/barman-cloud v0.0.0-20241105055149-ae6c2408bd14 github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241113134512-8608232c2813 github.com/cloudnative-pg/cnpg-i v0.0.0-20241109002750-8abd359df734 - github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241030141108-7e59fc9f4797 + github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241129144432-bd94f16685d3 github.com/cloudnative-pg/machinery v0.0.0-20241105070525-042a028b767c github.com/docker/docker v27.3.1+incompatible github.com/onsi/ginkgo/v2 v2.21.0 diff --git a/go.sum b/go.sum index a79af78..114462d 100644 --- a/go.sum +++ b/go.sum @@ -32,8 +32,8 @@ github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241113134512-8608232c2813 h github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241113134512-8608232c2813/go.mod h1:f4hObdRVoQtMmVtWqZ6VDZBrI6ok9Td/UMhojQ+EPmk= github.com/cloudnative-pg/cnpg-i v0.0.0-20241109002750-8abd359df734 h1:4jq/FUrlAKxu0Kw9PL5lj5Njq8pAnmUpP/kXKOrJAaE= github.com/cloudnative-pg/cnpg-i v0.0.0-20241109002750-8abd359df734/go.mod h1:3U7miYasKr2rYCQzrn/IvbSQc0OpYF8ieZt2FKG4nv0= -github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241030141108-7e59fc9f4797 h1:8iaPgTx16yzx8rrhOi99u+GWGp47kqveF9NShElsYKM= -github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241030141108-7e59fc9f4797/go.mod h1:X6r1fRuUEIAv4+5SSBY2RmQ201K6GcptOXgnmaX/8tY= +github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241129144432-bd94f16685d3 h1:hKTlmgyOq5ZS7t1eVa4SY1hH361gZ7VIb0an+BH9rJs= +github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241129144432-bd94f16685d3/go.mod h1:X6r1fRuUEIAv4+5SSBY2RmQ201K6GcptOXgnmaX/8tY= github.com/cloudnative-pg/machinery v0.0.0-20241105070525-042a028b767c h1:t0RBU2gBiwJQ9XGeXlHPBYpsTscSKHgB5TfcWaiwanc= github.com/cloudnative-pg/machinery v0.0.0-20241105070525-042a028b767c/go.mod h1:uBHGRIk5rt07mO4zjIC1uvGBWTH6PqIiD1PfpvPGZKU= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= diff --git a/internal/cnpgi/instance/manager.go b/internal/cnpgi/instance/manager.go index 0c4dfa2..a28fd81 100644 --- a/internal/cnpgi/instance/manager.go +++ b/internal/cnpgi/instance/manager.go @@ -2,7 +2,6 @@ package instance import ( "context" - "os" "path" cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" @@ -66,7 +65,7 @@ func Start(ctx context.Context) error { }) if err != nil { setupLog.Error(err, "unable to start manager") - os.Exit(1) + return err } barmanObjectKey := client.ObjectKey{ @@ -93,8 +92,7 @@ func Start(ctx context.Context) error { return err } - if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { - setupLog.Error(err, "problem running manager") + if err := mgr.Start(ctx); err != nil { return err } diff --git a/internal/cnpgi/operator/manager.go b/internal/cnpgi/operator/manager.go index f7ca78a..f51d269 100644 --- a/internal/cnpgi/operator/manager.go +++ b/internal/cnpgi/operator/manager.go @@ -155,7 +155,6 @@ func Start(ctx context.Context) error { setupLog.Info("starting manager") if err := mgr.Start(ctx); err != nil { - setupLog.Error(err, "problem running manager") return err } diff --git a/internal/cnpgi/restore/manager.go b/internal/cnpgi/restore/manager.go index ac00640..7571491 100644 --- a/internal/cnpgi/restore/manager.go +++ b/internal/cnpgi/restore/manager.go @@ -2,7 +2,6 @@ package restore import ( "context" - "os" cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" "github.com/spf13/viper" @@ -69,7 +68,7 @@ func Start(ctx context.Context) error { }) if err != nil { setupLog.Error(err, "unable to start manager") - os.Exit(1) + return err } if err := mgr.Add(&CNPGI{ @@ -92,8 +91,7 @@ func Start(ctx context.Context) error { return err } - if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { - setupLog.Error(err, "problem running manager") + if err := mgr.Start(ctx); err != nil { return err }