Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Add --abandon and --yes flags to svcat deprovision command
Browse files Browse the repository at this point in the history
  • Loading branch information
Tara Gu committed Mar 31, 2019
1 parent 05181ac commit 72b631e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
45 changes: 44 additions & 1 deletion cmd/svcat/instance/deprovision_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ limitations under the License.
package instance

import (
"bufio"
"fmt"
"os"
"strings"

"github.com/kubernetes-incubator/service-catalog/cmd/svcat/output"
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kubernetes-incubator/service-catalog/cmd/svcat/command"
"github.com/spf13/cobra"
Expand All @@ -31,6 +35,8 @@ type deprovisonCmd struct {
*command.Waitable

instanceName string
abandon bool
skipPrompt bool
}

// NewDeprovisionCmd builds a "svcat deprovision" command
Expand All @@ -44,12 +50,26 @@ func NewDeprovisionCmd(cxt *command.Context) *cobra.Command {
Short: "Deletes an instance of a service",
Example: command.NormalizeExamples(`
svcat deprovision wordpress-mysql-instance
svcat deprovision --abandon wordpress-mysql-instance
`),
PreRunE: command.PreRunE(deprovisonCmd),
RunE: command.RunE(deprovisonCmd),
}
deprovisonCmd.AddNamespaceFlags(cmd.Flags(), false)
deprovisonCmd.AddWaitFlags(cmd)
cmd.Flags().BoolVar(
&deprovisonCmd.abandon,
"abandon",
false,
"Forcefully and immediately delete the resource from Service Catalog ONLY, potentially abandoning any broker resources that you may continue to be charged for.",
)
cmd.Flags().BoolVarP(
&deprovisonCmd.skipPrompt,
"yes",
"y",
false,
`Automatic yes to prompts. Assume "yes" as answer to all prompts and run non-interactively.`,
)

return cmd
}
Expand All @@ -68,7 +88,30 @@ func (c *deprovisonCmd) Run() error {
}

func (c *deprovisonCmd) deprovision() error {
err := c.App.Deprovision(c.Namespace, c.instanceName)
var err error
if c.abandon {
fmt.Fprintln(c.Output, "This action is not reversible and may cause you to be charged for the broker resources that are abandoned.")
if !c.skipPrompt {
fmt.Fprintln(c.Output, "Are you sure? [y|n]: ")
s := bufio.NewScanner(os.Stdin)
s.Scan()

err = s.Err()
fmt.Fprintln(c.Output, err)

if strings.ToLower(s.Text()) != "y" {
err = fmt.Errorf("aborted abandon operation")
return err
}
}

si := &v1beta1.ServiceInstance{ObjectMeta: metav1.ObjectMeta{Name: c.instanceName, Namespace: c.Namespace}}
if _, err = c.App.RemoveBindingFinalizerByInstance(si); err != nil {
return err
}
}

err = c.App.Deprovision(c.Namespace, c.instanceName)
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/svcat/testdata/output/completion-bash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ _svcat_deprovision()
flags_with_completion=()
flags_completion=()

flags+=("--abandon")
local_nonpersistent_flags+=("--abandon")
flags+=("--interval=")
local_nonpersistent_flags+=("--interval=")
flags+=("--namespace=")
Expand All @@ -382,6 +384,9 @@ _svcat_deprovision()
local_nonpersistent_flags+=("--timeout=")
flags+=("--wait")
local_nonpersistent_flags+=("--wait")
flags+=("--yes")
flags+=("-y")
local_nonpersistent_flags+=("--yes")
flags+=("--context=")
flags+=("--kubeconfig=")
flags+=("--logtostderr")
Expand Down
5 changes: 5 additions & 0 deletions cmd/svcat/testdata/output/completion-zsh.txt
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ _svcat_deprovision()
flags_with_completion=()
flags_completion=()
flags+=("--abandon")
local_nonpersistent_flags+=("--abandon")
flags+=("--interval=")
local_nonpersistent_flags+=("--interval=")
flags+=("--namespace=")
Expand All @@ -516,6 +518,9 @@ _svcat_deprovision()
local_nonpersistent_flags+=("--timeout=")
flags+=("--wait")
local_nonpersistent_flags+=("--wait")
flags+=("--yes")
flags+=("-y")
local_nonpersistent_flags+=("--yes")
flags+=("--context=")
flags+=("--kubeconfig=")
flags+=("--logtostderr")
Expand Down
12 changes: 11 additions & 1 deletion cmd/svcat/testdata/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ tree:
use: class [NAME] --from [EXISTING_NAME]
use: create
- command: ./svcat deprovision
example: ' svcat deprovision wordpress-mysql-instance'
example: |2-
svcat deprovision wordpress-mysql-instance
svcat deprovision --abandon wordpress-mysql-instance
flags:
- desc: Forcefully and immediately delete the resource from Service Catalog ONLY,
potentially abandoning any broker resources that you may continue to be charged
for.
name: abandon
- desc: 'Poll interval for --wait, specified in human readable format: 30s, 1m,
1h'
name: interval
Expand All @@ -89,6 +95,10 @@ tree:
name: timeout
- desc: Wait until the operation completes.
name: wait
- desc: Automatic yes to prompts. Assume "yes" as answer to all prompts and run
non-interactively.
name: "yes"
shorthand: "y"
name: deprovision
shortDesc: Deletes an instance of a service
use: deprovision NAME
Expand Down

0 comments on commit 72b631e

Please sign in to comment.