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

Add availibity to add default attrs #636

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Guide. Typically, running Registrator looks like this:
Usage of /bin/registrator:
/bin/registrator [options] <registry URI>

-attrs="": Append attrs (ServiceMeta) for all registered services (only for consul)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like that:

registrator --attrs "key_1=something,key_2=something_else"

Should I add more detail in the doc?

-cleanup=false: Remove dangling services
-deregister="always": Deregister exited services "always" or "on-success"
-internal=false: Use internal ports instead of published ones
Expand All @@ -52,8 +53,8 @@ Usage of /bin/registrator:
-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
-ttl=0: TTL for services (default is no expiry)
-ttl-refresh=0: Frequency with which service TTLs are refreshed
-ttl=0: TTL for services (default is no expiry)
```

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service {
port.HostIP = b.config.HostIp
}

metadata, metadataFromPort := serviceMetaData(container.Config, port.ExposedPort)
metadata, metadataFromPort := serviceMetaData(container.Config, port.ExposedPort, b.config.ForceAttrs)

ignore := mapDefault(metadata, "ignore", "")
if ignore != "" {
Expand Down
1 change: 1 addition & 0 deletions bridge/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
Explicit bool
UseIpFromLabel string
ForceTags string
ForceAttrs string
RefreshTtl int
RefreshInterval int
DeregisterCheck string
Expand Down
12 changes: 11 additions & 1 deletion bridge/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,23 @@ func combineTags(tagParts ...string) []string {
return tags
}

func serviceMetaData(config *dockerapi.Config, port string) (map[string]string, map[string]bool) {
func serviceMetaData(config *dockerapi.Config, port string, default_attrs string) (map[string]string, map[string]bool) {
meta := config.Env
for k, v := range config.Labels {
meta = append(meta, k+"="+v)
}
metadata := make(map[string]string)
metadataFromPort := make(map[string]bool)

meta_attrs := strings.Split(default_attrs, ",")
if len(meta_attrs) > 1 {
for _, kv := range meta_attrs {
kvp := strings.SplitN(kv, "=", 2)
key := strings.ToLower(kvp[0])
metadata[key] = kvp[1]
}
}

for _, kv := range meta {
kvp := strings.SplitN(kv, "=", 2)
if strings.HasPrefix(kvp[0], "SERVICE_") && len(kvp) > 1 {
Expand Down
1 change: 1 addition & 0 deletions docs/user/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ hostname (`-h $HOSTNAME`) and using the `-ip` Registrator option below.

Option | Since | Description
------ | ----- | -----------
`-attrs <attrs>` | v? | Force comma-separated attrs on all registered services (Consul Only)
`-cleanup` | v7 | Cleanup dangling services
`-deregister <mode>` | v6 | Deregister exited services "always" or "on-success". Default: always
`-internal` | | Use exposed ports instead of published ports
Expand Down
2 changes: 2 additions & 0 deletions registrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var useIpFromLabel = flag.String("useIpFromLabel", "", "Use IP which is stored i
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 forceAttrs = flag.String("attrs", "", "Append attrs (ServiceMeta) for all registered services (only for consul)")
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")
Expand Down Expand Up @@ -108,6 +109,7 @@ func main() {
Explicit: *explicit,
UseIpFromLabel: *useIpFromLabel,
ForceTags: *forceTags,
ForceAttrs: *forceAttrs,
RefreshTtl: *refreshTtl,
RefreshInterval: *refreshInterval,
DeregisterCheck: *deregister,
Expand Down