Skip to content

Commit

Permalink
fix: network interfaces aren't attached to newly created task (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp authored Jun 17, 2024
1 parent a7407ab commit dc6b98a
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ func (c *cage) StartCanaryTask(
loadBalancers = service.LoadBalancers
}
}
var task ecstypes.Task
// Phase 1: Start canary task
var taskArn *string
if c.Env.CanaryInstanceArn != "" {
// ec2
startTask := &ecs.StartTaskInput{
Expand All @@ -265,7 +266,7 @@ func (c *cage) StartCanaryTask(
if o, err := c.Ecs.StartTask(ctx, startTask); err != nil {
return result, err
} else {
task = o.Tasks[0]
taskArn = o.Tasks[0].TaskArn
}
} else {
// fargate
Expand All @@ -279,18 +280,19 @@ func (c *cage) StartCanaryTask(
}); err != nil {
return result, err
} else {
task = o.Tasks[0]
taskArn = o.Tasks[0].TaskArn
}
}
result.taskArn = task.TaskArn
log.Infof("🥚 waiting for canary task '%s' is running...", *task.TaskArn)
result.taskArn = taskArn
// Phase 2: Wait until canary task is running
log.Infof("🥚 waiting for canary task '%s' is running...", *taskArn)
if err := ecs.NewTasksRunningWaiter(c.Ecs).Wait(ctx, &ecs.DescribeTasksInput{
Cluster: &c.Env.Cluster,
Tasks: []string{*task.TaskArn},
Tasks: []string{*taskArn},
}, c.MaxWait); err != nil {
return result, err
}
log.Infof("🐣 canary task '%s' is running!", *task.TaskArn)
log.Infof("🐣 canary task '%s' is running!", *taskArn)
if len(loadBalancers) == 0 {
log.Infof("no load balancer is attached to service '%s'. skip registration to target group", c.Env.Service)
log.Infof("wait %d seconds for ensuring the task goes stable", c.Env.CanaryTaskIdleDuration)
Expand All @@ -311,7 +313,7 @@ func (c *cage) StartCanaryTask(
<-wait
o, err := c.Ecs.DescribeTasks(ctx, &ecs.DescribeTasksInput{
Cluster: &c.Env.Cluster,
Tasks: []string{*task.TaskArn},
Tasks: []string{*taskArn},
})
if err != nil {
return result, err
Expand All @@ -322,6 +324,16 @@ func (c *cage) StartCanaryTask(
}
return result, nil
}
// Phase 3: Get task details after network interface is attached
var task ecstypes.Task
if o, err := c.Ecs.DescribeTasks(ctx, &ecs.DescribeTasksInput{
Cluster: &c.Env.Cluster,
Tasks: []string{*taskArn},
}); err != nil {
return result, err
} else {
task = o.Tasks[0]
}
var targetId *string
var targetPort *int32
var subnet ec2types.Subnet
Expand Down

0 comments on commit dc6b98a

Please sign in to comment.