diff --git a/Gopkg.lock b/Gopkg.lock index 962188f19..b825ff8df 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -134,12 +134,12 @@ version = "v1.0.0" [[projects]] - digest = "1:7d9085638f210faa86720b5fe8c4cd9303edb853ed93929852a4384a4e6c956f" + digest = "1:8b20ed6a6df0628913a69e4c1709537b2e26c7be4aca856bf52b431cf1ce6d90" name = "github.com/hashicorp/consul" packages = ["api"] pruneopts = "UT" - revision = "fb848fc48818f58690db09d14640513aa6bf3c02" - version = "v1.0.7" + revision = "a82e6a7fd33a0d05b9b871bcaf1d7595c9b8dedc" + version = "v1.5.2" [[projects]] branch = "master" @@ -181,6 +181,14 @@ pruneopts = "UT" revision = "b8bc1bf767474819792c23f32d8286a45736f1c6" +[projects]] + digest = "1:53bc4cd4914cd7cd52139990d5170d6dc99067ae31c56530621b18b35fc30318" + name = "github.com/mitchellh/mapstructure" + packages = ["."] + pruneopts = "UT" + revision = "3536a929edddb9a5b34bd6861dc4a9647cb459fe" + version = "v1.1.2" + [[projects]] digest = "1:ee4d4af67d93cc7644157882329023ce9a7bcfce956a079069a9405521c7cc8d" name = "github.com/opencontainers/go-digest" diff --git a/Gopkg.toml b/Gopkg.toml index 67a8d910d..df97566ab 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -6,7 +6,7 @@ [[constraint]] name = "github.com/hashicorp/consul" - version = "1.0.7" + version = "1.5.1" [[constraint]] branch = "master" diff --git a/bridge/bridge.go b/bridge/bridge.go index f02ca99c9..8c86b1765 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -346,9 +346,17 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service { service.ID = id } + mesh := mapDefault(metadata, "mesh", "") + if mesh != "" { + service.Mesh, _ = strconv.ParseBool(mesh) + } else { + service.Mesh = b.config.ServiceMesh + } + delete(metadata, "id") delete(metadata, "tags") delete(metadata, "name") + delete(metadata, "mesh") service.Attrs = metadata service.TTL = b.config.RefreshTtl diff --git a/bridge/types.go b/bridge/types.go index e643ed3f5..9aaed3ace 100644 --- a/bridge/types.go +++ b/bridge/types.go @@ -29,6 +29,7 @@ type Config struct { RefreshInterval int DeregisterCheck string Cleanup bool + ServiceMesh bool } type Service struct { @@ -39,6 +40,7 @@ type Service struct { Tags []string Attrs map[string]string TTL int + Mesh bool Origin ServicePort } diff --git a/consul/consul.go b/consul/consul.go index 13e8f18b3..61e5211dc 100644 --- a/consul/consul.go +++ b/consul/consul.go @@ -22,10 +22,10 @@ func init() { bridge.Register(f, "consul-unix") } -func (r *ConsulAdapter) interpolateService(script string, service *bridge.Service) string { +func (r *ConsulAdapter) interpolateService(script string, service *bridge.Service) []string { withIp := strings.Replace(script, "$SERVICE_IP", service.IP, -1) withPort := strings.Replace(withIp, "$SERVICE_PORT", strconv.Itoa(service.Port), -1) - return withPort + return strings.Split(withPort, " ") } type Factory struct{} @@ -86,6 +86,11 @@ func (r *ConsulAdapter) Register(service *bridge.Service) error { registration.Address = service.IP registration.Check = r.buildCheck(service) registration.Meta = service.Attrs + if service.Mesh == true { + registration.Connect = &consulapi.AgentServiceConnect{ + SidecarService: &consulapi.AgentServiceRegistration{}, + } + } return r.client.Agent().ServiceRegister(registration) } diff --git a/docs/user/backends.md b/docs/user/backends.md index 6321c043e..226741d6b 100644 --- a/docs/user/backends.md +++ b/docs/user/backends.md @@ -126,6 +126,24 @@ If enabled this should be much longer than any expected recoverable outage. SERVICE_CHECK_DEREGISTER_AFTER=10m ``` +### Consul ServiceMesh Support + +Consul can support ServiceMesh by integrating with proxies like Envoy, the most convenient way to enable this capability is creating a Service like [this](https://www.consul.io/docs/connect/registration/sidecar-service.html#minimal-example): + +```json +{ + "service": { + "name": "web", + "port": 8080, + "connect": { "sidecar_service": {} } + } +} +``` + +Then Consul will automatically generate a corresponding SidecarService with default configurations. + +In Registrator, you may add the `"connect": { "sidecar_service": {} }` configuration by the `-service-mesh` flag. It's also overridable by `SERVICE_MESH`. + ## Consul KV consulkv://
:/ diff --git a/docs/user/run.md b/docs/user/run.md index 5c084474b..e0508b0ca 100644 --- a/docs/user/run.md +++ b/docs/user/run.md @@ -44,6 +44,7 @@ Option | Since | Description `-ttl ` | | TTL for services. Default: 0, no expiry (supported backends only) `-ttl-refresh ` | | Frequency service TTLs are refreshed (supported backends only) `-useIpFromLabel