Skip to content

Commit

Permalink
add a bunch more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
djeebus committed Dec 19, 2023
1 parent 5bf3b3f commit d1291b3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
6 changes: 5 additions & 1 deletion pkg/config/app_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func (d *AppDirectory) FindAppsBasedOnChangeList(changeList []string, targetBran
log.Debug().Msgf("change: %s", changePath)

for dir, appNames := range d.appDirs {
log.Debug().Msgf("- app path: %s", dir)
if strings.HasPrefix(changePath, dir) {
log.Debug().Msg("dir match!")
for _, appName := range appNames {
Expand Down Expand Up @@ -147,6 +146,11 @@ func (d *AppDirectory) GetApps(filter func(stub v1alpha1.Application) bool) []v1
}

func (d *AppDirectory) AddApp(app v1alpha1.Application) {
log.Debug().
Str("appName", app.Name).
Str("cluster-name", app.Spec.Destination.Name).
Str("cluster-server", app.Spec.Destination.Server).
Msg("found app")
d.appsMap[app.Name] = app
d.AddDir(app.Name, getSourcePath(app))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ changedFilePath should be the root of the changed folder
from https://github.com/argoproj/argo-cd/blob/d3ff9757c460ae1a6a11e1231251b5d27aadcdd1/cmd/argocd/commands/app.go#L879
*/
func GetDiff(ctx context.Context, name string, manifests []string, app argoappv1.Application, addApp func(argoappv1.Application)) (pkg.CheckResult, string, error) {
func GetDiff(ctx context.Context, manifests []string, app argoappv1.Application, addApp func(argoappv1.Application)) (pkg.CheckResult, string, error) {
ctx, span := otel.Tracer("Kubechecks").Start(ctx, "GetDiff")
defer span.End()

argoClient := argo_client.GetArgoClient()

log.Debug().Str("name", name).Msg("generating diff for application...")
log.Debug().Str("name", app.Name).Msg("generating diff for application...")

settingsCloser, settingsClient := argoClient.GetSettingsClient()
defer settingsCloser.Close()
Expand Down
33 changes: 16 additions & 17 deletions pkg/events/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type CheckEvent struct {

cfg *config.ServerConfig

createdApps map[string]v1alpha1.Application
addedAppsSet map[string]struct{}
appChannel chan *v1alpha1.Application
doneChannel chan bool
Expand All @@ -54,10 +53,9 @@ var inFlight int32

func NewCheckEvent(repo *repo.Repo, client pkg.Client, cfg *config.ServerConfig) *CheckEvent {
ce := &CheckEvent{
cfg: cfg,
client: client,
createdApps: make(map[string]v1alpha1.Application),
repo: repo,
cfg: cfg,
client: client,
repo: repo,
}

ce.logger = log.Logger.With().Str("repo", repo.Name).Int("event_id", repo.CheckID).Logger()
Expand Down Expand Up @@ -257,14 +255,18 @@ func (ce *CheckEvent) queueApp(app v1alpha1.Application) {
name := app.Name
dir := app.Spec.GetSource().Path

ce.logger.Debug().Str("app", name).Str("dir", dir).Msg("producing app on channel")
ce.logger.Debug().
Str("app", name).
Str("dir", dir).
Str("cluster-name", app.Spec.Destination.Name).
Str("cluster-server", app.Spec.Destination.Server).
Msg("producing app on channel")

key := fmt.Sprintf("%s::%s", name, dir)
if _, ok := ce.addedAppsSet[key]; ok {
if _, ok := ce.addedAppsSet[name]; ok {
return
}

ce.addedAppsSet[key] = struct{}{}
ce.addedAppsSet[name] = struct{}{}
ce.appChannel <- &app
}

Expand Down Expand Up @@ -317,7 +319,7 @@ func (ce *CheckEvent) processApp(ctx context.Context, app v1alpha1.Application)
ce.vcsNote.AddNewApp(ctx, appName)

ce.logger.Debug().Msgf("Getting manifests for app: %s with code at %s/%s", appName, ce.TempWorkingDir, dir)
manifests, err := argo_client.GetManifestsLocal(ctx, appName, ce.TempWorkingDir, dir, ce.createdApps[appName])
manifests, err := argo_client.GetManifestsLocal(ctx, appName, ce.TempWorkingDir, dir, app)
if err != nil {
ce.logger.Error().Err(err).Msgf("Unable to get manifests for %s in %s", appName, dir)
cr := pkg.CheckResult{State: pkg.StateError, Summary: "Unable to get manifests", Details: fmt.Sprintf("```\n%s\n```", ce.cleanupGetManifestsError(err))}
Expand All @@ -343,10 +345,7 @@ func (ce *CheckEvent) processApp(ctx context.Context, app v1alpha1.Application)
run := ce.createRunner(span, ctx, appName, &wg)

run("validating app against schema", ce.validateSchemas(ctx, appName, k8sVersion, ce.TempWorkingDir, formattedManifests))
run("generating diff for app", ce.generateDiff(ctx, appName, manifests, func(app v1alpha1.Application) {
ce.createdApps[app.Name] = app
ce.queueApp(app)
}))
run("generating diff for app", ce.generateDiff(ctx, app, manifests, ce.queueApp))

if viper.GetBool("enable-conftest") {
run("validation policy", ce.validatePolicy(ctx, appName))
Expand Down Expand Up @@ -436,14 +435,14 @@ func (ce *CheckEvent) validatePolicy(ctx context.Context, app string) func() (pk
}
}

func (ce *CheckEvent) generateDiff(ctx context.Context, appName string, manifests []string, addApp func(app v1alpha1.Application)) func() (pkg.CheckResult, error) {
func (ce *CheckEvent) generateDiff(ctx context.Context, app v1alpha1.Application, manifests []string, addApp func(app v1alpha1.Application)) func() (pkg.CheckResult, error) {
return func() (pkg.CheckResult, error) {
cr, rawDiff, err := diff.GetDiff(ctx, appName, manifests, ce.createdApps[appName], addApp)
cr, rawDiff, err := diff.GetDiff(ctx, manifests, app, addApp)
if err != nil {
return pkg.CheckResult{}, err
}

diff.AIDiffSummary(ctx, ce.vcsNote, appName, manifests, rawDiff)
diff.AIDiffSummary(ctx, ce.vcsNote, app.Name, manifests, rawDiff)

return cr, nil
}
Expand Down

0 comments on commit d1291b3

Please sign in to comment.