Skip to content

Commit

Permalink
Add availibity to add default attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
gokuatkai committed Aug 16, 2018
1 parent 4b918ac commit 07e7416
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
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
9 changes: 8 additions & 1 deletion bridge/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,20 @@ 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)

for _, kv := range strings.Split(default_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
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

0 comments on commit 07e7416

Please sign in to comment.