Skip to content

Commit 1c158d1

Browse files
committed
Addressed changes as mentioned in PR comments
Signed-off-by: Horiodino <holiodin@gmail.com>
1 parent fc636ce commit 1c158d1

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

catalogd/cmd/catalogd/main.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"context"
2021
"crypto/tls"
2122
"flag"
2223
"fmt"
@@ -96,24 +97,29 @@ func init() {
9697
}
9798

9899
func main() {
99-
cfg := &config{}
100-
cmd := newRootCmd(cfg)
100+
cmd := newRootCmd()
101101
if err := cmd.Execute(); err != nil {
102102
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
103103
os.Exit(1)
104104
}
105105
}
106106

107-
func newRootCmd(cfg *config) *cobra.Command {
107+
func newRootCmd() *cobra.Command {
108+
cfg := &config{}
108109
cmd := &cobra.Command{
109110
Use: "catalogd",
110111
Short: "Catalogd is a Kubernetes operator for managing operator catalogs",
111112
RunE: func(cmd *cobra.Command, args []string) error {
112-
return run(cfg)
113+
if err := validateTLSConfig(cfg); err != nil {
114+
return err
115+
}
116+
cmd.SilenceUsage = true
117+
118+
return run(cfg, ctrl.SetupSignalHandler())
113119
},
114120
}
115121

116-
flags := cmd.PersistentFlags()
122+
flags := cmd.Flags()
117123
flags.StringVar(&cfg.metricsAddr, "metrics-bind-address", "", "The address for the metrics endpoint. Requires tls-cert and tls-key. (Default: ':7443')")
118124
flags.StringVar(&cfg.probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
119125
flags.StringVar(&cfg.pprofAddr, "pprof-bind-address", "0", "The address the pprof endpoint binds to. an empty string or 0 disables pprof")
@@ -147,7 +153,7 @@ func newVersionCmd() *cobra.Command {
147153
}
148154
}
149155

150-
func run(cfg *config) error {
156+
func run(cfg *config, ctx context.Context) error {
151157
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
152158

153159
authFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s.json", authFilePrefix, apimachineryrand.String(8)))
@@ -163,10 +169,6 @@ func run(cfg *config) error {
163169
}
164170
}
165171

166-
if err := validateTLSConfig(cfg); err != nil {
167-
return err
168-
}
169-
170172
protocol := "http://"
171173
if cfg.certFile != "" && cfg.keyFile != "" {
172174
protocol = "https://"
@@ -243,7 +245,7 @@ func run(cfg *config) error {
243245
return err
244246
}
245247

246-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
248+
if err := mgr.Start(ctx); err != nil {
247249
return fmt.Errorf("problem running manager: %w", err)
248250
}
249251

0 commit comments

Comments
 (0)