Skip to content

Commit

Permalink
fix(clean-up): Call env cleanup method when executing render and sync
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzduchardt committed Nov 1, 2023
1 parent b6dd8bb commit 82e52fb
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions internal/myks/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,38 @@ func (e *Environment) Render(asyncLevel int) error {
return e.Cleanup()
}

func (e *Environment) SyncAndRender(asyncLevel int, vendirSecrets string) error {
if err := e.renderArgoCD(); err != nil {
return err
}
err := process(asyncLevel, e.Applications, func(item interface{}) error {
app, ok := item.(*Application)
if !ok {
return fmt.Errorf("Unable to cast item to *Application")
}
if err := app.Sync(vendirSecrets); err != nil {
return err
}
yamlTemplatingTools := []YamlTemplatingTool{
&Helm{ident: "helm", app: app, additive: true},
&YttPkg{ident: "ytt-pkg", app: app, additive: true},
&Ytt{ident: "ytt", app: app, additive: false},
&GlobalYtt{ident: "global-ytt", app: app, additive: false},
}
if err := app.RenderAndSlice(yamlTemplatingTools); err != nil {
return err
}
return app.renderArgoCD()
})

if err != nil {
log.Error().Err(err).Msg(e.Msg("Unable to sync and render applications"))
return err
}

return e.Cleanup()
}

func (e *Environment) Cleanup() error {
apps, err := e.renderedApplications()
if err != nil {
Expand Down Expand Up @@ -171,31 +203,6 @@ func (e *Environment) missingApplications() ([]string, error) {
return missingApps, nil
}

func (e *Environment) SyncAndRender(asyncLevel int, vendirSecrets string) error {
if err := e.renderArgoCD(); err != nil {
return err
}
return process(asyncLevel, e.Applications, func(item interface{}) error {
app, ok := item.(*Application)
if !ok {
return fmt.Errorf("Unable to cast item to *Application")
}
if err := app.Sync(vendirSecrets); err != nil {
return err
}
yamlTemplatingTools := []YamlTemplatingTool{
&Helm{ident: "helm", app: app, additive: true},
&YttPkg{ident: "ytt-pkg", app: app, additive: true},
&Ytt{ident: "ytt", app: app, additive: false},
&GlobalYtt{ident: "global-ytt", app: app, additive: false},
}
if err := app.RenderAndSlice(yamlTemplatingTools); err != nil {
return err
}
return app.renderArgoCD()
})
}

func (e *Environment) setId() error {
yamlBytes, err := os.ReadFile(e.EnvironmentDataFile)
if err != nil {
Expand Down

0 comments on commit 82e52fb

Please sign in to comment.