Skip to content

Commit

Permalink
chore: improve error logs (argoproj#10592) (argoproj#15059)
Browse files Browse the repository at this point in the history
* chore: improve error logs

Signed-off-by: AvhiMaz <avhimazumder5@outlook.com>

* chore: Changes made according to the reviewer

Signed-off-by: AvhiMaz <avhimazumder5@outlook.com>

* chore: Chnages according to the reviewerI"

Signed-off-by: AvhiMaz <avhimazumder5@outlook.com>

* Update cmpserver/apiclient/plugin.pb.go

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: AvhiMaz <avhimazumder5@outlook.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Lev <lozeryan@akami.com>
  • Loading branch information
2 people authored and Lev committed Aug 17, 2023
1 parent 4f022a2 commit f7a9090
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
18 changes: 9 additions & 9 deletions cmd/argocd-notification/commands/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,26 @@ func NewCommand() *cobra.Command {

restConfig, err := clientConfig.ClientConfig()
if err != nil {
return err
return fmt.Errorf("failed to create REST client config: %w", err)
}
restConfig.UserAgent = fmt.Sprintf("argocd-notifications-controller/%s (%s)", vers.Version, vers.Platform)
dynamicClient, err := dynamic.NewForConfig(restConfig)
if err != nil {
return err
return fmt.Errorf("failed to create dynamic client: %w", err)
}
k8sClient, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return err
return fmt.Errorf("failed to create Kubernetes client: %w", err)
}
if namespace == "" {
namespace, _, err = clientConfig.Namespace()
if err != nil {
return err
return fmt.Errorf("failed to determine controller's host namespace: %w", err)
}
}
level, err := log.ParseLevel(logLevel)
if err != nil {
return err
return fmt.Errorf("failed to parse log level: %w", err)
}
log.SetLevel(level)

Expand All @@ -105,7 +105,7 @@ func NewCommand() *cobra.Command {
log.SetFormatter(&log.TextFormatter{ForceColors: true})
}
default:
return fmt.Errorf("Unknown log format '%s'", logFormat)
return fmt.Errorf("unknown log format '%s'", logFormat)
}

tlsConfig := apiclient.TLSConfiguration{
Expand All @@ -118,14 +118,14 @@ func NewCommand() *cobra.Command {
fmt.Sprintf("%s/reposerver/tls/ca.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
)
if err != nil {
return err
return fmt.Errorf("failed to load repo-server certificate pool: %w", err)
}
tlsConfig.Certificates = pool
}
repoClientset := apiclient.NewRepoServerClientset(argocdRepoServer, 5, tlsConfig)
argocdService, err := service.NewArgoCDService(k8sClient, namespace, repoClientset)
if err != nil {
return err
return fmt.Errorf("failed to initialize Argo CD service: %w", err)
}
defer argocdService.Close()

Expand All @@ -141,7 +141,7 @@ func NewCommand() *cobra.Command {
ctrl := notificationscontroller.NewController(k8sClient, dynamicClient, argocdService, namespace, appLabelSelector, registry, secretName, configMapName)
err = ctrl.Init(ctx)
if err != nil {
return err
return fmt.Errorf("failed to initialize controller: %w", err)
}

go ctrl.Run(ctx, processorsCount)
Expand Down
26 changes: 13 additions & 13 deletions cmd/argocd/commands/headless/headless.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ func (c *forwardRepoClientset) NewRepoServerClient() (io.Closer, repoapiclient.R
func testAPI(ctx context.Context, clientOpts *apiclient.ClientOptions) error {
apiClient, err := apiclient.NewClient(clientOpts)
if err != nil {
return err
return fmt.Errorf("failed to create API client: %w", err)
}
closer, versionClient, err := apiClient.NewVersionClient()
if err != nil {
return err
return fmt.Errorf("failed to create version client: %w", err)
}
defer io.Close(closer)
_, err = versionClient.Version(ctx, &empty.Empty{})
return err
return fmt.Errorf("failed to get version: %w", err)
}

// StartLocalServer allows executing command in a headless mode: on the fly starts Argo CD API server and
Expand All @@ -147,12 +147,12 @@ func StartLocalServer(ctx context.Context, clientOpts *apiclient.ClientOptions,
if !startInProcessAPI {
localCfg, err := localconfig.ReadLocalConfig(clientOpts.ConfigPath)
if err != nil {
return err
return fmt.Errorf("error reading local config: %w", err)
}
if localCfg != nil {
configCtx, err := localCfg.ResolveContext(clientOpts.Context)
if err != nil {
return err
return fmt.Errorf("error resolving context: %w", err)
}
startInProcessAPI = configCtx.Server.Core
}
Expand All @@ -173,33 +173,33 @@ func StartLocalServer(ctx context.Context, clientOpts *apiclient.ClientOptions,
addr := fmt.Sprintf("%s:0", *address)
ln, err := net.Listen("tcp", addr)
if err != nil {
return err
return fmt.Errorf("failed to listen on %q: %w", addr, err)
}
port = &ln.Addr().(*net.TCPAddr).Port
io.Close(ln)
}

restConfig, err := clientConfig.ClientConfig()
if err != nil {
return err
return fmt.Errorf("error creating client config: %w", err)
}
appClientset, err := appclientset.NewForConfig(restConfig)
if err != nil {
return err
return fmt.Errorf("error creating app clientset: %w", err)
}
kubeClientset, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return err
return fmt.Errorf("error creating kubernetes clientset: %w", err)
}

namespace, _, err := clientConfig.Namespace()
if err != nil {
return err
return fmt.Errorf("error getting namespace: %w", err)
}

mr, err := miniredis.Run()
if err != nil {
return err
return fmt.Errorf("error running miniredis: %w", err)
}
appstateCache := appstatecache.NewCache(cache.NewCache(&forwardCacheClient{namespace: namespace, context: ctxStr, compression: compression}), time.Hour)
srv := server.NewServer(ctx, server.ArgoCDServerOpts{
Expand All @@ -220,7 +220,7 @@ func StartLocalServer(ctx context.Context, clientOpts *apiclient.ClientOptions,

lns, err := srv.Listen()
if err != nil {
return err
return fmt.Errorf("failed to listen: %w", err)
}
go srv.Run(ctx, lns)
clientOpts.ServerAddr = fmt.Sprintf("%s:%d", *address, *port)
Expand All @@ -236,7 +236,7 @@ func StartLocalServer(ctx context.Context, clientOpts *apiclient.ClientOptions,
}
time.Sleep(time.Second)
}
return err
return fmt.Errorf("all retries failed: %w", err)
}

// NewClientOrDie creates a new API client from a set of config options, or fails fatally if the new client creation fails.
Expand Down
2 changes: 1 addition & 1 deletion controller/clusterinfoupdater.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *clusterInfoUpdater) Run(ctx context.Context) {
select {
case <-ctx.Done():
ticker.Stop()
break
return
case <-ticker.C:
c.updateClusters()
}
Expand Down

0 comments on commit f7a9090

Please sign in to comment.