Skip to content

Commit de58b9c

Browse files
committed
chore: review
Signed-off-by: Leonardo Cecchi <[email protected]>
1 parent 39be04c commit de58b9c

File tree

6 files changed

+15
-29
lines changed

6 files changed

+15
-29
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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package instance
22

33
import (
44
"context"
5-
"errors"
6-
"os"
75
"path"
86

97
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
@@ -67,7 +65,7 @@ func Start(ctx context.Context) error {
6765
})
6866
if err != nil {
6967
setupLog.Error(err, "unable to start manager")
70-
os.Exit(1)
68+
return err
7169
}
7270

7371
barmanObjectKey := client.ObjectKey{
@@ -94,12 +92,7 @@ func Start(ctx context.Context) error {
9492
return err
9593
}
9694

97-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
98-
if errors.Is(err, context.Canceled) {
99-
return nil
100-
}
101-
102-
setupLog.Error(err, "problem running manager")
95+
if err := mgr.Start(ctx); err != nil {
10396
return err
10497
}
10598

internal/cnpgi/operator/manager.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package operator
1919
import (
2020
"context"
2121
"crypto/tls"
22-
"errors"
2322

2423
// +kubebuilder:scaffold:imports
2524
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
@@ -156,11 +155,6 @@ func Start(ctx context.Context) error {
156155

157156
setupLog.Info("starting manager")
158157
if err := mgr.Start(ctx); err != nil {
159-
if errors.Is(err, context.Canceled) {
160-
return nil
161-
}
162-
163-
setupLog.Error(err, "problem running manager")
164158
return err
165159
}
166160

internal/cnpgi/restore/manager.go

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

33
import (
44
"context"
5-
"errors"
6-
"os"
75

86
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
97
"github.com/spf13/viper"
@@ -70,7 +68,7 @@ func Start(ctx context.Context) error {
7068
})
7169
if err != nil {
7270
setupLog.Error(err, "unable to start manager")
73-
os.Exit(1)
71+
return err
7472
}
7573

7674
if err := mgr.Add(&CNPGI{
@@ -93,11 +91,7 @@ func Start(ctx context.Context) error {
9391
return err
9492
}
9593

96-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
97-
if errors.Is(err, context.Canceled) {
98-
return nil
99-
}
100-
setupLog.Error(err, "problem running manager")
94+
if err := mgr.Start(ctx); err != nil {
10195
return err
10296
}
10397

0 commit comments

Comments
 (0)