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

Uniq services? #434

Closed
Telmo opened this issue Oct 16, 2015 · 4 comments
Closed

Uniq services? #434

Telmo opened this issue Oct 16, 2015 · 4 comments

Comments

@Telmo
Copy link

Telmo commented Oct 16, 2015

I need to list all services across datacenter, this is usually not a big deal but I am running into duplicate listing if the container running the service is deployed to multiple datacenters (for redundancy)

Because the template iterates through datacenters and then services I can't find a way of de-duplicating the list. Is there a way of accomplishing this?

{{ range $dc := datacenters }}
  {{range services (print "@" $dc) }}
   {{ if .Tags | contains "asl" }}
    {{if key (print "asl/services/" .Name "/public") | parseBool }}
     {{key_or_default (print "asl/services/" .Name "/image") "..." }}"
     {key (print "asl/services/" .Name "/name")}}
     {{key_or_default (print "asl/services/" .Name "/description") "No Description" }}
     {{key_or_default (print "asl/services/" .Name "/documentation") "#" }}
   {{end}} 
   {{end}} 
 {{end}}
 {{end}}
@sethvargo
Copy link
Contributor

Hi @Telmo

Unfortunately this is not possible with Go's templating language. There's no way to mutate the data or create a map function 😦. Sorry!

@erolg
Copy link

erolg commented Jul 22, 2020

Folks, Is there any way to do this today?

@eikenb
Copy link
Contributor

eikenb commented Jul 22, 2020

Hey @erolg,

First a bit of book-keeping... In the future if you are interested in an issue that has been closed please consider filing a new issue and linking to the old one. This works much better as it communicates a rewnewed interest instead of being tied to a years old/closed ticket. We should probably lock these old issues to help point people in the right direction.

I'm not sure if the template library changed, but this should be possible. Looking around it seems the sprig library already does this and there is a POC PR about adding sprig to consul-template. So to see progress on this front you could either vote (:+1:) for the sprig PR or file a new issue requesting the uniq feature.

Thanks.

@eikenb
Copy link
Contributor

eikenb commented Jul 22, 2020

@erolg, I forgot to mention in regard to your question... Using the scratch (map) template functions you might be able to do something like uniq as maps are often used like Sets to determine this sort of thing. Would be worth a look.

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