Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only destroy load balancers when the app is destroyed. #801

Merged
merged 2 commits into from
Apr 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* `emp scale -l` now lists configured scale, not the running processes [#769](https://github.com/remind101/empire/pull/769)
* Fixed a bug where it was previously possible to create a signed access token with an empty username [#780](https://github.com/remind101/empire/pull/780)
* ECR authentication now supports multiple regions, and works independently of ECS region [#784](https://github.com/remind101/empire/pull/784)
* Provisioned ELB's are only destroyed when the entire app is removed [#801](https://github.com/remind101/empire/pull/801)

**Performance**

Expand Down
24 changes: 11 additions & 13 deletions scheduler/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (m *Scheduler) Submit(ctx context.Context, app *scheduler.App) error {
return nil
}

// Remove removes any ECS services that belong to this app.
// Remove removes all of the AWS resources for this app.
func (m *Scheduler) Remove(ctx context.Context, appID string) error {
processes, err := m.Processes(ctx, appID)
if err != nil {
Expand All @@ -206,7 +206,7 @@ func (m *Scheduler) Remove(ctx context.Context, appID string) error {
}
}

return nil
return m.removeLoadBalancers(ctx, appID)
}

// Instances returns all instances that are currently running, pending or
Expand Down Expand Up @@ -527,16 +527,18 @@ func (m *Scheduler) loadBalancer(ctx context.Context, app *scheduler.App, p *sch
return l, nil
}

func (m *Scheduler) removeLoadBalancer(ctx context.Context, app string, p string) error {
l, err := m.findLoadBalancer(ctx, app, p)
func (m *Scheduler) removeLoadBalancers(ctx context.Context, app string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this called somewhere else before? I'm not sure how this stops the previous behavior - only that it adds the behavior that it will now make sure that the LBs are destroyed when Remove is called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, Remove is called when the entire app is destroyed. Previously, this was in RemoveProcess, which is called to remove an individual process in the app (say for example, you had a worker1 process, but then you changed its name to worker, we remove the irrelevant ecs service).

tags := map[string]string{
"AppID": app,
}

lbs, err := m.lb.LoadBalancers(ctx, tags)
if err != nil {
// TODO: Maybe we shouldn't care here.
return err
}

if l != nil {
if err := m.lb.DestroyLoadBalancer(ctx, l); err != nil {
// TODO: Maybe we shouldn't care here.
for _, lb := range lbs {
if err := m.lb.DestroyLoadBalancer(ctx, lb); err != nil {
return err
}
}
Expand Down Expand Up @@ -610,11 +612,7 @@ func (m *Scheduler) RemoveProcess(ctx context.Context, app string, process strin
return nil
}

if err != nil {
return err
}

return m.removeLoadBalancer(ctx, app, process)
return err
}

// Scale scales an ECS service to the desired number of instances.
Expand Down
3 changes: 1 addition & 2 deletions scheduler/ecs/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ func TestScheduler_Remove(t *testing.T) {
defer s.Close()

m.lb.(*mockLBManager).On("LoadBalancers", map[string]string{
"AppID": "1234",
"ProcessType": "web",
"AppID": "1234",
}).Return([]*lb.LoadBalancer{}, nil)

if err := m.Remove(context.Background(), "1234"); err != nil {
Expand Down