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

Get unique tags #200

Closed
hoffoo opened this issue Feb 18, 2015 · 5 comments
Closed

Get unique tags #200

hoffoo opened this issue Feb 18, 2015 · 5 comments

Comments

@hoffoo
Copy link
Contributor

hoffoo commented Feb 18, 2015

I would like to list all tags and create groups of hosts based on them. The issue is that I only want one group per tag, even if multiple services in the Catalog have the same tag. Right now when I range by service im getting duplicate tags (which makes perfect sense).

I tried various things i read trough but cannot come up with a workaround for me (If only I could use a map in a template or just add a function on the fly).

Any ideas would be super helpful!

@sethvargo
Copy link
Contributor

Hi @hoffoo

This is a duplicate of #33. Right now this is not possible because Consul does not provide a way to query on just a tag. Your case is interesting because you need to invert the result from services (i.e. map[tag]services instead of map[service]tags). Unfortunately this is not something that is currently possible due to the upstream bug in Consul. You can read more information on the linked issue. Sorry about that.

@hoffoo
Copy link
Contributor Author

hoffoo commented Feb 18, 2015

no problem thanks a lot for clarifying!

@sielaq
Copy link

sielaq commented Mar 1, 2015

Hi @hoffoo,

We have workaround it like this,

{{range services}}
  {{range $tag, $services := service .Name|byTag}}
    #{{$tag}}
    {{$service_name := (index $services 0).Name}}
    {{$service_name}}
    {{range $services}}
      {{.Node}} {{.Port}} {{.Address}}
    {{end}}
  {{end}}
{{end}}

or you can ensure only specific Tags like:

{{range services}}
  {{range $tag, $services := service .Name|byTag}}
    {{if or (eq $tag "YOUR_TAG_1") (eq $tag "YOUR_TAG_2")}}
      #{{$tag}}
      {{$service_name := (index $services 0).Name}}
      {{$service_name}}
      {{range $services}}
        {{.Node}} {{.Port}} {{.Address}}
      {{end}}
    {{end}}
  {{end}}
{{end}}

I'm not sure if this would also help for you.

@scalp42
Copy link

scalp42 commented Sep 1, 2015

@sielaq in your example the if or acts as a AND operation. How can we query YOUR_TAG_1 OR YOUR_TAG_2 ?

@sielaq
Copy link

sielaq commented Sep 2, 2015

Actually it behaves like logical OR , if any appearance of YOUR_TAG_1 or YOUR_TAG_2 exists in tags, then service is generated. Might be you are setting tags not properly (for ex. you have only one big tag).

see our HAproxy set up in PaaS project which works already
https://github.com/eBayClassifiedsGroup/PanteraS/blob/master/infrastructure/template.conf

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

4 participants