Skip to content

Commit

Permalink
chore: give context to error logs (argoproj#10592) (argoproj#14915)
Browse files Browse the repository at this point in the history
* chore: wrap error objects to include context

Signed-off-by: Vipin M S <vipinachar2016@gmail.com>

* chore: wrap error objects to include context

Signed-off-by: Vipin M S <vipinachar2016@gmail.com>

* chore: wrap error objects to include context

Signed-off-by: Vipin M S <vipinachar2016@gmail.com>

* chore: wrap error objects to include context

Signed-off-by: Vipin M S <vipinachar2016@gmail.com>

* Update applicationset/controllers/applicationset_controller.go

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

---------

Signed-off-by: Vipin M S <vipinachar2016@gmail.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>
  • Loading branch information
2 people authored and tesla59 committed Dec 16, 2023
1 parent 93e597b commit 6196ab8
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (r *ApplicationSetReconciler) validateGeneratedApplications(ctx context.Con

conditions, err := argoutil.ValidatePermissions(ctx, &app.Spec, proj, r.ArgoDB)
if err != nil {
return nil, err
return nil, fmt.Errorf("error validating permissions: %s", err)
}
if len(conditions) > 0 {
errorsByIndex[i] = fmt.Errorf("application spec is invalid: %s", argoutil.FormatAppConditions(conditions))
Expand Down Expand Up @@ -692,7 +692,7 @@ func (r *ApplicationSetReconciler) getCurrentApplications(_ context.Context, app
err := r.Client.List(context.Background(), &current, client.MatchingFields{".metadata.controller": applicationSet.Name})

if err != nil {
return nil, err
return nil, fmt.Errorf("error retrieving applications: %w", err)
}

return current.Items, nil
Expand Down
4 changes: 2 additions & 2 deletions applicationset/generators/duck_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (g *DuckTypeGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.A
// ListCluster from Argo CD's util/db package will include the local cluster in the list of clusters
clustersFromArgoCD, err := utils.ListClusters(g.ctx, g.clientset, g.namespace)
if err != nil {
return nil, err
return nil, fmt.Errorf("error listing clusters: %w", err)
}

if clustersFromArgoCD == nil {
Expand All @@ -85,7 +85,7 @@ func (g *DuckTypeGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.A
cm, err := g.clientset.CoreV1().ConfigMaps(g.namespace).Get(g.ctx, appSetGenerator.ClusterDecisionResource.ConfigMapRef, metav1.GetOptions{})

if err != nil {
return nil, err
return nil, fmt.Errorf("error reading configMapRef: %w", err)
}

// Extract GVK data for the dynamic client to use
Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/generator_spec_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func GetRelevantGenerators(requestedGenerator *argoprojiov1alpha1.ApplicationSet
func flattenParameters(in map[string]interface{}) (map[string]string, error) {
flat, err := flatten.Flatten(in, "", flatten.DotStyle)
if err != nil {
return nil, err
return nil, fmt.Errorf("error flatenning parameters: %w", err)
}

out := make(map[string]string, len(flat))
Expand Down
4 changes: 2 additions & 2 deletions applicationset/generators/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (m *MatrixGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.App

g0, err := m.getParams(appSetGenerator.Matrix.Generators[0], appSet, nil)
if err != nil {
return nil, err
return nil, fmt.Errorf("error failed to get params for first generator in matrix generator: %w", err)
}
for _, a := range g0 {
g1, err := m.getParams(appSetGenerator.Matrix.Generators[1], appSet, a)
Expand Down Expand Up @@ -94,7 +94,7 @@ func (m *MatrixGenerator) getParams(appSetBaseGenerator argoprojiov1alpha1.Appli
}
mergeGen, err := getMergeGenerator(appSetBaseGenerator)
if err != nil {
return nil, err
return nil, fmt.Errorf("error retrieving merge generator: %w", err)
}
if mergeGen != nil && !appSet.Spec.ApplyNestedSelectors {
foundSelector := dropDisabledNestedSelectors(mergeGen.Generators)
Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func getMergeGenerator(r argoprojiov1alpha1.ApplicationSetNestedGenerator) (*arg
}
merge, err := argoprojiov1alpha1.ToNestedMergeGenerator(r.Merge)
if err != nil {
return nil, err
return nil, fmt.Errorf("error converting to nested merge generator: %w", err)
}
return merge.ToMergeGenerator(), nil
}
Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (g *PluginGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.App

res, err := g.generateParams(appSetGenerator, applicationSetInfo, list.Output.Parameters, appSetGenerator.Plugin.Input.Parameters, applicationSetInfo.Spec.GoTemplate)
if err != nil {
return nil, err
return nil, fmt.Errorf("error generating params: %w", err)
}

return res, nil
Expand Down
8 changes: 4 additions & 4 deletions applicationset/services/repo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func (a *argoCDService) GetFiles(ctx context.Context, repoURL string, revision s
}
closer, client, err := a.repoServerClientSet.NewRepoServerClient()
if err != nil {
return nil, err
return nil, fmt.Errorf("error initialising new repo server client: %w", err)
}
defer io.Close(closer)

fileResponse, err := client.GetGitFiles(ctx, fileRequest)
if err != nil {
return nil, err
return nil, fmt.Errorf("error retrieving Git files: %w", err)
}
return fileResponse.GetMap(), nil
}
Expand All @@ -83,13 +83,13 @@ func (a *argoCDService) GetDirectories(ctx context.Context, repoURL string, revi

closer, client, err := a.repoServerClientSet.NewRepoServerClient()
if err != nil {
return nil, err
return nil, fmt.Errorf("error initialising new repo server client: %w", err)
}
defer io.Close(closer)

dirResponse, err := client.GetGitDirectories(ctx, dirRequest)
if err != nil {
return nil, err
return nil, fmt.Errorf("error retrieving Git Directories: %w", err)
}
return dirResponse.GetPaths(), nil

Expand Down
16 changes: 8 additions & 8 deletions util/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ func (mgr *SettingsManager) GetIgnoreResourceUpdatesOverrides() (map[string]v1al
func (mgr *SettingsManager) GetIsIgnoreResourceUpdatesEnabled() (bool, error) {
argoCDCM, err := mgr.getConfigMap()
if err != nil {
return false, err
return false, fmt.Errorf("error retrieving config map: %w", err)
}

if argoCDCM.Data[resourceIgnoreResourceUpdatesEnabledKey] == "" {
Expand All @@ -834,7 +834,7 @@ func (mgr *SettingsManager) GetIsIgnoreResourceUpdatesEnabled() (bool, error) {
func (mgr *SettingsManager) GetResourceOverrides() (map[string]v1alpha1.ResourceOverride, error) {
argoCDCM, err := mgr.getConfigMap()
if err != nil {
return nil, err
return nil, fmt.Errorf("error retrieving config map: %w", err)
}
resourceOverrides := map[string]v1alpha1.ResourceOverride{}
if value, ok := argoCDCM.Data[resourceCustomizationsKey]; ok && value != "" {
Expand Down Expand Up @@ -1088,14 +1088,14 @@ func addKustomizeVersion(prefix, name, path string, kvMap map[string]KustomizeVe
func (mgr *SettingsManager) GetHelmRepositories() ([]HelmRepoCredentials, error) {
argoCDCM, err := mgr.getConfigMap()
if err != nil {
return nil, err
return nil, fmt.Errorf("error retrieving config map: %w", err)
}
helmRepositories := make([]HelmRepoCredentials, 0)
helmRepositoriesStr := argoCDCM.Data[helmRepositoriesKey]
if helmRepositoriesStr != "" {
err := yaml.Unmarshal([]byte(helmRepositoriesStr), &helmRepositories)
if err != nil {
return nil, err
return nil, fmt.Errorf("error unmarshalling helm repositories: %w", err)
}
}
return helmRepositories, nil
Expand Down Expand Up @@ -1173,7 +1173,7 @@ func (mgr *SettingsManager) GetRepositoryCredentials() ([]RepositoryCredentials,
// Get the config map outside of the lock
argoCDCM, err := mgr.getConfigMap()
if err != nil {
return nil, err
return nil, fmt.Errorf("error retrieving config map: %w", err)
}

mgr.mutex.Lock()
Expand All @@ -1194,7 +1194,7 @@ func (mgr *SettingsManager) GetRepositoryCredentials() ([]RepositoryCredentials,
func (mgr *SettingsManager) GetGoogleAnalytics() (*GoogleAnalytics, error) {
argoCDCM, err := mgr.getConfigMap()
if err != nil {
return nil, err
return nil, fmt.Errorf("error retrieving config map: %w", err)
}
return &GoogleAnalytics{
TrackingID: argoCDCM.Data[gaTrackingID],
Expand All @@ -1205,7 +1205,7 @@ func (mgr *SettingsManager) GetGoogleAnalytics() (*GoogleAnalytics, error) {
func (mgr *SettingsManager) GetHelp() (*Help, error) {
argoCDCM, err := mgr.getConfigMap()
if err != nil {
return nil, err
return nil, fmt.Errorf("error retrieving config map: %w", err)
}
chatText, ok := argoCDCM.Data[helpChatText]
if !ok {
Expand Down Expand Up @@ -1957,7 +1957,7 @@ func (mgr *SettingsManager) InitializeSettings(insecureModeEnabled bool) (*ArgoC
// set JWT signature
signature, err := util.MakeSignature(32)
if err != nil {
return nil, err
return nil, fmt.Errorf("error setting JWT signature: %w", err)
}
cdSettings.ServerSignature = signature
log.Info("Initialized server signature")
Expand Down
4 changes: 2 additions & 2 deletions util/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func generatePEM(opts CertOptions) ([]byte, []byte, error) {
func GenerateX509KeyPair(opts CertOptions) (*tls.Certificate, error) {
certpem, keypem, err := generatePEM(opts)
if err != nil {
return nil, err
return nil, fmt.Errorf("error generating X509 key pair: %w", err)
}
cert, err := tls.X509KeyPair(certpem, keypem)
if err != nil {
Expand Down Expand Up @@ -420,7 +420,7 @@ func CreateServerTLSConfig(tlsCertPath, tlsKeyPath string, hosts []string) (*tls
IsCA: false,
})
if err != nil {
return nil, err
return nil, fmt.Errorf("error generating X509 key pair: %w", err)
}
cert = c
} else {
Expand Down
4 changes: 2 additions & 2 deletions util/tls/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,15 @@ func getCert(pemCerts []byte) (*x509.Certificate, error) {
certBytes := block.Bytes
cert, err := x509.ParseCertificate(certBytes)
if err != nil {
return nil, err
return nil, fmt.Errorf("error parsing certificate: %w", err)
}
return cert, nil
}

func getCertFromFile(path string) (*x509.Certificate, error) {
certBytes, err := os.ReadFile(path)
if err != nil {
return nil, err
return nil, fmt.Errorf("error reading file: %w", err)
}
return getCert(certBytes)
}
Expand Down

0 comments on commit 6196ab8

Please sign in to comment.