Add labels for peers
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
f4f89765ea
commit
235ddbdc7e
3 changed files with 19 additions and 12 deletions
|
@ -37,6 +37,8 @@ type Config struct {
|
||||||
Peers []string
|
Peers []string
|
||||||
// Debug output for memberlist
|
// Debug output for memberlist
|
||||||
Debug bool
|
Debug bool
|
||||||
|
// Labels for the peer
|
||||||
|
Labels map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) Config() *Config {
|
func (a *Agent) Config() *Config {
|
||||||
|
@ -57,7 +59,7 @@ func (cfg *Config) memberListConfig(peerUpdateChan chan bool, nodeEventChan chan
|
||||||
}
|
}
|
||||||
|
|
||||||
mc.Name = cfg.NodeName
|
mc.Name = cfg.NodeName
|
||||||
mc.Delegate = NewAgentDelegate(cfg.NodeName, cfg.Address, peerUpdateChan, nodeEventChan)
|
mc.Delegate = NewAgentDelegate(cfg.NodeName, cfg.Address, cfg.Labels, peerUpdateChan, nodeEventChan)
|
||||||
mc.Events = NewEventHandler(nodeEventChan)
|
mc.Events = NewEventHandler(nodeEventChan)
|
||||||
|
|
||||||
if !cfg.Debug {
|
if !cfg.Debug {
|
||||||
|
|
19
delegate.go
19
delegate.go
|
@ -8,19 +8,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type agentDelegate struct {
|
type agentDelegate struct {
|
||||||
Name string
|
PeerAgent
|
||||||
Addr string
|
Peers map[string]*PeerAgent `json:"peers"`
|
||||||
Updated time.Time
|
|
||||||
Peers map[string]*PeerAgent
|
|
||||||
updateChan chan bool
|
updateChan chan bool
|
||||||
nodeEventChan chan *NodeEvent
|
nodeEventChan chan *NodeEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAgentDelegate is the agent delegate used to handle cluster events
|
// NewAgentDelegate is the agent delegate used to handle cluster events
|
||||||
func NewAgentDelegate(name, addr string, updateCh chan bool, nodeEventCh chan *NodeEvent) *agentDelegate {
|
func NewAgentDelegate(name, addr string, labels map[string]string, updateCh chan bool, nodeEventCh chan *NodeEvent) *agentDelegate {
|
||||||
agent := &agentDelegate{
|
agent := &agentDelegate{
|
||||||
Name: name,
|
PeerAgent: PeerAgent{
|
||||||
Addr: addr,
|
Name: name,
|
||||||
|
Addr: addr,
|
||||||
|
Labels: labels,
|
||||||
|
},
|
||||||
Peers: make(map[string]*PeerAgent),
|
Peers: make(map[string]*PeerAgent),
|
||||||
updateChan: updateCh,
|
updateChan: updateCh,
|
||||||
nodeEventChan: nodeEventCh,
|
nodeEventChan: nodeEventCh,
|
||||||
|
@ -83,7 +85,8 @@ func (d *agentDelegate) MergeRemoteState(buf []byte, join bool) {
|
||||||
d.Peers[remoteAgent.Name] = &PeerAgent{
|
d.Peers[remoteAgent.Name] = &PeerAgent{
|
||||||
Name: remoteAgent.Name,
|
Name: remoteAgent.Name,
|
||||||
Addr: remoteAgent.Addr,
|
Addr: remoteAgent.Addr,
|
||||||
Updated: time.Now(),
|
Updated: d.Updated,
|
||||||
|
Labels: remoteAgent.Labels,
|
||||||
}
|
}
|
||||||
// notify update
|
// notify update
|
||||||
d.updateChan <- true
|
d.updateChan <- true
|
||||||
|
|
8
peers.go
8
peers.go
|
@ -7,9 +7,10 @@ import (
|
||||||
|
|
||||||
// PeerAgent is the peer information for an agent in the cluster including name and GRPC address
|
// PeerAgent is the peer information for an agent in the cluster including name and GRPC address
|
||||||
type PeerAgent struct {
|
type PeerAgent struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Addr string
|
Addr string `json:"addr"`
|
||||||
Updated time.Time
|
Updated time.Time `json:"updated"`
|
||||||
|
Labels map[string]string `json:"labels"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peers returns all known peers in the cluster
|
// Peers returns all known peers in the cluster
|
||||||
|
@ -36,5 +37,6 @@ func (a *Agent) LocalNode() (*PeerAgent, error) {
|
||||||
Name: a.config.NodeName,
|
Name: a.config.NodeName,
|
||||||
Addr: a.config.Address,
|
Addr: a.config.Address,
|
||||||
Updated: time.Now(),
|
Updated: time.Now(),
|
||||||
|
Labels: a.config.Labels,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue