Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installer/*: Add --continue-on-error to destroy workflow #252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions installer/cmd/tectonic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ var (
clusterInstallCommand = kingpin.Command("install", "Create a new Tectonic cluster")
clusterInstallDirFlag = clusterInstallCommand.Flag("dir", "Cluster directory").Default(".").ExistingDir()

clusterDestroyCommand = kingpin.Command("destroy", "Destroy an existing Tectonic cluster")
clusterDestroyDirFlag = clusterDestroyCommand.Flag("dir", "Cluster directory").Default(".").ExistingDir()
clusterDestroyCommand = kingpin.Command("destroy", "Destroy an existing Tectonic cluster")
clusterDestroyDirFlag = clusterDestroyCommand.Flag("dir", "Cluster directory").Default(".").ExistingDir()
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is there a precedent for --continue-on-error? --keep-going is in Make. Consistency with existing tools isn't critical, but it's nice to reuse existing wording where we can.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of spf13/pflag which is, admittedly, obscure.


convertCommand = kingpin.Command("convert", "Convert a tfvars.json to a Tectonic config.yaml")
convertConfigFlag = convertCommand.Flag("config", "tfvars.json file").Required().ExistingFile()
Expand All @@ -34,7 +35,7 @@ func main() {
case clusterInstallCommand.FullCommand():
w = workflow.InstallWorkflow(*clusterInstallDirFlag)
case clusterDestroyCommand.FullCommand():
w = workflow.DestroyWorkflow(*clusterDestroyDirFlag)
w = workflow.DestroyWorkflow(*clusterDestroyDirFlag, *clusterDestroyContOnErr)
case convertCommand.FullCommand():
w = workflow.ConvertWorkflow(*convertConfigFlag)
}
Expand Down
7 changes: 5 additions & 2 deletions installer/pkg/workflow/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ const (
// DestroyWorkflow creates new instances of the 'destroy' workflow,
// responsible for running the actions required to remove resources
// of an existing cluster and clean up any remaining artefacts.
func DestroyWorkflow(clusterDir string) Workflow {
func DestroyWorkflow(clusterDir string, contOnErr bool) Workflow {
return Workflow{
metadata: metadata{clusterDir: clusterDir},
metadata: metadata{
clusterDir: clusterDir,
contOnErr: contOnErr,
},
steps: []step{
readClusterConfigStep,
generateTerraformVariablesStep,
Expand Down
17 changes: 14 additions & 3 deletions installer/pkg/workflow/workflow.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package workflow

import "github.com/openshift/installer/installer/pkg/config"
import (
log "github.com/Sirupsen/logrus"
"github.com/openshift/installer/installer/pkg/config"
)

// metadata is the state store of the current workflow execution.
// It is meant to carry state for one step to another.
Expand All @@ -12,6 +15,7 @@ type metadata struct {
cluster config.Cluster
configFilePath string
clusterDir string
contOnErr bool
}

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

// Execute runs all steps in order.
func (w Workflow) Execute() error {
var firstError error
for _, step := range w.steps {
if err := step(&w.metadata); err != nil {
return err
if !w.metadata.contOnErr {
return err
}
if firstError == nil {
firstError = err
}
log.Warn(err)
}
}

return nil
return firstError
}