Skip to content

Commit 23915f2

Browse files
wkingeparis
authored andcommitted
installer/*: Add --continue-on-error to destroy workflow
This would let us skip destroying things like worker machines. Useful if the API never came up. As those resources can't exist yet. I'm currently not passing the continue-on-error down into the individual steps, but we could do that later if we need more granularity.
1 parent a6f7f67 commit 23915f2

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

installer/cmd/tectonic/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ var (
1616
clusterInstallCommand = kingpin.Command("install", "Create a new Tectonic cluster")
1717
clusterInstallDirFlag = clusterInstallCommand.Flag("dir", "Cluster directory").Default(".").ExistingDir()
1818

19-
clusterDestroyCommand = kingpin.Command("destroy", "Destroy an existing Tectonic cluster")
20-
clusterDestroyDirFlag = clusterDestroyCommand.Flag("dir", "Cluster directory").Default(".").ExistingDir()
19+
clusterDestroyCommand = kingpin.Command("destroy", "Destroy an existing Tectonic cluster")
20+
clusterDestroyDirFlag = clusterDestroyCommand.Flag("dir", "Cluster directory").Default(".").ExistingDir()
21+
clusterDestroyContOnErr = clusterDestroyCommand.Flag("continue-on-error", "Log errors, but attempt to continue cleaning up the cluster. THIS MAY LEAK RESOURCES, because you may not have enough state left after a partial removal to be able to perform a second destroy.").Default("false").Bool()
2122

2223
convertCommand = kingpin.Command("convert", "Convert a tfvars.json to a Tectonic config.yaml")
2324
convertConfigFlag = convertCommand.Flag("config", "tfvars.json file").Required().ExistingFile()
@@ -34,7 +35,7 @@ func main() {
3435
case clusterInstallCommand.FullCommand():
3536
w = workflow.InstallWorkflow(*clusterInstallDirFlag)
3637
case clusterDestroyCommand.FullCommand():
37-
w = workflow.DestroyWorkflow(*clusterDestroyDirFlag)
38+
w = workflow.DestroyWorkflow(*clusterDestroyDirFlag, *clusterDestroyContOnErr)
3839
case convertCommand.FullCommand():
3940
w = workflow.ConvertWorkflow(*convertConfigFlag)
4041
}

installer/pkg/workflow/destroy.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ const (
2222
// DestroyWorkflow creates new instances of the 'destroy' workflow,
2323
// responsible for running the actions required to remove resources
2424
// of an existing cluster and clean up any remaining artefacts.
25-
func DestroyWorkflow(clusterDir string) Workflow {
25+
func DestroyWorkflow(clusterDir string, contOnErr bool) Workflow {
2626
return Workflow{
27-
metadata: metadata{clusterDir: clusterDir},
27+
metadata: metadata{
28+
clusterDir: clusterDir,
29+
contOnErr: contOnErr,
30+
},
2831
steps: []step{
2932
readClusterConfigStep,
3033
generateTerraformVariablesStep,

installer/pkg/workflow/workflow.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package workflow
22

3-
import "github.com/openshift/installer/installer/pkg/config"
3+
import (
4+
log "github.com/Sirupsen/logrus"
5+
"github.com/openshift/installer/installer/pkg/config"
6+
)
47

58
// metadata is the state store of the current workflow execution.
69
// It is meant to carry state for one step to another.
@@ -12,6 +15,7 @@ type metadata struct {
1215
cluster config.Cluster
1316
configFilePath string
1417
clusterDir string
18+
contOnErr bool
1519
}
1620

1721
// step is the entrypoint of a workflow step implementation.
@@ -28,11 +32,18 @@ type Workflow struct {
2832

2933
// Execute runs all steps in order.
3034
func (w Workflow) Execute() error {
35+
var firstError error
3136
for _, step := range w.steps {
3237
if err := step(&w.metadata); err != nil {
33-
return err
38+
if !w.metadata.contOnErr {
39+
return err
40+
}
41+
if firstError == nil {
42+
firstError = err
43+
}
44+
log.Warn(err)
3445
}
3546
}
3647

37-
return nil
48+
return firstError
3849
}

0 commit comments

Comments
 (0)