Skip to content
Open
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
39 changes: 24 additions & 15 deletions ext/lb/haproxy/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,34 @@ func (p *HAProxyLoadBalancer) Template() string {
}

func (p *HAProxyLoadBalancer) Reload(proxyContainers []types.Container) error {
// drop SYN to allow for restarts
if err := p.dropSYN(); err != nil {
log().Warnf("error signaling clients to resend; you will notice dropped packets: %s", err)
}

// reload all interlock managed haproxy containers
for _, cnt := range proxyContainers {
// restart
log().Debugf("restarting proxy container: id=%s", cnt.ID)
d := time.Millisecond * 1000
if err := p.client.ContainerRestart(context.Background(), cnt.ID, &d); err != nil {
log().Errorf("error restarting container: id=%s err=%s", cnt.ID[:12], err)
// update the proxy container status
cInfo, err := p.client.ContainerInspect(context.Background(), cnt.ID)
if err != nil {
log().Errorf("unable to inspect proxy container: %s", err)
Copy link
Owner

Choose a reason for hiding this comment

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

This will fall through without a continue.

Copy link
Author

Choose a reason for hiding this comment

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

The continue is there.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah I didn't see it from the diff. 👍

continue
}
switch cInfo.State.Status {
case "exited":
log().Infof("restarting proxy container: id=%s", cnt.ID)
d := time.Millisecond * 1000
if err := p.client.ContainerRestart(context.Background(), cnt.ID, &d); err != nil {
log().Errorf("error restarting container: id=%s err=%s", cnt.ID[:12], err)
continue
}
case "running":
log().Debugf("reloading proxy container: id=%s", cnt.ID)
Copy link
Owner

Choose a reason for hiding this comment

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

This is needed to safely reload (see above comment).

if err := p.client.ContainerKill(context.Background(), cnt.ID, "HUP"); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

Are you sure HAProxy handles this properly? I believe we've tried HUP before and found that it didn't always reload the config.

Copy link
Owner

Choose a reason for hiding this comment

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

That being said, if we can test it I would love to get rid of the TCP hacks. :)

Copy link
Author

Choose a reason for hiding this comment

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

Pretty sure it is stable in v1.7.x. I have been using it (outside of interlock) for a while.

log().Errorf("error reloading container: id=%s err=%s", cnt.ID[:12], err)
continue
}
Copy link
Owner

Choose a reason for hiding this comment

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

Are you sure this catches all cases? A default with log probably wouldn't hurt.

Copy link
Author

Choose a reason for hiding this comment

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

I will add it and update the PR.

default:
log().Infof("haproxy container id=%s name=%s in state %s", cnt.ID[:12], cnt.Names[0], cInfo.State.Status)
continue
}

log().Infof("restarted proxy container: id=%s name=%s", cnt.ID[:12], cnt.Names[0])
}

if err := p.resumeSYN(); err != nil {
log().Warnf("error signaling clients to resume; you will notice dropped packets: %s", err)
log().Infof("reloaded proxy container: id=%s name=%s", cnt.ID[:12], cnt.Names[0])
}

return nil
Expand Down