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
|
||||
// Debug output for memberlist
|
||||
Debug bool
|
||||
// Labels for the peer
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
func (a *Agent) Config() *Config {
|
||||
|
@ -57,7 +59,7 @@ func (cfg *Config) memberListConfig(peerUpdateChan chan bool, nodeEventChan chan
|
|||
}
|
||||
|
||||
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)
|
||||
|
||||
if !cfg.Debug {
|
||||
|
|
15
delegate.go
15
delegate.go
|
@ -8,19 +8,21 @@ import (
|
|||
)
|
||||
|
||||
type agentDelegate struct {
|
||||
Name string
|
||||
Addr string
|
||||
Updated time.Time
|
||||
Peers map[string]*PeerAgent
|
||||
PeerAgent
|
||||
Peers map[string]*PeerAgent `json:"peers"`
|
||||
|
||||
updateChan chan bool
|
||||
nodeEventChan chan *NodeEvent
|
||||
}
|
||||
|
||||
// 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{
|
||||
PeerAgent: PeerAgent{
|
||||
Name: name,
|
||||
Addr: addr,
|
||||
Labels: labels,
|
||||
},
|
||||
Peers: make(map[string]*PeerAgent),
|
||||
updateChan: updateCh,
|
||||
nodeEventChan: nodeEventCh,
|
||||
|
@ -83,7 +85,8 @@ func (d *agentDelegate) MergeRemoteState(buf []byte, join bool) {
|
|||
d.Peers[remoteAgent.Name] = &PeerAgent{
|
||||
Name: remoteAgent.Name,
|
||||
Addr: remoteAgent.Addr,
|
||||
Updated: time.Now(),
|
||||
Updated: d.Updated,
|
||||
Labels: remoteAgent.Labels,
|
||||
}
|
||||
// notify update
|
||||
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
|
||||
type PeerAgent struct {
|
||||
Name string
|
||||
Addr string
|
||||
Updated time.Time
|
||||
Name string `json:"name"`
|
||||
Addr string `json:"addr"`
|
||||
Updated time.Time `json:"updated"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
}
|
||||
|
||||
// Peers returns all known peers in the cluster
|
||||
|
@ -36,5 +37,6 @@ func (a *Agent) LocalNode() (*PeerAgent, error) {
|
|||
Name: a.config.NodeName,
|
||||
Addr: a.config.Address,
|
||||
Updated: time.Now(),
|
||||
Labels: a.config.Labels,
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue