From 71bee28a299bb4143844c4fec245ba782e3ebdd9 Mon Sep 17 00:00:00 2001 From: psyhomb Date: Tue, 25 Feb 2020 02:39:38 +0100 Subject: [PATCH] Support Go template in -tags flag - Add custom Go template functions - Update signiture of existing Go template fuctions to support pipelines - Migrate to Go modules for managing dependencies - Update versions of builder and runtime docker images (Dockerfile) - Update README.md --- CHANGELOG.md | 23 +++- Dockerfile | 8 +- Gopkg.lock | 316 -------------------------------------------- Gopkg.toml | 53 -------- README.md | 2 +- VERSION | 2 +- bridge/bridge.go | 337 +++++++++++++++++++++++++++++++++++++++++++++-- go.mod | 56 ++++++++ go.sum | 198 ++++++++++++++++++++++++++++ registrator.go | 2 +- 10 files changed, 611 insertions(+), 386 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml create mode 100644 go.mod create mode 100644 go.sum diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d541ef2f..e78435137 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,35 @@ # Change Log All notable changes to this project will be documented in this file. -## [Unreleased][unreleased] +## [v7.4.0]() - 2021-09-22 ### Fixed +- Minor code styling changes ### Added +- Support Go template in -tags flag + - Custom Go template functions: + - `strSlice` + - `sIndex` + - `mIndex` + - `toUpper` + - `toLower` + - `replace` + - `join` + - `split` + - `splitIndex` + - `matchFirstElement` + - `matchAllElements` + - `httpGet` + - `jsonParse` +- Prebuilt Docker images available on [DockerHub](https://hub.docker.com/r/psyhomb/registrator/tags) ### Removed ### Changed +- [Migrated to Go modules for managing dependencies](https://go.dev/blog/migrating-to-go-modules) +- Upgraded Docker base images: + - builder: `golang:1.9.4-alpine3.7` => `golang:1.17.1-alpine3.14` + - runtime: `alpine:3.7` => `alpine:3.14` ## [v7] - 2016-03-05 ### Fixed diff --git a/Dockerfile b/Dockerfile index 515a26f94..0ae4dd166 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,15 @@ -FROM golang:1.9.4-alpine3.7 AS builder +FROM golang:1.17.1-alpine3.14 AS builder WORKDIR /go/src/github.com/gliderlabs/registrator/ COPY . . RUN \ - apk add --no-cache curl git \ - && curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh \ - && dep ensure -vendor-only \ + apk add --no-cache git \ && CGO_ENABLED=0 GOOS=linux go build \ -a -installsuffix cgo \ -ldflags "-X main.Version=$(cat VERSION)" \ -o bin/registrator \ . -FROM alpine:3.7 +FROM alpine:3.14 RUN apk add --no-cache ca-certificates COPY --from=builder /go/src/github.com/gliderlabs/registrator/bin/registrator /bin/registrator diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 962188f19..000000000 --- a/Gopkg.lock +++ /dev/null @@ -1,316 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - branch = "master" - digest = "1:6da51e5ec493ad2b44cb04129e2d0a068c8fb9bd6cb5739d199573558696bb94" - name = "github.com/Azure/go-ansiterm" - packages = [ - ".", - "winterm", - ] - pruneopts = "UT" - revision = "d6e3b3328b783f23731bc4d058875b0371ff8109" - -[[projects]] - digest = "1:bf42be3cb1519bf8018dfd99720b1005ee028d947124cab3ccf965da59381df6" - name = "github.com/Microsoft/go-winio" - packages = ["."] - pruneopts = "UT" - revision = "7da180ee92d8bd8bb8c37fc560e673e6557c392f" - version = "v0.4.7" - -[[projects]] - branch = "master" - digest = "1:3721a10686511b80c052323423f0de17a8c06d417dbdd3b392b1578432a33aae" - name = "github.com/Nvveen/Gotty" - packages = ["."] - pruneopts = "UT" - revision = "cd527374f1e5bff4938207604a14f2e38a9cf512" - -[[projects]] - digest = "1:2209584c0f7c9b68c23374e659357ab546e1b70eec2761f03280f69a8fd23d77" - name = "github.com/cenkalti/backoff" - packages = ["."] - pruneopts = "UT" - revision = "2ea60e5f094469f9e65adb9cd103795b73ae743e" - version = "v2.0.0" - -[[projects]] - branch = "master" - digest = "1:fc8dbcc2a5de7c093e167828ebbdf551641761d2ad75431d3a167d467a264115" - name = "github.com/containerd/continuity" - packages = ["pathdriver"] - pruneopts = "UT" - revision = "c6cef34830231743494fe2969284df7b82cc0ad0" - -[[projects]] - digest = "1:b61d4e32d5101ba4056bce8ff33831ab40884ff13fabc1d2e2a3d67648e0fdcb" - name = "github.com/coreos/go-etcd" - packages = ["etcd"] - pruneopts = "UT" - revision = "f02171fbd43c7b9b53ce8679b03235a1ef3c7b12" - version = "v2.0.0" - -[[projects]] - digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39" - name = "github.com/davecgh/go-spew" - packages = ["spew"] - pruneopts = "UT" - revision = "346938d642f2ec3594ed81d874461961cd0faa76" - version = "v1.1.0" - -[[projects]] - digest = "1:49a2a779b1af8f02547b5a505eb1382f9d42299ec7215f34a32535e6af9a1c9e" - name = "github.com/docker/docker" - packages = [ - "api/types", - "api/types/blkiodev", - "api/types/container", - "api/types/filters", - "api/types/mount", - "api/types/network", - "api/types/registry", - "api/types/strslice", - "api/types/swarm", - "api/types/swarm/runtime", - "api/types/versions", - "opts", - "pkg/archive", - "pkg/fileutils", - "pkg/homedir", - "pkg/idtools", - "pkg/ioutils", - "pkg/jsonmessage", - "pkg/longpath", - "pkg/mount", - "pkg/pools", - "pkg/stdcopy", - "pkg/system", - "pkg/term", - "pkg/term/windows", - ] - pruneopts = "UT" - revision = "a422774e593b33bd287d9890544ad9e09b380d8c" - -[[projects]] - digest = "1:87dcb59127512b84097086504c16595cf8fef35b9e0bfca565dfc06e198158d7" - name = "github.com/docker/go-connections" - packages = ["nat"] - pruneopts = "UT" - revision = "3ede32e2033de7505e6500d6c868c2b9ed9f169d" - version = "v0.3.0" - -[[projects]] - digest = "1:6f82cacd0af5921e99bf3f46748705239b36489464f4529a1589bc895764fb18" - name = "github.com/docker/go-units" - packages = ["."] - pruneopts = "UT" - revision = "47565b4f722fb6ceae66b95f853feed578a4a51c" - version = "v0.3.3" - -[[projects]] - digest = "1:ef99b8925cb8a662a4cc98bb84cc3b431e45b8d8570957b9a2d053b467b9ec03" - name = "github.com/fsouza/go-dockerclient" - packages = ["."] - pruneopts = "UT" - revision = "ca33ff277b527ce11b793e62f9ba244129b01caf" - version = "v1.2.0" - -[[projects]] - branch = "master" - digest = "1:54165f19429ccbd6d48f0ae7df3954b9485b166e6b163c028529892a5a87fabf" - name = "github.com/gliderlabs/pkg" - packages = ["usage"] - pruneopts = "UT" - revision = "36f28d47ec7aae4d25d3d2741ac5af91f7f18680" - -[[projects]] - digest = "1:9a688317f3231e0175b3429033f44411906c0ce119361b7b5019d01375f8cff7" - name = "github.com/gogo/protobuf" - packages = ["proto"] - pruneopts = "UT" - revision = "1adfc126b41513cc696b209667c8656ea7aac67c" - version = "v1.0.0" - -[[projects]] - digest = "1:7d9085638f210faa86720b5fe8c4cd9303edb853ed93929852a4384a4e6c956f" - name = "github.com/hashicorp/consul" - packages = ["api"] - pruneopts = "UT" - revision = "fb848fc48818f58690db09d14640513aa6bf3c02" - version = "v1.0.7" - -[[projects]] - branch = "master" - digest = "1:77cb3be9b21ba7f1a4701e870c84ea8b66e7d74c7c8951c58155fdadae9414ec" - name = "github.com/hashicorp/go-cleanhttp" - packages = ["."] - pruneopts = "UT" - revision = "d5fe4b57a186c716b0e00b8c301cbd9b4182694d" - -[[projects]] - branch = "master" - digest = "1:45aad874d3c7d5e8610427c81870fb54970b981692930ec2a319ce4cb89d7a00" - name = "github.com/hashicorp/go-rootcerts" - packages = ["."] - pruneopts = "UT" - revision = "6bb64b370b90e7ef1fa532be9e591a81c3493e00" - -[[projects]] - digest = "1:0dd7b7b01769f9df356dc99f9e4144bdbabf6c79041ea7c0892379c5737f3c44" - name = "github.com/hashicorp/serf" - packages = ["coordinate"] - pruneopts = "UT" - revision = "d6574a5bb1226678d7010325fb6c985db20ee458" - version = "v0.8.1" - -[[projects]] - digest = "1:39404cfbb35df632e9225831977e498395916ff8b20bec1aca98b4daace26e22" - name = "github.com/miekg/dns" - packages = ["."] - pruneopts = "UT" - revision = "83c435cc65d2862736428b9b4d07d0ab10ad3e4d" - version = "v1.0.5" - -[[projects]] - branch = "master" - digest = "1:12ae6210bdbdad658a9a67fd95cd9c99f7fdbf12f6d36eaf0af704e69dacf4f5" - name = "github.com/mitchellh/go-homedir" - packages = ["."] - pruneopts = "UT" - revision = "b8bc1bf767474819792c23f32d8286a45736f1c6" - -[[projects]] - digest = "1:ee4d4af67d93cc7644157882329023ce9a7bcfce956a079069a9405521c7cc8d" - name = "github.com/opencontainers/go-digest" - packages = ["."] - pruneopts = "UT" - revision = "279bed98673dd5bef374d3b6e4b09e2af76183bf" - version = "v1.0.0-rc1" - -[[projects]] - digest = "1:11db38d694c130c800d0aefb502fb02519e514dc53d9804ce51d1ad25ec27db6" - name = "github.com/opencontainers/image-spec" - packages = [ - "specs-go", - "specs-go/v1", - ] - pruneopts = "UT" - revision = "d60099175f88c47cd379c4738d158884749ed235" - version = "v1.0.1" - -[[projects]] - digest = "1:1869683e323ebff2bdf8adcb560f82bf6f8d94019d35099e3403f7df12e9c07e" - name = "github.com/opencontainers/runc" - packages = [ - "libcontainer/system", - "libcontainer/user", - ] - pruneopts = "UT" - revision = "baf6536d6259209c3edfa2b22237af82942d3dfa" - version = "v0.1.1" - -[[projects]] - digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747" - name = "github.com/pkg/errors" - packages = ["."] - pruneopts = "UT" - revision = "645ef00459ed84a119197bfb8d8205042c6df63d" - version = "v0.8.0" - -[[projects]] - digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - pruneopts = "UT" - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - branch = "master" - digest = "1:4d92d3bcd412de705100c10f0428a0b63b12f3d12455ebae46e9ea384c23b333" - name = "github.com/samuel/go-zookeeper" - packages = ["zk"] - pruneopts = "UT" - revision = "c4fab1ac1bec58281ad0667dc3f0907a9476ac47" - -[[projects]] - digest = "1:9e9193aa51197513b3abcb108970d831fbcf40ef96aa845c4f03276e1fa316d2" - name = "github.com/sirupsen/logrus" - packages = ["."] - pruneopts = "UT" - revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc" - version = "v1.0.5" - -[[projects]] - digest = "1:f85e109eda8f6080877185d1c39e98dd8795e1780c08beca28304b87fd855a1c" - name = "github.com/stretchr/testify" - packages = ["assert"] - pruneopts = "UT" - revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" - version = "v1.2.1" - -[[projects]] - branch = "master" - digest = "1:0faa1e97cfa78445bc4d20d70b40929e88040c8f3110eb497f965d41bb6e593a" - name = "golang.org/x/crypto" - packages = [ - "ed25519", - "ed25519/internal/edwards25519", - "ssh/terminal", - ] - pruneopts = "UT" - revision = "e73bf333ef8920dbb52ad18d4bd38ad9d9bc76d7" - -[[projects]] - branch = "master" - digest = "1:ebe951b4df51f83f0de0847319bb022f9c96a4649f1cf18a90aa4893ef2b82fd" - name = "golang.org/x/net" - packages = [ - "bpf", - "context", - "context/ctxhttp", - "internal/iana", - "internal/socket", - "ipv4", - "ipv6", - ] - pruneopts = "UT" - revision = "5f9ae10d9af5b1c89ae6904293b14b064d4ada23" - -[[projects]] - branch = "master" - digest = "1:6372ba5b1cf771e7774ee197d79827fea93a995e46b6c49e1bbfdce6ab46f77d" - name = "golang.org/x/sys" - packages = [ - "unix", - "windows", - ] - pruneopts = "UT" - revision = "79b0c6888797020a994db17c8510466c72fe75d9" - -[[projects]] - digest = "1:77b931135abb2ac4c127e7843d1231af0977227aafa21d9bb8c79b74644dcc39" - name = "gopkg.in/coreos/go-etcd.v0" - packages = ["etcd"] - pruneopts = "UT" - revision = "6aa2da5a7a905609c93036b9307185a04a5a84a5" - version = "v0.4.6" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/cenkalti/backoff", - "github.com/coreos/go-etcd/etcd", - "github.com/fsouza/go-dockerclient", - "github.com/gliderlabs/pkg/usage", - "github.com/hashicorp/consul/api", - "github.com/hashicorp/go-cleanhttp", - "github.com/samuel/go-zookeeper/zk", - "github.com/stretchr/testify/assert", - "gopkg.in/coreos/go-etcd.v0/etcd", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 67a8d910d..000000000 --- a/Gopkg.toml +++ /dev/null @@ -1,53 +0,0 @@ -# constraints - -[[constraint]] - name = "github.com/cenkalti/backoff" - version = "2.0.0" - -[[constraint]] - name = "github.com/hashicorp/consul" - version = "1.0.7" - -[[constraint]] - branch = "master" - name = "github.com/hashicorp/go-cleanhttp" - -[[constraint]] - name = "github.com/fsouza/go-dockerclient" - version = "1.2.0" - -[[constraint]] - name = "github.com/coreos/go-etcd" - version = "2.0.0" - -[[constraint]] - name = "gopkg.in/coreos/go-etcd.v0" - version = "0.4.6" - -[[constraint]] - branch = "master" - name = "github.com/samuel/go-zookeeper" - -[[constraint]] - branch = "master" - name = "github.com/gliderlabs/pkg" - -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.2.1" - -# overrides - -[[override]] - name = "github.com/docker/docker" - revision = "a422774e593b33bd287d9890544ad9e09b380d8c" - -[[override]] - branch = "master" - name = "github.com/Azure/go-ansiterm" - -# prune - -[prune] - go-tests = true - unused-packages = true diff --git a/README.md b/README.md index c3151649e..50c4350af 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Usage of /bin/registrator: -resync=0: Frequency with which services are resynchronized -retry-attempts=0: Max retry attempts to establish a connection with the backend. Use -1 for infinite retries -retry-interval=2000: Interval (in millisecond) between retry-attempts. - -tags="": Append tags for all registered services + -tags="": Append tags for all registered services (supports Go template) -ttl=0: TTL for services (default is no expiry) -ttl-refresh=0: Frequency with which service TTLs are refreshed ``` diff --git a/VERSION b/VERSION index 02a819f21..c29440ae3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v7 +v7.4.0 diff --git a/bridge/bridge.go b/bridge/bridge.go index f02ca99c9..b5d6e4bfa 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -1,9 +1,12 @@ package bridge import ( + "bytes" "errors" + "io/ioutil" "log" "net" + "net/http" "net/url" "os" "path" @@ -11,7 +14,10 @@ import ( "strconv" "strings" "sync" + "text/template" + "time" + jsonp "github.com/buger/jsonparser" dockerapi "github.com/fsouza/go-dockerclient" ) @@ -127,7 +133,7 @@ func (b *Bridge) Sync(quiet bool) { log.Println("error listing nonExitedContainers, skipping sync", err) return } - for listingId, _ := range b.services { + for listingId := range b.services { found := false for _, container := range nonExitedContainers { if listingId == container.ID { @@ -201,8 +207,8 @@ func (b *Bridge) add(containerId string, quiet bool) { ports := make(map[string]ServicePort) // Extract configured host port mappings, relevant when using --net=host - for port, _ := range container.Config.ExposedPorts { - published := []dockerapi.PortBinding{ {"0.0.0.0", port.Port()}, } + for port := range container.Config.ExposedPorts { + published := []dockerapi.PortBinding{{HostIP: "0.0.0.0", HostPort: port.Port()}} ports[string(port)] = servicePort(container, port, published) } @@ -218,7 +224,7 @@ func (b *Bridge) add(containerId string, quiet bool) { servicePorts := make(map[string]ServicePort) for key, port := range ports { - if b.config.Internal != true && port.HostPort == "" { + if !b.config.Internal && port.HostPort == "" { if !quiet { log.Println("ignored:", container.ID[:12], "port", port.ExposedPort, "not published on host") } @@ -290,7 +296,7 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service { } var p int - if b.config.Internal == true { + if b.config.Internal { service.IP = port.ExposedIP p, _ = strconv.Atoi(port.ExposedPort) } else { @@ -309,7 +315,7 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service { service.IP = containerIp } log.Println("using container IP " + service.IP + " from label '" + - b.config.UseIpFromLabel + "'") + b.config.UseIpFromLabel + "'") } else { log.Println("Label '" + b.config.UseIpFromLabel + "' not found in container configuration") @@ -332,13 +338,328 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service { } } + // Use container inspect data to populate tags list + // https://github.com/fsouza/go-dockerclient/blob/master/container.go#L441-L483 + ForceTags := b.config.ForceTags + if len(ForceTags) != 0 { + // Template functions + fm := template.FuncMap{ + // Template function name: strSlice + // Description: Slice string from start to end (same as s[start:end] where s represents string). + // + // Usage: strSlice s start end + // + // Example: strSlice .ID 0 12 + // { + // "Id": "e20f9c1a76565d62ae24a3bb877b17b862b6eab94f4e95a0e07ccf25087aaf4f" + // } + // Output: "e20f9c1a7656" + // + "strSlice": func(v string, i ...int) string { + if len(i) == 1 { + if len(v) >= i[0] { + return v[i[0]:] + } + } + + if len(i) == 2 { + if len(v) >= i[0] && len(v) >= i[1] { + if i[0] == 0 { + return v[:i[1]] + } + if i[1] < i[0] { + return v[i[0]:] + } + return v[i[0]:i[1]] + } + } + + return v + }, + // Template function name: sIndex + // Description: Return element from slice or array s by specifiying index i (same as s[i] where s represents slice or array - index i can also take negative values to extract elements in reverse order). + // + // Usage: sIndex i s + // + // Example: sIndex 0 .Config.Env + // { + // "Config": { + // "Env": [ + // "ENVIRONMENT=test", + // "SERVICE_8105_NAME=foo", + // "HOME=/home/foobar", + // "SERVICE_9404_NAME=bar" + // ] + // } + // } + // Output: "ENVIRONMENT=test" + // + "sIndex": func(i int, s []string) string { + if i < 0 { + i = i * -1 + if i >= len(s) { + return s[0] + } + return s[len(s)-i] + } + + if i >= len(s) { + return s[len(s)-1] + } + + return s[i] + }, + // Template function name: mIndex + // Description: Return value for key k stored in the map m (same as m["k"]). + // + // Usage: mIndex k m + // + // Example: mIndex "com.amazonaws.ecs.task-arn" .Config.Labels + // { + // "Config": { + // "Labels": { + // "com.amazonaws.ecs.task-arn": "arn:aws:ecs:region:xxxxxxxxxxxx:task/368f4403-0ee4-4f4c-b7a5-be50c57db5cf" + // } + // } + // } + // Output: "arn:aws:ecs:region:xxxxxxxxxxxx:task/368f4403-0ee4-4f4c-b7a5-be50c57db5cf" + // + "mIndex": func(k string, m map[string]string) string { + return m[k] + }, + // Template function name: toUpper + // Description: Return s with all letters mapped to their upper case. + // + // Usage: toUpper s + // + // Example: toUpper "foo" + // Output: "FOO" + // + "toUpper": func(v string) string { + return strings.ToUpper(v) + }, + // Template function name: toLower + // Description: Return s with all letters mapped to their lower case. + // + // Usage: toLower s + // + // Example: toLower "FoO" + // Output: "foo" + // + "toLower": func(v string) string { + return strings.ToLower(v) + }, + // Template function name: replace + // Description: Replace all (-1) or first n occurrences of "old" with "new" found in the designated string s. + // + // Usage: replace n old new s + // + // Example: replace -1 "=" "" "=foo=" + // Output: "foo" + // + "replace": func(n int, old, new, v string) string { + return strings.Replace(v, old, new, n) + }, + // Template function name: join + // Description: Create a single string from all the elements found in the slice s where sep will be used as separator. + // + // Usage: join sep s + // + // Example: join "," .Config.Env + // { + // "Config": { + // "Env": [ + // "ENVIRONMENT=test", + // "SERVICE_8105_NAME=foo", + // "HOME=/home/foobar", + // "SERVICE_9404_NAME=bar" + // ] + // } + // } + // Output: "ENVIRONMENT=test,SERVICE_8105_NAME=foo,HOME=/home/foobar,SERVICE_9404_NAME=bar" + // + "join": func(sep string, s []string) string { + return strings.Join(s, sep) + }, + // Template function name: split + // Description: Split string s into all substrings separated by sep and return a slice of the substrings between those separators. + // + // Usage: split sep s + // + // Example: split "," "/proc/bus,/proc/fs,/proc/irq" + // Output: [/proc/bus /proc/fs /proc/irq] + // + "split": func(sep, v string) []string { + return strings.Split(v, sep) + }, + // Template function name: splitIndex + // Description: split and sIndex function combined, index i can also take negative values to extract elements in reverse order. + // Same result can be achieved if using pipeline with both functions: {{ split sep s | sIndex i }} + // + // Usage: splitIndex i sep s + // + // Example: splitIndex -1 "/" "arn:aws:ecs:region:xxxxxxxxxxxx:task/368f4403-0ee4-4f4c-b7a5-be50c57db5cf" + // Output: "368f4403-0ee4-4f4c-b7a5-be50c57db5cf" + // + "splitIndex": func(i int, sep, v string) string { + l := strings.Split(v, sep) + + if i < 0 { + i = i * -1 + if i >= len(l) { + return l[0] + } + return l[len(l)-i] + } + + if i >= len(l) { + return l[len(l)-1] + } + + return l[i] + }, + // Template function name: matchFirstElement + // Description: Iterate through slice s and return first element that match regex expression. + // + // Usage: matchFirstElement regex s + // + // Example: matchFirstElement "^SERVICE_" .Config.Env + // { + // "Config": { + // "Env": [ + // "ENVIRONMENT=test", + // "SERVICE_8105_NAME=foo", + // "HOME=/home/foobar", + // "SERVICE_9404_NAME=bar" + // ] + // } + // } + // Output: "SERVICE_8105_NAME=foo" + // + "matchFirstElement": func(r string, s []string) string { + var m string + + re := regexp.MustCompile(r) + for _, e := range s { + if re.MatchString(e) { + m = e + break + } + } + + return m + }, + // Template function name: matchAllElements + // Description: Iterate through slice s and return slice of all elements that match regex expression. + // + // Usage: matchAllElements regex s + // + // Example: matchAllElements "^SERVICE_" .Config.Env + // { + // "Config": { + // "Env": [ + // "ENVIRONMENT=test", + // "SERVICE_8105_NAME=foo", + // "HOME=/home/foobar", + // "SERVICE_9404_NAME=bar" + // ] + // } + // } + // Output: [SERVICE_8105_NAME=foo SERVICE_9404_NAME=bar] + // + "matchAllElements": func(r string, s []string) []string { + var m []string + + re := regexp.MustCompile(r) + for _, e := range s { + if re.MatchString(e) { + m = append(m, e) + } + } + + return m + }, + // Template function name: httpGet + // Description: Fetch an object from URL. + // + // Usage: httpGet url + // + // Example: httpGet "https://ajpi.me/all" + // Output: []byte (e.g. JSON object) + // + "httpGet": func(url string) []byte { + // HTTP client configuration + c := &http.Client{ + Timeout: 10 * time.Second, + } + + res, err := c.Get(url) + if err != nil { + log.Printf("httpGet template function encountered an error while executing HTTP request: %v", err) + return []byte("") + } + + body, err := ioutil.ReadAll(res.Body) + res.Body.Close() + if err != nil { + log.Printf("httpGet template function encountered an error while reading HTTP body payload: %v", err) + return []byte("") + } + + return body + }, + // Template function name: jsonParse + // Description: Extract value from JSON object by specifying exact path (nested objects). Keys in path has to be separated with double colon sign. + // + // Usage: jsonParse b key1::key2::key3::keyN + // + // Example: jsonParse b "Additional::Country" + // { + // "Additional": { + // "Country": "United States" + // } + // } + // Output: "United States" + // + "jsonParse": func(b []byte, k string) string { + var ( + keys []string + js []byte + err error + ) + + keys = strings.Split(k, "::") + + js, _, _, err = jsonp.Get(b, keys...) + if err != nil { + log.Printf("jsonParse template function encountered an error while parsing JSON object %v: %v", keys, err) + } + + return string(js) + }, + } + + tmpl, err := template.New("tags").Funcs(fm).Parse(ForceTags) + if err != nil { + log.Fatalf("%s template parsing failed with error: %s", ForceTags, err) + } + + var b bytes.Buffer + err = tmpl.Execute(&b, container) + if err != nil { + log.Fatalf("%s template execution failed with error: %s", ForceTags, err) + } + + ForceTags = b.String() + } + if port.PortType == "udp" { service.Tags = combineTags( - mapDefault(metadata, "tags", ""), b.config.ForceTags, "udp") + mapDefault(metadata, "tags", ""), ForceTags, "udp") service.ID = service.ID + ":udp" } else { service.Tags = combineTags( - mapDefault(metadata, "tags", ""), b.config.ForceTags) + mapDefault(metadata, "tags", ""), ForceTags) } id := mapDefault(metadata, "id", "") diff --git a/go.mod b/go.mod new file mode 100644 index 000000000..0c2317997 --- /dev/null +++ b/go.mod @@ -0,0 +1,56 @@ +module github.com/gliderlabs/registrator + +go 1.17 + +require ( + github.com/buger/jsonparser v1.1.1 + github.com/cenkalti/backoff v2.0.0+incompatible + github.com/coreos/go-etcd v2.0.0+incompatible + github.com/fsouza/go-dockerclient v1.2.0 + github.com/gliderlabs/pkg v0.0.0-20161206023812-36f28d47ec7a + github.com/hashicorp/consul v1.0.7 + github.com/hashicorp/go-cleanhttp v0.5.0 + github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec + github.com/stretchr/testify v1.4.0 + gopkg.in/coreos/go-etcd.v0 v0.4.6 +) + +require ( + github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect + github.com/Microsoft/go-winio v0.4.7 // indirect + github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect + github.com/armon/go-metrics v0.3.9 // indirect + github.com/containerd/continuity v0.0.0-20180416230128-c6cef3483023 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/docker/docker v17.12.0-ce-rc1.0.20180412203414-a422774e593b+incompatible // indirect + github.com/docker/go-connections v0.3.0 // indirect + github.com/docker/go-units v0.3.3 // indirect + github.com/gogo/protobuf v1.1.1 // indirect + github.com/google/go-cmp v0.5.6 // indirect + github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect + github.com/hashicorp/go-msgpack v1.1.5 // indirect + github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 // indirect + github.com/hashicorp/go-uuid v1.0.2 // indirect + github.com/hashicorp/memberlist v0.2.4 // indirect + github.com/hashicorp/serf v0.8.1 // indirect + github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect + github.com/kr/pretty v0.1.0 // indirect + github.com/miekg/dns v1.1.26 // indirect + github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747 // indirect + github.com/mitchellh/go-testing-interface v1.14.1 // indirect + github.com/opencontainers/go-digest v1.0.0-rc1 // indirect + github.com/opencontainers/image-spec v1.0.1 // indirect + github.com/opencontainers/runc v0.1.1 // indirect + github.com/opencontainers/selinux v1.8.5 // indirect + github.com/pascaldekloe/goe v0.1.0 // indirect + github.com/pkg/errors v0.8.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/sirupsen/logrus v1.4.2 // indirect + golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 // indirect + golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect + golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect + golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect + gopkg.in/yaml.v2 v2.2.5 // indirect + gotest.tools v2.2.0+incompatible // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 000000000..4fb2a4efb --- /dev/null +++ b/go.sum @@ -0,0 +1,198 @@ +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= +github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/Microsoft/go-winio v0.4.7 h1:vOvDiY/F1avSWlCWiKJjdYKz2jVjTK3pWPHndeG4OAY= +github.com/Microsoft/go-winio v0.4.7/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= +github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= +github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-metrics v0.3.9 h1:O2sNqxBdvq8Eq5xmzljcYzAORli6RWCvEym4cJf9m18= +github.com/armon/go-metrics v0.3.9/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA= +github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/cenkalti/backoff v2.0.0+incompatible h1:5IIPUHhlnUZbcHQsQou5k1Tn58nJkeJL9U+ig5CHJbY= +github.com/cenkalti/backoff v2.0.0+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= +github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/containerd/continuity v0.0.0-20180416230128-c6cef3483023 h1:ydDbSX89iFHufaVN8xlS22aWpajSFfmXL+fQNWnhrIg= +github.com/containerd/continuity v0.0.0-20180416230128-c6cef3483023/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= +github.com/coreos/go-etcd v2.0.0+incompatible h1:bXhRBIXoTm9BYHS3gE0TtQuyNZyeEMux2sDi4oo5YOo= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/docker v17.12.0-ce-rc1.0.20180412203414-a422774e593b+incompatible h1:E2pBMI3Tq4xAK5BgWDM9Ywtm5goU95Ccl5Ed7a+taGI= +github.com/docker/docker v17.12.0-ce-rc1.0.20180412203414-a422774e593b+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.3.0 h1:3lOnM9cSzgGwx8VfK/NGOW5fLQ0GjIlCkaktF+n1M6o= +github.com/docker/go-connections v0.3.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk= +github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/fsouza/go-dockerclient v1.2.0 h1:lmjnUbZFR+De5PfuXCk62hAIlkokNtD9CaGPR8Iu5UU= +github.com/fsouza/go-dockerclient v1.2.0/go.mod h1:KpcjM623fQYE9MZiTGzKhjfxXAV9wbyX2C1cyRHfhl0= +github.com/gliderlabs/pkg v0.0.0-20161206023812-36f28d47ec7a h1:W1kDuts+zUix32MZSYO4AbmcdrH3uCNOhCLMdjb6CSw= +github.com/gliderlabs/pkg v0.0.0-20161206023812-36f28d47ec7a/go.mod h1:q6y6xycWu/sznLV4L12VC5wlCGigNs/Q++1C/kd6E0w= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/gotestyourself/gotestyourself v2.2.0+incompatible h1:AQwinXlbQR2HvPjQZOmDhRqsv5mZf+Jb1RnSLxcqZcI= +github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY= +github.com/hashicorp/consul v1.0.7 h1:GuHjalgSkzFdlBVxfKzlLJJ6bT4VCvAXV678UWpuJbw= +github.com/hashicorp/consul v1.0.7/go.mod h1:mFrjN1mfidgJfYP1xrJCF+AfRhr6Eaqhb2+sfyn/OOI= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-msgpack v1.1.5 h1:9byZdVjKTe5mce63pRVNP1L7UAmdHOTEMGehn6KvJWs= +github.com/hashicorp/go-msgpack v1.1.5/go.mod h1:gWVc3sv/wbDmR3rQsj1CAktEZzoz1YNK9NfGLXJ69/4= +github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= +github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 h1:VBj0QYQ0u2MCJzBfeYXGexnAl17GsH1yidnoxCqqD9E= +github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90/go.mod h1:o4zcYY1e0GEZI6eSEr+43QDYmuGglw1qSO6qdHUHCgg= +github.com/hashicorp/go-sockaddr v1.0.0 h1:GeH6tui99pF4NJgfnhp+L6+FfobzVW3Ah46sLo0ICXs= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE= +github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/memberlist v0.2.4 h1:OOhYzSvFnkFQXm1ysE8RjXTHsqSRDyP4emusC9K7DYg= +github.com/hashicorp/memberlist v0.2.4/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= +github.com/hashicorp/serf v0.8.1 h1:mYs6SMzu72+90OcPa5wr3nfznA4Dw9UyR791ZFNOIf4= +github.com/hashicorp/serf v0.8.1/go.mod h1:h/Ru6tmZazX7WO/GDmwdpS975F019L4t5ng5IgwbNrE= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.1.26 h1:gPxPSwALAeHJSjarOs00QjVdV9QoBvc1D2ujQUr5BzU= +github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747 h1:eQox4Rh4ewJF+mqYPxCkmBAirRnPaHEB26UkNuPyjlk= +github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= +github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= +github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= +github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= +github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJGY8Y= +github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= +github.com/opencontainers/selinux v1.8.5 h1:OkT6bMHOQ1JQQO4ihjQ49sj0+wciDcjziSVTRn8VeTA= +github.com/opencontainers/selinux v1.8.5/go.mod h1:HTvjPFoGMbpQsG886e3lQwnsRWtE4TC1OF3OUvG9FAo= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= +github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec h1:6ncX5ko6B9LntYM0YBRXkiSaZMmLYeZ/NWcmeB43mMY= +github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g= +golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190424220101-1e8e1cfdf96b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/coreos/go-etcd.v0 v0.4.6 h1:91sWpOr0QlkUqiMQ4NxB8fj3lOGEd7BLbf7t1jYkEbI= +gopkg.in/coreos/go-etcd.v0 v0.4.6/go.mod h1:LB84YzibjlMqvhy969+j43t01Pkar4RFf6ENDi+mqBM= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= diff --git a/registrator.go b/registrator.go index e26d3397a..bcb483124 100644 --- a/registrator.go +++ b/registrator.go @@ -25,7 +25,7 @@ var explicit = flag.Bool("explicit", false, "Only register containers which have var useIpFromLabel = flag.String("useIpFromLabel", "", "Use IP which is stored in a label assigned to the container") var refreshInterval = flag.Int("ttl-refresh", 0, "Frequency with which service TTLs are refreshed") var refreshTtl = flag.Int("ttl", 0, "TTL for services (default is no expiry)") -var forceTags = flag.String("tags", "", "Append tags for all registered services") +var forceTags = flag.String("tags", "", "Append tags for all registered services (supports Go template)") var resyncInterval = flag.Int("resync", 0, "Frequency with which services are resynchronized") var deregister = flag.String("deregister", "always", "Deregister exited services \"always\" or \"on-success\"") var retryAttempts = flag.Int("retry-attempts", 0, "Max retry attempts to establish a connection with the backend. Use -1 for infinite retries")