Skip to content
Merged
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
10 changes: 10 additions & 0 deletions cmd/openshift-install/destroy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"os"
"path/filepath"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -16,6 +19,7 @@ import (
_ "github.com/openshift/installer/pkg/destroy/openstack"
_ "github.com/openshift/installer/pkg/destroy/ovirt"
_ "github.com/openshift/installer/pkg/destroy/vsphere"
"github.com/openshift/installer/pkg/terraform"
)

func newDestroyCmd() *cobra.Command {
Expand Down Expand Up @@ -73,6 +77,12 @@ func runDestroyCmd(directory string) error {
return errors.Wrap(err, "failed to remove state file")
}

tfStateFilePath := filepath.Join(directory, terraform.StateFileName)
err = os.Remove(tfStateFilePath)
if err != nil && !os.IsNotExist(err) {
return errors.Wrap(err, "failed to remove Terraform state")
}
Copy link
Contributor

@patrickdillon patrickdillon Sep 30, 2019

Choose a reason for hiding this comment

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

You might be able to tighten this up a little:

if err = os.Remove(tfStateFilePath); !os.IsNotExist(err) {
		return errors.Wrap(err, "failed to remove Terraform state")
	}

(stolen from here)

Copy link
Member Author

Choose a reason for hiding this comment

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

if err = os.Remove(tfStateFilePath); !os.IsNotExist(err) {

We don't want to error on nil, and IsNotExist(nil) is false. I like separating the call from the error-handling conditionals, but I can squash down to:

if err = os.Remove(tfStateFilePath); err != nil && !os.IsNotExist(err) {

if folks see that as a blocker ;).

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want to error on nil

Oh of course. I left out the most important condition. Nvm!


return nil
}

Expand Down