forked from minamijoyo/myaws
/
ecs_node_drain.go
41 lines (34 loc) · 1.14 KB
/
ecs_node_drain.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
package myaws
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/pkg/errors"
)
// ECSNodeDrainOptions customize the behavior of the Drain command.
type ECSNodeDrainOptions struct {
Cluster string
ContainerInstances []*string
Wait bool
}
// ECSNodeDrain Drain ECS container instances.
// We want to wait until drain action is completed, but the ECSNodeUpdate
// method is general purpose, so we implement a wait option to specialized
// method for draining.
func (client *Client) ECSNodeDrain(options ECSNodeDrainOptions) error {
_, err := client.ECS.UpdateContainerInstancesState(
&ecs.UpdateContainerInstancesStateInput{
Cluster: &options.Cluster,
ContainerInstances: options.ContainerInstances,
Status: aws.String("DRAINING"),
},
)
if err != nil {
return errors.Wrapf(err, "UpdateContainerInstancesState failed")
}
if options.Wait {
fmt.Fprintln(client.stdout, "Wait until container instances are drained...")
return client.WaitUntilECSContainerInstancesAreDrained(options.Cluster, options.ContainerInstances)
}
return nil
}