-
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathdelete.go
More file actions
64 lines (55 loc) · 1.45 KB
/
Copy pathdelete.go
File metadata and controls
64 lines (55 loc) · 1.45 KB
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
package ecspresso
import (
"context"
"fmt"
"github.com/Songmu/prompter"
"github.com/aws/aws-sdk-go-v2/service/ecs"
)
type DeleteOption struct {
DryRun bool `help:"dry-run" default:"false"`
Force bool `help:"delete without confirmation" default:"false"`
Terminate bool `help:"delete with terminate tasks" default:"false"`
}
func (opt DeleteOption) DryRunString() string {
if opt.DryRun {
return dryRunStr
}
return ""
}
func (d *App) Delete(ctx context.Context, opt DeleteOption) error {
ctx, cancel := d.Start(ctx)
defer cancel()
d.LogInfo("Deleting service", withDryRun(opt.DryRun)...)
sv, err := d.DescribeServiceStatus(ctx, 3)
if err != nil {
return err
}
if opt.DryRun {
d.LogInfo("DRY RUN OK")
return nil
}
if !opt.Force {
service := prompter.Prompt(`Enter the service name to DELETE`, "")
if service != *sv.ServiceName {
d.LogInfo("Aborted")
return fmt.Errorf("confirmation failed")
}
}
if sv.isExpressMode() {
return d.deleteExpressGatewayService(ctx, sv, opt)
} else {
return d.deleteService(ctx, sv, opt)
}
}
func (d *App) deleteService(ctx context.Context, sv *Service, opt DeleteOption) error {
in := &ecs.DeleteServiceInput{
Cluster: &d.config.Cluster,
Service: sv.ServiceName,
Force: &opt.Terminate, // == aws ecs delete-service --force
}
if _, err := d.ecs.DeleteService(ctx, in); err != nil {
return fmt.Errorf("failed to delete service: %w", err)
}
d.LogInfo("Service is deleted")
return nil
}