From 495d5c3cc2918f6446a8b2f4b11733a1c23964eb Mon Sep 17 00:00:00 2001 From: Nithunikzz Date: Fri, 26 Apr 2024 10:54:34 +0530 Subject: [PATCH] Fix --- agent/container/pkg/clients/nats_client.go | 27 ++++++++---------- agent/git/pkg/clients/nats_client.go | 27 ++++++++---------- agent/kubviz/k8smetrics_agent.go | 32 ++++++++++------------ client/pkg/clients/clients.go | 26 ++++++++---------- 4 files changed, 51 insertions(+), 61 deletions(-) diff --git a/agent/container/pkg/clients/nats_client.go b/agent/container/pkg/clients/nats_client.go index 7d824da4..2c12d062 100755 --- a/agent/container/pkg/clients/nats_client.go +++ b/agent/container/pkg/clients/nats_client.go @@ -54,25 +54,22 @@ func NewNATSContext(conf *config.Config) (*NATSContext, error) { if mtlsConfig.IsEnabled { tlsConfig, err := mtlsnats.GetTlsConfig() if err != nil { - log.Println("error while getting tls config ", err) - time.Sleep(time.Minute * 30) - } else { - conn, err = nats.Connect(conf.NatsAddress, - nats.Name("Github metrics"), - //nats.Token(conf.NatsToken), - nats.Secure(tlsConfig), - ) - if err != nil { - log.Fatal("error while connecting with mtls ", err) - } + log.Println("Error while getting TLS config:", err) + return nil, err } - } - - if conn == nil { + conn, err = nats.Connect(conf.NatsAddress, + nats.Name("Github metrics"), + nats.Secure(tlsConfig), + ) + if err != nil { + log.Fatal("Error while connecting with mTLS:", err) + } + } else { conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) if err != nil { - return nil, fmt.Errorf("error while connecting with token: %w", err) + log.Println("Error while connecting with token:", err) + return nil, err } } diff --git a/agent/git/pkg/clients/nats_client.go b/agent/git/pkg/clients/nats_client.go index e28b5104..378bb842 100644 --- a/agent/git/pkg/clients/nats_client.go +++ b/agent/git/pkg/clients/nats_client.go @@ -44,25 +44,22 @@ func NewNATSContext(conf *config.Config) (*NATSContext, error) { if mtlsConfig.IsEnabled { tlsConfig, err := mtlsnats.GetTlsConfig() if err != nil { - log.Println("error while getting tls config ", err) - time.Sleep(time.Minute * 30) - } else { - conn, err = nats.Connect(conf.NatsAddress, - nats.Name("Github metrics"), - //nats.Token(conf.NatsToken), - nats.Secure(tlsConfig), - ) - if err != nil { - log.Fatal("error while connecting with mtls ", err) - } + log.Println("Error while getting TLS config:", err) + return nil, err } - } - - if conn == nil { + conn, err = nats.Connect(conf.NatsAddress, + nats.Name("Github metrics"), + nats.Secure(tlsConfig), + ) + if err != nil { + log.Fatal("Error while connecting with mTLS:", err) + } + } else { conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) if err != nil { - return nil, fmt.Errorf("error while connecting with token: %w", err) + log.Println("Error while connecting with token:", err) + return nil, err } } diff --git a/agent/kubviz/k8smetrics_agent.go b/agent/kubviz/k8smetrics_agent.go index aa0facad..df460d44 100644 --- a/agent/kubviz/k8smetrics_agent.go +++ b/agent/kubviz/k8smetrics_agent.go @@ -83,25 +83,23 @@ func main() { if mtlsConfig.IsEnabled { tlsConfig, err := mtlsnats.GetTlsConfig() if err != nil { - log.Println("error while getting tls config ", err) - time.Sleep(time.Minute * 30) - } else { - nc, err = nats.Connect( - natsurl, - nats.Name("K8s Metrics"), - //nats.Token(token), - nats.Secure(tlsConfig), - ) - if err != nil { - log.Fatal("error while connecting with mtls ", err) - } + log.Println("Error while getting TLS config:", err) + //return nil, err } - } - - if nc == nil { - nc, err = nats.Connect(natsurl, nats.Name("K8s Metrics"), nats.Token(token)) - events.CheckErr(err) + nc, err = nats.Connect(natsurl, + nats.Name("Github metrics"), + nats.Secure(tlsConfig), + ) + if err != nil { + log.Fatal("Error while connecting with mTLS:", err) + } + } else { + nc, err = nats.Connect(natsurl, nats.Name("Github metrics"), nats.Token(token)) + if err != nil { + log.Println("Error while connecting with token:", err) + //return nil, err + } } js, err := nc.JetStream() events.CheckErr(err) diff --git a/client/pkg/clients/clients.go b/client/pkg/clients/clients.go index 344e62d6..00df5132 100644 --- a/client/pkg/clients/clients.go +++ b/client/pkg/clients/clients.go @@ -31,24 +31,22 @@ func NewNATSContext(conf *config.Config, dbClient clickhouse.DBInterface) (*NATS if mtlsConfig.IsEnabled { tlsConfig, err := mtlsnats.GetTlsConfig() if err != nil { - log.Println("error while getting tls config ", err) - time.Sleep(time.Minute * 30) - } else { - conn, err = nats.Connect(conf.NatsAddress, - nats.Name("Github metrics"), - //nats.Token(conf.NatsToken), - nats.Secure(tlsConfig), - ) - if err != nil { - log.Fatal("error while connecting with mtls ", err) - } + log.Println("Error while getting TLS config:", err) + return nil, err } - } - if conn == nil { + conn, err = nats.Connect(conf.NatsAddress, + nats.Name("Github metrics"), + nats.Secure(tlsConfig), + ) + if err != nil { + log.Fatal("Error while connecting with mTLS:", err) + } + } else { conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) if err != nil { - return nil, fmt.Errorf("error while connecting with token: %w", err) + log.Println("Error while connecting with token:", err) + return nil, err } }