Skip to content

Commit

Permalink
Added confirmation for storage deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
surajnarwade committed May 23, 2018
1 parent 7108574 commit 7b78a4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"strings"

"github.com/redhat-developer/odo/pkg/application"
"github.com/redhat-developer/odo/pkg/project"
Expand All @@ -10,9 +11,10 @@ import (
)

var (
storageComponent string
storageSize string
storagePath string
storageComponent string
storageSize string
storagePath string
storageForceDeleteflag bool
)

var storageCmd = &cobra.Command{
Expand Down Expand Up @@ -50,10 +52,20 @@ var storageDeleteCmd = &cobra.Command{
checkError(err, "")
projectName := project.GetCurrent(client)
componentName := getComponent(client, storageComponent, applicationName, projectName)

err = storage.Remove(client, storageName, componentName, applicationName)
checkError(err, "failed to delete storage")
fmt.Printf("Deleted %v from %v\n", storageName, componentName)
var confirmDeletion string
if storageForceDeleteflag {
confirmDeletion = "y"
} else {
fmt.Printf("Are you sure you want to delete the storage: %v? [y/N] ", storageName)
fmt.Scanln(&confirmDeletion)
}
if strings.ToLower(confirmDeletion) == "y" {
err = storage.Remove(client, storageName, componentName, applicationName)
checkError(err, "failed to delete storage")
fmt.Printf("Deleted %v from %v\n", storageName, componentName)
} else {
fmt.Printf("Aborting deletion of storage: %v\n", storageName)
}
},
}

Expand Down Expand Up @@ -83,6 +95,7 @@ var storageListCmd = &cobra.Command{
}

func init() {
storageDeleteCmd.Flags().BoolVarP(&storageForceDeleteflag, "force", "f", false, "Delete storage without prompting")
storageCreateCmd.Flags().StringVar(&storageSize, "size", "", "Size of storage to add")
storageCreateCmd.MarkFlagRequired("size")
storageCreateCmd.Flags().StringVar(&storagePath, "path", "", "Path to mount the storage on")
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ var _ = Describe("odoe2e", func() {

// TODO: Verify if the storage removed using odo deletes pvc
It("should be able to delete the storage added", func() {
runCmd("odo storage delete pv1")
runCmd("odo storage delete pv1 -f")

storList := runCmd("odo storage list")
Expect(storList).NotTo(ContainSubstring("pv1"))
Expand Down

0 comments on commit 7b78a4d

Please sign in to comment.