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

Add --remove-nontcp-binding option preventing creating frontend port … #674

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Longhelp.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ optional arguments:
--dont-bind-http-https
Don't bind to HTTP and HTTPS frontends. (default:
False)
--remove-nontcp-binding
Remove port binding for non-tcp. (default: False)
--group-https-by-vhost
Group https frontends by vhost. (default: False)
--ssl-certs SSL_CERTS
Expand Down
38 changes: 25 additions & 13 deletions marathon_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def calculate_server_id(server_name, taken_server_ids):
return calculate_server_id(new_server_name, taken_server_ids)


def config(apps, groups, bind_http_https, ssl_certs, templater,
def config(apps, groups, bind_http_https, remove_nontcp_binding, ssl_certs, templater,
haproxy_map=False, domain_map_array=[], app_map_array=[],
config_file="/etc/haproxy/haproxy.cfg",
group_https_by_vhosts=False):
Expand Down Expand Up @@ -545,14 +545,16 @@ def config(apps, groups, bind_http_https, ssl_certs, templater,
)

frontend_head = templater.haproxy_frontend_head(app)
frontends += frontend_head.format(
bindAddr=app.bindAddr,
backend=backend,
servicePort=app.servicePort,
mode=app.mode,
sslCert=' ssl crt ' + app.sslCert if app.sslCert else '',
bindOptions=' ' + app.bindOptions if app.bindOptions else ''
)

if app.mode == 'tcp' or not remove_nontcp_binding:
frontends += frontend_head.format(
bindAddr=app.bindAddr,
backend=backend,
servicePort=app.servicePort,
mode=app.mode,
sslCert=' ssl crt ' + app.sslCert if app.sslCert else '',
bindOptions=' ' + app.bindOptions if app.bindOptions else ''
)

backend_head = templater.haproxy_backend_head(app)
backends += backend_head.format(
Expand Down Expand Up @@ -657,7 +659,8 @@ def config(apps, groups, bind_http_https, ssl_certs, templater,
backends += templater.haproxy_backend_sticky_options(app)

frontend_backend_glue = templater.haproxy_frontend_backend_glue(app)
frontends += frontend_backend_glue.format(backend=backend)
if app.mode == 'tcp' or not remove_nontcp_binding:
frontends += frontend_backend_glue.format(backend=backend)

do_backend_healthcheck_options_once = True
key_func = attrgetter('host', 'port')
Expand Down Expand Up @@ -1851,13 +1854,14 @@ def get_apps(marathon, apps=[]):


def regenerate_config(marathon, config_file, groups, bind_http_https,
ssl_certs, templater, haproxy_map, group_https_by_vhost):
remove_nontcp_binding, ssl_certs, templater,
haproxy_map, group_https_by_vhost):
domain_map_array = []
app_map_array = []
raw_apps = marathon.list()
apps = get_apps(marathon, raw_apps)
generated_config = config(apps, groups, bind_http_https, ssl_certs,
templater, haproxy_map, domain_map_array,
generated_config = config(apps, groups, bind_http_https, remove_nontcp_binding,
ssl_certs, templater, haproxy_map, domain_map_array,
app_map_array, config_file, group_https_by_vhost)
(changed, config_valid) = compareWriteAndReloadConfig(
generated_config, config_file, domain_map_array, app_map_array,
Expand Down Expand Up @@ -1954,6 +1958,7 @@ def __init__(self, marathon,
config_file,
groups,
bind_http_https,
remove_nontcp_binding,
ssl_certs,
haproxy_map,
group_https_by_vhost):
Expand All @@ -1964,6 +1969,7 @@ def __init__(self, marathon,
self.__groups = groups
self.__templater = ConfigTemplater()
self.__bind_http_https = bind_http_https
self.__remove_nontcp_binding = remove_nontcp_binding
self.__group_https_by_vhost = group_https_by_vhost
self.__ssl_certs = ssl_certs

Expand Down Expand Up @@ -2031,6 +2037,7 @@ def do_reset(self):
self.__config_file,
self.__groups,
self.__bind_http_https,
self.__remove_nontcp_binding,
self.__ssl_certs,
self.__templater,
self.__haproxy_map,
Expand Down Expand Up @@ -2151,6 +2158,9 @@ def get_arg_parser():
parser.add_argument("--dont-bind-http-https",
help="Don't bind to HTTP and HTTPS frontends.",
action="store_true")
parser.add_argument("--remove-nontcp-binding",
help="Remove port binding for non-tcp",
action="store_true")
parser.add_argument("--group-https-by-vhost",
help="Group https frontends by vhost.",
action="store_true")
Expand Down Expand Up @@ -2252,6 +2262,7 @@ def load_json(data_str):
args.haproxy_config,
args.group,
not args.dont_bind_http_https,
args.remove_nontcp_binding,
args.ssl_certs,
args.haproxy_map,
args.group_https_by_vhost)
Expand Down Expand Up @@ -2323,6 +2334,7 @@ def load_json(data_str):
args.haproxy_config,
args.group,
not args.dont_bind_http_https,
args.remove_nontcp_binding,
args.ssl_certs,
ConfigTemplater(),
args.haproxy_map,
Expand Down