Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db): Do not write argo apps if disabled #1989

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading