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

dont create frontend port binding for non tcp apps #533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
37 changes: 28 additions & 9 deletions marathon_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,26 @@ 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 args.remove_nontcp_binding:
Copy link
Contributor

Choose a reason for hiding this comment

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

args is not defined in this function, remove_nontcp_binding should be passed through the MarathonEventProcessor and regenerate_config much like how args.dont_bind_http_https is.

if app.mode == 'tcp':
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 ''
)
else:
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 ''
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be DRY'd up to something like

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 @@ -507,7 +519,11 @@ 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 args.remove_nontcp_binding:
Copy link
Contributor

Choose a reason for hiding this comment

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

The same logic from above can be used here to DRY it up.

if app.mode == 'tcp':
frontends += frontend_backend_glue.format(backend=backend)
else:
frontends += frontend_backend_glue.format(backend=backend)

do_backend_healthcheck_options_once = True
key_func = attrgetter('host', 'port')
Expand Down Expand Up @@ -1796,6 +1812,9 @@ def get_arg_parser():
parser.add_argument("--skip-validation",
help="Skip haproxy config file validation",
action="store_true")
parser.add_argument("--remove-nontcp-binding",
help="Remove port binding for non-tcp",
action="store_true")
parser.add_argument("--dry", "-d",
help="Only print configuration to console",
action="store_true")
Expand Down