in updater/aws.go [246:278]
func (u *updater) drainInstance(containerInstance string) error {
log.Printf("Starting drain on container instance %q", containerInstance)
resp, err := u.ecs.UpdateContainerInstancesState(&ecs.UpdateContainerInstancesStateInput{
Cluster: &u.cluster,
ContainerInstances: aws.StringSlice([]string{containerInstance}),
Status: aws.String("DRAINING"),
})
if err != nil {
return fmt.Errorf("failed to change instance state to DRAINING: %w", err)
}
if len(resp.Failures) != 0 {
log.Printf("There are API failures in draining the container instance %q, therefore attempting to"+
" re-activate", containerInstance)
err = u.activateInstance(containerInstance)
if err != nil {
log.Printf("Instance failed to re-activate after failing to change state to DRAINING: %v", err)
}
return fmt.Errorf("failures in API call: %v", resp.Failures)
}
log.Printf("Container instance state changed to DRAINING")
err = u.waitUntilDrained(containerInstance)
if err != nil {
log.Printf("Container instance %q failed to drain, therefore attempting to re-activate", containerInstance)
err2 := u.activateInstance(containerInstance)
if err2 != nil {
log.Printf("Instance failed to re-activate after failing to wait for drain to complete: %v", err2)
}
return fmt.Errorf("error while waiting to drain: %w", err)
}
log.Printf("Container instance %q drained successfully!", containerInstance)
return nil
}