Skip to content

Commit

Permalink
Merge pull request #620 from dsouzajude/consul-meta
Browse files Browse the repository at this point in the history
Populate Consul's ServiceMeta using service.Attrs
  • Loading branch information
josegonzalez authored Jun 24, 2018
2 parents 7d5571e + ab7a235 commit b737bf7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
20 changes: 11 additions & 9 deletions consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"log"
"net/url"
"strings"
"strconv"
"os"
"strconv"
"strings"

"github.com/gliderlabs/registrator/bridge"
consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/go-cleanhttp"
Expand Down Expand Up @@ -34,16 +35,16 @@ func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
if uri.Scheme == "consul-unix" {
config.Address = strings.TrimPrefix(uri.String(), "consul-")
} else if uri.Scheme == "consul-tls" {
tlsConfigDesc := &consulapi.TLSConfig {
Address: uri.Host,
CAFile: os.Getenv("CONSUL_CACERT"),
CertFile: os.Getenv("CONSUL_TLSCERT"),
KeyFile: os.Getenv("CONSUL_TLSKEY"),
InsecureSkipVerify: false,
tlsConfigDesc := &consulapi.TLSConfig{
Address: uri.Host,
CAFile: os.Getenv("CONSUL_CACERT"),
CertFile: os.Getenv("CONSUL_TLSCERT"),
KeyFile: os.Getenv("CONSUL_TLSKEY"),
InsecureSkipVerify: false,
}
tlsConfig, err := consulapi.SetupTLSConfig(tlsConfigDesc)
if err != nil {
log.Fatal("Cannot set up Consul TLSConfig", err)
log.Fatal("Cannot set up Consul TLSConfig", err)
}
config.Scheme = "https"
transport := cleanhttp.DefaultPooledTransport()
Expand Down Expand Up @@ -84,6 +85,7 @@ func (r *ConsulAdapter) Register(service *bridge.Service) error {
registration.Tags = service.Tags
registration.Address = service.IP
registration.Check = r.buildCheck(service)
registration.Meta = service.Attrs
return r.client.Agent().ServiceRegister(registration)
}

Expand Down
8 changes: 5 additions & 3 deletions docs/user/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ These can be implicitly set from the Dockerfile or explicitly set with `docker r
You can also tell Registrator to ignore a container by setting a
label or environment variable for `SERVICE_IGNORE`.

If you need to ignore individual service on some container, you can use
If you need to ignore individual service on some container, you can use
`SERVICE_<port>_IGNORE=true`.

## Service Name
Expand Down Expand Up @@ -93,8 +93,10 @@ Docker-assigned internal IP of the container**.
## Tags and Attributes

Tags and attributes are extra metadata fields for services. Not all backends
support them. In fact, currently Consul supports tags and none support
attributes.
support them. In fact, currently Consul supports tags and more recently as of
version 1.0.7, it added support for attributes as well in the form of
[KV metadata](https://www.consul.io/api/agent/service.html#meta) but no other
backend supports attributes.

Attributes can also be used by backends for registry specific features, not just
generic metadata. For example, Consul uses them for [specifying HTTP health
Expand Down

0 comments on commit b737bf7

Please sign in to comment.