Skip to content

Commit

Permalink
🐛 clean up resource's even if analysis fails (#293)
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley authored Jul 30, 2024
1 parent c93c6cc commit c5a6351
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 c5a6351

Please sign in to comment.