Skip to content

Commit

Permalink
🐛 clean up resource's even if analysis fails (#294)
Browse files Browse the repository at this point in the history
🐛 clean up resource's even if analysis fails (#293)

Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley authored Jul 30, 2024
1 parent 8f2fa1b commit 7ecbb57
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
log.Error(err, "failed to set provider init info")
return err
}
// defer cleaning created resources here instead of PostRun
// if Run returns an error, PostRun does not run
defer func() {
if err := analyzeCmd.CleanAnalysisResources(cmd.Context()); err != nil {
log.Error(err, "failed to clean temporary directories")
}
}()
containerNetworkName, err := analyzeCmd.createContainerNetwork()
if err != nil {
log.Error(err, "failed to create container network")
Expand All @@ -267,13 +274,6 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
log.Error(err, "failed to run analysis")
return err
}
// defer cleaning created resources here instead of PostRun
// if Run returns an error, PostRun does not run
defer func() {
if err := analyzeCmd.CleanAnalysisResources(cmd.Context()); err != nil {
log.Error(err, "failed to clean temporary directories")
}
}()
} else {
err := analyzeCmd.RunAnalysisOverrideProviderSettings(cmd.Context())
if err != nil {
Expand Down

0 comments on commit 7ecbb57

Please sign in to comment.