2015-08-16 01:54:41 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
2016-10-17 17:48:04 +00:00
|
|
|
"encoding/base64"
|
2017-02-26 22:28:23 +00:00
|
|
|
"errors"
|
2015-08-16 01:54:41 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2015-09-11 00:48:02 +00:00
|
|
|
"net"
|
2015-08-16 01:54:41 +00:00
|
|
|
"os"
|
2019-09-05 19:05:42 +00:00
|
|
|
"os/exec"
|
2019-08-14 19:29:37 +00:00
|
|
|
"os/user"
|
2015-08-16 01:54:41 +00:00
|
|
|
"path/filepath"
|
2015-10-29 12:30:26 +00:00
|
|
|
"runtime"
|
2015-12-15 07:05:25 +00:00
|
|
|
"sort"
|
2016-03-12 02:24:58 +00:00
|
|
|
"strconv"
|
2015-08-16 01:54:41 +00:00
|
|
|
"strings"
|
2015-12-02 19:55:29 +00:00
|
|
|
"time"
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2019-08-14 19:29:37 +00:00
|
|
|
sockaddr "github.com/hashicorp/go-sockaddr"
|
2017-02-26 22:28:23 +00:00
|
|
|
"github.com/hashicorp/go-sockaddr/template"
|
2015-09-06 01:41:00 +00:00
|
|
|
client "github.com/hashicorp/nomad/client/config"
|
2017-01-18 23:55:14 +00:00
|
|
|
"github.com/hashicorp/nomad/helper"
|
2015-09-06 01:41:00 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad"
|
2018-10-02 20:36:04 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2016-05-22 03:15:58 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs/config"
|
2017-08-16 22:42:15 +00:00
|
|
|
"github.com/hashicorp/nomad/version"
|
2015-08-16 01:54:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the configuration for the Nomad agent.
|
2019-04-25 20:47:03 +00:00
|
|
|
//
|
|
|
|
// time.Duration values have two parts:
|
|
|
|
// - a string field tagged with an hcl:"foo" and json:"-"
|
|
|
|
// - a time.Duration field in the same struct and a call to duration
|
|
|
|
// in config_parse.go ParseConfigFile
|
|
|
|
//
|
|
|
|
// All config structs should have an ExtraKeysHCL field to check for
|
|
|
|
// unexpected keys
|
2015-08-16 01:54:41 +00:00
|
|
|
type Config struct {
|
2015-09-14 01:18:40 +00:00
|
|
|
// Region is the region this agent is in. Defaults to global.
|
2019-04-04 18:16:08 +00:00
|
|
|
Region string `hcl:"region"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2015-08-31 01:10:23 +00:00
|
|
|
// Datacenter is the datacenter this agent is in. Defaults to dc1
|
2019-04-04 18:16:08 +00:00
|
|
|
Datacenter string `hcl:"datacenter"`
|
2015-08-31 01:10:23 +00:00
|
|
|
|
|
|
|
// NodeName is the name we register as. Defaults to hostname.
|
2019-04-04 18:16:08 +00:00
|
|
|
NodeName string `hcl:"name"`
|
2015-08-31 01:10:23 +00:00
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
// DataDir is the directory to store our state in
|
2019-04-04 18:16:08 +00:00
|
|
|
DataDir string `hcl:"data_dir"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2018-08-30 20:43:09 +00:00
|
|
|
// PluginDir is the directory to lookup plugins.
|
2019-04-04 18:16:08 +00:00
|
|
|
PluginDir string `hcl:"plugin_dir"`
|
2018-08-30 20:43:09 +00:00
|
|
|
|
2019-01-11 19:36:26 +00:00
|
|
|
// LogLevel is the level of the logs to put out
|
2019-04-04 18:16:08 +00:00
|
|
|
LogLevel string `hcl:"log_level"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2019-01-11 19:36:26 +00:00
|
|
|
// LogJson enables log output in a JSON format
|
2019-04-04 18:16:08 +00:00
|
|
|
LogJson bool `hcl:"log_json"`
|
2019-01-11 19:36:26 +00:00
|
|
|
|
2019-10-07 12:16:59 +00:00
|
|
|
// LogFile enables logging to a file
|
|
|
|
LogFile string `hcl:"log_file"`
|
|
|
|
|
|
|
|
// LogRotateDuration is the time period that logs should be rotated in
|
|
|
|
LogRotateDuration string `hcl:"log_rotate_duration"`
|
|
|
|
|
|
|
|
// LogRotateBytes is the max number of bytes that should be written to a file
|
|
|
|
LogRotateBytes int `hcl:"log_rotate_bytes"`
|
|
|
|
|
|
|
|
// LogRotateMaxFiles is the max number of log files to keep
|
|
|
|
LogRotateMaxFiles int `hcl:"log_rotate_max_files"`
|
|
|
|
|
2015-09-11 00:48:02 +00:00
|
|
|
// BindAddr is the address on which all of nomad's services will
|
|
|
|
// be bound. If not specified, this defaults to 127.0.0.1.
|
2019-04-04 18:16:08 +00:00
|
|
|
BindAddr string `hcl:"bind_addr"`
|
2015-09-11 00:48:02 +00:00
|
|
|
|
2015-08-24 00:50:33 +00:00
|
|
|
// EnableDebug is used to enable debugging HTTP endpoints
|
2019-04-04 18:16:08 +00:00
|
|
|
EnableDebug bool `hcl:"enable_debug"`
|
2015-08-24 00:50:33 +00:00
|
|
|
|
2015-09-11 01:37:42 +00:00
|
|
|
// Ports is used to control the network ports we bind to.
|
2019-04-04 18:16:08 +00:00
|
|
|
Ports *Ports `hcl:"ports"`
|
2015-09-11 01:37:42 +00:00
|
|
|
|
|
|
|
// Addresses is used to override the network addresses we bind to.
|
2016-11-09 19:37:41 +00:00
|
|
|
//
|
|
|
|
// Use normalizedAddrs if you need the host+port to bind to.
|
2019-04-04 18:16:08 +00:00
|
|
|
Addresses *Addresses `hcl:"addresses"`
|
2015-09-11 01:37:42 +00:00
|
|
|
|
2016-11-09 19:37:41 +00:00
|
|
|
// normalizedAddr is set to the Address+Port by normalizeAddrs()
|
|
|
|
normalizedAddrs *Addresses
|
|
|
|
|
2015-09-11 01:37:42 +00:00
|
|
|
// AdvertiseAddrs is used to control the addresses we advertise.
|
2019-04-04 18:16:08 +00:00
|
|
|
AdvertiseAddrs *AdvertiseAddrs `hcl:"advertise"`
|
2015-09-11 01:37:42 +00:00
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
// Client has our client related settings
|
2019-04-04 18:16:08 +00:00
|
|
|
Client *ClientConfig `hcl:"client"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
|
|
|
// Server has our server related settings
|
2019-04-04 18:16:08 +00:00
|
|
|
Server *ServerConfig `hcl:"server"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2017-08-13 20:46:47 +00:00
|
|
|
// ACL has our acl related settings
|
2019-04-04 18:16:08 +00:00
|
|
|
ACL *ACLConfig `hcl:"acl"`
|
2017-08-13 20:46:47 +00:00
|
|
|
|
2015-09-22 17:41:12 +00:00
|
|
|
// Telemetry is used to configure sending telemetry
|
2019-04-04 18:16:08 +00:00
|
|
|
Telemetry *Telemetry `hcl:"telemetry"`
|
2015-08-16 20:54:49 +00:00
|
|
|
|
2015-09-22 17:41:12 +00:00
|
|
|
// LeaveOnInt is used to gracefully leave on the interrupt signal
|
2019-04-04 18:16:08 +00:00
|
|
|
LeaveOnInt bool `hcl:"leave_on_interrupt"`
|
2015-08-16 21:34:38 +00:00
|
|
|
|
2015-09-22 17:41:12 +00:00
|
|
|
// LeaveOnTerm is used to gracefully leave on the terminate signal
|
2019-04-04 18:16:08 +00:00
|
|
|
LeaveOnTerm bool `hcl:"leave_on_terminate"`
|
2015-08-16 21:34:38 +00:00
|
|
|
|
2015-09-22 17:41:12 +00:00
|
|
|
// EnableSyslog is used to enable sending logs to syslog
|
2019-04-04 18:16:08 +00:00
|
|
|
EnableSyslog bool `hcl:"enable_syslog"`
|
2015-08-24 00:40:27 +00:00
|
|
|
|
2015-09-22 17:41:12 +00:00
|
|
|
// SyslogFacility is used to control the syslog facility used.
|
2019-04-04 18:16:08 +00:00
|
|
|
SyslogFacility string `hcl:"syslog_facility"`
|
2015-09-22 17:41:12 +00:00
|
|
|
|
|
|
|
// DisableUpdateCheck is used to disable the periodic update
|
|
|
|
// and security bulletin checking.
|
2019-04-04 18:16:08 +00:00
|
|
|
DisableUpdateCheck *bool `hcl:"disable_update_check"`
|
2015-09-22 17:41:12 +00:00
|
|
|
|
|
|
|
// DisableAnonymousSignature is used to disable setting the
|
|
|
|
// anonymous signature when doing the update check and looking
|
|
|
|
// for security bulletins
|
2019-04-04 18:16:08 +00:00
|
|
|
DisableAnonymousSignature bool `hcl:"disable_anonymous_signature"`
|
2015-09-06 01:41:00 +00:00
|
|
|
|
2016-05-22 00:39:45 +00:00
|
|
|
// Consul contains the configuration for the Consul Agent and
|
|
|
|
// parameters necessary to register services, their checks, and
|
|
|
|
// discover the current Nomad servers.
|
2019-04-04 18:16:08 +00:00
|
|
|
Consul *config.ConsulConfig `hcl:"consul"`
|
2016-03-31 06:20:24 +00:00
|
|
|
|
2016-08-06 01:13:06 +00:00
|
|
|
// Vault contains the configuration for the Vault Agent and
|
|
|
|
// parameters necessary to derive tokens.
|
2019-04-04 18:16:08 +00:00
|
|
|
Vault *config.VaultConfig `hcl:"vault"`
|
2016-08-06 01:13:06 +00:00
|
|
|
|
2021-11-24 16:20:02 +00:00
|
|
|
// UI is used to configure the web UI
|
|
|
|
UI *config.UIConfig `hcl:"ui"`
|
|
|
|
|
2015-09-06 01:41:00 +00:00
|
|
|
// NomadConfig is used to override the default config.
|
2018-03-11 18:21:52 +00:00
|
|
|
// This is largely used for testing purposes.
|
2019-04-04 18:16:08 +00:00
|
|
|
NomadConfig *nomad.Config `hcl:"-" json:"-"`
|
2015-09-06 01:41:00 +00:00
|
|
|
|
|
|
|
// ClientConfig is used to override the default config.
|
2018-03-11 18:21:52 +00:00
|
|
|
// This is largely used for testing purposes.
|
2019-04-04 18:16:08 +00:00
|
|
|
ClientConfig *client.Config `hcl:"-" json:"-"`
|
2015-09-22 17:41:12 +00:00
|
|
|
|
|
|
|
// DevMode is set by the -dev CLI flag.
|
2019-04-04 18:16:08 +00:00
|
|
|
DevMode bool `hcl:"-"`
|
2015-09-22 17:41:12 +00:00
|
|
|
|
|
|
|
// Version information is set at compilation time
|
2017-08-16 22:42:15 +00:00
|
|
|
Version *version.VersionInfo
|
2015-12-05 00:52:17 +00:00
|
|
|
|
|
|
|
// List of config files that have been loaded (in order)
|
2019-04-04 18:16:08 +00:00
|
|
|
Files []string `hcl:"-"`
|
2016-01-22 18:52:20 +00:00
|
|
|
|
2016-10-24 20:46:22 +00:00
|
|
|
// TLSConfig provides TLS related configuration for the Nomad server and
|
|
|
|
// client
|
2019-04-04 18:16:08 +00:00
|
|
|
TLSConfig *config.TLSConfig `hcl:"tls"`
|
2016-10-24 05:22:00 +00:00
|
|
|
|
2016-01-22 18:52:20 +00:00
|
|
|
// HTTPAPIResponseHeaders allows users to configure the Nomad http agent to
|
2018-03-11 17:40:03 +00:00
|
|
|
// set arbitrary headers on API responses
|
2019-04-04 18:16:08 +00:00
|
|
|
HTTPAPIResponseHeaders map[string]string `hcl:"http_api_response_headers"`
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
// Sentinel holds sentinel related settings
|
2019-04-04 18:16:08 +00:00
|
|
|
Sentinel *config.SentinelConfig `hcl:"sentinel"`
|
2017-12-18 21:16:23 +00:00
|
|
|
|
|
|
|
// Autopilot contains the configuration for Autopilot behavior.
|
2019-04-04 18:16:08 +00:00
|
|
|
Autopilot *config.AutopilotConfig `hcl:"autopilot"`
|
2018-08-29 23:26:44 +00:00
|
|
|
|
|
|
|
// Plugins is the set of configured plugins
|
2019-04-04 18:16:08 +00:00
|
|
|
Plugins []*config.PluginConfig `hcl:"plugin"`
|
|
|
|
|
2020-01-15 15:41:59 +00:00
|
|
|
// Limits contains the configuration for timeouts.
|
|
|
|
Limits config.Limits `hcl:"limits"`
|
|
|
|
|
2020-03-22 16:17:33 +00:00
|
|
|
// Audit contains the configuration for audit logging.
|
|
|
|
Audit *config.AuditConfig `hcl:"audit"`
|
|
|
|
|
2019-04-04 18:16:08 +00:00
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 17:41:12 +00:00
|
|
|
// ClientConfig is configuration specific to the client mode
|
2015-08-16 01:54:41 +00:00
|
|
|
type ClientConfig struct {
|
|
|
|
// Enabled controls if we are a client
|
2019-04-04 18:16:08 +00:00
|
|
|
Enabled bool `hcl:"enabled"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2015-08-31 01:10:23 +00:00
|
|
|
// StateDir is the state directory
|
2019-04-04 18:16:08 +00:00
|
|
|
StateDir string `hcl:"state_dir"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2015-08-31 01:10:23 +00:00
|
|
|
// AllocDir is the directory for storing allocation data
|
2019-04-04 18:16:08 +00:00
|
|
|
AllocDir string `hcl:"alloc_dir"`
|
2015-08-31 01:10:23 +00:00
|
|
|
|
|
|
|
// Servers is a list of known server addresses. These are as "host:port"
|
2019-04-04 18:16:08 +00:00
|
|
|
Servers []string `hcl:"servers"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2015-08-31 01:10:23 +00:00
|
|
|
// NodeClass is used to group the node by class
|
2019-04-04 18:16:08 +00:00
|
|
|
NodeClass string `hcl:"node_class"`
|
2015-08-31 01:10:23 +00:00
|
|
|
|
2015-09-28 23:45:32 +00:00
|
|
|
// Options is used for configuration of nomad internals,
|
|
|
|
// like fingerprinters and drivers. The format is:
|
|
|
|
//
|
|
|
|
// namespace.option = value
|
2019-04-04 18:16:08 +00:00
|
|
|
Options map[string]string `hcl:"options"`
|
2015-09-28 23:45:32 +00:00
|
|
|
|
2015-08-31 01:10:23 +00:00
|
|
|
// Metadata associated with the node
|
2019-04-04 18:16:08 +00:00
|
|
|
Meta map[string]string `hcl:"meta"`
|
2015-10-01 15:31:47 +00:00
|
|
|
|
2016-08-02 02:58:32 +00:00
|
|
|
// A mapping of directories on the host OS to attempt to embed inside each
|
|
|
|
// task's chroot.
|
2019-04-04 18:16:08 +00:00
|
|
|
ChrootEnv map[string]string `hcl:"chroot_env"`
|
2016-08-02 02:58:32 +00:00
|
|
|
|
2015-10-01 15:31:47 +00:00
|
|
|
// Interface to use for network fingerprinting
|
2019-04-04 18:16:08 +00:00
|
|
|
NetworkInterface string `hcl:"network_interface"`
|
2015-10-03 00:32:11 +00:00
|
|
|
|
2016-11-15 21:55:51 +00:00
|
|
|
// NetworkSpeed is used to override any detected or default network link
|
|
|
|
// speed.
|
2019-04-04 18:16:08 +00:00
|
|
|
NetworkSpeed int `hcl:"network_speed"`
|
2015-12-23 00:10:30 +00:00
|
|
|
|
2017-03-14 19:56:31 +00:00
|
|
|
// CpuCompute is used to override any detected or default total CPU compute.
|
2019-04-04 18:16:08 +00:00
|
|
|
CpuCompute int `hcl:"cpu_total_compute"`
|
2017-03-14 19:56:31 +00:00
|
|
|
|
2018-01-22 20:28:29 +00:00
|
|
|
// MemoryMB is used to override any detected or default total memory.
|
2019-04-04 18:16:08 +00:00
|
|
|
MemoryMB int `hcl:"memory_total_mb"`
|
2018-01-22 20:28:29 +00:00
|
|
|
|
2021-03-29 18:05:12 +00:00
|
|
|
// ReservableCores is used to override detected reservable cpu cores.
|
|
|
|
ReserveableCores string `hcl:"reservable_cores"`
|
|
|
|
|
2015-12-23 00:10:30 +00:00
|
|
|
// MaxKillTimeout allows capping the user-specifiable KillTimeout.
|
2019-04-04 18:16:08 +00:00
|
|
|
MaxKillTimeout string `hcl:"max_kill_timeout"`
|
2016-02-08 21:29:53 +00:00
|
|
|
|
|
|
|
// ClientMaxPort is the upper range of the ports that the client uses for
|
|
|
|
// communicating with plugin subsystems
|
2019-04-04 18:16:08 +00:00
|
|
|
ClientMaxPort int `hcl:"client_max_port"`
|
2016-02-08 21:29:53 +00:00
|
|
|
|
|
|
|
// ClientMinPort is the lower range of the ports that the client uses for
|
|
|
|
// communicating with plugin subsystems
|
2019-04-04 18:16:08 +00:00
|
|
|
ClientMinPort int `hcl:"client_min_port"`
|
2016-03-12 02:24:58 +00:00
|
|
|
|
2021-09-10 08:52:47 +00:00
|
|
|
// MaxDynamicPort is the upper range of the dynamic ports that the client
|
|
|
|
// uses for allocations
|
|
|
|
MaxDynamicPort int `hcl:"max_dynamic_port"`
|
|
|
|
|
|
|
|
// MinDynamicPort is the lower range of the dynamic ports that the client
|
|
|
|
// uses for allocations
|
|
|
|
MinDynamicPort int `hcl:"min_dynamic_port"`
|
|
|
|
|
2016-03-12 02:24:58 +00:00
|
|
|
// Reserved is used to reserve resources from being used by Nomad. This can
|
|
|
|
// be used to target a certain utilization or to prevent Nomad from using a
|
|
|
|
// particular set of ports.
|
2019-04-04 18:16:08 +00:00
|
|
|
Reserved *Resources `hcl:"reserved"`
|
2017-01-31 23:32:20 +00:00
|
|
|
|
|
|
|
// GCInterval is the time interval at which the client triggers garbage
|
|
|
|
// collection
|
2019-04-04 18:16:08 +00:00
|
|
|
GCInterval time.Duration
|
2019-04-25 18:54:20 +00:00
|
|
|
GCIntervalHCL string `hcl:"gc_interval" json:"-"`
|
2017-01-31 23:32:20 +00:00
|
|
|
|
2017-03-11 00:27:00 +00:00
|
|
|
// GCParallelDestroys is the number of parallel destroys the garbage
|
|
|
|
// collector will allow.
|
2019-04-04 18:16:08 +00:00
|
|
|
GCParallelDestroys int `hcl:"gc_parallel_destroys"`
|
2017-03-11 00:27:00 +00:00
|
|
|
|
2017-05-11 00:39:45 +00:00
|
|
|
// GCDiskUsageThreshold is the disk usage threshold given as a percent
|
|
|
|
// beyond which the Nomad client triggers GC of terminal allocations
|
2019-04-04 18:16:08 +00:00
|
|
|
GCDiskUsageThreshold float64 `hcl:"gc_disk_usage_threshold"`
|
2017-01-31 23:32:20 +00:00
|
|
|
|
|
|
|
// GCInodeUsageThreshold is the inode usage threshold beyond which the Nomad
|
|
|
|
// client triggers GC of the terminal allocations
|
2019-04-04 18:16:08 +00:00
|
|
|
GCInodeUsageThreshold float64 `hcl:"gc_inode_usage_threshold"`
|
2017-02-27 21:42:37 +00:00
|
|
|
|
2017-05-11 00:39:45 +00:00
|
|
|
// GCMaxAllocs is the maximum number of allocations a node can have
|
|
|
|
// before garbage collection is triggered.
|
2019-04-04 18:16:08 +00:00
|
|
|
GCMaxAllocs int `hcl:"gc_max_allocs"`
|
2017-05-11 00:39:45 +00:00
|
|
|
|
2017-02-27 21:42:37 +00:00
|
|
|
// NoHostUUID disables using the host's UUID and will force generation of a
|
|
|
|
// random UUID.
|
2019-04-04 18:16:08 +00:00
|
|
|
NoHostUUID *bool `hcl:"no_host_uuid"`
|
2018-05-11 19:52:05 +00:00
|
|
|
|
2019-06-03 19:31:39 +00:00
|
|
|
// DisableRemoteExec disables remote exec targeting tasks on this client
|
|
|
|
DisableRemoteExec bool `hcl:"disable_remote_exec"`
|
|
|
|
|
2019-08-02 19:20:14 +00:00
|
|
|
// TemplateConfig includes configuration for template rendering
|
|
|
|
TemplateConfig *ClientTemplateConfig `hcl:"template"`
|
|
|
|
|
2018-05-11 19:52:05 +00:00
|
|
|
// ServerJoin contains information that is used to attempt to join servers
|
2019-04-04 18:16:08 +00:00
|
|
|
ServerJoin *ServerJoin `hcl:"server_join"`
|
|
|
|
|
2019-07-25 14:45:41 +00:00
|
|
|
// HostVolumes contains information about the volumes an operator has made
|
|
|
|
// available to jobs running on this node.
|
|
|
|
HostVolumes []*structs.ClientHostVolumeConfig `hcl:"host_volume"`
|
|
|
|
|
2019-06-14 03:05:57 +00:00
|
|
|
// CNIPath is the path to search for CNI plugins, multiple paths can be
|
|
|
|
// specified colon delimited
|
|
|
|
CNIPath string `hcl:"cni_path"`
|
|
|
|
|
2020-07-08 19:45:04 +00:00
|
|
|
// CNIConfigDir is the directory where CNI network configuration is located. The
|
|
|
|
// client will use this path when fingerprinting CNI networks.
|
|
|
|
CNIConfigDir string `hcl:"cni_config_dir"`
|
|
|
|
|
2019-06-14 03:05:57 +00:00
|
|
|
// BridgeNetworkName is the name of the bridge to create when using the
|
|
|
|
// bridge network mode
|
|
|
|
BridgeNetworkName string `hcl:"bridge_network_name"`
|
|
|
|
|
|
|
|
// BridgeNetworkSubnet is the subnet to allocate IP addresses from when
|
|
|
|
// creating allocations with bridge networking mode. This range is local to
|
|
|
|
// the host
|
|
|
|
BridgeNetworkSubnet string `hcl:"bridge_network_subnet"`
|
2020-02-28 19:23:13 +00:00
|
|
|
|
2020-07-06 22:51:46 +00:00
|
|
|
// HostNetworks describes the different host networks available to the host
|
|
|
|
// if the host uses multiple interfaces
|
2020-06-16 15:53:10 +00:00
|
|
|
HostNetworks []*structs.ClientHostNetworkConfig `hcl:"host_network"`
|
|
|
|
|
2020-07-06 22:51:46 +00:00
|
|
|
// BindWildcardDefaultHostNetwork toggles if when there are no host networks,
|
|
|
|
// should the port mapping rules match the default network address (false) or
|
|
|
|
// matching any destination address (true). Defaults to true
|
|
|
|
BindWildcardDefaultHostNetwork bool `hcl:"bind_wildcard_default_host_network"`
|
|
|
|
|
2021-03-25 02:09:37 +00:00
|
|
|
// CgroupParent sets the parent cgroup for subsystems managed by Nomad. If the cgroup
|
|
|
|
// doest not exist Nomad will attempt to create it during startup. Defaults to '/nomad'
|
|
|
|
CgroupParent string `hcl:"cgroup_parent"`
|
|
|
|
|
2020-02-28 19:23:13 +00:00
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 19:20:14 +00:00
|
|
|
// ClientTemplateConfig is configuration on the client specific to template
|
|
|
|
// rendering
|
|
|
|
type ClientTemplateConfig struct {
|
|
|
|
|
2020-10-01 18:08:49 +00:00
|
|
|
// FunctionDenylist disables functions in consul-template that
|
2019-08-02 19:20:14 +00:00
|
|
|
// are unsafe because they expose information from the client host.
|
2020-10-01 18:08:49 +00:00
|
|
|
FunctionDenylist []string `hcl:"function_denylist"`
|
|
|
|
|
2020-10-14 22:17:47 +00:00
|
|
|
// Deprecated: COMPAT(1.0) consul-template uses inclusive language from
|
|
|
|
// v0.25.0 - function_blacklist is kept for compatibility
|
2019-08-02 19:20:14 +00:00
|
|
|
FunctionBlacklist []string `hcl:"function_blacklist"`
|
|
|
|
|
|
|
|
// DisableSandbox allows templates to access arbitrary files on the
|
|
|
|
// client host. By default templates can access files only within
|
|
|
|
// the task directory.
|
|
|
|
DisableSandbox bool `hcl:"disable_file_sandbox"`
|
|
|
|
}
|
|
|
|
|
2017-08-13 20:46:47 +00:00
|
|
|
// ACLConfig is configuration specific to the ACL system
|
|
|
|
type ACLConfig struct {
|
|
|
|
// Enabled controls if we are enforce and manage ACLs
|
2019-04-04 18:16:08 +00:00
|
|
|
Enabled bool `hcl:"enabled"`
|
2017-08-13 20:46:47 +00:00
|
|
|
|
|
|
|
// TokenTTL controls how long we cache ACL tokens. This controls
|
|
|
|
// how stale they can be when we are enforcing policies. Defaults
|
|
|
|
// to "30s". Reducing this impacts performance by forcing more
|
|
|
|
// frequent resolution.
|
2019-04-04 18:16:08 +00:00
|
|
|
TokenTTL time.Duration
|
2019-04-25 18:54:20 +00:00
|
|
|
TokenTTLHCL string `hcl:"token_ttl" json:"-"`
|
2017-08-13 20:46:47 +00:00
|
|
|
|
|
|
|
// PolicyTTL controls how long we cache ACL policies. This controls
|
|
|
|
// how stale they can be when we are enforcing policies. Defaults
|
|
|
|
// to "30s". Reducing this impacts performance by forcing more
|
|
|
|
// frequent resolution.
|
2019-04-04 18:16:08 +00:00
|
|
|
PolicyTTL time.Duration
|
2019-04-25 18:54:20 +00:00
|
|
|
PolicyTTLHCL string `hcl:"policy_ttl" json:"-"`
|
2017-08-21 03:51:30 +00:00
|
|
|
|
|
|
|
// ReplicationToken is used by servers to replicate tokens and policies
|
|
|
|
// from the authoritative region. This must be a valid management token
|
|
|
|
// within the authoritative region.
|
2019-04-04 18:16:08 +00:00
|
|
|
ReplicationToken string `hcl:"replication_token"`
|
|
|
|
|
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2017-08-13 20:46:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 17:41:12 +00:00
|
|
|
// ServerConfig is configuration specific to the server mode
|
2015-08-16 01:54:41 +00:00
|
|
|
type ServerConfig struct {
|
|
|
|
// Enabled controls if we are a server
|
2019-04-04 18:16:08 +00:00
|
|
|
Enabled bool `hcl:"enabled"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2017-08-13 20:46:47 +00:00
|
|
|
// AuthoritativeRegion is used to control which region is treated as
|
|
|
|
// the source of truth for global tokens and ACL policies.
|
2019-04-04 18:16:08 +00:00
|
|
|
AuthoritativeRegion string `hcl:"authoritative_region"`
|
2017-08-13 20:46:47 +00:00
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
// BootstrapExpect tries to automatically bootstrap the Consul cluster,
|
2016-05-15 16:41:34 +00:00
|
|
|
// by withholding peers until enough servers join.
|
2019-04-04 18:16:08 +00:00
|
|
|
BootstrapExpect int `hcl:"bootstrap_expect"`
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2015-08-31 01:10:23 +00:00
|
|
|
// DataDir is the directory to store our state in
|
2019-04-04 18:16:08 +00:00
|
|
|
DataDir string `hcl:"data_dir"`
|
2015-08-31 01:10:23 +00:00
|
|
|
|
|
|
|
// ProtocolVersion is the protocol version to speak. This must be between
|
|
|
|
// ProtocolVersionMin and ProtocolVersionMax.
|
2019-04-04 18:16:08 +00:00
|
|
|
ProtocolVersion int `hcl:"protocol_version"`
|
2015-08-31 01:10:23 +00:00
|
|
|
|
2017-11-22 00:29:11 +00:00
|
|
|
// RaftProtocol is the Raft protocol version to speak. This must be from [1-3].
|
2019-04-04 18:16:08 +00:00
|
|
|
RaftProtocol int `hcl:"raft_protocol"`
|
2017-11-22 00:29:11 +00:00
|
|
|
|
2020-05-30 13:27:33 +00:00
|
|
|
// RaftMultiplier scales the Raft timing parameters
|
|
|
|
RaftMultiplier *int `hcl:"raft_multiplier"`
|
|
|
|
|
2015-08-31 01:10:23 +00:00
|
|
|
// 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.
|
2019-04-04 18:16:08 +00:00
|
|
|
NumSchedulers *int `hcl:"num_schedulers"`
|
2015-08-31 01:10:23 +00:00
|
|
|
|
|
|
|
// 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.
|
2019-04-04 18:16:08 +00:00
|
|
|
EnabledSchedulers []string `hcl:"enabled_schedulers"`
|
2015-10-29 13:47:06 +00:00
|
|
|
|
2016-03-04 23:44:12 +00:00
|
|
|
// NodeGCThreshold controls how "old" a node must be to be collected by GC.
|
2017-02-27 19:58:10 +00:00
|
|
|
// Age is not the only requirement for a node to be GCed but the threshold
|
|
|
|
// can be used to filter by age.
|
2019-04-04 18:16:08 +00:00
|
|
|
NodeGCThreshold string `hcl:"node_gc_threshold"`
|
2015-12-02 19:55:29 +00:00
|
|
|
|
2019-07-18 12:57:47 +00:00
|
|
|
// JobGCInterval controls how often we dispatch a job to GC jobs that are
|
|
|
|
// available for garbage collection.
|
|
|
|
JobGCInterval string `hcl:"job_gc_interval"`
|
|
|
|
|
2017-02-27 19:58:10 +00:00
|
|
|
// JobGCThreshold controls how "old" a job must be to be collected by GC.
|
|
|
|
// Age is not the only requirement for a Job to be GCed but the threshold
|
|
|
|
// can be used to filter by age.
|
2019-04-04 18:16:08 +00:00
|
|
|
JobGCThreshold string `hcl:"job_gc_threshold"`
|
2017-02-27 19:58:10 +00:00
|
|
|
|
|
|
|
// EvalGCThreshold controls how "old" an eval must be to be collected by GC.
|
|
|
|
// Age is not the only requirement for a eval to be GCed but the threshold
|
|
|
|
// can be used to filter by age.
|
2019-04-04 18:16:08 +00:00
|
|
|
EvalGCThreshold string `hcl:"eval_gc_threshold"`
|
2017-02-27 19:58:10 +00:00
|
|
|
|
2017-06-29 18:29:44 +00:00
|
|
|
// DeploymentGCThreshold controls how "old" a deployment must be to be
|
|
|
|
// collected by GC. Age is not the only requirement for a deployment to be
|
|
|
|
// GCed but the threshold can be used to filter by age.
|
2019-04-04 18:16:08 +00:00
|
|
|
DeploymentGCThreshold string `hcl:"deployment_gc_threshold"`
|
2017-06-29 18:29:44 +00:00
|
|
|
|
2020-05-11 12:20:50 +00:00
|
|
|
// CSIVolumeClaimGCThreshold controls how "old" a CSI volume must be to
|
|
|
|
// have its claims collected by GC. Age is not the only requirement for
|
|
|
|
// a volume to be GCed but the threshold can be used to filter by age.
|
|
|
|
CSIVolumeClaimGCThreshold string `hcl:"csi_volume_claim_gc_threshold"`
|
|
|
|
|
2020-05-06 20:49:12 +00:00
|
|
|
// CSIPluginGCThreshold controls how "old" a CSI plugin must be to be
|
|
|
|
// collected by GC. Age is not the only requirement for a plugin to be
|
|
|
|
// GCed but the threshold can be used to filter by age.
|
|
|
|
CSIPluginGCThreshold string `hcl:"csi_plugin_gc_threshold"`
|
|
|
|
|
2016-03-04 23:44:12 +00:00
|
|
|
// HeartbeatGrace is the grace period beyond the TTL to account for network,
|
|
|
|
// processing delays and clock skew before marking a node as "down".
|
2019-04-04 18:16:08 +00:00
|
|
|
HeartbeatGrace time.Duration
|
2019-04-25 18:54:20 +00:00
|
|
|
HeartbeatGraceHCL string `hcl:"heartbeat_grace" json:"-"`
|
2017-07-19 16:38:35 +00:00
|
|
|
|
|
|
|
// MinHeartbeatTTL is the minimum time between heartbeats. This is used as
|
|
|
|
// a floor to prevent excessive updates.
|
2019-04-04 18:16:08 +00:00
|
|
|
MinHeartbeatTTL time.Duration
|
2019-04-25 18:54:20 +00:00
|
|
|
MinHeartbeatTTLHCL string `hcl:"min_heartbeat_ttl" json:"-"`
|
2017-07-19 16:38:35 +00:00
|
|
|
|
|
|
|
// MaxHeartbeatsPerSecond is the maximum target rate of heartbeats
|
|
|
|
// being processed per second. This allows the TTL to be increased
|
|
|
|
// to meet the target rate.
|
2019-04-04 18:16:08 +00:00
|
|
|
MaxHeartbeatsPerSecond float64 `hcl:"max_heartbeats_per_second"`
|
2016-03-04 23:44:12 +00:00
|
|
|
|
2021-10-06 22:48:12 +00:00
|
|
|
// FailoverHeartbeatTTL is the TTL applied to heartbeats after
|
|
|
|
// a new leader is elected, since we no longer know the status
|
|
|
|
// of all the heartbeats.
|
|
|
|
FailoverHeartbeatTTL time.Duration
|
|
|
|
FailoverHeartbeatTTLHCL string `hcl:"failover_heartbeat_ttl" json:"-"`
|
|
|
|
|
2015-12-02 19:55:29 +00:00
|
|
|
// StartJoin is a list of addresses to attempt to join when the
|
|
|
|
// agent starts. If Serf is unable to communicate with any of these
|
|
|
|
// addresses, then the agent will error and exit.
|
2018-05-11 19:52:05 +00:00
|
|
|
// Deprecated in Nomad 0.10
|
2019-04-04 18:16:08 +00:00
|
|
|
StartJoin []string `hcl:"start_join"`
|
2015-12-02 19:55:29 +00:00
|
|
|
|
|
|
|
// RetryJoin is a list of addresses to join with retry enabled.
|
2018-05-11 19:52:05 +00:00
|
|
|
// Deprecated in Nomad 0.10
|
2019-04-04 18:16:08 +00:00
|
|
|
RetryJoin []string `hcl:"retry_join"`
|
2015-12-02 19:55:29 +00:00
|
|
|
|
|
|
|
// RetryMaxAttempts specifies the maximum number of times to retry joining a
|
|
|
|
// host on startup. This is useful for cases where we know the node will be
|
|
|
|
// online eventually.
|
2018-05-11 19:52:05 +00:00
|
|
|
// Deprecated in Nomad 0.10
|
2019-04-04 18:16:08 +00:00
|
|
|
RetryMaxAttempts int `hcl:"retry_max"`
|
2015-12-02 19:55:29 +00:00
|
|
|
|
|
|
|
// RetryInterval specifies the amount of time to wait in between join
|
|
|
|
// attempts on agent start. The minimum allowed value is 1 second and
|
|
|
|
// the default is 30s.
|
2018-05-11 19:52:05 +00:00
|
|
|
// Deprecated in Nomad 0.10
|
2019-04-04 18:16:08 +00:00
|
|
|
RetryInterval time.Duration
|
2019-04-25 18:54:20 +00:00
|
|
|
RetryIntervalHCL string `hcl:"retry_interval" json:"-"`
|
2015-12-02 19:55:29 +00:00
|
|
|
|
|
|
|
// RejoinAfterLeave controls our interaction with the cluster after leave.
|
|
|
|
// When set to false (default), a leave causes Consul to not rejoin
|
|
|
|
// the cluster until an explicit join is received. If this is set to
|
|
|
|
// true, we ignore the leave, and rejoin the cluster on start.
|
2019-04-04 18:16:08 +00:00
|
|
|
RejoinAfterLeave bool `hcl:"rejoin_after_leave"`
|
2016-10-17 17:48:04 +00:00
|
|
|
|
2018-01-30 03:53:34 +00:00
|
|
|
// (Enterprise-only) NonVotingServer is whether this server will act as a
|
|
|
|
// non-voting member of the cluster to help provide read scalability.
|
2019-04-04 18:16:08 +00:00
|
|
|
NonVotingServer bool `hcl:"non_voting_server"`
|
2017-12-18 21:16:23 +00:00
|
|
|
|
2018-01-30 03:53:34 +00:00
|
|
|
// (Enterprise-only) RedundancyZone is the redundancy zone to use for this server.
|
2019-04-04 18:16:08 +00:00
|
|
|
RedundancyZone string `hcl:"redundancy_zone"`
|
2018-01-30 03:53:34 +00:00
|
|
|
|
|
|
|
// (Enterprise-only) UpgradeVersion is the custom upgrade version to use when
|
|
|
|
// performing upgrade migrations.
|
2019-04-04 18:16:08 +00:00
|
|
|
UpgradeVersion string `hcl:"upgrade_version"`
|
2018-01-30 03:53:34 +00:00
|
|
|
|
2016-10-17 17:48:04 +00:00
|
|
|
// Encryption key to use for the Serf communication
|
2019-04-04 18:16:08 +00:00
|
|
|
EncryptKey string `hcl:"encrypt" json:"-"`
|
2018-05-11 19:52:05 +00:00
|
|
|
|
|
|
|
// ServerJoin contains information that is used to attempt to join servers
|
2019-04-04 18:16:08 +00:00
|
|
|
ServerJoin *ServerJoin `hcl:"server_join"`
|
|
|
|
|
2020-01-28 16:09:36 +00:00
|
|
|
// DefaultSchedulerConfig configures the initial scheduler config to be persisted in Raft.
|
|
|
|
// Once the cluster is bootstrapped, and Raft persists the config (from here or through API),
|
|
|
|
// This value is ignored.
|
|
|
|
DefaultSchedulerConfig *structs.SchedulerConfiguration `hcl:"default_scheduler_config"`
|
2020-01-12 20:50:18 +00:00
|
|
|
|
2020-10-08 18:27:52 +00:00
|
|
|
// EnableEventBroker configures whether this server's state store
|
2020-10-02 19:04:05 +00:00
|
|
|
// will generate events for its event stream.
|
2020-10-08 18:27:52 +00:00
|
|
|
EnableEventBroker *bool `hcl:"enable_event_broker"`
|
2020-10-06 20:21:58 +00:00
|
|
|
|
|
|
|
// EventBufferSize configure the amount of events to be held in memory.
|
2020-10-08 18:27:52 +00:00
|
|
|
// If EnableEventBroker is set to true, the minimum allowable value
|
2020-10-06 20:21:58 +00:00
|
|
|
// for the EventBufferSize is 1.
|
2020-10-08 18:27:52 +00:00
|
|
|
EventBufferSize *int `hcl:"event_buffer_size"`
|
2020-10-02 19:04:05 +00:00
|
|
|
|
2021-03-23 13:08:14 +00:00
|
|
|
// LicensePath is the path to search for an enterprise license.
|
|
|
|
LicensePath string `hcl:"license_path"`
|
|
|
|
|
|
|
|
// LicenseEnv is the full enterprise license. If NOMAD_LICENSE
|
|
|
|
// is set, LicenseEnv will be set to the value at startup.
|
|
|
|
LicenseEnv string
|
|
|
|
|
2021-04-27 20:50:07 +00:00
|
|
|
// licenseAdditionalPublicKeys is an internal-only field used to
|
|
|
|
// setup test licenses.
|
|
|
|
licenseAdditionalPublicKeys []string
|
|
|
|
|
2019-04-04 18:16:08 +00:00
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
api: implement fuzzy search API
This PR introduces the /v1/search/fuzzy API endpoint, used for fuzzy
searching objects in Nomad. The fuzzy search endpoint routes requests
to the Nomad Server leader, which implements the Search.FuzzySearch RPC
method.
Requests to the fuzzy search API are based on the api.FuzzySearchRequest
object, e.g.
{
"Text": "ed",
"Context": "all"
}
Responses from the fuzzy search API are based on the api.FuzzySearchResponse
object, e.g.
{
"Index": 27,
"KnownLeader": true,
"LastContact": 0,
"Matches": {
"tasks": [
{
"ID": "redis",
"Scope": [
"default",
"example",
"cache"
]
}
],
"evals": [],
"deployment": [],
"volumes": [],
"scaling_policy": [],
"images": [
{
"ID": "redis:3.2",
"Scope": [
"default",
"example",
"cache",
"redis"
]
}
]
},
"Truncations": {
"volumes": false,
"scaling_policy": false,
"evals": false,
"deployment": false
}
}
The API is tunable using the new server.search stanza, e.g.
server {
search {
fuzzy_enabled = true
limit_query = 200
limit_results = 1000
min_term_length = 5
}
}
These values can be increased or decreased, so as to provide more
search results or to reduce load on the Nomad Server. The fuzzy search
API can be disabled entirely by setting `fuzzy_enabled` to `false`.
2021-02-23 20:24:52 +00:00
|
|
|
|
|
|
|
Search *Search `hcl:"search"`
|
2021-06-04 19:38:46 +00:00
|
|
|
|
|
|
|
// DeploymentQueryRateLimit is in queries per second and is used by the
|
|
|
|
// DeploymentWatcher to throttle the amount of simultaneously deployments
|
|
|
|
DeploymentQueryRateLimit float64 `hcl:"deploy_query_rate_limit"`
|
api: implement fuzzy search API
This PR introduces the /v1/search/fuzzy API endpoint, used for fuzzy
searching objects in Nomad. The fuzzy search endpoint routes requests
to the Nomad Server leader, which implements the Search.FuzzySearch RPC
method.
Requests to the fuzzy search API are based on the api.FuzzySearchRequest
object, e.g.
{
"Text": "ed",
"Context": "all"
}
Responses from the fuzzy search API are based on the api.FuzzySearchResponse
object, e.g.
{
"Index": 27,
"KnownLeader": true,
"LastContact": 0,
"Matches": {
"tasks": [
{
"ID": "redis",
"Scope": [
"default",
"example",
"cache"
]
}
],
"evals": [],
"deployment": [],
"volumes": [],
"scaling_policy": [],
"images": [
{
"ID": "redis:3.2",
"Scope": [
"default",
"example",
"cache",
"redis"
]
}
]
},
"Truncations": {
"volumes": false,
"scaling_policy": false,
"evals": false,
"deployment": false
}
}
The API is tunable using the new server.search stanza, e.g.
server {
search {
fuzzy_enabled = true
limit_query = 200
limit_results = 1000
min_term_length = 5
}
}
These values can be increased or decreased, so as to provide more
search results or to reduce load on the Nomad Server. The fuzzy search
API can be disabled entirely by setting `fuzzy_enabled` to `false`.
2021-02-23 20:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Search is used in servers to configure search API options.
|
|
|
|
type Search struct {
|
|
|
|
// FuzzyEnabled toggles whether the FuzzySearch API is enabled. If not
|
|
|
|
// enabled, requests to /v1/search/fuzzy will reply with a 404 response code.
|
|
|
|
//
|
|
|
|
// Default: enabled.
|
|
|
|
FuzzyEnabled bool `hcl:"fuzzy_enabled"`
|
|
|
|
|
|
|
|
// LimitQuery limits the number of objects searched in the FuzzySearch API.
|
|
|
|
// The results are indicated as truncated if the limit is reached.
|
|
|
|
//
|
|
|
|
// Lowering this value can reduce resource consumption of Nomad server when
|
|
|
|
// the FuzzySearch API is enabled.
|
|
|
|
//
|
|
|
|
// Default value: 20.
|
|
|
|
LimitQuery int `hcl:"limit_query"`
|
|
|
|
|
|
|
|
// LimitResults limits the number of results provided by the FuzzySearch API.
|
|
|
|
// The results are indicated as truncate if the limit is reached.
|
|
|
|
//
|
|
|
|
// Lowering this value can reduce resource consumption of Nomad server per
|
|
|
|
// fuzzy search request when the FuzzySearch API is enabled.
|
|
|
|
//
|
|
|
|
// Default value: 100.
|
|
|
|
LimitResults int `hcl:"limit_results"`
|
|
|
|
|
|
|
|
// MinTermLength is the minimum length of Text required before the FuzzySearch
|
|
|
|
// API will return results.
|
|
|
|
//
|
|
|
|
// Increasing this value can avoid resource consumption on Nomad server by
|
|
|
|
// reducing searches with less meaningful results.
|
|
|
|
//
|
|
|
|
// Default value: 2.
|
|
|
|
MinTermLength int `hcl:"min_term_length"`
|
2018-05-11 19:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ServerJoin is used in both clients and servers to bootstrap connections to
|
|
|
|
// servers
|
|
|
|
type ServerJoin struct {
|
|
|
|
// StartJoin is a list of addresses to attempt to join when the
|
|
|
|
// agent starts. If Serf is unable to communicate with any of these
|
|
|
|
// addresses, then the agent will error and exit.
|
2019-04-04 18:16:08 +00:00
|
|
|
StartJoin []string `hcl:"start_join"`
|
2018-05-11 19:52:05 +00:00
|
|
|
|
2018-05-25 22:43:33 +00:00
|
|
|
// RetryJoin is a list of addresses to join with retry enabled, or a single
|
|
|
|
// value to find multiple servers using go-discover syntax.
|
2019-04-04 18:16:08 +00:00
|
|
|
RetryJoin []string `hcl:"retry_join"`
|
2018-05-11 19:52:05 +00:00
|
|
|
|
|
|
|
// RetryMaxAttempts specifies the maximum number of times to retry joining a
|
|
|
|
// host on startup. This is useful for cases where we know the node will be
|
|
|
|
// online eventually.
|
2019-04-04 18:16:08 +00:00
|
|
|
RetryMaxAttempts int `hcl:"retry_max"`
|
2018-05-11 19:52:05 +00:00
|
|
|
|
|
|
|
// RetryInterval specifies the amount of time to wait in between join
|
|
|
|
// attempts on agent start. The minimum allowed value is 1 second and
|
|
|
|
// the default is 30s.
|
2019-04-04 18:16:08 +00:00
|
|
|
RetryInterval time.Duration
|
2019-04-25 18:54:20 +00:00
|
|
|
RetryIntervalHCL string `hcl:"retry_interval" json:"-"`
|
2019-04-04 18:16:08 +00:00
|
|
|
|
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2016-10-17 17:48:04 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:25:09 +00:00
|
|
|
func (s *ServerJoin) Merge(b *ServerJoin) *ServerJoin {
|
|
|
|
if s == nil {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
result := *s
|
|
|
|
|
|
|
|
if b == nil {
|
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
2018-05-24 21:19:51 +00:00
|
|
|
if len(b.StartJoin) != 0 {
|
2018-05-29 15:25:09 +00:00
|
|
|
result.StartJoin = b.StartJoin
|
2018-05-24 21:19:51 +00:00
|
|
|
}
|
|
|
|
if len(b.RetryJoin) != 0 {
|
2018-05-29 15:25:09 +00:00
|
|
|
result.RetryJoin = b.RetryJoin
|
2018-05-24 21:19:51 +00:00
|
|
|
}
|
|
|
|
if b.RetryMaxAttempts != 0 {
|
2018-05-29 15:25:09 +00:00
|
|
|
result.RetryMaxAttempts = b.RetryMaxAttempts
|
2018-05-24 21:19:51 +00:00
|
|
|
}
|
2018-05-25 21:12:13 +00:00
|
|
|
if b.RetryInterval != 0 {
|
2018-05-29 15:25:09 +00:00
|
|
|
result.RetryInterval = b.RetryInterval
|
2018-05-24 21:19:51 +00:00
|
|
|
}
|
2018-05-29 15:25:09 +00:00
|
|
|
|
|
|
|
return &result
|
2016-10-17 17:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EncryptBytes returns the encryption key configured.
|
|
|
|
func (s *ServerConfig) EncryptBytes() ([]byte, error) {
|
|
|
|
return base64.StdEncoding.DecodeString(s.EncryptKey)
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Telemetry is the telemetry configuration for the server
|
|
|
|
type Telemetry struct {
|
2019-04-04 18:16:08 +00:00
|
|
|
StatsiteAddr string `hcl:"statsite_address"`
|
|
|
|
StatsdAddr string `hcl:"statsd_address"`
|
|
|
|
DataDogAddr string `hcl:"datadog_address"`
|
|
|
|
DataDogTags []string `hcl:"datadog_tags"`
|
|
|
|
PrometheusMetrics bool `hcl:"prometheus_metrics"`
|
|
|
|
DisableHostname bool `hcl:"disable_hostname"`
|
|
|
|
UseNodeName bool `hcl:"use_node_name"`
|
|
|
|
CollectionInterval string `hcl:"collection_interval"`
|
|
|
|
collectionInterval time.Duration `hcl:"-"`
|
|
|
|
PublishAllocationMetrics bool `hcl:"publish_allocation_metrics"`
|
|
|
|
PublishNodeMetrics bool `hcl:"publish_node_metrics"`
|
2016-07-22 16:33:10 +00:00
|
|
|
|
2018-11-14 16:13:52 +00:00
|
|
|
// PrefixFilter allows for filtering out metrics from being collected
|
2019-04-04 18:16:08 +00:00
|
|
|
PrefixFilter []string `hcl:"prefix_filter"`
|
2018-11-14 16:13:52 +00:00
|
|
|
|
2018-11-14 20:02:49 +00:00
|
|
|
// FilterDefault controls whether to allow metrics that have not been specified
|
|
|
|
// by the filter
|
2019-04-04 18:16:08 +00:00
|
|
|
FilterDefault *bool `hcl:"filter_default"`
|
2018-11-14 20:02:49 +00:00
|
|
|
|
2018-11-30 03:27:39 +00:00
|
|
|
// DisableDispatchedJobSummaryMetrics allows ignoring dispatched jobs when
|
|
|
|
// publishing Job summary metrics. This is useful in environments that produce
|
2018-11-14 16:13:52 +00:00
|
|
|
// high numbers of single count dispatch jobs as the metrics for each take up
|
|
|
|
// a small memory overhead.
|
2019-04-04 18:16:08 +00:00
|
|
|
DisableDispatchedJobSummaryMetrics bool `hcl:"disable_dispatched_job_summary_metrics"`
|
2018-11-14 16:13:52 +00:00
|
|
|
|
2016-07-22 16:33:10 +00:00
|
|
|
// Circonus: see https://github.com/circonus-labs/circonus-gometrics
|
|
|
|
// for more details on the various configuration options.
|
|
|
|
// Valid configuration combinations:
|
|
|
|
// - CirconusAPIToken
|
|
|
|
// metric management enabled (search for existing check or create a new one)
|
|
|
|
// - CirconusSubmissionUrl
|
|
|
|
// metric management disabled (use check with specified submission_url,
|
|
|
|
// broker must be using a public SSL certificate)
|
|
|
|
// - CirconusAPIToken + CirconusCheckSubmissionURL
|
|
|
|
// metric management enabled (use check with specified submission_url)
|
|
|
|
// - CirconusAPIToken + CirconusCheckID
|
|
|
|
// metric management enabled (use check with specified id)
|
|
|
|
|
|
|
|
// CirconusAPIToken is a valid API Token used to create/manage check. If provided,
|
|
|
|
// metric management is enabled.
|
|
|
|
// Default: none
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusAPIToken string `hcl:"circonus_api_token"`
|
2016-07-22 16:33:10 +00:00
|
|
|
// CirconusAPIApp is an app name associated with API token.
|
2016-11-01 12:53:13 +00:00
|
|
|
// Default: "nomad"
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusAPIApp string `hcl:"circonus_api_app"`
|
2016-07-22 16:33:10 +00:00
|
|
|
// CirconusAPIURL is the base URL to use for contacting the Circonus API.
|
|
|
|
// Default: "https://api.circonus.com/v2"
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusAPIURL string `hcl:"circonus_api_url"`
|
2016-07-22 16:33:10 +00:00
|
|
|
// CirconusSubmissionInterval is the interval at which metrics are submitted to Circonus.
|
|
|
|
// Default: 10s
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusSubmissionInterval string `hcl:"circonus_submission_interval"`
|
2016-07-22 16:33:10 +00:00
|
|
|
// CirconusCheckSubmissionURL is the check.config.submission_url field from a
|
|
|
|
// previously created HTTPTRAP check.
|
|
|
|
// Default: none
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusCheckSubmissionURL string `hcl:"circonus_submission_url"`
|
2016-07-22 16:33:10 +00:00
|
|
|
// CirconusCheckID is the check id (not check bundle id) from a previously created
|
|
|
|
// HTTPTRAP check. The numeric portion of the check._cid field.
|
|
|
|
// Default: none
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusCheckID string `hcl:"circonus_check_id"`
|
2016-07-22 16:33:10 +00:00
|
|
|
// CirconusCheckForceMetricActivation will force enabling metrics, as they are encountered,
|
|
|
|
// if the metric already exists and is NOT active. If check management is enabled, the default
|
2018-03-11 17:58:59 +00:00
|
|
|
// behavior is to add new metrics as they are encountered. If the metric already exists in the
|
2016-07-22 16:33:10 +00:00
|
|
|
// check, it will *NOT* be activated. This setting overrides that behavior.
|
|
|
|
// Default: "false"
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusCheckForceMetricActivation string `hcl:"circonus_check_force_metric_activation"`
|
2017-08-07 21:13:05 +00:00
|
|
|
// CirconusCheckInstanceID serves to uniquely identify the metrics coming from this "instance".
|
2016-07-22 16:33:10 +00:00
|
|
|
// It can be used to maintain metric continuity with transient or ephemeral instances as
|
|
|
|
// they move around within an infrastructure.
|
|
|
|
// Default: hostname:app
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusCheckInstanceID string `hcl:"circonus_check_instance_id"`
|
2016-07-22 16:33:10 +00:00
|
|
|
// CirconusCheckSearchTag is a special tag which, when coupled with the instance id, helps to
|
|
|
|
// narrow down the search results when neither a Submission URL or Check ID is provided.
|
2016-11-01 12:53:13 +00:00
|
|
|
// Default: service:app (e.g. service:nomad)
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusCheckSearchTag string `hcl:"circonus_check_search_tag"`
|
2016-11-09 20:12:30 +00:00
|
|
|
// CirconusCheckTags is a comma separated list of tags to apply to the check. Note that
|
|
|
|
// the value of CirconusCheckSearchTag will always be added to the check.
|
|
|
|
// Default: none
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusCheckTags string `hcl:"circonus_check_tags"`
|
2016-11-09 20:12:30 +00:00
|
|
|
// CirconusCheckDisplayName is the name for the check which will be displayed in the Circonus UI.
|
|
|
|
// Default: value of CirconusCheckInstanceID
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusCheckDisplayName string `hcl:"circonus_check_display_name"`
|
2016-07-22 16:33:10 +00:00
|
|
|
// CirconusBrokerID is an explicit broker to use when creating a new check. The numeric portion
|
|
|
|
// of broker._cid. If metric management is enabled and neither a Submission URL nor Check ID
|
|
|
|
// is provided, an attempt will be made to search for an existing check using Instance ID and
|
|
|
|
// Search Tag. If one is not found, a new HTTPTRAP check will be created.
|
|
|
|
// Default: use Select Tag if provided, otherwise, a random Enterprise Broker associated
|
|
|
|
// with the specified API token or the default Circonus Broker.
|
|
|
|
// Default: none
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusBrokerID string `hcl:"circonus_broker_id"`
|
2016-07-22 16:33:10 +00:00
|
|
|
// CirconusBrokerSelectTag is a special tag which will be used to select a broker when
|
|
|
|
// a Broker ID is not provided. The best use of this is to as a hint for which broker
|
|
|
|
// should be used based on *where* this particular instance is running.
|
|
|
|
// (e.g. a specific geo location or datacenter, dc:sfo)
|
|
|
|
// Default: none
|
2019-04-04 18:16:08 +00:00
|
|
|
CirconusBrokerSelectTag string `hcl:"circonus_broker_select_tag"`
|
|
|
|
|
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 16:13:52 +00:00
|
|
|
// PrefixFilters parses the PrefixFilter field and returns a list of allowed and blocked filters
|
|
|
|
func (t *Telemetry) PrefixFilters() (allowed, blocked []string, err error) {
|
|
|
|
for _, rule := range t.PrefixFilter {
|
|
|
|
if rule == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
switch rule[0] {
|
|
|
|
case '+':
|
|
|
|
allowed = append(allowed, rule[1:])
|
|
|
|
case '-':
|
|
|
|
blocked = append(blocked, rule[1:])
|
|
|
|
default:
|
|
|
|
return nil, nil, fmt.Errorf("Filter rule must begin with either '+' or '-': %q", rule)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return allowed, blocked, nil
|
|
|
|
}
|
|
|
|
|
2016-11-09 19:37:41 +00:00
|
|
|
// Ports encapsulates the various ports we bind to for network services. If any
|
|
|
|
// are not specified then the defaults are used instead.
|
2015-09-11 01:37:42 +00:00
|
|
|
type Ports struct {
|
2019-04-04 18:16:08 +00:00
|
|
|
HTTP int `hcl:"http"`
|
|
|
|
RPC int `hcl:"rpc"`
|
|
|
|
Serf int `hcl:"serf"`
|
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2015-09-11 01:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Addresses encapsulates all of the addresses we bind to for various
|
|
|
|
// network services. Everything is optional and defaults to BindAddr.
|
|
|
|
type Addresses struct {
|
2019-04-04 18:16:08 +00:00
|
|
|
HTTP string `hcl:"http"`
|
|
|
|
RPC string `hcl:"rpc"`
|
|
|
|
Serf string `hcl:"serf"`
|
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2015-09-11 01:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AdvertiseAddrs is used to control the addresses we advertise out for
|
2016-11-09 19:37:41 +00:00
|
|
|
// different network services. All are optional and default to BindAddr and
|
|
|
|
// their default Port.
|
2015-09-11 01:37:42 +00:00
|
|
|
type AdvertiseAddrs struct {
|
2019-04-04 18:16:08 +00:00
|
|
|
HTTP string `hcl:"http"`
|
|
|
|
RPC string `hcl:"rpc"`
|
|
|
|
Serf string `hcl:"serf"`
|
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2016-03-12 02:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Resources struct {
|
2019-04-04 18:16:08 +00:00
|
|
|
CPU int `hcl:"cpu"`
|
|
|
|
MemoryMB int `hcl:"memory"`
|
|
|
|
DiskMB int `hcl:"disk"`
|
|
|
|
ReservedPorts string `hcl:"reserved_ports"`
|
2021-03-25 02:09:37 +00:00
|
|
|
Cores string `hcl:"cores"`
|
2019-04-04 18:16:08 +00:00
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2016-03-12 02:24:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 12:15:50 +00:00
|
|
|
// devModeConfig holds the config for the -dev and -dev-connect flags
|
2019-08-14 19:29:37 +00:00
|
|
|
type devModeConfig struct {
|
2019-08-30 12:15:50 +00:00
|
|
|
// mode flags are set at the command line via -dev and -dev-connect
|
2019-08-14 19:29:37 +00:00
|
|
|
defaultMode bool
|
|
|
|
connectMode bool
|
|
|
|
|
|
|
|
bindAddr string
|
|
|
|
iface string
|
|
|
|
}
|
|
|
|
|
|
|
|
// newDevModeConfig parses the optional string value of the -dev flag
|
2019-08-30 12:15:50 +00:00
|
|
|
func newDevModeConfig(devMode, connectMode bool) (*devModeConfig, error) {
|
|
|
|
if !devMode && !connectMode {
|
|
|
|
return nil, nil
|
2019-08-14 19:29:37 +00:00
|
|
|
}
|
|
|
|
mode := &devModeConfig{}
|
2019-08-30 12:15:50 +00:00
|
|
|
mode.defaultMode = devMode
|
|
|
|
if connectMode {
|
|
|
|
if runtime.GOOS != "linux" {
|
|
|
|
// strictly speaking -dev-connect only binds to the
|
|
|
|
// non-localhost interface, but given its purpose
|
|
|
|
// is to support a feature with network namespaces
|
|
|
|
// we'll return an error here rather than let the agent
|
|
|
|
// come up and fail unexpectedly to run jobs
|
|
|
|
return nil, fmt.Errorf("-dev-connect is only supported on linux.")
|
|
|
|
}
|
|
|
|
u, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf(
|
|
|
|
"-dev-connect uses network namespaces and is only supported for root: %v", err)
|
|
|
|
}
|
|
|
|
if u.Uid != "0" {
|
|
|
|
return nil, fmt.Errorf(
|
|
|
|
"-dev-connect uses network namespaces and is only supported for root.")
|
2019-08-14 19:29:37 +00:00
|
|
|
}
|
2019-09-05 19:05:42 +00:00
|
|
|
// Ensure Consul is on PATH
|
|
|
|
if _, err := exec.LookPath("consul"); err != nil {
|
|
|
|
return nil, fmt.Errorf("-dev-connect requires a 'consul' binary in Nomad's $PATH")
|
|
|
|
}
|
2019-08-30 12:15:50 +00:00
|
|
|
mode.connectMode = true
|
2019-08-14 19:29:37 +00:00
|
|
|
}
|
|
|
|
err := mode.networkConfig()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return mode, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mode *devModeConfig) networkConfig() error {
|
2020-03-28 16:01:51 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
mode.bindAddr = "127.0.0.1"
|
|
|
|
mode.iface = "Loopback Pseudo-Interface 1"
|
|
|
|
return nil
|
|
|
|
}
|
2019-08-14 19:29:37 +00:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
mode.bindAddr = "127.0.0.1"
|
|
|
|
mode.iface = "lo0"
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if mode != nil && mode.connectMode {
|
|
|
|
// if we hit either of the errors here we're in a weird situation
|
|
|
|
// where syscalls to get the list of network interfaces are failing.
|
|
|
|
// rather than throwing errors, we'll fall back to the default.
|
|
|
|
ifAddrs, err := sockaddr.GetDefaultInterfaces()
|
|
|
|
errMsg := "-dev=connect uses network namespaces: %v"
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf(errMsg, err)
|
|
|
|
}
|
|
|
|
if len(ifAddrs) < 1 {
|
2021-04-20 17:55:10 +00:00
|
|
|
return fmt.Errorf(errMsg, "could not find public network interface")
|
2019-08-14 19:29:37 +00:00
|
|
|
}
|
|
|
|
iface := ifAddrs[0].Name
|
|
|
|
mode.iface = iface
|
2019-08-23 15:49:24 +00:00
|
|
|
mode.bindAddr = "0.0.0.0" // allows CLI to "just work"
|
2019-08-14 19:29:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
mode.bindAddr = "127.0.0.1"
|
|
|
|
mode.iface = "lo"
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
// DevConfig is a Config that is used for dev mode of Nomad.
|
2019-08-14 19:29:37 +00:00
|
|
|
func DevConfig(mode *devModeConfig) *Config {
|
|
|
|
if mode == nil {
|
|
|
|
mode = &devModeConfig{defaultMode: true}
|
|
|
|
mode.networkConfig()
|
|
|
|
}
|
2015-09-06 00:06:05 +00:00
|
|
|
conf := DefaultConfig()
|
2019-08-14 19:29:37 +00:00
|
|
|
conf.BindAddr = mode.bindAddr
|
2015-09-06 00:06:05 +00:00
|
|
|
conf.LogLevel = "DEBUG"
|
|
|
|
conf.Client.Enabled = true
|
|
|
|
conf.Server.Enabled = true
|
2020-03-02 15:29:24 +00:00
|
|
|
conf.DevMode = true
|
|
|
|
conf.Server.BootstrapExpect = 1
|
2015-09-06 00:06:05 +00:00
|
|
|
conf.EnableDebug = true
|
|
|
|
conf.DisableAnonymousSignature = true
|
2017-01-18 23:55:14 +00:00
|
|
|
conf.Consul.AutoAdvertise = helper.BoolToPtr(true)
|
2019-08-14 19:29:37 +00:00
|
|
|
conf.Client.NetworkInterface = mode.iface
|
2015-12-10 23:24:21 +00:00
|
|
|
conf.Client.Options = map[string]string{
|
|
|
|
"driver.raw_exec.enable": "true",
|
2018-10-04 19:08:20 +00:00
|
|
|
"driver.docker.volumes": "true",
|
2016-09-27 20:13:55 +00:00
|
|
|
}
|
2017-01-31 23:32:20 +00:00
|
|
|
conf.Client.GCInterval = 10 * time.Minute
|
|
|
|
conf.Client.GCDiskUsageThreshold = 99
|
|
|
|
conf.Client.GCInodeUsageThreshold = 99
|
2017-05-12 22:57:27 +00:00
|
|
|
conf.Client.GCMaxAllocs = 50
|
2019-08-02 19:20:14 +00:00
|
|
|
conf.Client.TemplateConfig = &ClientTemplateConfig{
|
2020-10-01 18:08:49 +00:00
|
|
|
FunctionDenylist: []string{"plugin"},
|
|
|
|
DisableSandbox: false,
|
2019-08-02 19:20:14 +00:00
|
|
|
}
|
2020-07-06 22:51:46 +00:00
|
|
|
conf.Client.BindWildcardDefaultHostNetwork = true
|
2017-11-15 21:21:06 +00:00
|
|
|
conf.Telemetry.PrometheusMetrics = true
|
|
|
|
conf.Telemetry.PublishAllocationMetrics = true
|
|
|
|
conf.Telemetry.PublishNodeMetrics = true
|
2015-10-29 12:30:26 +00:00
|
|
|
|
2015-09-06 00:06:05 +00:00
|
|
|
return conf
|
2015-08-16 20:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultConfig is a the baseline configuration for Nomad
|
|
|
|
func DefaultConfig() *Config {
|
|
|
|
return &Config{
|
2015-09-11 19:19:05 +00:00
|
|
|
LogLevel: "INFO",
|
2015-09-14 01:18:40 +00:00
|
|
|
Region: "global",
|
2015-09-11 19:19:05 +00:00
|
|
|
Datacenter: "dc1",
|
2016-11-04 22:24:28 +00:00
|
|
|
BindAddr: "0.0.0.0",
|
2015-09-11 19:19:05 +00:00
|
|
|
Ports: &Ports{
|
|
|
|
HTTP: 4646,
|
|
|
|
RPC: 4647,
|
|
|
|
Serf: 4648,
|
|
|
|
},
|
2015-09-11 01:37:42 +00:00
|
|
|
Addresses: &Addresses{},
|
|
|
|
AdvertiseAddrs: &AdvertiseAddrs{},
|
2016-06-17 03:41:05 +00:00
|
|
|
Consul: config.DefaultConsulConfig(),
|
2016-08-06 01:13:06 +00:00
|
|
|
Vault: config.DefaultVaultConfig(),
|
2021-11-24 16:20:02 +00:00
|
|
|
UI: config.DefaultUIConfig(),
|
2015-09-06 00:06:05 +00:00
|
|
|
Client: &ClientConfig{
|
2017-09-05 17:30:51 +00:00
|
|
|
Enabled: false,
|
|
|
|
MaxKillTimeout: "30s",
|
|
|
|
ClientMinPort: 14000,
|
|
|
|
ClientMaxPort: 14512,
|
2021-09-10 08:52:47 +00:00
|
|
|
MinDynamicPort: 20000,
|
|
|
|
MaxDynamicPort: 32000,
|
2017-09-05 17:30:51 +00:00
|
|
|
Reserved: &Resources{},
|
|
|
|
GCInterval: 1 * time.Minute,
|
|
|
|
GCParallelDestroys: 2,
|
|
|
|
GCDiskUsageThreshold: 80,
|
|
|
|
GCInodeUsageThreshold: 70,
|
|
|
|
GCMaxAllocs: 50,
|
|
|
|
NoHostUUID: helper.BoolToPtr(true),
|
2019-06-03 19:31:39 +00:00
|
|
|
DisableRemoteExec: false,
|
2018-05-30 23:51:55 +00:00
|
|
|
ServerJoin: &ServerJoin{
|
|
|
|
RetryJoin: []string{},
|
|
|
|
RetryInterval: 30 * time.Second,
|
|
|
|
RetryMaxAttempts: 0,
|
|
|
|
},
|
2019-08-02 19:20:14 +00:00
|
|
|
TemplateConfig: &ClientTemplateConfig{
|
2020-10-01 18:08:49 +00:00
|
|
|
FunctionDenylist: []string{"plugin"},
|
|
|
|
DisableSandbox: false,
|
2019-08-02 19:20:14 +00:00
|
|
|
},
|
2020-07-06 22:51:46 +00:00
|
|
|
BindWildcardDefaultHostNetwork: true,
|
2021-07-08 13:56:57 +00:00
|
|
|
CNIPath: "/opt/cni/bin",
|
|
|
|
CNIConfigDir: "/opt/cni/config",
|
2015-09-06 00:06:05 +00:00
|
|
|
},
|
|
|
|
Server: &ServerConfig{
|
2020-10-08 18:27:52 +00:00
|
|
|
Enabled: false,
|
|
|
|
EnableEventBroker: helper.BoolToPtr(true),
|
|
|
|
EventBufferSize: helper.IntToPtr(100),
|
|
|
|
StartJoin: []string{},
|
2018-05-30 23:51:55 +00:00
|
|
|
ServerJoin: &ServerJoin{
|
|
|
|
RetryJoin: []string{},
|
|
|
|
RetryInterval: 30 * time.Second,
|
|
|
|
RetryMaxAttempts: 0,
|
|
|
|
},
|
api: implement fuzzy search API
This PR introduces the /v1/search/fuzzy API endpoint, used for fuzzy
searching objects in Nomad. The fuzzy search endpoint routes requests
to the Nomad Server leader, which implements the Search.FuzzySearch RPC
method.
Requests to the fuzzy search API are based on the api.FuzzySearchRequest
object, e.g.
{
"Text": "ed",
"Context": "all"
}
Responses from the fuzzy search API are based on the api.FuzzySearchResponse
object, e.g.
{
"Index": 27,
"KnownLeader": true,
"LastContact": 0,
"Matches": {
"tasks": [
{
"ID": "redis",
"Scope": [
"default",
"example",
"cache"
]
}
],
"evals": [],
"deployment": [],
"volumes": [],
"scaling_policy": [],
"images": [
{
"ID": "redis:3.2",
"Scope": [
"default",
"example",
"cache",
"redis"
]
}
]
},
"Truncations": {
"volumes": false,
"scaling_policy": false,
"evals": false,
"deployment": false
}
}
The API is tunable using the new server.search stanza, e.g.
server {
search {
fuzzy_enabled = true
limit_query = 200
limit_results = 1000
min_term_length = 5
}
}
These values can be increased or decreased, so as to provide more
search results or to reduce load on the Nomad Server. The fuzzy search
API can be disabled entirely by setting `fuzzy_enabled` to `false`.
2021-02-23 20:24:52 +00:00
|
|
|
Search: &Search{
|
|
|
|
FuzzyEnabled: true,
|
|
|
|
LimitQuery: 20,
|
|
|
|
LimitResults: 100,
|
|
|
|
MinTermLength: 2,
|
|
|
|
},
|
2015-09-06 00:06:05 +00:00
|
|
|
},
|
2017-08-13 20:46:47 +00:00
|
|
|
ACL: &ACLConfig{
|
|
|
|
Enabled: false,
|
2017-08-19 22:30:01 +00:00
|
|
|
TokenTTL: 30 * time.Second,
|
|
|
|
PolicyTTL: 30 * time.Second,
|
2017-08-13 20:46:47 +00:00
|
|
|
},
|
2015-12-08 23:57:06 +00:00
|
|
|
SyslogFacility: "LOCAL0",
|
2016-06-16 20:30:29 +00:00
|
|
|
Telemetry: &Telemetry{
|
|
|
|
CollectionInterval: "1s",
|
|
|
|
collectionInterval: 1 * time.Second,
|
|
|
|
},
|
2018-03-22 20:53:08 +00:00
|
|
|
TLSConfig: &config.TLSConfig{},
|
|
|
|
Sentinel: &config.SentinelConfig{},
|
|
|
|
Version: version.GetVersion(),
|
|
|
|
Autopilot: config.DefaultAutopilotConfig(),
|
2020-03-22 16:17:33 +00:00
|
|
|
Audit: &config.AuditConfig{},
|
2018-03-22 20:53:08 +00:00
|
|
|
DisableUpdateCheck: helper.BoolToPtr(false),
|
2020-01-15 15:41:59 +00:00
|
|
|
Limits: config.DefaultLimits(),
|
2015-08-16 20:54:49 +00:00
|
|
|
}
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
|
2015-12-09 00:05:15 +00:00
|
|
|
// Listener can be used to get a new listener using a custom bind address.
|
2015-09-11 00:48:02 +00:00
|
|
|
// If the bind provided address is empty, the BindAddr is used instead.
|
|
|
|
func (c *Config) Listener(proto, addr string, port int) (net.Listener, error) {
|
|
|
|
if addr == "" {
|
|
|
|
addr = c.BindAddr
|
|
|
|
}
|
2015-12-02 18:57:40 +00:00
|
|
|
|
|
|
|
// Do our own range check to avoid bugs in package net.
|
|
|
|
//
|
|
|
|
// golang.org/issue/11715
|
|
|
|
// golang.org/issue/13447
|
|
|
|
//
|
|
|
|
// Both of the above bugs were fixed by golang.org/cl/12447 which will be
|
|
|
|
// included in Go 1.6. The error returned below is the same as what Go 1.6
|
|
|
|
// will return.
|
|
|
|
if 0 > port || port > 65535 {
|
|
|
|
return nil, &net.OpError{
|
|
|
|
Op: "listen",
|
|
|
|
Net: proto,
|
|
|
|
Err: &net.AddrError{Err: "invalid port", Addr: fmt.Sprint(port)},
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 18:38:54 +00:00
|
|
|
return net.Listen(proto, net.JoinHostPort(addr, strconv.Itoa(port)))
|
2015-09-11 00:48:02 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
// Merge merges two configurations.
|
2015-12-09 00:05:15 +00:00
|
|
|
func (c *Config) Merge(b *Config) *Config {
|
|
|
|
result := *c
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2015-09-10 04:42:50 +00:00
|
|
|
if b.Region != "" {
|
|
|
|
result.Region = b.Region
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
2015-09-10 04:42:50 +00:00
|
|
|
if b.Datacenter != "" {
|
|
|
|
result.Datacenter = b.Datacenter
|
|
|
|
}
|
|
|
|
if b.NodeName != "" {
|
|
|
|
result.NodeName = b.NodeName
|
|
|
|
}
|
|
|
|
if b.DataDir != "" {
|
|
|
|
result.DataDir = b.DataDir
|
|
|
|
}
|
2018-08-30 20:43:09 +00:00
|
|
|
if b.PluginDir != "" {
|
|
|
|
result.PluginDir = b.PluginDir
|
|
|
|
}
|
2015-09-10 04:42:50 +00:00
|
|
|
if b.LogLevel != "" {
|
|
|
|
result.LogLevel = b.LogLevel
|
|
|
|
}
|
2019-01-11 19:36:26 +00:00
|
|
|
if b.LogJson {
|
|
|
|
result.LogJson = true
|
|
|
|
}
|
2019-10-07 12:16:59 +00:00
|
|
|
if b.LogFile != "" {
|
|
|
|
result.LogFile = b.LogFile
|
|
|
|
}
|
|
|
|
if b.LogRotateDuration != "" {
|
|
|
|
result.LogRotateDuration = b.LogRotateDuration
|
|
|
|
}
|
|
|
|
if b.LogRotateBytes != 0 {
|
|
|
|
result.LogRotateBytes = b.LogRotateBytes
|
|
|
|
}
|
|
|
|
if b.LogRotateMaxFiles != 0 {
|
|
|
|
result.LogRotateMaxFiles = b.LogRotateMaxFiles
|
|
|
|
}
|
2015-09-11 00:48:02 +00:00
|
|
|
if b.BindAddr != "" {
|
|
|
|
result.BindAddr = b.BindAddr
|
|
|
|
}
|
2015-09-10 04:42:50 +00:00
|
|
|
if b.EnableDebug {
|
|
|
|
result.EnableDebug = true
|
|
|
|
}
|
|
|
|
if b.LeaveOnInt {
|
|
|
|
result.LeaveOnInt = true
|
|
|
|
}
|
|
|
|
if b.LeaveOnTerm {
|
|
|
|
result.LeaveOnTerm = true
|
|
|
|
}
|
|
|
|
if b.EnableSyslog {
|
|
|
|
result.EnableSyslog = true
|
|
|
|
}
|
|
|
|
if b.SyslogFacility != "" {
|
|
|
|
result.SyslogFacility = b.SyslogFacility
|
|
|
|
}
|
2018-03-22 20:53:08 +00:00
|
|
|
if b.DisableUpdateCheck != nil {
|
|
|
|
result.DisableUpdateCheck = helper.BoolToPtr(*b.DisableUpdateCheck)
|
2015-09-10 04:42:50 +00:00
|
|
|
}
|
|
|
|
if b.DisableAnonymousSignature {
|
|
|
|
result.DisableAnonymousSignature = true
|
|
|
|
}
|
2015-09-10 18:24:59 +00:00
|
|
|
|
|
|
|
// Apply the telemetry config
|
|
|
|
if result.Telemetry == nil && b.Telemetry != nil {
|
|
|
|
telemetry := *b.Telemetry
|
|
|
|
result.Telemetry = &telemetry
|
|
|
|
} else if b.Telemetry != nil {
|
|
|
|
result.Telemetry = result.Telemetry.Merge(b.Telemetry)
|
|
|
|
}
|
|
|
|
|
2016-10-24 20:46:22 +00:00
|
|
|
// Apply the TLS Config
|
|
|
|
if result.TLSConfig == nil && b.TLSConfig != nil {
|
2017-11-15 01:53:23 +00:00
|
|
|
result.TLSConfig = b.TLSConfig.Copy()
|
2016-10-24 20:46:22 +00:00
|
|
|
} else if b.TLSConfig != nil {
|
|
|
|
result.TLSConfig = result.TLSConfig.Merge(b.TLSConfig)
|
|
|
|
}
|
|
|
|
|
2015-09-10 18:24:59 +00:00
|
|
|
// Apply the client config
|
|
|
|
if result.Client == nil && b.Client != nil {
|
|
|
|
client := *b.Client
|
|
|
|
result.Client = &client
|
|
|
|
} else if b.Client != nil {
|
|
|
|
result.Client = result.Client.Merge(b.Client)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the server config
|
|
|
|
if result.Server == nil && b.Server != nil {
|
|
|
|
server := *b.Server
|
|
|
|
result.Server = &server
|
|
|
|
} else if b.Server != nil {
|
|
|
|
result.Server = result.Server.Merge(b.Server)
|
|
|
|
}
|
|
|
|
|
2017-08-13 20:46:47 +00:00
|
|
|
// Apply the acl config
|
|
|
|
if result.ACL == nil && b.ACL != nil {
|
|
|
|
server := *b.ACL
|
|
|
|
result.ACL = &server
|
|
|
|
} else if b.ACL != nil {
|
|
|
|
result.ACL = result.ACL.Merge(b.ACL)
|
|
|
|
}
|
|
|
|
|
2020-03-22 16:17:33 +00:00
|
|
|
// Apply the Audit config
|
|
|
|
if result.Audit == nil && b.Audit != nil {
|
|
|
|
audit := *b.Audit
|
|
|
|
result.Audit = &audit
|
|
|
|
} else if b.ACL != nil {
|
|
|
|
result.Audit = result.Audit.Merge(b.Audit)
|
|
|
|
}
|
|
|
|
|
2015-09-11 01:37:42 +00:00
|
|
|
// Apply the ports config
|
|
|
|
if result.Ports == nil && b.Ports != nil {
|
|
|
|
ports := *b.Ports
|
|
|
|
result.Ports = &ports
|
|
|
|
} else if b.Ports != nil {
|
|
|
|
result.Ports = result.Ports.Merge(b.Ports)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the address config
|
|
|
|
if result.Addresses == nil && b.Addresses != nil {
|
|
|
|
addrs := *b.Addresses
|
|
|
|
result.Addresses = &addrs
|
|
|
|
} else if b.Addresses != nil {
|
|
|
|
result.Addresses = result.Addresses.Merge(b.Addresses)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the advertise addrs config
|
|
|
|
if result.AdvertiseAddrs == nil && b.AdvertiseAddrs != nil {
|
|
|
|
advertise := *b.AdvertiseAddrs
|
|
|
|
result.AdvertiseAddrs = &advertise
|
|
|
|
} else if b.AdvertiseAddrs != nil {
|
|
|
|
result.AdvertiseAddrs = result.AdvertiseAddrs.Merge(b.AdvertiseAddrs)
|
|
|
|
}
|
|
|
|
|
2016-05-11 22:24:37 +00:00
|
|
|
// Apply the Consul Configuration
|
2016-05-22 00:39:45 +00:00
|
|
|
if result.Consul == nil && b.Consul != nil {
|
2017-02-02 19:12:07 +00:00
|
|
|
result.Consul = b.Consul.Copy()
|
2016-05-22 00:39:45 +00:00
|
|
|
} else if b.Consul != nil {
|
|
|
|
result.Consul = result.Consul.Merge(b.Consul)
|
2016-05-11 22:24:37 +00:00
|
|
|
}
|
|
|
|
|
2016-08-06 01:13:06 +00:00
|
|
|
// Apply the Vault Configuration
|
|
|
|
if result.Vault == nil && b.Vault != nil {
|
|
|
|
vaultConfig := *b.Vault
|
|
|
|
result.Vault = &vaultConfig
|
|
|
|
} else if b.Vault != nil {
|
|
|
|
result.Vault = result.Vault.Merge(b.Vault)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:20:02 +00:00
|
|
|
// Apply the UI Configuration
|
|
|
|
if result.UI == nil && b.UI != nil {
|
|
|
|
uiConfig := *b.UI
|
|
|
|
result.UI = &uiConfig
|
|
|
|
} else if b.UI != nil {
|
|
|
|
result.UI = result.UI.Merge(b.UI)
|
|
|
|
}
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
// Apply the sentinel config
|
|
|
|
if result.Sentinel == nil && b.Sentinel != nil {
|
|
|
|
server := *b.Sentinel
|
|
|
|
result.Sentinel = &server
|
|
|
|
} else if b.Sentinel != nil {
|
|
|
|
result.Sentinel = result.Sentinel.Merge(b.Sentinel)
|
|
|
|
}
|
|
|
|
|
2017-12-18 21:16:23 +00:00
|
|
|
if result.Autopilot == nil && b.Autopilot != nil {
|
|
|
|
autopilot := *b.Autopilot
|
|
|
|
result.Autopilot = &autopilot
|
|
|
|
} else if b.Autopilot != nil {
|
|
|
|
result.Autopilot = result.Autopilot.Merge(b.Autopilot)
|
|
|
|
}
|
|
|
|
|
2018-08-29 23:26:44 +00:00
|
|
|
if len(result.Plugins) == 0 && len(b.Plugins) != 0 {
|
|
|
|
copy := make([]*config.PluginConfig, len(b.Plugins))
|
|
|
|
for i, v := range b.Plugins {
|
|
|
|
copy[i] = v.Copy()
|
|
|
|
}
|
|
|
|
result.Plugins = copy
|
|
|
|
} else if len(b.Plugins) != 0 {
|
|
|
|
result.Plugins = config.PluginConfigSetMerge(result.Plugins, b.Plugins)
|
|
|
|
}
|
|
|
|
|
2015-12-05 00:52:17 +00:00
|
|
|
// Merge config files lists
|
2015-12-05 00:59:04 +00:00
|
|
|
result.Files = append(result.Files, b.Files...)
|
2015-12-05 00:52:17 +00:00
|
|
|
|
2016-05-17 03:57:54 +00:00
|
|
|
// Add the http API response header map values
|
|
|
|
if result.HTTPAPIResponseHeaders == nil {
|
|
|
|
result.HTTPAPIResponseHeaders = make(map[string]string)
|
|
|
|
}
|
|
|
|
for k, v := range b.HTTPAPIResponseHeaders {
|
|
|
|
result.HTTPAPIResponseHeaders[k] = v
|
|
|
|
}
|
|
|
|
|
2020-01-15 15:41:59 +00:00
|
|
|
result.Limits = c.Limits.Merge(b.Limits)
|
|
|
|
|
2015-09-10 18:24:59 +00:00
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
2016-11-09 23:51:00 +00:00
|
|
|
// normalizeAddrs normalizes Addresses and AdvertiseAddrs to always be
|
2021-04-20 17:55:10 +00:00
|
|
|
// initialized and have reasonable defaults.
|
2016-11-09 19:37:41 +00:00
|
|
|
func (c *Config) normalizeAddrs() error {
|
2017-02-26 22:28:23 +00:00
|
|
|
if c.BindAddr != "" {
|
|
|
|
ipStr, err := parseSingleIPTemplate(c.BindAddr)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Bind address resolution failed: %v", err)
|
|
|
|
}
|
|
|
|
c.BindAddr = ipStr
|
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := normalizeBind(c.Addresses.HTTP, c.BindAddr)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to parse HTTP address: %v", err)
|
|
|
|
}
|
|
|
|
c.Addresses.HTTP = addr
|
|
|
|
|
|
|
|
addr, err = normalizeBind(c.Addresses.RPC, c.BindAddr)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to parse RPC address: %v", err)
|
|
|
|
}
|
|
|
|
c.Addresses.RPC = addr
|
|
|
|
|
|
|
|
addr, err = normalizeBind(c.Addresses.Serf, c.BindAddr)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to parse Serf address: %v", err)
|
|
|
|
}
|
|
|
|
c.Addresses.Serf = addr
|
|
|
|
|
2016-11-09 19:37:41 +00:00
|
|
|
c.normalizedAddrs = &Addresses{
|
2016-11-28 18:38:54 +00:00
|
|
|
HTTP: net.JoinHostPort(c.Addresses.HTTP, strconv.Itoa(c.Ports.HTTP)),
|
|
|
|
RPC: net.JoinHostPort(c.Addresses.RPC, strconv.Itoa(c.Ports.RPC)),
|
|
|
|
Serf: net.JoinHostPort(c.Addresses.Serf, strconv.Itoa(c.Ports.Serf)),
|
2016-11-09 19:37:41 +00:00
|
|
|
}
|
|
|
|
|
2017-03-13 21:43:06 +00:00
|
|
|
addr, err = normalizeAdvertise(c.AdvertiseAddrs.HTTP, c.Addresses.HTTP, c.Ports.HTTP, c.DevMode)
|
2016-11-09 19:37:41 +00:00
|
|
|
if err != nil {
|
2017-07-21 04:07:32 +00:00
|
|
|
return fmt.Errorf("Failed to parse HTTP advertise address (%v, %v, %v, %v): %v", c.AdvertiseAddrs.HTTP, c.Addresses.HTTP, c.Ports.HTTP, c.DevMode, err)
|
2016-11-09 19:37:41 +00:00
|
|
|
}
|
|
|
|
c.AdvertiseAddrs.HTTP = addr
|
|
|
|
|
|
|
|
addr, err = normalizeAdvertise(c.AdvertiseAddrs.RPC, c.Addresses.RPC, c.Ports.RPC, c.DevMode)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to parse RPC advertise address: %v", err)
|
|
|
|
}
|
|
|
|
c.AdvertiseAddrs.RPC = addr
|
|
|
|
|
2016-11-18 19:51:27 +00:00
|
|
|
// Skip serf if server is disabled
|
|
|
|
if c.Server != nil && c.Server.Enabled {
|
|
|
|
addr, err = normalizeAdvertise(c.AdvertiseAddrs.Serf, c.Addresses.Serf, c.Ports.Serf, c.DevMode)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to parse Serf advertise address: %v", err)
|
|
|
|
}
|
|
|
|
c.AdvertiseAddrs.Serf = addr
|
2016-11-09 19:37:41 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 17:55:10 +00:00
|
|
|
// Skip network_interface evaluation if not a client
|
|
|
|
if c.Client != nil && c.Client.Enabled && c.Client.NetworkInterface != "" {
|
|
|
|
parsed, err := parseSingleInterfaceTemplate(c.Client.NetworkInterface)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to parse network-interface: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Client.NetworkInterface = parsed
|
|
|
|
}
|
|
|
|
|
2016-11-09 19:37:41 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-20 17:55:10 +00:00
|
|
|
// parseSingleInterfaceTemplate parses a go-sockaddr template and returns an
|
|
|
|
// error if it doesn't result in a single value.
|
|
|
|
func parseSingleInterfaceTemplate(tpl string) (string, error) {
|
|
|
|
out, err := template.Parse(tpl)
|
|
|
|
if err != nil {
|
|
|
|
// Typically something like:
|
|
|
|
// unable to parse template "{{printfl \"en50\"}}": template: sockaddr.Parse:1: function "printfl" not defined
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any extra empty space around the rendered result and check if the
|
|
|
|
// result is also not empty if the user provided a template.
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
if tpl != "" && out == "" {
|
|
|
|
return "", fmt.Errorf("template %q evaluated to empty result", tpl)
|
|
|
|
}
|
|
|
|
|
|
|
|
// `template.Parse` returns a space-separated list of results, but on
|
|
|
|
// Windows network interfaces are allowed to have spaces, so there is no
|
|
|
|
// guaranteed separators that we can use to test if the template returned
|
|
|
|
// multiple interfaces.
|
|
|
|
// The test below checks if the template results to a single valid interface.
|
|
|
|
_, err = net.InterfaceByName(out)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("invalid interface name %q", out)
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2017-02-26 22:28:23 +00:00
|
|
|
// parseSingleIPTemplate is used as a helper function to parse out a single IP
|
|
|
|
// address from a config parameter.
|
|
|
|
func parseSingleIPTemplate(ipTmpl string) (string, error) {
|
|
|
|
out, err := template.Parse(ipTmpl)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Unable to parse address template %q: %v", ipTmpl, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ips := strings.Split(out, " ")
|
|
|
|
switch len(ips) {
|
|
|
|
case 0:
|
|
|
|
return "", errors.New("No addresses found, please configure one.")
|
|
|
|
case 1:
|
|
|
|
return ips[0], nil
|
|
|
|
default:
|
|
|
|
return "", fmt.Errorf("Multiple addresses found (%q), please configure one.", out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 19:37:41 +00:00
|
|
|
// normalizeBind returns a normalized bind address.
|
2016-11-08 23:44:10 +00:00
|
|
|
//
|
2016-11-09 19:37:41 +00:00
|
|
|
// If addr is set it is used, if not the default bind address is used.
|
2017-02-26 22:28:23 +00:00
|
|
|
func normalizeBind(addr, bind string) (string, error) {
|
2016-11-09 19:37:41 +00:00
|
|
|
if addr == "" {
|
2017-02-26 22:28:23 +00:00
|
|
|
return bind, nil
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
2017-05-12 20:53:35 +00:00
|
|
|
return parseSingleIPTemplate(addr)
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 19:37:41 +00:00
|
|
|
// normalizeAdvertise returns a normalized advertise address.
|
|
|
|
//
|
|
|
|
// If addr is set, it is used and the default port is appended if no port is
|
|
|
|
// set.
|
|
|
|
//
|
|
|
|
// If addr is not set and bind is a valid address, the returned string is the
|
|
|
|
// bind+port.
|
|
|
|
//
|
|
|
|
// If addr is not set and bind is not a valid advertise address, the hostname
|
|
|
|
// is resolved and returned with the port.
|
|
|
|
//
|
|
|
|
// Loopback is only considered a valid advertise address in dev mode.
|
|
|
|
func normalizeAdvertise(addr string, bind string, defport int, dev bool) (string, error) {
|
2017-03-13 20:40:37 +00:00
|
|
|
addr, err := parseSingleIPTemplate(addr)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Error parsing advertise address template: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-11-09 19:37:41 +00:00
|
|
|
if addr != "" {
|
2016-11-08 23:44:10 +00:00
|
|
|
// Default to using manually configured address
|
2017-05-12 20:53:35 +00:00
|
|
|
_, _, err = net.SplitHostPort(addr)
|
2016-11-08 23:44:10 +00:00
|
|
|
if err != nil {
|
2017-06-29 17:46:31 +00:00
|
|
|
if !isMissingPort(err) && !isTooManyColons(err) {
|
2016-11-09 19:37:41 +00:00
|
|
|
return "", fmt.Errorf("Error parsing advertise address %q: %v", addr, err)
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
2017-05-12 20:53:35 +00:00
|
|
|
|
|
|
|
// missing port, append the default
|
|
|
|
return net.JoinHostPort(addr, strconv.Itoa(defport)), nil
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 20:53:35 +00:00
|
|
|
return addr, nil
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 19:37:41 +00:00
|
|
|
// Fallback to bind address first, and then try resolving the local hostname
|
|
|
|
ips, err := net.LookupIP(bind)
|
2016-11-08 23:44:10 +00:00
|
|
|
if err != nil {
|
2016-11-09 19:37:41 +00:00
|
|
|
return "", fmt.Errorf("Error resolving bind address %q: %v", bind, err)
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 20:53:35 +00:00
|
|
|
// Return the first non-localhost unicast address
|
2016-11-09 19:37:41 +00:00
|
|
|
for _, ip := range ips {
|
|
|
|
if ip.IsLinkLocalUnicast() || ip.IsGlobalUnicast() {
|
2016-11-28 18:38:54 +00:00
|
|
|
return net.JoinHostPort(ip.String(), strconv.Itoa(defport)), nil
|
2016-11-09 19:37:41 +00:00
|
|
|
}
|
2017-05-12 20:53:35 +00:00
|
|
|
if ip.IsLoopback() {
|
|
|
|
if dev {
|
|
|
|
// loopback is fine for dev mode
|
|
|
|
return net.JoinHostPort(ip.String(), strconv.Itoa(defport)), nil
|
|
|
|
}
|
|
|
|
return "", fmt.Errorf("Defaulting advertise to localhost is unsafe, please set advertise manually")
|
2016-11-09 19:37:41 +00:00
|
|
|
}
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 20:53:35 +00:00
|
|
|
// Bind is not localhost but not a valid advertise IP, use first private IP
|
2017-03-13 21:43:06 +00:00
|
|
|
addr, err = parseSingleIPTemplate("{{ GetPrivateIP }}")
|
2016-11-08 23:44:10 +00:00
|
|
|
if err != nil {
|
2017-03-13 21:43:06 +00:00
|
|
|
return "", fmt.Errorf("Unable to parse default advertise address: %v", err)
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
2017-03-13 21:43:06 +00:00
|
|
|
return net.JoinHostPort(addr, strconv.Itoa(defport)), nil
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// isMissingPort returns true if an error is a "missing port" error from
|
|
|
|
// net.SplitHostPort.
|
|
|
|
func isMissingPort(err error) bool {
|
|
|
|
// matches error const in net/ipsock.go
|
|
|
|
const missingPort = "missing port in address"
|
2017-02-16 21:10:24 +00:00
|
|
|
return err != nil && strings.Contains(err.Error(), missingPort)
|
2016-11-08 23:44:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-29 17:46:31 +00:00
|
|
|
// isTooManyColons returns true if an error is a "too many colons" error from
|
|
|
|
// net.SplitHostPort.
|
|
|
|
func isTooManyColons(err error) bool {
|
|
|
|
// matches error const in net/ipsock.go
|
|
|
|
const tooManyColons = "too many colons in address"
|
|
|
|
return err != nil && strings.Contains(err.Error(), tooManyColons)
|
|
|
|
}
|
|
|
|
|
2017-08-22 00:09:09 +00:00
|
|
|
// Merge is used to merge two ACL configs together. The settings from the input always take precedence.
|
2017-08-13 20:46:47 +00:00
|
|
|
func (a *ACLConfig) Merge(b *ACLConfig) *ACLConfig {
|
|
|
|
result := *a
|
|
|
|
|
|
|
|
if b.Enabled {
|
|
|
|
result.Enabled = true
|
|
|
|
}
|
2017-08-19 22:30:01 +00:00
|
|
|
if b.TokenTTL != 0 {
|
2017-08-13 20:46:47 +00:00
|
|
|
result.TokenTTL = b.TokenTTL
|
|
|
|
}
|
2019-06-11 19:25:56 +00:00
|
|
|
if b.TokenTTLHCL != "" {
|
|
|
|
result.TokenTTLHCL = b.TokenTTLHCL
|
|
|
|
}
|
2017-08-19 22:30:01 +00:00
|
|
|
if b.PolicyTTL != 0 {
|
2017-08-13 20:46:47 +00:00
|
|
|
result.PolicyTTL = b.PolicyTTL
|
|
|
|
}
|
2019-06-11 19:25:56 +00:00
|
|
|
if b.PolicyTTLHCL != "" {
|
|
|
|
result.PolicyTTLHCL = b.PolicyTTLHCL
|
|
|
|
}
|
2017-08-21 03:51:30 +00:00
|
|
|
if b.ReplicationToken != "" {
|
|
|
|
result.ReplicationToken = b.ReplicationToken
|
|
|
|
}
|
2017-08-13 20:46:47 +00:00
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
2015-09-10 18:24:59 +00:00
|
|
|
// Merge is used to merge two server configs together
|
|
|
|
func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
|
2015-12-09 00:05:15 +00:00
|
|
|
result := *a
|
2015-09-10 18:24:59 +00:00
|
|
|
|
|
|
|
if b.Enabled {
|
|
|
|
result.Enabled = true
|
|
|
|
}
|
2017-08-13 20:46:47 +00:00
|
|
|
if b.AuthoritativeRegion != "" {
|
|
|
|
result.AuthoritativeRegion = b.AuthoritativeRegion
|
|
|
|
}
|
2015-09-10 18:24:59 +00:00
|
|
|
if b.BootstrapExpect > 0 {
|
|
|
|
result.BootstrapExpect = b.BootstrapExpect
|
|
|
|
}
|
|
|
|
if b.DataDir != "" {
|
|
|
|
result.DataDir = b.DataDir
|
|
|
|
}
|
|
|
|
if b.ProtocolVersion != 0 {
|
|
|
|
result.ProtocolVersion = b.ProtocolVersion
|
|
|
|
}
|
2017-11-22 00:29:11 +00:00
|
|
|
if b.RaftProtocol != 0 {
|
|
|
|
result.RaftProtocol = b.RaftProtocol
|
|
|
|
}
|
2020-05-30 13:27:33 +00:00
|
|
|
if b.RaftMultiplier != nil {
|
|
|
|
c := *b.RaftMultiplier
|
|
|
|
result.RaftMultiplier = &c
|
|
|
|
}
|
2018-05-31 20:11:11 +00:00
|
|
|
if b.NumSchedulers != nil {
|
|
|
|
result.NumSchedulers = helper.IntToPtr(*b.NumSchedulers)
|
2015-09-10 18:24:59 +00:00
|
|
|
}
|
2015-10-29 13:47:06 +00:00
|
|
|
if b.NodeGCThreshold != "" {
|
|
|
|
result.NodeGCThreshold = b.NodeGCThreshold
|
|
|
|
}
|
2019-07-18 12:57:47 +00:00
|
|
|
if b.JobGCInterval != "" {
|
|
|
|
result.JobGCInterval = b.JobGCInterval
|
|
|
|
}
|
2017-02-27 19:58:10 +00:00
|
|
|
if b.JobGCThreshold != "" {
|
|
|
|
result.JobGCThreshold = b.JobGCThreshold
|
|
|
|
}
|
|
|
|
if b.EvalGCThreshold != "" {
|
|
|
|
result.EvalGCThreshold = b.EvalGCThreshold
|
|
|
|
}
|
2017-06-29 18:29:44 +00:00
|
|
|
if b.DeploymentGCThreshold != "" {
|
|
|
|
result.DeploymentGCThreshold = b.DeploymentGCThreshold
|
|
|
|
}
|
2020-05-11 12:20:50 +00:00
|
|
|
if b.CSIVolumeClaimGCThreshold != "" {
|
|
|
|
result.CSIVolumeClaimGCThreshold = b.CSIVolumeClaimGCThreshold
|
|
|
|
}
|
2020-05-06 20:49:12 +00:00
|
|
|
if b.CSIPluginGCThreshold != "" {
|
|
|
|
result.CSIPluginGCThreshold = b.CSIPluginGCThreshold
|
|
|
|
}
|
2017-07-19 16:38:35 +00:00
|
|
|
if b.HeartbeatGrace != 0 {
|
2016-03-04 23:44:12 +00:00
|
|
|
result.HeartbeatGrace = b.HeartbeatGrace
|
|
|
|
}
|
2019-06-11 19:25:56 +00:00
|
|
|
if b.HeartbeatGraceHCL != "" {
|
|
|
|
result.HeartbeatGraceHCL = b.HeartbeatGraceHCL
|
|
|
|
}
|
2017-07-19 16:38:35 +00:00
|
|
|
if b.MinHeartbeatTTL != 0 {
|
|
|
|
result.MinHeartbeatTTL = b.MinHeartbeatTTL
|
|
|
|
}
|
2019-06-11 19:25:56 +00:00
|
|
|
if b.MinHeartbeatTTLHCL != "" {
|
|
|
|
result.MinHeartbeatTTLHCL = b.MinHeartbeatTTLHCL
|
|
|
|
}
|
2017-07-19 16:38:35 +00:00
|
|
|
if b.MaxHeartbeatsPerSecond != 0.0 {
|
|
|
|
result.MaxHeartbeatsPerSecond = b.MaxHeartbeatsPerSecond
|
|
|
|
}
|
2021-10-06 22:48:12 +00:00
|
|
|
if b.FailoverHeartbeatTTL != 0 {
|
|
|
|
result.FailoverHeartbeatTTL = b.FailoverHeartbeatTTL
|
|
|
|
}
|
|
|
|
if b.FailoverHeartbeatTTLHCL != "" {
|
|
|
|
result.FailoverHeartbeatTTLHCL = b.FailoverHeartbeatTTLHCL
|
|
|
|
}
|
2015-12-02 19:55:29 +00:00
|
|
|
if b.RetryMaxAttempts != 0 {
|
|
|
|
result.RetryMaxAttempts = b.RetryMaxAttempts
|
|
|
|
}
|
2018-05-30 23:51:55 +00:00
|
|
|
if b.RetryInterval != 0 {
|
2015-12-02 19:55:29 +00:00
|
|
|
result.RetryInterval = b.RetryInterval
|
|
|
|
}
|
2019-06-11 19:25:56 +00:00
|
|
|
if b.RetryIntervalHCL != "" {
|
|
|
|
result.RetryIntervalHCL = b.RetryIntervalHCL
|
|
|
|
}
|
2015-12-02 19:55:29 +00:00
|
|
|
if b.RejoinAfterLeave {
|
|
|
|
result.RejoinAfterLeave = true
|
|
|
|
}
|
2017-12-18 21:16:23 +00:00
|
|
|
if b.NonVotingServer {
|
|
|
|
result.NonVotingServer = true
|
|
|
|
}
|
2018-01-30 03:53:34 +00:00
|
|
|
if b.RedundancyZone != "" {
|
|
|
|
result.RedundancyZone = b.RedundancyZone
|
|
|
|
}
|
|
|
|
if b.UpgradeVersion != "" {
|
|
|
|
result.UpgradeVersion = b.UpgradeVersion
|
|
|
|
}
|
2016-10-17 17:48:04 +00:00
|
|
|
if b.EncryptKey != "" {
|
|
|
|
result.EncryptKey = b.EncryptKey
|
|
|
|
}
|
2018-05-11 19:52:05 +00:00
|
|
|
if b.ServerJoin != nil {
|
2018-05-29 15:25:09 +00:00
|
|
|
result.ServerJoin = result.ServerJoin.Merge(b.ServerJoin)
|
2018-05-11 19:52:05 +00:00
|
|
|
}
|
2021-03-23 13:08:14 +00:00
|
|
|
if b.LicensePath != "" {
|
|
|
|
result.LicensePath = b.LicensePath
|
|
|
|
}
|
2015-09-10 18:24:59 +00:00
|
|
|
|
2020-10-08 18:27:52 +00:00
|
|
|
if b.EnableEventBroker != nil {
|
|
|
|
result.EnableEventBroker = b.EnableEventBroker
|
2020-10-06 20:21:58 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 18:27:52 +00:00
|
|
|
if b.EventBufferSize != nil {
|
2020-10-06 20:21:58 +00:00
|
|
|
result.EventBufferSize = b.EventBufferSize
|
2020-10-02 19:04:05 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 16:09:36 +00:00
|
|
|
if b.DefaultSchedulerConfig != nil {
|
|
|
|
c := *b.DefaultSchedulerConfig
|
|
|
|
result.DefaultSchedulerConfig = &c
|
|
|
|
}
|
|
|
|
|
2021-06-04 19:38:46 +00:00
|
|
|
if b.DeploymentQueryRateLimit != 0 {
|
|
|
|
result.DeploymentQueryRateLimit = b.DeploymentQueryRateLimit
|
|
|
|
}
|
|
|
|
|
api: implement fuzzy search API
This PR introduces the /v1/search/fuzzy API endpoint, used for fuzzy
searching objects in Nomad. The fuzzy search endpoint routes requests
to the Nomad Server leader, which implements the Search.FuzzySearch RPC
method.
Requests to the fuzzy search API are based on the api.FuzzySearchRequest
object, e.g.
{
"Text": "ed",
"Context": "all"
}
Responses from the fuzzy search API are based on the api.FuzzySearchResponse
object, e.g.
{
"Index": 27,
"KnownLeader": true,
"LastContact": 0,
"Matches": {
"tasks": [
{
"ID": "redis",
"Scope": [
"default",
"example",
"cache"
]
}
],
"evals": [],
"deployment": [],
"volumes": [],
"scaling_policy": [],
"images": [
{
"ID": "redis:3.2",
"Scope": [
"default",
"example",
"cache",
"redis"
]
}
]
},
"Truncations": {
"volumes": false,
"scaling_policy": false,
"evals": false,
"deployment": false
}
}
The API is tunable using the new server.search stanza, e.g.
server {
search {
fuzzy_enabled = true
limit_query = 200
limit_results = 1000
min_term_length = 5
}
}
These values can be increased or decreased, so as to provide more
search results or to reduce load on the Nomad Server. The fuzzy search
API can be disabled entirely by setting `fuzzy_enabled` to `false`.
2021-02-23 20:24:52 +00:00
|
|
|
if b.Search != nil {
|
|
|
|
result.Search = &Search{FuzzyEnabled: b.Search.FuzzyEnabled}
|
|
|
|
if b.Search.LimitQuery > 0 {
|
|
|
|
result.Search.LimitQuery = b.Search.LimitQuery
|
|
|
|
}
|
|
|
|
if b.Search.LimitResults > 0 {
|
|
|
|
result.Search.LimitResults = b.Search.LimitResults
|
|
|
|
}
|
|
|
|
if b.Search.MinTermLength > 0 {
|
|
|
|
result.Search.MinTermLength = b.Search.MinTermLength
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-10 18:24:59 +00:00
|
|
|
// Add the schedulers
|
|
|
|
result.EnabledSchedulers = append(result.EnabledSchedulers, b.EnabledSchedulers...)
|
|
|
|
|
2015-12-02 19:55:29 +00:00
|
|
|
// Copy the start join addresses
|
|
|
|
result.StartJoin = make([]string, 0, len(a.StartJoin)+len(b.StartJoin))
|
|
|
|
result.StartJoin = append(result.StartJoin, a.StartJoin...)
|
|
|
|
result.StartJoin = append(result.StartJoin, b.StartJoin...)
|
|
|
|
|
|
|
|
// Copy the retry join addresses
|
|
|
|
result.RetryJoin = make([]string, 0, len(a.RetryJoin)+len(b.RetryJoin))
|
|
|
|
result.RetryJoin = append(result.RetryJoin, a.RetryJoin...)
|
|
|
|
result.RetryJoin = append(result.RetryJoin, b.RetryJoin...)
|
2015-09-10 18:24:59 +00:00
|
|
|
|
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge is used to merge two client configs together
|
|
|
|
func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
|
2015-12-09 00:05:15 +00:00
|
|
|
result := *a
|
2015-09-10 18:24:59 +00:00
|
|
|
|
|
|
|
if b.Enabled {
|
|
|
|
result.Enabled = true
|
|
|
|
}
|
|
|
|
if b.StateDir != "" {
|
|
|
|
result.StateDir = b.StateDir
|
|
|
|
}
|
|
|
|
if b.AllocDir != "" {
|
|
|
|
result.AllocDir = b.AllocDir
|
|
|
|
}
|
|
|
|
if b.NodeClass != "" {
|
|
|
|
result.NodeClass = b.NodeClass
|
|
|
|
}
|
2015-10-02 07:29:18 +00:00
|
|
|
if b.NetworkInterface != "" {
|
|
|
|
result.NetworkInterface = b.NetworkInterface
|
2015-10-01 15:31:47 +00:00
|
|
|
}
|
2015-10-03 00:32:11 +00:00
|
|
|
if b.NetworkSpeed != 0 {
|
|
|
|
result.NetworkSpeed = b.NetworkSpeed
|
|
|
|
}
|
2017-03-14 19:56:31 +00:00
|
|
|
if b.CpuCompute != 0 {
|
|
|
|
result.CpuCompute = b.CpuCompute
|
|
|
|
}
|
2018-01-22 20:28:29 +00:00
|
|
|
if b.MemoryMB != 0 {
|
|
|
|
result.MemoryMB = b.MemoryMB
|
|
|
|
}
|
2015-12-23 00:10:30 +00:00
|
|
|
if b.MaxKillTimeout != "" {
|
|
|
|
result.MaxKillTimeout = b.MaxKillTimeout
|
|
|
|
}
|
2016-02-08 21:29:53 +00:00
|
|
|
if b.ClientMaxPort != 0 {
|
|
|
|
result.ClientMaxPort = b.ClientMaxPort
|
|
|
|
}
|
|
|
|
if b.ClientMinPort != 0 {
|
|
|
|
result.ClientMinPort = b.ClientMinPort
|
|
|
|
}
|
2021-09-10 08:52:47 +00:00
|
|
|
if b.MaxDynamicPort != 0 {
|
|
|
|
result.MaxDynamicPort = b.MaxDynamicPort
|
|
|
|
}
|
|
|
|
if b.MinDynamicPort != 0 {
|
|
|
|
result.MinDynamicPort = b.MinDynamicPort
|
|
|
|
}
|
2017-02-03 16:39:57 +00:00
|
|
|
if result.Reserved == nil && b.Reserved != nil {
|
|
|
|
reserved := *b.Reserved
|
|
|
|
result.Reserved = &reserved
|
|
|
|
} else if b.Reserved != nil {
|
2016-03-12 02:24:58 +00:00
|
|
|
result.Reserved = result.Reserved.Merge(b.Reserved)
|
|
|
|
}
|
2017-02-01 23:58:21 +00:00
|
|
|
if b.GCInterval != 0 {
|
|
|
|
result.GCInterval = b.GCInterval
|
|
|
|
}
|
2019-06-11 19:25:56 +00:00
|
|
|
if b.GCIntervalHCL != "" {
|
|
|
|
result.GCIntervalHCL = b.GCIntervalHCL
|
|
|
|
}
|
2017-03-11 00:27:00 +00:00
|
|
|
if b.GCParallelDestroys != 0 {
|
|
|
|
result.GCParallelDestroys = b.GCParallelDestroys
|
|
|
|
}
|
2017-02-01 23:58:21 +00:00
|
|
|
if b.GCDiskUsageThreshold != 0 {
|
|
|
|
result.GCDiskUsageThreshold = b.GCDiskUsageThreshold
|
|
|
|
}
|
|
|
|
if b.GCInodeUsageThreshold != 0 {
|
|
|
|
result.GCInodeUsageThreshold = b.GCInodeUsageThreshold
|
|
|
|
}
|
2017-05-11 00:39:45 +00:00
|
|
|
if b.GCMaxAllocs != 0 {
|
|
|
|
result.GCMaxAllocs = b.GCMaxAllocs
|
|
|
|
}
|
2017-06-23 23:23:01 +00:00
|
|
|
// NoHostUUID defaults to true, merge if false
|
2017-07-04 00:41:20 +00:00
|
|
|
if b.NoHostUUID != nil {
|
2017-02-27 21:42:37 +00:00
|
|
|
result.NoHostUUID = b.NoHostUUID
|
|
|
|
}
|
2015-09-10 18:24:59 +00:00
|
|
|
|
2019-06-03 19:31:39 +00:00
|
|
|
if b.DisableRemoteExec {
|
|
|
|
result.DisableRemoteExec = b.DisableRemoteExec
|
|
|
|
}
|
|
|
|
|
2019-08-02 19:20:14 +00:00
|
|
|
if b.TemplateConfig != nil {
|
|
|
|
result.TemplateConfig = b.TemplateConfig
|
|
|
|
}
|
|
|
|
|
2015-09-10 18:24:59 +00:00
|
|
|
// Add the servers
|
|
|
|
result.Servers = append(result.Servers, b.Servers...)
|
|
|
|
|
2015-09-28 23:45:32 +00:00
|
|
|
// Add the options map values
|
|
|
|
if result.Options == nil {
|
|
|
|
result.Options = make(map[string]string)
|
|
|
|
}
|
|
|
|
for k, v := range b.Options {
|
|
|
|
result.Options[k] = v
|
|
|
|
}
|
|
|
|
|
2015-09-10 18:24:59 +00:00
|
|
|
// Add the meta map values
|
|
|
|
if result.Meta == nil {
|
|
|
|
result.Meta = make(map[string]string)
|
|
|
|
}
|
|
|
|
for k, v := range b.Meta {
|
|
|
|
result.Meta[k] = v
|
|
|
|
}
|
|
|
|
|
2016-08-02 02:58:32 +00:00
|
|
|
// Add the chroot_env map values
|
|
|
|
if result.ChrootEnv == nil {
|
|
|
|
result.ChrootEnv = make(map[string]string)
|
|
|
|
}
|
|
|
|
for k, v := range b.ChrootEnv {
|
|
|
|
result.ChrootEnv[k] = v
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:52:05 +00:00
|
|
|
if b.ServerJoin != nil {
|
2018-05-29 19:12:08 +00:00
|
|
|
result.ServerJoin = result.ServerJoin.Merge(b.ServerJoin)
|
2018-05-11 19:52:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 14:45:41 +00:00
|
|
|
if len(a.HostVolumes) == 0 && len(b.HostVolumes) != 0 {
|
2019-08-01 09:33:26 +00:00
|
|
|
result.HostVolumes = structs.CopySliceClientHostVolumeConfig(b.HostVolumes)
|
2019-07-25 14:45:41 +00:00
|
|
|
} else if len(b.HostVolumes) != 0 {
|
|
|
|
result.HostVolumes = structs.HostVolumeSliceMerge(a.HostVolumes, b.HostVolumes)
|
|
|
|
}
|
|
|
|
|
2020-02-28 19:23:13 +00:00
|
|
|
if b.CNIPath != "" {
|
|
|
|
result.CNIPath = b.CNIPath
|
|
|
|
}
|
2020-07-08 19:45:04 +00:00
|
|
|
if b.CNIConfigDir != "" {
|
|
|
|
result.CNIConfigDir = b.CNIConfigDir
|
|
|
|
}
|
2020-02-28 19:23:13 +00:00
|
|
|
if b.BridgeNetworkName != "" {
|
|
|
|
result.BridgeNetworkName = b.BridgeNetworkName
|
|
|
|
}
|
|
|
|
if b.BridgeNetworkSubnet != "" {
|
|
|
|
result.BridgeNetworkSubnet = b.BridgeNetworkSubnet
|
|
|
|
}
|
|
|
|
|
2020-12-08 20:47:04 +00:00
|
|
|
result.HostNetworks = a.HostNetworks
|
|
|
|
|
2020-06-16 15:53:10 +00:00
|
|
|
if len(b.HostNetworks) != 0 {
|
2020-12-08 20:47:04 +00:00
|
|
|
result.HostNetworks = append(result.HostNetworks, b.HostNetworks...)
|
2020-06-16 15:53:10 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 22:51:46 +00:00
|
|
|
if b.BindWildcardDefaultHostNetwork {
|
|
|
|
result.BindWildcardDefaultHostNetwork = true
|
|
|
|
}
|
2015-09-10 18:24:59 +00:00
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge is used to merge two telemetry configs together
|
|
|
|
func (a *Telemetry) Merge(b *Telemetry) *Telemetry {
|
2015-12-09 00:05:15 +00:00
|
|
|
result := *a
|
2015-09-10 18:24:59 +00:00
|
|
|
|
|
|
|
if b.StatsiteAddr != "" {
|
|
|
|
result.StatsiteAddr = b.StatsiteAddr
|
|
|
|
}
|
|
|
|
if b.StatsdAddr != "" {
|
|
|
|
result.StatsdAddr = b.StatsdAddr
|
|
|
|
}
|
2016-10-15 08:49:33 +00:00
|
|
|
if b.DataDogAddr != "" {
|
|
|
|
result.DataDogAddr = b.DataDogAddr
|
|
|
|
}
|
2018-02-06 16:21:15 +00:00
|
|
|
if b.DataDogTags != nil {
|
|
|
|
result.DataDogTags = b.DataDogTags
|
|
|
|
}
|
2017-09-11 13:47:44 +00:00
|
|
|
if b.PrometheusMetrics {
|
|
|
|
result.PrometheusMetrics = b.PrometheusMetrics
|
|
|
|
}
|
2015-09-10 18:24:59 +00:00
|
|
|
if b.DisableHostname {
|
|
|
|
result.DisableHostname = true
|
|
|
|
}
|
2017-07-02 03:31:09 +00:00
|
|
|
|
|
|
|
if b.UseNodeName {
|
|
|
|
result.UseNodeName = true
|
|
|
|
}
|
2016-06-16 20:30:29 +00:00
|
|
|
if b.CollectionInterval != "" {
|
|
|
|
result.CollectionInterval = b.CollectionInterval
|
|
|
|
}
|
|
|
|
if b.collectionInterval != 0 {
|
|
|
|
result.collectionInterval = b.collectionInterval
|
|
|
|
}
|
2016-08-31 18:19:00 +00:00
|
|
|
if b.PublishNodeMetrics {
|
|
|
|
result.PublishNodeMetrics = true
|
|
|
|
}
|
|
|
|
if b.PublishAllocationMetrics {
|
|
|
|
result.PublishAllocationMetrics = true
|
|
|
|
}
|
2016-07-22 16:33:10 +00:00
|
|
|
if b.CirconusAPIToken != "" {
|
|
|
|
result.CirconusAPIToken = b.CirconusAPIToken
|
|
|
|
}
|
|
|
|
if b.CirconusAPIApp != "" {
|
|
|
|
result.CirconusAPIApp = b.CirconusAPIApp
|
|
|
|
}
|
|
|
|
if b.CirconusAPIURL != "" {
|
|
|
|
result.CirconusAPIURL = b.CirconusAPIURL
|
|
|
|
}
|
|
|
|
if b.CirconusCheckSubmissionURL != "" {
|
|
|
|
result.CirconusCheckSubmissionURL = b.CirconusCheckSubmissionURL
|
|
|
|
}
|
|
|
|
if b.CirconusSubmissionInterval != "" {
|
|
|
|
result.CirconusSubmissionInterval = b.CirconusSubmissionInterval
|
|
|
|
}
|
|
|
|
if b.CirconusCheckID != "" {
|
|
|
|
result.CirconusCheckID = b.CirconusCheckID
|
|
|
|
}
|
|
|
|
if b.CirconusCheckForceMetricActivation != "" {
|
|
|
|
result.CirconusCheckForceMetricActivation = b.CirconusCheckForceMetricActivation
|
|
|
|
}
|
|
|
|
if b.CirconusCheckInstanceID != "" {
|
|
|
|
result.CirconusCheckInstanceID = b.CirconusCheckInstanceID
|
|
|
|
}
|
|
|
|
if b.CirconusCheckSearchTag != "" {
|
|
|
|
result.CirconusCheckSearchTag = b.CirconusCheckSearchTag
|
|
|
|
}
|
2016-11-09 20:12:30 +00:00
|
|
|
if b.CirconusCheckTags != "" {
|
|
|
|
result.CirconusCheckTags = b.CirconusCheckTags
|
|
|
|
}
|
|
|
|
if b.CirconusCheckDisplayName != "" {
|
|
|
|
result.CirconusCheckDisplayName = b.CirconusCheckDisplayName
|
|
|
|
}
|
2016-07-22 16:33:10 +00:00
|
|
|
if b.CirconusBrokerID != "" {
|
|
|
|
result.CirconusBrokerID = b.CirconusBrokerID
|
|
|
|
}
|
|
|
|
if b.CirconusBrokerSelectTag != "" {
|
|
|
|
result.CirconusBrokerSelectTag = b.CirconusBrokerSelectTag
|
|
|
|
}
|
2017-09-05 21:58:35 +00:00
|
|
|
|
2018-11-14 16:13:52 +00:00
|
|
|
if b.PrefixFilter != nil {
|
|
|
|
result.PrefixFilter = b.PrefixFilter
|
|
|
|
}
|
|
|
|
|
2018-11-14 20:02:49 +00:00
|
|
|
if b.FilterDefault != nil {
|
|
|
|
result.FilterDefault = b.FilterDefault
|
|
|
|
}
|
|
|
|
|
2018-11-14 16:13:52 +00:00
|
|
|
if b.DisableDispatchedJobSummaryMetrics {
|
|
|
|
result.DisableDispatchedJobSummaryMetrics = b.DisableDispatchedJobSummaryMetrics
|
|
|
|
}
|
|
|
|
|
2015-09-10 04:42:50 +00:00
|
|
|
return &result
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 01:37:42 +00:00
|
|
|
// Merge is used to merge two port configurations.
|
|
|
|
func (a *Ports) Merge(b *Ports) *Ports {
|
2015-12-09 00:05:15 +00:00
|
|
|
result := *a
|
2015-09-11 01:37:42 +00:00
|
|
|
|
|
|
|
if b.HTTP != 0 {
|
|
|
|
result.HTTP = b.HTTP
|
|
|
|
}
|
|
|
|
if b.RPC != 0 {
|
|
|
|
result.RPC = b.RPC
|
|
|
|
}
|
|
|
|
if b.Serf != 0 {
|
|
|
|
result.Serf = b.Serf
|
|
|
|
}
|
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge is used to merge two address configs together.
|
|
|
|
func (a *Addresses) Merge(b *Addresses) *Addresses {
|
2015-12-09 00:05:15 +00:00
|
|
|
result := *a
|
2015-09-11 01:37:42 +00:00
|
|
|
|
|
|
|
if b.HTTP != "" {
|
|
|
|
result.HTTP = b.HTTP
|
|
|
|
}
|
|
|
|
if b.RPC != "" {
|
|
|
|
result.RPC = b.RPC
|
|
|
|
}
|
|
|
|
if b.Serf != "" {
|
|
|
|
result.Serf = b.Serf
|
|
|
|
}
|
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge merges two advertise addrs configs together.
|
|
|
|
func (a *AdvertiseAddrs) Merge(b *AdvertiseAddrs) *AdvertiseAddrs {
|
2015-12-09 00:05:15 +00:00
|
|
|
result := *a
|
2015-09-11 01:37:42 +00:00
|
|
|
|
|
|
|
if b.RPC != "" {
|
|
|
|
result.RPC = b.RPC
|
|
|
|
}
|
|
|
|
if b.Serf != "" {
|
|
|
|
result.Serf = b.Serf
|
|
|
|
}
|
2016-02-12 17:40:28 +00:00
|
|
|
if b.HTTP != "" {
|
|
|
|
result.HTTP = b.HTTP
|
|
|
|
}
|
2015-09-11 01:37:42 +00:00
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
2016-03-12 02:24:58 +00:00
|
|
|
func (r *Resources) Merge(b *Resources) *Resources {
|
|
|
|
result := *r
|
|
|
|
if b.CPU != 0 {
|
|
|
|
result.CPU = b.CPU
|
|
|
|
}
|
|
|
|
if b.MemoryMB != 0 {
|
|
|
|
result.MemoryMB = b.MemoryMB
|
|
|
|
}
|
|
|
|
if b.DiskMB != 0 {
|
|
|
|
result.DiskMB = b.DiskMB
|
|
|
|
}
|
2016-03-12 03:02:44 +00:00
|
|
|
if b.ReservedPorts != "" {
|
|
|
|
result.ReservedPorts = b.ReservedPorts
|
2016-03-12 02:24:58 +00:00
|
|
|
}
|
2021-03-25 02:09:37 +00:00
|
|
|
if b.Cores != "" {
|
|
|
|
result.Cores = b.Cores
|
|
|
|
}
|
2016-03-12 02:24:58 +00:00
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
2019-06-12 02:35:43 +00:00
|
|
|
// LoadConfig loads the configuration at the given path, regardless if its a file or
|
|
|
|
// directory. Called for each -config to build up the runtime config value. Do not apply any
|
|
|
|
// default values, defaults should be added once in DefaultConfig
|
2015-08-16 01:54:41 +00:00
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
|
|
fi, err := os.Stat(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if fi.IsDir() {
|
2019-06-12 01:59:44 +00:00
|
|
|
return LoadConfigDir(path)
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
|
2016-03-12 02:24:58 +00:00
|
|
|
cleaned := filepath.Clean(path)
|
|
|
|
config, err := ParseConfigFile(cleaned)
|
2015-08-16 01:54:41 +00:00
|
|
|
if err != nil {
|
2016-03-12 02:24:58 +00:00
|
|
|
return nil, fmt.Errorf("Error loading %s: %s", cleaned, err)
|
2015-12-05 00:52:17 +00:00
|
|
|
}
|
2019-06-12 01:59:44 +00:00
|
|
|
|
2016-03-12 02:24:58 +00:00
|
|
|
config.Files = append(config.Files, cleaned)
|
|
|
|
return config, nil
|
2015-09-22 18:29:53 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
// LoadConfigDir loads all the configurations in the given directory
|
|
|
|
// in alphabetical order.
|
|
|
|
func LoadConfigDir(dir string) (*Config, error) {
|
|
|
|
f, err := os.Open(dir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
fi, err := f.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if !fi.IsDir() {
|
|
|
|
return nil, fmt.Errorf(
|
2016-03-12 02:24:58 +00:00
|
|
|
"configuration path must be a directory: %s", dir)
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var files []string
|
|
|
|
err = nil
|
|
|
|
for err != io.EOF {
|
|
|
|
var fis []os.FileInfo
|
|
|
|
fis, err = f.Readdir(128)
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, fi := range fis {
|
|
|
|
// Ignore directories
|
|
|
|
if fi.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only care about files that are valid to load.
|
|
|
|
name := fi.Name()
|
|
|
|
skip := true
|
|
|
|
if strings.HasSuffix(name, ".hcl") {
|
|
|
|
skip = false
|
|
|
|
} else if strings.HasSuffix(name, ".json") {
|
|
|
|
skip = false
|
|
|
|
}
|
|
|
|
if skip || isTemporaryFile(name) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
path := filepath.Join(dir, name)
|
|
|
|
files = append(files, path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 22:07:41 +00:00
|
|
|
// Fast-path if we have no files
|
|
|
|
if len(files) == 0 {
|
|
|
|
return &Config{}, nil
|
|
|
|
}
|
|
|
|
|
2015-12-15 07:05:25 +00:00
|
|
|
sort.Strings(files)
|
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
var result *Config
|
|
|
|
for _, f := range files {
|
2016-03-12 02:24:58 +00:00
|
|
|
config, err := ParseConfigFile(f)
|
2015-08-16 01:54:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error loading %s: %s", f, err)
|
|
|
|
}
|
2016-03-12 02:24:58 +00:00
|
|
|
config.Files = append(config.Files, f)
|
2015-08-16 01:54:41 +00:00
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
result = config
|
|
|
|
} else {
|
|
|
|
result = result.Merge(config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// isTemporaryFile returns true or false depending on whether the
|
|
|
|
// provided file name is a temporary file for the following editors:
|
|
|
|
// emacs or vim.
|
|
|
|
func isTemporaryFile(name string) bool {
|
|
|
|
return strings.HasSuffix(name, "~") || // vim
|
|
|
|
strings.HasPrefix(name, ".#") || // emacs
|
|
|
|
(strings.HasPrefix(name, "#") && strings.HasSuffix(name, "#")) // emacs
|
|
|
|
}
|