Skip to content

Commit 7c9c205

Browse files
authored
Improve logs for ArgoCD API interaction (#5)
Add error messages for each failure type Ensure any app-specific failure fails the whole "diff" action
1 parent c7be471 commit 7c9c205

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

internal/pkg/argocd/argocd.go

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
argoio "github.com/argoproj/argo-cd/v2/util/io"
2020
"github.com/argoproj/gitops-engine/pkg/sync/hook"
2121
"github.com/google/go-cmp/cmp"
22+
log "github.com/sirupsen/logrus"
2223
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2324
)
2425

@@ -185,13 +186,15 @@ func generateDiffOfAComponent(ctx context.Context, componentPath string, prBranc
185186
app, err := appIf.Get(ctx, &appNameQuery)
186187
if err != nil {
187188
componentDiffResult.DiffError = err
189+
log.Errorf("Error getting app %s: %v", foundApps.Items[0].Name, err)
188190
return componentDiffResult
189191
}
190192
componentDiffResult.ArgoCdAppName = app.Name
191193
componentDiffResult.ArgoCdAppURL = fmt.Sprintf("%s/applications/%s", argoSettings.URL, app.Name)
192194
resources, err := appIf.ManagedResources(ctx, &application.ResourcesQuery{ApplicationName: &app.Name, AppNamespace: &app.Namespace})
193195
if err != nil {
194196
componentDiffResult.DiffError = err
197+
log.Errorf("Error getting (live)resources for app %s: %v", app.Name, err)
195198
return componentDiffResult
196199
}
197200

@@ -206,6 +209,7 @@ func generateDiffOfAComponent(ctx context.Context, componentPath string, prBranc
206209
manifests, err := appIf.GetManifests(ctx, &manifestQuery)
207210
if err != nil {
208211
componentDiffResult.DiffError = err
212+
log.Errorf("Error getting manifests for app %s, revision %s: %v", app.Name, prBranch, err)
209213
return componentDiffResult
210214
}
211215
diffOption.res = manifests
@@ -215,6 +219,7 @@ func generateDiffOfAComponent(ctx context.Context, componentPath string, prBranc
215219
detailedProject, err := projIf.GetDetailedProject(ctx, &projectpkg.ProjectQuery{Name: app.Spec.Project})
216220
if err != nil {
217221
componentDiffResult.DiffError = err
222+
log.Errorf("Error getting project %s: %v", app.Spec.Project, err)
218223
return componentDiffResult
219224
}
220225

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

0 commit comments

Comments
 (0)