Skip to content

Commit

Permalink
Wait for newly created services to stabilize.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejholmes committed Jun 14, 2016
1 parent 5439056 commit 26969f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
13 changes: 12 additions & 1 deletion server/cloudformation/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ecsClient interface {
CreateService(*ecs.CreateServiceInput) (*ecs.CreateServiceOutput, error)
DeleteService(*ecs.DeleteServiceInput) (*ecs.DeleteServiceOutput, error)
UpdateService(*ecs.UpdateServiceInput) (*ecs.UpdateServiceOutput, error)
WaitUntilServicesStable(*ecs.DescribeServicesInput) error
}

type LoadBalancer struct {
Expand Down Expand Up @@ -117,7 +118,17 @@ func (p *ECSServiceResource) create(properties *ECSServiceProperties) (string, e
return "", fmt.Errorf("error creating service: %v", err)
}

return *resp.Service.ServiceArn, nil
arn := resp.Service.ServiceArn
if err := p.ecs.WaitUntilServicesStable(&ecs.DescribeServicesInput{
Cluster: properties.Cluster,
Services: []*string{arn},
}); err != nil {
// We're ignoring this error, because the service was created,
// and if the service doesn't stabilize, it's better to just let
// the stack finish creating than rolling back.
}

return *arn, nil
}

func (p *ECSServiceResource) delete(service, cluster *string) error {
Expand Down
15 changes: 15 additions & 0 deletions server/cloudformation/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func TestECSServiceResource_Create(t *testing.T) {
},
}, nil)

e.On("WaitUntilServicesStable", &ecs.DescribeServicesInput{
Cluster: aws.String("cluster"),
Services: []*string{aws.String("arn:aws:ecs:us-east-1:012345678901:service/acme-inc-web-A")},
}).Return(nil)

id, data, err := p.Provision(Request{
RequestType: Create,
ResourceProperties: &ECSServiceProperties{
Expand Down Expand Up @@ -98,6 +103,11 @@ func TestECSServiceResource_Update_RequiresReplacement(t *testing.T) {
},
}, nil)

e.On("WaitUntilServicesStable", &ecs.DescribeServicesInput{
Cluster: aws.String("clusterB"),
Services: []*string{aws.String("arn:aws:ecs:us-east-1:012345678901:service/acme-inc-web-B")},
}).Return(nil)

id, data, err := p.Provision(Request{
RequestType: Update,
PhysicalResourceId: "arn:aws:ecs:us-east-1:012345678901:service/acme-inc-web-A",
Expand Down Expand Up @@ -263,3 +273,8 @@ func (m *mockECS) DeleteService(input *ecs.DeleteServiceInput) (*ecs.DeleteServi
args := m.Called(input)
return args.Get(0).(*ecs.DeleteServiceOutput), args.Error(1)
}

func (m *mockECS) WaitUntilServicesStable(input *ecs.DescribeServicesInput) error {
args := m.Called(input)
return args.Error(0)
}

0 comments on commit 26969f4

Please sign in to comment.