diff --git a/cmd/es-index-cleaner/app/flags.go b/cmd/es-index-cleaner/app/flags.go index 671e1aabc9b..7c1d8ee7974 100644 --- a/cmd/es-index-cleaner/app/flags.go +++ b/cmd/es-index-cleaner/app/flags.go @@ -7,6 +7,9 @@ import ( "flag" "github.com/spf13/viper" + "go.opentelemetry.io/collector/config/configtls" + + "github.com/jaegertracing/jaeger/pkg/config/tlscfg" ) const ( @@ -19,6 +22,8 @@ const ( password = "es.password" ) +var tlsFlagsCfg = tlscfg.ClientFlagsConfig{Prefix: "es"} + // Config holds configuration for index cleaner binary. type Config struct { IndexPrefix string @@ -29,6 +34,7 @@ type Config struct { Username string Password string TLSEnabled bool + TLSConfig configtls.ClientConfig } // AddFlags adds flags for TLS to the FlagSet. @@ -40,6 +46,7 @@ func (*Config) AddFlags(flags *flag.FlagSet) { flags.String(indexDateSeparator, "-", "Index date separator") flags.String(username, "", "The username required by storage") flags.String(password, "", "The password required by storage") + tlsFlagsCfg.AddFlags(flags) } // InitFromViper initializes config from viper.Viper. @@ -55,4 +62,9 @@ func (c *Config) InitFromViper(v *viper.Viper) { c.IndexDateSeparator = v.GetString(indexDateSeparator) c.Username = v.GetString(username) c.Password = v.GetString(password) + opts, err := tlsFlagsCfg.InitFromViper(v) + if err != nil { + panic(err) + } + c.TLSConfig = opts.ToOtelClientConfig() } diff --git a/cmd/es-index-cleaner/main.go b/cmd/es-index-cleaner/main.go index a0ea71775c2..50d7bbcdcae 100644 --- a/cmd/es-index-cleaner/main.go +++ b/cmd/es-index-cleaner/main.go @@ -4,6 +4,7 @@ package main import ( + "context" "encoding/base64" "errors" "fmt" @@ -18,7 +19,6 @@ import ( "github.com/jaegertracing/jaeger/cmd/es-index-cleaner/app" "github.com/jaegertracing/jaeger/pkg/config" - "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/es/client" ) @@ -26,7 +26,6 @@ func main() { logger, _ := zap.NewProduction() v := viper.New() cfg := &app.Config{} - tlsFlags := tlscfg.ClientFlagsConfig{Prefix: "es"} command := &cobra.Command{ Use: "jaeger-es-index-cleaner NUM_OF_DAYS http://HOSTNAME:PORT", @@ -42,21 +41,18 @@ func main() { } cfg.InitFromViper(v) - tlsOpts, err := tlsFlags.InitFromViper(v) - if err != nil { - return err - } - tlsCfg, err := tlsOpts.Config(logger) + + ctx := context.Background() + tlscfg, err := cfg.TLSConfig.LoadTLSConfig(ctx) if err != nil { - return err + return fmt.Errorf("error loading tls config : %w", err) } - defer tlsOpts.Close() c := &http.Client{ Timeout: time.Duration(cfg.MasterNodeTimeoutSeconds) * time.Second, Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, - TLSClientConfig: tlsCfg, + TLSClientConfig: tlscfg, }, } i := client.IndicesClient{ @@ -101,7 +97,6 @@ func main() { v, command, cfg.AddFlags, - tlsFlags.AddFlags, ) if err := command.Execute(); err != nil {