Added some docs
This commit is contained in:
parent
d94e651c6e
commit
ecd995b283
|
@ -110,8 +110,6 @@ type Config struct {
|
||||||
// Revision is the commit number of the Nomad client
|
// Revision is the commit number of the Nomad client
|
||||||
Revision string
|
Revision string
|
||||||
|
|
||||||
ClientServiceName string
|
|
||||||
|
|
||||||
// ConsulConfig is the configuration to connect with Consul Agent
|
// ConsulConfig is the configuration to connect with Consul Agent
|
||||||
ConsulConfig *consul.ConsulConfig
|
ConsulConfig *consul.ConsulConfig
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,10 @@ type ConsulService struct {
|
||||||
client *consul.Client
|
client *consul.Client
|
||||||
availble bool
|
availble bool
|
||||||
|
|
||||||
serviceIdentifier string
|
serviceIdentifier string // serviceIdentifier is a token which identifies which task/alloc the service belongs to
|
||||||
delegateChecks map[string]struct{}
|
delegateChecks map[string]struct{} // delegateChecks are the checks that the Nomad client runs and reports to Consul
|
||||||
createCheck func(*structs.ServiceCheck, string) (Check, error)
|
createCheck func(*structs.ServiceCheck, string) (Check, error)
|
||||||
addrFinder func(string) (string, int)
|
addrFinder func(portLabel string) (string, int)
|
||||||
|
|
||||||
trackedServices map[string]*consul.AgentService
|
trackedServices map[string]*consul.AgentService
|
||||||
trackedChecks map[string]*consul.AgentCheckRegistration
|
trackedChecks map[string]*consul.AgentCheckRegistration
|
||||||
|
@ -132,7 +132,7 @@ func (c *ConsulService) SetDelegatedChecks(delegateChecks map[string]struct{}, c
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAddrFinder sets a function to find the host and port for a Service
|
// SetAddrFinder sets a function to find the host and port for a Service given its port label
|
||||||
func (c *ConsulService) SetAddrFinder(addrFinder func(string) (string, int)) *ConsulService {
|
func (c *ConsulService) SetAddrFinder(addrFinder func(string) (string, int)) *ConsulService {
|
||||||
c.addrFinder = addrFinder
|
c.addrFinder = addrFinder
|
||||||
return c
|
return c
|
||||||
|
@ -466,3 +466,9 @@ func (c *ConsulService) runCheck(check Check) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generateServiceIdentifier returns a service identifier based on an allocation
|
||||||
|
// id and task name
|
||||||
|
func generateServiceIdentifier(allocID string, taskName string) string {
|
||||||
|
return fmt.Sprintf("%s-%s", taskName, allocID)
|
||||||
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ type Agent struct {
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
logOutput io.Writer
|
logOutput io.Writer
|
||||||
|
|
||||||
consulService *consul.ConsulService
|
consulService *consul.ConsulService // consulService registers the Nomad agent with the consul agent
|
||||||
consulConfig *consul.ConsulConfig
|
consulConfig *consul.ConsulConfig // consulConfig is the consul configuration the Nomad client uses to connect with Consul agent
|
||||||
serverHTTPAddr string
|
serverHTTPAddr string
|
||||||
clientHTTPAddr string
|
clientHTTPAddr string
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ func NewAgent(config *Config, logOutput io.Writer) (*Agent, error) {
|
||||||
shutdownCh: make(chan struct{}),
|
shutdownCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// creating the consul client configuration that both the server and client
|
||||||
|
// uses
|
||||||
a.createConsulConfig()
|
a.createConsulConfig()
|
||||||
|
|
||||||
if err := a.setupServer(); err != nil {
|
if err := a.setupServer(); err != nil {
|
||||||
|
@ -493,35 +495,28 @@ func (a *Agent) syncAgentServicesWithConsul(clientHttpAddr string, serverHttpAdd
|
||||||
}
|
}
|
||||||
a.consulService = cs
|
a.consulService = cs
|
||||||
var services []*structs.Service
|
var services []*structs.Service
|
||||||
addrs := make(map[string]string)
|
|
||||||
if a.client != nil && a.config.ConsulConfig.ClientServiceName != "" {
|
if a.client != nil && a.config.ConsulConfig.ClientServiceName != "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
clientService := &structs.Service{
|
clientService := &structs.Service{
|
||||||
Name: a.config.ConsulConfig.ClientServiceName,
|
Name: a.config.ConsulConfig.ClientServiceName,
|
||||||
PortLabel: "clienthttpaddr",
|
PortLabel: clientHttpAddr,
|
||||||
}
|
}
|
||||||
addrs["clienthttpaddr"] = clientHttpAddr
|
|
||||||
services = append(services, clientService)
|
services = append(services, clientService)
|
||||||
cs.SetServiceIdentifier("agent-client")
|
cs.SetServiceIdentifier("agent-client")
|
||||||
}
|
}
|
||||||
if a.server != nil && a.config.ConsulConfig.ServerServiceName != "" {
|
if a.server != nil && a.config.ConsulConfig.ServerServiceName != "" {
|
||||||
serverService := &structs.Service{
|
serverService := &structs.Service{
|
||||||
Name: a.config.ConsulConfig.ServerServiceName,
|
Name: a.config.ConsulConfig.ServerServiceName,
|
||||||
PortLabel: "serverhttpaddr",
|
PortLabel: serverHttpAddr,
|
||||||
}
|
}
|
||||||
addrs["serverhttpaddr"] = serverHttpAddr
|
|
||||||
services = append(services, serverService)
|
services = append(services, serverService)
|
||||||
cs.SetServiceIdentifier("agent-server")
|
cs.SetServiceIdentifier("agent-server")
|
||||||
}
|
}
|
||||||
|
|
||||||
cs.SetAddrFinder(func(portLabel string) (string, int) {
|
cs.SetAddrFinder(func(portLabel string) (string, int) {
|
||||||
addr := addrs[portLabel]
|
host, port, err := net.SplitHostPort(portLabel)
|
||||||
if addr == "" {
|
|
||||||
return "", 0
|
|
||||||
}
|
|
||||||
host, port, err := net.SplitHostPort(addr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0
|
return "", 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue