Skip to content

Commit

Permalink
fix(db): Do not write argo apps if disabled (#1989)
Browse files Browse the repository at this point in the history
While the helm parameter argocd.generateFiles=false technically worked,
it would still request a lot of data that is not necessary. With this
change, we reduce the number of queries to the database, 
for the case argocd.generateFiles=false.

Ref: SRX-YNEAHU
  • Loading branch information
sven-urbanski-freiheit-com authored Sep 27, 2024
1 parent 1182251 commit 5db1f4b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
33 changes: 17 additions & 16 deletions services/cd-service/pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,9 @@ func (r *repository) afterTransform(ctx context.Context, state State, transactio
func (r *repository) updateArgoCdApps(ctx context.Context, state *State, env string, config config.EnvironmentConfig, transaction *sql.Tx) error {
span, ctx := tracer.StartSpanFromContext(ctx, "updateArgoCdApps")
defer span.Finish()
if !r.config.ArgoCdGenerateFiles {
return nil
}
fs := state.Filesystem
if apps, err := state.GetEnvironmentApplications(ctx, transaction, env); err != nil {
return err
Expand Down Expand Up @@ -1219,22 +1222,20 @@ func (r *repository) updateArgoCdApps(ctx context.Context, state *State, env str
}
spanCollectData.Finish()

if r.config.ArgoCdGenerateFiles {
spanRenderAndWrite, ctx := tracer.StartSpanFromContext(ctx, "RenderAndWrite")
defer spanRenderAndWrite.Finish()
if manifests, err := argocd.Render(ctx, r.config.URL, r.config.Branch, config, env, appData); err != nil {
return err
} else {
spanWrite, _ := tracer.StartSpanFromContext(ctx, "Write")
defer spanWrite.Finish()
for apiVersion, content := range manifests {
if err := fs.MkdirAll(fs.Join("argocd", string(apiVersion)), 0777); err != nil {
return err
}
target := fs.Join("argocd", string(apiVersion), fmt.Sprintf("%s.yaml", env))
if err := util.WriteFile(fs, target, content, 0666); err != nil {
return err
}
spanRenderAndWrite, ctx := tracer.StartSpanFromContext(ctx, "RenderAndWrite")
defer spanRenderAndWrite.Finish()
if manifests, err := argocd.Render(ctx, r.config.URL, r.config.Branch, config, env, appData); err != nil {
return err
} else {
spanWrite, _ := tracer.StartSpanFromContext(ctx, "Write")
defer spanWrite.Finish()
for apiVersion, content := range manifests {
if err := fs.MkdirAll(fs.Join("argocd", string(apiVersion)), 0777); err != nil {
return err
}
target := fs.Join("argocd", string(apiVersion), fmt.Sprintf("%s.yaml", env))
if err := util.WriteFile(fs, target, content, 0666); err != nil {
return err
}
}
}
Expand Down
33 changes: 17 additions & 16 deletions services/manifest-repo-export-service/pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,9 @@ func (r *repository) afterTransform(ctx context.Context, transaction *sql.Tx, st
func (r *repository) updateArgoCdApps(ctx context.Context, transaction *sql.Tx, state *State, env string, config config.EnvironmentConfig) error {
span, ctx := tracer.StartSpanFromContext(ctx, "updateArgoCdApps")
defer span.Finish()
if !r.config.ArgoCdGenerateFiles {
return nil
}
fs := state.Filesystem
if apps, err := state.GetEnvironmentApplications(ctx, transaction, env); err != nil {
return err
Expand Down Expand Up @@ -759,22 +762,20 @@ func (r *repository) updateArgoCdApps(ctx context.Context, transaction *sql.Tx,
}
spanCollectData.Finish()

if r.config.ArgoCdGenerateFiles {
spanRenderAndWrite, ctx := tracer.StartSpanFromContext(ctx, "RenderAndWrite")
defer spanRenderAndWrite.Finish()
if manifests, err := argocd.Render(ctx, r.config.URL, r.config.Branch, config, env, appData); err != nil {
return err
} else {
spanWrite, _ := tracer.StartSpanFromContext(ctx, "Write")
defer spanWrite.Finish()
for apiVersion, content := range manifests {
if err := fs.MkdirAll(fs.Join("argocd", string(apiVersion)), 0777); err != nil {
return err
}
target := fs.Join("argocd", string(apiVersion), fmt.Sprintf("%s.yaml", env))
if err := util.WriteFile(fs, target, content, 0666); err != nil {
return err
}
spanRenderAndWrite, ctx := tracer.StartSpanFromContext(ctx, "RenderAndWrite")
defer spanRenderAndWrite.Finish()
if manifests, err := argocd.Render(ctx, r.config.URL, r.config.Branch, config, env, appData); err != nil {
return err
} else {
spanWrite, _ := tracer.StartSpanFromContext(ctx, "Write")
defer spanWrite.Finish()
for apiVersion, content := range manifests {
if err := fs.MkdirAll(fs.Join("argocd", string(apiVersion)), 0777); err != nil {
return err
}
target := fs.Join("argocd", string(apiVersion), fmt.Sprintf("%s.yaml", env))
if err := util.WriteFile(fs, target, content, 0666); err != nil {
return err
}
}
}
Expand Down

0 comments on commit 5db1f4b

Please sign in to comment.