add delete-cluster flag on down cmd

Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
aiordache 2020-04-23 14:50:18 +02:00
parent 3c9905c474
commit 3d7e062215
3 changed files with 12 additions and 4 deletions

View File

@ -133,6 +133,7 @@ func UpCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOptions)
type downOptions struct {
KeepLoadBalancer bool
DeleteCluster bool
}
func DownCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOptions) *cobra.Command {
@ -144,9 +145,10 @@ func DownCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOption
if err != nil {
return err
}
return client.ComposeDown(project, opts.KeepLoadBalancer)
return client.ComposeDown(project, opts.KeepLoadBalancer, opts.DeleteCluster)
}),
}
cmd.Flags().BoolVar(&opts.KeepLoadBalancer, "keep-load-balancer", false, "Keep Load Balancer for further use")
cmd.Flags().BoolVar(&opts.DeleteCluster, "delete-cluster", false, "Delete cluster")
return cmd
}

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/ecs-plugin/pkg/compose"
)
func (c *client) ComposeDown(project *compose.Project, keepLoadBalancer bool) error {
func (c *client) ComposeDown(project *compose.Project, keepLoadBalancer, deleteCluster bool) error {
_, err := c.CF.DeleteStack(&cloudformation.DeleteStackInput{
StackName: &project.Name,
})
@ -19,7 +19,13 @@ func (c *client) ComposeDown(project *compose.Project, keepLoadBalancer bool) er
if err = c.CF.WaitUntilStackDeleteComplete(&cf.DescribeStacksInput{StackName: &project.Name}); err != nil {
return err
}
fmt.Printf("... done.\nDelete cluster %s", c.Cluster)
fmt.Printf("... done.\n")
if !deleteCluster {
return nil
}
fmt.Printf("Delete cluster %s", c.Cluster)
if err = c.DeleteCluster(); err != nil {
return err
}

View File

@ -5,5 +5,5 @@ import "github.com/awslabs/goformation/v4/cloudformation"
type API interface {
Convert(project *Project, loadBalancerArn *string) (*cloudformation.Template, error)
ComposeUp(project *Project, loadBalancerArn *string) error
ComposeDown(project *Project, keepLoadBalancer bool) error
ComposeDown(project *Project, keepLoadBalancer, deleteCluster bool) error
}