Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 642c504

Browse files
authored
Merge pull request #139 from mumoshu/kube-aws-node-pools-destroy-cmd
Add `kube-aws node-pools destroy` command
2 parents bf3fc63 + babd661 commit 642c504

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

cfnstack/provisioner.go

+9
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,12 @@ func (c *Provisioner) Validate(stackBody string, s3URI string) (string, error) {
281281

282282
return validationReport.String(), nil
283283
}
284+
285+
func (c *Provisioner) Destroy() error {
286+
cfSvc := cloudformation.New(c.session)
287+
dreq := &cloudformation.DeleteStackInput{
288+
StackName: aws.String(c.stackName),
289+
}
290+
_, err := cfSvc.DeleteStack(dreq)
291+
return err
292+
}

cluster/cluster.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,7 @@ func (c *Cluster) Info() (*Info, error) {
306306
}
307307

308308
func (c *Cluster) Destroy() error {
309-
cfSvc := cloudformation.New(c.session)
310-
dreq := &cloudformation.DeleteStackInput{
311-
StackName: aws.String(c.ClusterName),
312-
}
313-
_, err := cfSvc.DeleteStack(dreq)
314-
return err
309+
return c.stackProvisioner().Destroy()
315310
}
316311

317312
func (c *Cluster) validateKeyPair(ec2Svc ec2Service) error {

cmd/nodepool/destroy.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package nodepool
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
8+
"github.com/coreos/kube-aws/nodepool/cluster"
9+
"github.com/coreos/kube-aws/nodepool/config"
10+
)
11+
12+
var (
13+
cmdDestroy = &cobra.Command{
14+
Use: "destroy",
15+
Short: "Destroy an existing node pool",
16+
Long: ``,
17+
RunE: runCmdDestroy,
18+
SilenceUsage: true,
19+
}
20+
destroyOpts = struct {
21+
awsDebug bool
22+
}{}
23+
)
24+
25+
func init() {
26+
NodePoolCmd.AddCommand(cmdDestroy)
27+
cmdDestroy.Flags().BoolVar(&destroyOpts.awsDebug, "aws-debug", false, "Log debug information from aws-sdk-go library")
28+
}
29+
30+
func runCmdDestroy(cmd *cobra.Command, args []string) error {
31+
cfg, err := config.ClusterFromFile(nodePoolClusterConfigFilePath())
32+
if err != nil {
33+
return fmt.Errorf("Error parsing node pool config: %v", err)
34+
}
35+
36+
c := cluster.New(cfg, destroyOpts.awsDebug)
37+
if err := c.Destroy(); err != nil {
38+
return fmt.Errorf("Failed destroying node pool: %v", err)
39+
}
40+
41+
fmt.Println("CloudFormation stack is being destroyed. This will take several minutes")
42+
return nil
43+
}

e2e/run

+6
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ nodepool() {
238238
${KUBE_AWS_CMD} node-pools up --node-pool-name ${KUBE_AWS_POOL_NAME} --s3-uri ${KUBE_AWS_S3_URI}
239239
}
240240

241+
nodepool_destroy() {
242+
cd ${WORK_DIR}
243+
244+
${KUBE_AWS_CMD} node-pools destroy --node-pool-name ${KUBE_AWS_POOL_NAME}
245+
}
246+
241247
all() {
242248
build
243249
prepare

nodepool/cluster/cluster.go

+4
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ func (c *Cluster) Info() (*Info, error) {
7878
}
7979
return &info, nil
8080
}
81+
82+
func (c *Cluster) Destroy() error {
83+
return c.stackProvisioner().Destroy()
84+
}

0 commit comments

Comments
 (0)