53e28a4963 | ||
---|---|---|
.. | ||
README.md | ||
checklist-adding-config-fields.md |
README.md
Agent Configuration
The Agent Configuration is the primary mechanism for configuring Consul. Agent Configuration also allows for specifying Config Entries, Services, and Checks that will be loaded when the agent starts.
Most configuration comes from hcl or json
files, but some configuration can also be
specified using command line flags, and some can be loaded with Auto-Config.
See also the checklist for adding a new field to the configuration.
Code
The Agent Configuration is implemented in agent/config, and the primary entrypoint is Load. Config loading is performed in phases:
- Command line flags are used to create a
config.LoadOpts
and passed toLoad
. Load
reads all the config files and builds an ordered list ofconfig.Source
.- Each
config.Source
is read to produce aconfig.Config
. - Each
config.Config
is merged ontop the previous. - A
config.RuntimeConfig
is produced from the mergedconfig.Config
- The
config.RuntimeConfig
is validated. - Finally a result is returned with the
RuntimeConfig
and any warnings, or an error.
If Auto-Config is enabled, when it receives the config from the server, the
entire process is repeated a second time with the addition config provided as another
config.Source
.
Default values can be specified in one of the default sources or set when
converting from Config
to RuntimeConfig
in builder.build. Hopefully in the future we
should remove one of those ways of setting default values.
Auto-Config
Auto-Config is enabled by the auto_config field in an Agent Configuration file. It is implemented in a couple packages.
- the server RPC endpoint is in agent/consul/auto_config_endpoint.go
- the client that receives and applies the config is implemented in agent/auto-config