Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Allow a service to be configured as failover for another service in the same backend #120

Merged
merged 3 commits into from
Jan 23, 2017
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ Similar to using legacy links, here list some differences that you need to notic
Once the stack is up, you can scale the web service using `docker-compose scale web=3`. dockercloud/haproxy will automatically reload its configuration.

#### Running with Docker Compose v2 and Swarm (using envvar)
When using links like previous section, the Docker Swarm scheduler can be too restrictive.
Even with overlay network, swarm (As of 1.1.0) will attempt to schedule haproxy on the same node as the linked service due to legacy links behavior.
When using links like previous section, the Docker Swarm scheduler can be too restrictive.
Even with overlay network, swarm (As of 1.1.0) will attempt to schedule haproxy on the same node as the linked service due to legacy links behavior.
This can cause unwanted scheduling patterns or errors such as "Unable to find a node fulfilling all dependencies..."

Since Compose V2 allows discovery through the service names, Dockercloud haproxy only needs the links to indentify which service should be load balanced.
Expand Down Expand Up @@ -241,6 +241,7 @@ Settings here can overwrite the settings in HAProxy, which are only applied to t
|EXCLUDE_PORTS|comma separated port numbers(e.g. 3306, 3307). By default, HAProxy will add all the ports exposed by the application services to the backend routes. You can exclude the ports that you don't want to be routed, like database port|
|EXTRA_ROUTE_SETTINGS|a string which is append to the each backend route after the health check,possible value: "send-proxy"|
|EXTRA_SETTINGS|comma-separated string of extra settings, and each part will be appended to either related backend section or listen session in the configuration file. To escape comma, use `\,`. Possible value: `balance source`|
|FAILOVER|boolean setting that configures this service to be run as HAProxy `backup` for other configured service(s) in this backend|
|FORCE_SSL|if set(any value) together with ssl termination enabled. HAProxy will redirect HTTP request to HTTPS request.
|GZIP_COMPRESSION_TYPE|enable gzip compression. The value of this envvar is a list of MIME types that will be compressed. Some possible values: `text/html text/plain text/css application/javascript`. See:[HAProxy:compression](http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-compression)|
|HEALTH_CHECK|set health check on each backend route, possible value: "check inter 2000 rise 2 fall 3". See:[HAProxy:check](https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#5.2-check)|
Expand Down
8 changes: 6 additions & 2 deletions haproxy/helper/backend_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ def get_backend_section(details, routes, vhosts, service_alias, routes_added):
route_health_check = get_route_health_check(details, service_alias, HEALTH_CHECK)
extra_route_settings = get_extra_route_settings(details, service_alias, EXTRA_ROUTE_SETTINGS)
route_setting = " ".join([route_health_check, extra_route_settings]).strip()
backend_routes = get_backend_routes(route_setting, is_sticky, routes, routes_added, service_alias)
backend_routes = get_backend_routes(route_setting, is_sticky, routes, routes_added, service_alias, details)
backend.extend(backend_routes)

return backend


def get_backend_routes(route_setting, is_sticky, routes, routes_added, service_alias):
def get_backend_routes(route_setting, is_sticky, routes, routes_added, service_alias, details):
backend_routes = []
for _service_alias, routes in routes.iteritems():
if not service_alias or _service_alias == service_alias:
service_details = details[_service_alias]
addresses_added = []
for route in routes:
# avoid adding those tcp routes adding http backends
Expand All @@ -41,6 +42,9 @@ def get_backend_routes(route_setting, is_sticky, routes, routes_added, service_a
if route_setting:
backend_route.append(route_setting)

if 'failover' in service_details and service_details['failover']:
backend_route.append("backup")

backend_routes.append(" ".join(backend_route))

return sorted(backend_routes)
Expand Down
4 changes: 4 additions & 0 deletions haproxy/parser/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,7 @@ def parse_extra_settings(value):
@staticmethod
def parse_extra_route_settings(value):
return value

@staticmethod
def parse_failover(value):
return value