QubitProducts / bamboo

HAProxy auto configuration and auto service discovery for Mesos Marathon
Apache License 2.0
794 stars 215 forks source link

Allow haproxy template to list all app env values #218

Open jrandall opened 7 years ago

jrandall commented 7 years ago

Implements a new function getAppEnvValues to use from within haproxy template (also adds a unique function to unique a slice of strings from within the template, which I don't need for this example, but it may be useful).

I'm using this functionality to enable multiple apps to respond to a single tcp port. For example, by using something like:

{{ $apps := .Apps }}
{{ range $port := ($apps | getAppEnvValues "BAMBOO_TCP_PORT") }}
# Listener for TCP port {{ $port }}
listen marathon-app-tcp-{{ $port }}-cluster-tcp :{{ $port }}
        mode tcp
        option tcplog
        balance roundrobin
        use_backend marathon-app-tcp-{{ $port }}-cluster if TRUE

# Backend for TCP port {{ $port }}
backend marathon-app-tcp-{{ $port }}-cluster
        {{ range $appindex, $app := $apps }} {{ if eq $app.Env.BAMBOO_TCP_PORT $port }} {{ range $page, $task := .Tasks }}
        server {{ $app.EscapedId}}-{{ $task.Host }}-{{ $task.Port }} {{ $task.Host }}:{{ $task.Port }} {{ if $app.HealthCheckPath }} check inter 30000 {{ end }}
        {{ end }} {{ end }} {{ end }}

{{ end }}
swagatha-christie commented 7 years ago

By analyzing the blame information on this pull request, we identified @bluepeppers, @gomes and @activars to be potential reviewers

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.8%) to 42.899% when pulling feabf4cde6267110326b8d8f54c92f98f10123fa on wtsi-hgi:feature/haproxy-template-getAppEnvValues into 36532e313e4656df591224195d606143ffa05d4d on QubitProducts:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+1.4%) to 45.095% when pulling 18f5d5d6fab339c8fe9f6adbf0194b6481d43351 on wtsi-hgi:feature/haproxy-template-getAppEnvValues into 36532e313e4656df591224195d606143ffa05d4d on QubitProducts:master.

j1n6 commented 7 years ago

@jrandall that looks good. Can you fix go format by running the following command & commit the change?

go fmt ./...

Thank you.

jrandall commented 7 years ago

Formatting has now been fixed with go fmt ./... - sorry about that, and apologies for the delay in getting back to this!

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-3.3%) to 40.428% when pulling 3b5647f81456c9929d3ec2c2607ede50b5ad1cf9 on wtsi-hgi:feature/haproxy-template-getAppEnvValues into 36532e313e4656df591224195d606143ffa05d4d on QubitProducts:master.

j1n6 commented 7 years ago

@jrandall do you mind rebase & resolve the conflict? otherwise it lgtm.