Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
637 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package step | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
// Execute behavior is based on chose cleanup method. It is intended to be used with AddFlags | ||
func (r *Runner) Execute(steps []Step) error { | ||
r.log.Infof("Cleanup mode: %s", r.cleanup) | ||
var err error | ||
switch r.cleanup { | ||
case CleanupModeNo: | ||
err = r.Run(steps, true) | ||
case CleanupModeOnly: | ||
r.Cleanup(steps) | ||
case CleanupModeYes: | ||
err = r.Run(steps, false) | ||
case CleanupModeOnErrorOnly: | ||
err = r.Run(steps, true) | ||
if err != nil { | ||
r.Cleanup(steps) | ||
} | ||
} | ||
return err | ||
} | ||
|
||
// AddFlags add CLI flags so user may control runner behaviour easily | ||
func (r *Runner) AddFlags(set *pflag.FlagSet) { | ||
set.Var(&r.cleanup, "cleanup", "Cleanup mode. Allowed values: yes/no/only") | ||
} | ||
|
||
// CleanupMode says how runner should execute cleanup | ||
type CleanupMode string | ||
|
||
const ( | ||
// CleanupModeNo - Don't execute cleanup | ||
CleanupModeNo CleanupMode = "no" | ||
// CleanupModeOnly - Don't run steps, only cleanup | ||
CleanupModeOnly CleanupMode = "only" | ||
// Execute both steps and cleanup | ||
CleanupModeYes CleanupMode = "yes" | ||
// Execute steps. If steps fail then run cleanup. Keep resources in case of success | ||
CleanupModeOnErrorOnly CleanupMode = "onerroronly" | ||
) | ||
|
||
// String implements pflag.Value.String | ||
func (m CleanupMode) String() string { | ||
return string(m) | ||
} | ||
|
||
// Set implements pflag.Value.Set | ||
func (m *CleanupMode) Set(v string) error { | ||
switch CleanupMode(v) { | ||
case CleanupModeNo, CleanupModeYes, CleanupModeOnly, CleanupModeOnErrorOnly: | ||
default: | ||
return errors.Errorf("invalid cleanup value: %s", v) | ||
} | ||
*m = CleanupMode(v) | ||
return nil | ||
} | ||
|
||
// Type implements pflag.Value.Type | ||
func (m CleanupMode) Type() string { | ||
return "runner mode" | ||
} |
Oops, something went wrong.