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
…#125)

Closes #100
  • Loading branch information
fritzduchardt authored Nov 1, 2023
1 parent b29f264 commit cfedbde
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/logrusorgru/aurora/v4"
aurora "github.com/logrusorgru/aurora/v4"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down
56 changes: 31 additions & 25 deletions internal/myks/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,37 @@ 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 +202,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 cfedbde

Please sign in to comment.