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

Enable tag drift 02 #1147

Closed
wants to merge 8 commits into from
Closed
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: 3 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ func (a *Agent) consulConfig() *consul.Config {
if a.config.SessionTTLMinRaw != "" {
base.SessionTTLMin = a.config.SessionTTLMin
}
if a.config.EnableTagDrift {
base.EnableTagDrift = true
}

// Format the build string
revision := a.config.Revision
Expand Down
3 changes: 3 additions & 0 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func (c *Command) readConfig() *Config {
"number of retries for joining -wan")
cmdFlags.StringVar(&retryIntervalWan, "retry-interval-wan", "",
"interval between join -wan attempts")
cmdFlags.BoolVar(&cmdConfig.EnableTagDrift, "enable_tag_drift", false,
"enable tag drift - ignore tags during anti-entropy")

if err := cmdFlags.Parse(c.args); err != nil {
return nil
Expand Down Expand Up @@ -745,6 +747,7 @@ AFTER_MIGRATE:
c.Ui.Info(fmt.Sprintf("Gossip encrypt: %v, RPC-TLS: %v, TLS-Incoming: %v",
gossipEncrypted, config.VerifyOutgoing, config.VerifyIncoming))
c.Ui.Info(fmt.Sprintf(" Atlas: %s", atlas))
c.Ui.Info(fmt.Sprintf("EnableTagDrift: %v", config.EnableTagDrift))

// Enable log streaming
c.Ui.Info("")
Expand Down
7 changes: 7 additions & 0 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ type Config struct {
// Minimum Session TTL
SessionTTLMin time.Duration `mapstructure:"-"`
SessionTTLMinRaw string `mapstructure:"session_ttl_min"`

// EnableTagDrift when true will inhibit comparison
// of service tags during anti-entropy
EnableTagDrift bool `mapstructure:"enable_tag_drift"`
}

// UnixSocketPermissions contains information about a unix socket, and
Expand Down Expand Up @@ -1068,6 +1072,9 @@ func MergeConfig(a, b *Config) *Config {
result.HTTPAPIResponseHeaders[field] = value
}
}
if b.EnableTagDrift {
result.EnableTagDrift = true
}

// Copy the start join addresses
result.StartJoin = make([]string, 0, len(a.StartJoin)+len(b.StartJoin))
Expand Down
5 changes: 5 additions & 0 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,10 @@ func TestDecodeConfig(t *testing.T) {
t.Fatalf("bad: %#v", config)
}

if config.EnableTagDrift {
t.Fatalf("EnableTagDrift should be false by default. Actual config: %#v", config)
}

// ACLs
input = `{"acl_token": "1234", "acl_datacenter": "dc2",
"acl_ttl": "60s", "acl_down_policy": "deny",
Expand Down Expand Up @@ -1214,6 +1218,7 @@ func TestMergeConfig(t *testing.T) {
RPC: &net.TCPAddr{},
RPCRaw: "127.0.0.5:1233",
},
EnableTagDrift: false,
}

c := MergeConfig(a, b)
Expand Down
7 changes: 7 additions & 0 deletions command/agent/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ func (l *localState) setSyncState() error {
continue
}

if l.config.EnableTagDrift {
l.logger.Printf("[DEBUG] Tag drift enabled.")
existing.Tags = service.Tags
} else {
l.logger.Printf("[DEBUG] Tag drift disabled.")
}

// If our definition is different, we need to update it
equal := reflect.DeepEqual(existing, service)
l.serviceStatus[id] = syncStatus{inSync: equal}
Expand Down
4 changes: 4 additions & 0 deletions consul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ type Config struct {
// UserEventHandler callback can be used to handle incoming
// user events. This function should not block.
UserEventHandler func(serf.UserEvent)

// EnableTagDrift when true will inhibit comparison
// of service tags during anti-entropy
EnableTagDrift bool
}

// CheckVersion is used to check if the ProtocolVersion is valid
Expand Down