Skip to content

Commit

Permalink
Improve logs for ArgoCD API interaction (#5)
Browse files Browse the repository at this point in the history
Add error messages for each failure type
Ensure any app-specific failure fails the whole "diff" action
  • Loading branch information
Oded-B authored May 8, 2024
1 parent c7be471 commit 7c9c205
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
argoio "github.com/argoproj/argo-cd/v2/util/io"
"github.com/argoproj/gitops-engine/pkg/sync/hook"
"github.com/google/go-cmp/cmp"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

Expand Down Expand Up @@ -185,13 +186,15 @@ func generateDiffOfAComponent(ctx context.Context, componentPath string, prBranc
app, err := appIf.Get(ctx, &appNameQuery)
if err != nil {
componentDiffResult.DiffError = err
log.Errorf("Error getting app %s: %v", foundApps.Items[0].Name, err)
return componentDiffResult
}
componentDiffResult.ArgoCdAppName = app.Name
componentDiffResult.ArgoCdAppURL = fmt.Sprintf("%s/applications/%s", argoSettings.URL, app.Name)
resources, err := appIf.ManagedResources(ctx, &application.ResourcesQuery{ApplicationName: &app.Name, AppNamespace: &app.Namespace})
if err != nil {
componentDiffResult.DiffError = err
log.Errorf("Error getting (live)resources for app %s: %v", app.Name, err)
return componentDiffResult
}

Expand All @@ -206,6 +209,7 @@ func generateDiffOfAComponent(ctx context.Context, componentPath string, prBranc
manifests, err := appIf.GetManifests(ctx, &manifestQuery)
if err != nil {
componentDiffResult.DiffError = err
log.Errorf("Error getting manifests for app %s, revision %s: %v", app.Name, prBranch, err)
return componentDiffResult
}
diffOption.res = manifests
Expand All @@ -215,6 +219,7 @@ func generateDiffOfAComponent(ctx context.Context, componentPath string, prBranc
detailedProject, err := projIf.GetDetailedProject(ctx, &projectpkg.ProjectQuery{Name: app.Spec.Project})
if err != nil {
componentDiffResult.DiffError = err
log.Errorf("Error getting project %s: %v", app.Spec.Project, err)
return componentDiffResult
}

Expand Down Expand Up @@ -262,6 +267,7 @@ func GenerateDiffOfChangedComponents(ctx context.Context, componentPathList []st
currentDiffResult := generateDiffOfAComponent(ctx, componentPath, prBranch, repo, appIf, projIf, argoSettings)
if currentDiffResult.DiffError != nil {
hasComponentDiffErrors = true
err = currentDiffResult.DiffError
}
if currentDiffResult.HasDiff {
hasComponentDiff = true
Expand Down

0 comments on commit 7c9c205

Please sign in to comment.