Skip to content

Commit a99c9b1

Browse files
committed
fix error handling, fix lint issues and tidy go.mod
Signed-off-by: Omar Farag <[email protected]>
1 parent f26c37c commit a99c9b1

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

cmd/operator-controller/main.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ var (
8080
)
8181

8282
type config struct {
83-
metricsAddr string
84-
certFile string
85-
keyFile string
86-
enableLeaderElection bool
87-
probeAddr string
88-
cachePath string
89-
systemNamespace string
90-
catalogdCasDir string
91-
pullCasDir string
92-
globalPullSecret string
83+
metricsAddr string
84+
certFile string
85+
keyFile string
86+
enableLeaderElection bool
87+
probeAddr string
88+
cachePath string
89+
systemNamespace string
90+
catalogdCasDir string
91+
pullCasDir string
92+
globalPullSecret string
9393
}
9494

9595
const authFilePrefix = "operator-controller-global-pull-secrets"
@@ -111,7 +111,7 @@ var operatorControllerCmd = &cobra.Command{
111111
Short: "operator-controller is the central component of Operator Lifecycle Manager (OLM) v1",
112112
RunE: func(cmd *cobra.Command, args []string) error {
113113
if err := validateMetricsFlags(); err != nil {
114-
return fmt.Errorf("Error: %v\n", err)
114+
return err
115115
}
116116
return run()
117117
},
@@ -126,7 +126,6 @@ var versionCommand = &cobra.Command{
126126
}
127127

128128
func init() {
129-
130129
//create flagset, the collection of flags for this command
131130
flags := operatorControllerCmd.Flags()
132131
flags.StringVar(&cfg.metricsAddr, "metrics-bind-address", "", "The address for the metrics endpoint. Requires tls-cert and tls-key. (Default: ':8443')")
@@ -152,7 +151,6 @@ func init() {
152151

153152
//add feature gate flags to flagset
154153
features.OperatorControllerFeatureGate.AddFlag(flags)
155-
156154
}
157155

158156
func validateMetricsFlags() error {
@@ -474,7 +472,8 @@ func run() error {
474472
}
475473

476474
func main() {
477-
478-
operatorControllerCmd.Execute()
479-
475+
if err := operatorControllerCmd.Execute(); err != nil {
476+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
477+
os.Exit(1)
478+
}
480479
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/operator-framework/helm-operator-plugins v0.8.0
2323
github.com/operator-framework/operator-registry v1.50.0
2424
github.com/prometheus/client_golang v1.20.5
25+
github.com/spf13/cobra v1.8.1
2526
github.com/spf13/pflag v1.0.6
2627
github.com/stretchr/testify v1.10.0
2728
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
@@ -197,7 +198,6 @@ require (
197198
github.com/sigstore/sigstore v1.8.9 // indirect
198199
github.com/sirupsen/logrus v1.9.3 // indirect
199200
github.com/spf13/cast v1.7.0 // indirect
200-
github.com/spf13/cobra v1.8.1 // indirect
201201
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
202202
github.com/stoewer/go-strcase v1.3.0 // indirect
203203
github.com/stretchr/objx v0.5.2 // indirect

0 commit comments

Comments
 (0)