Skip to content

Commit

Permalink
Addressed changes as mentioned in PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Horiodino <holiodin@gmail.com>
  • Loading branch information
Horiodino committed Jan 15, 2025
1 parent fc636ce commit 623919d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions catalogd/cmd/catalogd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"context"
"crypto/tls"
"flag"
"fmt"
Expand Down Expand Up @@ -96,24 +97,29 @@ func init() {
}

func main() {
cfg := &config{}
cmd := newRootCmd(cfg)
cmd := newRootCmd()
if err := cmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}

func newRootCmd(cfg *config) *cobra.Command {
func newRootCmd() *cobra.Command {
cfg := &config{}
cmd := &cobra.Command{
Use: "catalogd",
Short: "Catalogd is a Kubernetes operator for managing operator catalogs",
RunE: func(cmd *cobra.Command, args []string) error {
return run(cfg)
if err := validateTLSConfig(cfg); err != nil {
return err
}
cmd.SilenceUsage = true

return run(ctrl.SetupSignalHandler(), cfg)
},
}

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

func run(cfg *config) error {
func run(ctx context.Context, cfg *config) error {
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))

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

if err := validateTLSConfig(cfg); err != nil {
return err
}

protocol := "http://"
if cfg.certFile != "" && cfg.keyFile != "" {
protocol = "https://"
Expand Down Expand Up @@ -243,7 +245,7 @@ func run(cfg *config) error {
return err
}

if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
if err := mgr.Start(ctx); err != nil {
return fmt.Errorf("problem running manager: %w", err)
}

Expand Down

0 comments on commit 623919d

Please sign in to comment.