-
Notifications
You must be signed in to change notification settings - Fork 787
/
delete_gke.go
79 lines (71 loc) · 1.91 KB
/
delete_gke.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package deletecmd
import (
"errors"
"github.com/jenkins-x/jx/v2/pkg/cloud"
"github.com/jenkins-x/jx/v2/pkg/cmd/get"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/spf13/cobra"
)
// DeleteGkeOptions Options for deleting a GKE cluster
type DeleteGkeOptions struct {
get.GetOptions
Region string
ProjectID string
}
var (
deleteGkeLong = templates.LongDesc(`
Deletes GKE cluster resource.
`)
deleteGkeExample = templates.Examples(`
# Delete GKE cluster
jx delete gke
`)
)
// NewCmdDeleteGke command for deleting a GKE cluster
func NewCmdDeleteGke(commonOpts *opts.CommonOptions) *cobra.Command {
options := &DeleteGkeOptions{
GetOptions: get.GetOptions{
CommonOptions: commonOpts,
},
}
cmd := &cobra.Command{
Use: "gke",
Short: "Deletes GKE cluster.",
Long: deleteGkeLong,
Example: deleteGkeExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
helper.CheckErr(err)
},
}
cmd.Flags().StringVarP(&options.Region, "region", "", "europe-west1-c", "GKE region to use. Default: europe-west1-c")
cmd.Flags().StringVarP(&options.ProjectID, "project-id", "p", "", "Google Project ID to delete cluster from")
options.AddGetFlags(cmd)
return cmd
}
// Run implements this command
func (o *DeleteGkeOptions) Run() error {
if len(o.Args) == 0 {
return errors.New("cluster name expected")
}
cluster := o.Args[0]
err := o.InstallRequirements(cloud.GKE)
if err != nil {
return err
}
args := []string{"container", "clusters", "delete", cluster, "--region=" + o.Region, "--quiet", "--async"}
if o.ProjectID != "" {
args = append(args, "--project="+o.ProjectID)
}
log.Logger().Info("Deleting cluster ...")
err = o.RunCommand("gcloud", args...)
if err != nil {
return err
}
return nil
}