mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
agent: config merging
This commit is contained in:
@@ -4,11 +4,14 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/nomad/client"
|
||||
"github.com/hashicorp/nomad/nomad"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
// Agent is a long running daemon that is used to run both
|
||||
@@ -65,9 +68,47 @@ func (a *Agent) setupServer() error {
|
||||
conf := nomad.DefaultConfig()
|
||||
conf.LogOutput = a.logOutput
|
||||
conf.DevMode = a.config.DevMode
|
||||
conf.Region = a.config.Region
|
||||
conf.Datacenter = a.config.Datacenter
|
||||
conf.NodeName = a.config.NodeName
|
||||
conf.Build = fmt.Sprintf("%s%s", a.config.Version, a.config.VersionPrerelease)
|
||||
if a.config.Server.Bootstrap {
|
||||
conf.Bootstrap = a.config.Server.Bootstrap
|
||||
}
|
||||
if a.config.Server.BootstrapExpect > 0 {
|
||||
conf.BootstrapExpect = a.config.Server.BootstrapExpect
|
||||
}
|
||||
if a.config.DataDir != "" {
|
||||
conf.DataDir = filepath.Join(a.config.DataDir, "server")
|
||||
}
|
||||
if a.config.Server.DataDir != "" {
|
||||
conf.DataDir = a.config.Server.DataDir
|
||||
}
|
||||
if a.config.Server.ProtocolVersion != 0 {
|
||||
conf.ProtocolVersion = uint8(a.config.Server.ProtocolVersion)
|
||||
}
|
||||
if a.config.Server.NumSchedulers != 0 {
|
||||
conf.NumSchedulers = a.config.Server.NumSchedulers
|
||||
}
|
||||
if len(a.config.Server.EnabledSchedulers) != 0 {
|
||||
conf.EnabledSchedulers = a.config.Server.EnabledSchedulers
|
||||
}
|
||||
if addr := a.config.Server.AdvertiseAddr; addr != "" {
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve advertise address: %v", err)
|
||||
}
|
||||
conf.RPCAdvertise = tcpAddr
|
||||
}
|
||||
if addr := a.config.Server.BindAddr; addr != "" {
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve bind address: %v", err)
|
||||
}
|
||||
conf.RPCAddr = tcpAddr
|
||||
}
|
||||
|
||||
// TODO: Merge configuration
|
||||
|
||||
// Create the server
|
||||
server, err := nomad.NewServer(conf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("server setup failed: %v", err)
|
||||
@@ -89,9 +130,20 @@ func (a *Agent) setupClient() error {
|
||||
}
|
||||
conf.LogOutput = a.logOutput
|
||||
conf.DevMode = a.config.DevMode
|
||||
conf.Region = a.config.Region
|
||||
conf.StateDir = a.config.Client.StateDir
|
||||
conf.AllocDir = a.config.Client.AllocDir
|
||||
conf.Servers = a.config.Client.Servers
|
||||
|
||||
// TODO: Merge configuration
|
||||
// Setup the node
|
||||
conf.Node = new(structs.Node)
|
||||
conf.Node.Datacenter = a.config.Datacenter
|
||||
conf.Node.Name = a.config.NodeName
|
||||
conf.Node.ID = a.config.Client.NodeID
|
||||
conf.Node.Meta = a.config.Client.Meta
|
||||
conf.Node.NodeClass = a.config.Client.NodeClass
|
||||
|
||||
// Create the client
|
||||
client, err := client.NewClient(conf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("client setup failed: %v", err)
|
||||
|
||||
@@ -17,6 +17,12 @@ type Config struct {
|
||||
// Region is the region this agent is in. Defaults to region1.
|
||||
Region string `hcl:"region"`
|
||||
|
||||
// Datacenter is the datacenter this agent is in. Defaults to dc1
|
||||
Datacenter string `hcl:"datacenter"`
|
||||
|
||||
// NodeName is the name we register as. Defaults to hostname.
|
||||
NodeName string `hcl:"name"`
|
||||
|
||||
// DataDir is the directory to store our state in
|
||||
DataDir string `hcl:"data_dir"`
|
||||
|
||||
@@ -57,15 +63,24 @@ type ClientConfig struct {
|
||||
// Enabled controls if we are a client
|
||||
Enabled bool `hcl:"enabled"`
|
||||
|
||||
// Datacenter is the datacenter this agent is in. Defaults to dc1
|
||||
Datacenter string `hcl:"datacenter"`
|
||||
// StateDir is the state directory
|
||||
StateDir string `hcl:"state_dir"`
|
||||
|
||||
// Name is the name we register as. Defaults to hostname.
|
||||
Name string `hcl:"name"`
|
||||
// AllocDir is the directory for storing allocation data
|
||||
AllocDir string `hcl:"alloc_dir"`
|
||||
|
||||
// Servers is a list of known server addresses. These are as "host:port"
|
||||
Servers []string `hcl:"servers"`
|
||||
|
||||
// NodeID is the unique node identifier to use. A UUID is used
|
||||
// if not provided, and stored in the data directory
|
||||
NodeID string `hcl:"node_id"`
|
||||
|
||||
// NodeClass is used to group the node by class
|
||||
NodeClass string `hcl:"node_class"`
|
||||
|
||||
// Metadata associated with the node
|
||||
Meta map[string]string `hcl:"meta"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
@@ -80,6 +95,13 @@ type ServerConfig struct {
|
||||
// by witholding peers until enough servers join.
|
||||
BootstrapExpect int `hcl:"bootstrap_expect"`
|
||||
|
||||
// DataDir is the directory to store our state in
|
||||
DataDir string `hcl:"data_dir"`
|
||||
|
||||
// ProtocolVersion is the protocol version to speak. This must be between
|
||||
// ProtocolVersionMin and ProtocolVersionMax.
|
||||
ProtocolVersion int `hcl:"protocol_version"`
|
||||
|
||||
// AdvertiseAddr is the address we use for advertising our Serf,
|
||||
// and Consul RPC IP. If not specified, bind address is used.
|
||||
AdvertiseAddr string `mapstructure:"advertise_addr"`
|
||||
@@ -89,6 +111,16 @@ type ServerConfig struct {
|
||||
// This controls the address we use for cluster facing
|
||||
// services (Gossip, Server RPC)
|
||||
BindAddr string `hcl:"bind_addr"`
|
||||
|
||||
// NumSchedulers is the number of scheduler thread that are run.
|
||||
// This can be as many as one per core, or zero to disable this server
|
||||
// from doing any scheduling work.
|
||||
NumSchedulers int `hcl:"num_schedulers"`
|
||||
|
||||
// EnabledSchedulers controls the set of sub-schedulers that are
|
||||
// enabled for this server to handle. This will restrict the evaluations
|
||||
// that the workers dequeue for processing.
|
||||
EnabledSchedulers []string `hcl:"enabled_schedulers"`
|
||||
}
|
||||
|
||||
// Telemetry is the telemetry configuration for the server
|
||||
|
||||
Reference in New Issue
Block a user