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

Support for Registrator's service attributes #551

Closed
denzuko opened this issue Feb 23, 2016 · 2 comments
Closed

Support for Registrator's service attributes #551

denzuko opened this issue Feb 23, 2016 · 2 comments

Comments

@denzuko
Copy link

denzuko commented Feb 23, 2016

As a user I would like to define two backends on deployment
So that I can route dynamically with acls in haproxy

Scenario:

Given I have the following template:

frontend www
    bind *:80
    reqadd x-forwarded-proto:\ http
    default_backend consul
{{ range services }}
  {{ if .Tags.Contains "http" }}
    acl host_{{ .Name }} hdr(host) -i {{ .Name }}.{{ or (env "HAPROXY_DOMAIN") "fmr.com" }}
    acl host_{{ .Name }}_uri path_beg -i /{{ .Name }}
    use_backend {{ .Name }}_backend if host_{{ .Name }}
    use_backend {{ .Name }}_backend if host_{{ .Name }}_uri
  {{ else if and (.Tags.Contains "http") (.Tags.Contains "deploy") }}
    acl host_{{ .service.Attrs.DirectName }} hdr(host) -i {{ .service.Attrs.DirectName }}.{{ or (env "HAPROXY_DOMAIN") "fmr.com" }}
    acl host_{{ .service.Attrs.DirectName }}_uri path_beg -i /{{ .service.Attrs.DirectName }}
    use_backend {{ .service.Attrs.DirectName }}_backend if host_{{ .Name }}
    use_backend {{ .service.Attrs.DirectName }}_backend if host_{{ .Name }}_uri
  {{ end }}
{{ end }}

{{ range services }}
  {{ if (.Tags.Contains "http") }}
backend {{ .Name }}_backend
    reqirep ^([^\ :]*\ /){{.Name}}[/]?(.*) \1\2
    {{ range service .Name}}
    server {{ .Node }} {{ .Address }}:{{ .Port }}
    {{ end }}

backend {{ .node.attrs.directname }}_backend
    reqirep ^([^\ :]*\ /){{.service.Attrs.DirectName}}[/]?(.*) \1\2
    {{ range service .Name}}
    server {{ .Node }} {{ .Address }}:{{ .Port }}
    {{ end }}
  {{ end }}
{{ end }}

And provide the environment variable SERVICE_DIRECTNAME
Then consul-template should expand the values from SERVICE_DIRECTNAME into service.Attrs.DirectName on template generation

@samber
Copy link

samber commented Mar 2, 2016

FYI, Consul still doesn't support attributes as noticed by Registrator doc: http://gliderlabs.com/registrator/latest/user/services/#tags-and-attributes

An issue is pending about adding this feature: hashicorp/consul/issues/1107

On the Registrator side, a PR is also pending, adding use of Consul KV as attribute storage: gliderlabs/registrator/pull/242

@sethvargo
Copy link
Contributor

Hi @denzuko

I'm not familiar with registrator, and Consul Template is designed to integrate with Consul and Vault. I don't think this is something we plan to implement ourselves, but we would gladly review a pull request to implement this functionality. Thanks! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants