Skip to content
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
5 changes: 4 additions & 1 deletion cmd/devstream/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/devstream-io/devstream/pkg/util/log"
)

var isForceDestroy bool

var destroyCMD = &cobra.Command{
Use: "destroy",
Short: "Destroy DevOps tools deployment according to DevStream configuration file & state file",
Expand All @@ -19,14 +21,15 @@ var destroyCMD = &cobra.Command{

func destroyCMDFunc(cmd *cobra.Command, args []string) {
log.Info("Destroy started.")
if err := pluginengine.Destroy(configFile, continueDirectly); err != nil {
if err := pluginengine.Destroy(configFile, continueDirectly, isForceDestroy); err != nil {
log.Errorf("Destroy failed => %s.", err)
os.Exit(1)
}
log.Success("Destroy finished.")
}

func init() {
destroyCMD.Flags().BoolVarP(&isForceDestroy, "force", "", false, "force destroy by config")
destroyCMD.Flags().StringVarP(&configFile, configFlagName, "f", "config.yaml", "config file")
destroyCMD.Flags().BoolVarP(&continueDirectly, "yes", "y", false, "destroy directly without confirmation")

Expand Down
8 changes: 7 additions & 1 deletion internal/pkg/pluginengine/change_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func changesForDelete(smgr statemanager.Manager, cfg *configmanager.Config, isFo
return changes, nil
}

func GetChangesForDestroy(smgr statemanager.Manager) ([]*Change, error) {
func GetChangesForDestroy(smgr statemanager.Manager, isForceDestroy bool) ([]*Change, error) {
changes := make([]*Change, 0)

// rebuilding tools from config
Expand All @@ -210,6 +210,12 @@ func GetChangesForDestroy(smgr statemanager.Manager) ([]*Change, error) {
for i := len(batchesOfTools) - 1; i >= 0; i-- {
batch := batchesOfTools[i]
for _, tool := range batch {
if !isForceDestroy {
state := smgr.GetState(statemanager.StateKeyGenerateFunc(&tool))
if state == nil {
continue
}
}
description := fmt.Sprintf("Tool (%s/%s) will be deleted.", tool.Name, tool.InstanceID)
changes = append(changes, generateDeleteAction(&tool, description))
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/pluginengine/cmd_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/devstream-io/devstream/pkg/util/log"
)

func Destroy(configFile string, continueDirectly bool) error {
func Destroy(configFile string, continueDirectly bool, isForceDestroy bool) error {
cfg, err := configmanager.NewManager(configFile).LoadConfig()
if err != nil {
return err
Expand All @@ -30,7 +30,7 @@ func Destroy(configFile string, continueDirectly bool) error {
return err
}

changes, err := GetChangesForDestroy(smgr)
changes, err := GetChangesForDestroy(smgr, isForceDestroy)
if err != nil {
log.Debugf("Get changes failed: %s.", err)
return err
Expand Down