Skip to content

Commit 9d8fa07

Browse files
authored
fix: exit code 0 on clean shutdown (#70)
Signed-off-by: Leonardo Cecchi <[email protected]>
1 parent afd4603 commit 9d8fa07

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

cmd/manager/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package main
22

33
import (
4+
"context"
5+
"errors"
46
"fmt"
57
"os"
68

79
"github.com/cloudnative-pg/machinery/pkg/log"
810
"github.com/spf13/cobra"
11+
ctrl "sigs.k8s.io/controller-runtime"
912

1013
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cmd/instance"
1114
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cmd/operator"
@@ -30,8 +33,10 @@ func main() {
3033
rootCmd.AddCommand(operator.NewCmd())
3134
rootCmd.AddCommand(restore.NewCmd())
3235

33-
if err := rootCmd.Execute(); err != nil {
34-
fmt.Println(err)
35-
os.Exit(1)
36+
if err := rootCmd.ExecuteContext(ctrl.SetupSignalHandler()); err != nil {
37+
if !errors.Is(err, context.Canceled) {
38+
fmt.Println(err)
39+
os.Exit(1)
40+
}
3641
}
3742
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/cloudnative-pg/barman-cloud v0.0.0-20241105055149-ae6c2408bd14
1010
github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241113134512-8608232c2813
1111
github.com/cloudnative-pg/cnpg-i v0.0.0-20241109002750-8abd359df734
12-
github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241030141108-7e59fc9f4797
12+
github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241129144432-bd94f16685d3
1313
github.com/cloudnative-pg/machinery v0.0.0-20241105070525-042a028b767c
1414
github.com/docker/docker v27.3.1+incompatible
1515
github.com/onsi/ginkgo/v2 v2.21.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241113134512-8608232c2813 h
3232
github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241113134512-8608232c2813/go.mod h1:f4hObdRVoQtMmVtWqZ6VDZBrI6ok9Td/UMhojQ+EPmk=
3333
github.com/cloudnative-pg/cnpg-i v0.0.0-20241109002750-8abd359df734 h1:4jq/FUrlAKxu0Kw9PL5lj5Njq8pAnmUpP/kXKOrJAaE=
3434
github.com/cloudnative-pg/cnpg-i v0.0.0-20241109002750-8abd359df734/go.mod h1:3U7miYasKr2rYCQzrn/IvbSQc0OpYF8ieZt2FKG4nv0=
35-
github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241030141108-7e59fc9f4797 h1:8iaPgTx16yzx8rrhOi99u+GWGp47kqveF9NShElsYKM=
36-
github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241030141108-7e59fc9f4797/go.mod h1:X6r1fRuUEIAv4+5SSBY2RmQ201K6GcptOXgnmaX/8tY=
35+
github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241129144432-bd94f16685d3 h1:hKTlmgyOq5ZS7t1eVa4SY1hH361gZ7VIb0an+BH9rJs=
36+
github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241129144432-bd94f16685d3/go.mod h1:X6r1fRuUEIAv4+5SSBY2RmQ201K6GcptOXgnmaX/8tY=
3737
github.com/cloudnative-pg/machinery v0.0.0-20241105070525-042a028b767c h1:t0RBU2gBiwJQ9XGeXlHPBYpsTscSKHgB5TfcWaiwanc=
3838
github.com/cloudnative-pg/machinery v0.0.0-20241105070525-042a028b767c/go.mod h1:uBHGRIk5rt07mO4zjIC1uvGBWTH6PqIiD1PfpvPGZKU=
3939
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=

internal/cnpgi/instance/manager.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package instance
22

33
import (
44
"context"
5-
"os"
65
"path"
76

87
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
@@ -66,7 +65,7 @@ func Start(ctx context.Context) error {
6665
})
6766
if err != nil {
6867
setupLog.Error(err, "unable to start manager")
69-
os.Exit(1)
68+
return err
7069
}
7170

7271
barmanObjectKey := client.ObjectKey{
@@ -93,8 +92,7 @@ func Start(ctx context.Context) error {
9392
return err
9493
}
9594

96-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
97-
setupLog.Error(err, "problem running manager")
95+
if err := mgr.Start(ctx); err != nil {
9896
return err
9997
}
10098

internal/cnpgi/operator/manager.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ func Start(ctx context.Context) error {
155155

156156
setupLog.Info("starting manager")
157157
if err := mgr.Start(ctx); err != nil {
158-
setupLog.Error(err, "problem running manager")
159158
return err
160159
}
161160

internal/cnpgi/restore/manager.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package restore
22

33
import (
44
"context"
5-
"os"
65

76
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
87
"github.com/spf13/viper"
@@ -69,7 +68,7 @@ func Start(ctx context.Context) error {
6968
})
7069
if err != nil {
7170
setupLog.Error(err, "unable to start manager")
72-
os.Exit(1)
71+
return err
7372
}
7473

7574
if err := mgr.Add(&CNPGI{
@@ -92,8 +91,7 @@ func Start(ctx context.Context) error {
9291
return err
9392
}
9493

95-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
96-
setupLog.Error(err, "problem running manager")
94+
if err := mgr.Start(ctx); err != nil {
9795
return err
9896
}
9997

0 commit comments

Comments
 (0)