fix: exit code 0 on clean shutdown (#70)

Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
This commit is contained in:
Leonardo Cecchi 2024-11-29 16:15:04 +01:00 committed by GitHub
parent afd4603023
commit 9d8fa079fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 15 deletions

View File

@ -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 {
if err := rootCmd.ExecuteContext(ctrl.SetupSignalHandler()); err != nil {
if !errors.Is(err, context.Canceled) {
fmt.Println(err)
os.Exit(1)
}
}
}

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}