Skip to content

Commit

Permalink
Merge pull request #5601 from hashicorp/b-config-parse-direct-hcl
Browse files Browse the repository at this point in the history
config parse direct hcl
  • Loading branch information
langmartin authored May 6, 2019
2 parents c75357c + d1dbbe8 commit 84306b0
Show file tree
Hide file tree
Showing 21 changed files with 1,172 additions and 1,824 deletions.
303 changes: 172 additions & 131 deletions command/agent/config.go

Large diffs are not rendered by default.

1,116 changes: 117 additions & 999 deletions command/agent/config_parse.go

Large diffs are not rendered by default.

1,146 changes: 530 additions & 616 deletions command/agent/config_parse_test.go

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions command/agent/testdata/config-slices-alt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"client": [
{
"chroot_env": [
{
"e0": "baz"
}
],
"meta": [
{
"m0": "foo",
"m1": "bar"
}
],
"options": [
{
"o0": "foo",
"o1": "bar"
}
],
"server_join": [
{
"retry_join": [
"foo",
"bar"
],
"start_join": [
"foo",
"bar"
]
}
],
"servers": [
"foo",
"bar"
]
}
],
"server": [
{
"enabled_schedulers": [
"foo",
"bar"
],
"retry_join": [
"foo",
"bar"
],
"server_join": [
{
"retry_join": [
"foo",
"bar"
],
"start_join": [
"foo",
"bar"
]
}
],
"start_join": [
"foo",
"bar"
]
}
]
}
13 changes: 13 additions & 0 deletions command/agent/testdata/config-slices.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
client "chroot_env" {
"e0" = "baz"
}

client "meta" {
"m0" = "foo"
"m1" = "bar"
}

client "options" {
"o0" = "foo"
"o1" = "bar"
}
41 changes: 41 additions & 0 deletions command/agent/testdata/config-slices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"client": {
"options": {
"o0": "foo",
"o1": "bar"
},
"meta": {
"m0": "foo",
"m1": "bar"
},
"chroot_env": {
"e0": "baz"
},
"servers": [
"foo",
"bar"
],
"server_join": {
"start_join": ["foo", "bar"],
"retry_join": ["foo", "bar"]
}
},
"server": {
"enabled_schedulers": [
"foo",
"bar"
],
"start_join": [
"foo",
"bar"
],
"retry_join": [
"foo",
"bar"
],
"server_join": {
"start_join": ["foo", "bar"],
"retry_join": ["foo", "bar"]
}
}
}
7 changes: 7 additions & 0 deletions command/agent/testdata/non-optional.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"client": [
{
"memory_total_mb": 5555
}
]
}
7 changes: 7 additions & 0 deletions command/agent/testdata/obj-len-one-server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"server": {
"server_join": {
"start_join": ["foo", "bar"]
}
},
}
5 changes: 5 additions & 0 deletions command/agent/testdata/obj-len-one.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
client {
options {
driver.whitelist = "docker"
}
}
8 changes: 8 additions & 0 deletions command/agent/testdata/obj-len-one.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"client": {
"options": {
"driver.whitelist": "docker"
}
},
"server": {}
}
57 changes: 57 additions & 0 deletions command/agent/testdata/sample0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"autopilot": {
"cleanup_dead_servers": true
},
"acl": {
"enabled": true
},
"advertise": {
"http": "host.example.com",
"rpc": "host.example.com",
"serf": "host.example.com"
},
"bind_addr": "0.0.0.0",
"consul": {
"server_auto_join": false,
"client_auto_join": false,
"token": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
},
"data_dir": "/opt/data/nomad/data",
"datacenter": "dc1",
"enable_syslog": true,
"leave_on_interrupt": true,
"leave_on_terminate": true,
"log_level": "INFO",
"region": "global",
"server": {
"bootstrap_expect": 3,
"enabled": true,
"encrypt": "sHck3WL6cxuhuY7Mso9BHA==",
"retry_join": [
"10.0.0.101",
"10.0.0.102",
"10.0.0.103"
]
},
"syslog_facility": "LOCAL0",
"telemetry": {
"collection_interval": "60s",
"disable_hostname": true,
"prometheus_metrics": true,
"publish_allocation_metrics": true,
"publish_node_metrics": true
},
"tls": {
"ca_file": "/opt/data/nomad/certs/nomad-ca.pem",
"cert_file": "/opt/data/nomad/certs/server.pem",
"http": true,
"key_file": "/opt/data/nomad/certs/server-key.pem",
"rpc": true,
"verify_server_hostname": true
},
"vault": {
"address": "http://host.example.com:8200",
"create_from_role": "nomad-cluster",
"enabled": true
}
}
19 changes: 12 additions & 7 deletions nomad/structs/config/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,37 @@ import (
type AutopilotConfig struct {
// CleanupDeadServers controls whether to remove dead servers when a new
// server is added to the Raft peers.
CleanupDeadServers *bool `mapstructure:"cleanup_dead_servers"`
CleanupDeadServers *bool `hcl:"cleanup_dead_servers"`

// ServerStabilizationTime is the minimum amount of time a server must be
// in a stable, healthy state before it can be added to the cluster. Only
// applicable with Raft protocol version 3 or higher.
ServerStabilizationTime time.Duration `mapstructure:"server_stabilization_time"`
ServerStabilizationTime time.Duration
ServerStabilizationTimeHCL string `hcl:"server_stabilization_time" json:"-"`

// LastContactThreshold is the limit on the amount of time a server can go
// without leader contact before being considered unhealthy.
LastContactThreshold time.Duration `mapstructure:"last_contact_threshold"`
LastContactThreshold time.Duration
LastContactThresholdHCL string `hcl:"last_contact_threshold" json:"-"`

// MaxTrailingLogs is the amount of entries in the Raft Log that a server can
// be behind before being considered unhealthy.
MaxTrailingLogs int `mapstructure:"max_trailing_logs"`
MaxTrailingLogs int `hcl:"max_trailing_logs"`

// (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones.
EnableRedundancyZones *bool `mapstructure:"enable_redundancy_zones"`
EnableRedundancyZones *bool `hcl:"enable_redundancy_zones"`

// (Enterprise-only) DisableUpgradeMigration will disable Autopilot's upgrade migration
// strategy of waiting until enough newer-versioned servers have been added to the
// cluster before promoting them to voters.
DisableUpgradeMigration *bool `mapstructure:"disable_upgrade_migration"`
DisableUpgradeMigration *bool `hcl:"disable_upgrade_migration"`

// (Enterprise-only) EnableCustomUpgrades specifies whether to enable using custom
// upgrade versions when performing migrations.
EnableCustomUpgrades *bool `mapstructure:"enable_custom_upgrades"`
EnableCustomUpgrades *bool `hcl:"enable_custom_upgrades"`

// ExtraKeysHCL is used by hcl to surface unexpected keys
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
}

// DefaultAutopilotConfig() returns the canonical defaults for the Nomad
Expand Down
42 changes: 23 additions & 19 deletions nomad/structs/config/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,73 +21,77 @@ import (
type ConsulConfig struct {
// ServerServiceName is the name of the service that Nomad uses to register
// servers with Consul
ServerServiceName string `mapstructure:"server_service_name"`
ServerServiceName string `hcl:"server_service_name"`

// ServerHTTPCheckName is the name of the health check that Nomad uses
// to register the server HTTP health check with Consul
ServerHTTPCheckName string `mapstructure:"server_http_check_name"`
ServerHTTPCheckName string `hcl:"server_http_check_name"`

// ServerSerfCheckName is the name of the health check that Nomad uses
// to register the server Serf health check with Consul
ServerSerfCheckName string `mapstructure:"server_serf_check_name"`
ServerSerfCheckName string `hcl:"server_serf_check_name"`

// ServerRPCCheckName is the name of the health check that Nomad uses
// to register the server RPC health check with Consul
ServerRPCCheckName string `mapstructure:"server_rpc_check_name"`
ServerRPCCheckName string `hcl:"server_rpc_check_name"`

// ClientServiceName is the name of the service that Nomad uses to register
// clients with Consul
ClientServiceName string `mapstructure:"client_service_name"`
ClientServiceName string `hcl:"client_service_name"`

// ClientHTTPCheckName is the name of the health check that Nomad uses
// to register the client HTTP health check with Consul
ClientHTTPCheckName string `mapstructure:"client_http_check_name"`
ClientHTTPCheckName string `hcl:"client_http_check_name"`

// AutoAdvertise determines if this Nomad Agent will advertise its
// services via Consul. When true, Nomad Agent will register
// services with Consul.
AutoAdvertise *bool `mapstructure:"auto_advertise"`
AutoAdvertise *bool `hcl:"auto_advertise"`

// ChecksUseAdvertise specifies that Consul checks should use advertise
// address instead of bind address
ChecksUseAdvertise *bool `mapstructure:"checks_use_advertise"`
ChecksUseAdvertise *bool `hcl:"checks_use_advertise"`

// Addr is the address of the local Consul agent
Addr string `mapstructure:"address"`
Addr string `hcl:"address"`

// Timeout is used by Consul HTTP Client
Timeout time.Duration `mapstructure:"timeout"`
Timeout time.Duration
TimeoutHCL string `hcl:"timeout" json:"-"`

// Token is used to provide a per-request ACL token. This options overrides
// the agent's default token
Token string `mapstructure:"token"`
Token string `hcl:"token"`

// Auth is the information to use for http access to Consul agent
Auth string `mapstructure:"auth"`
Auth string `hcl:"auth"`

// EnableSSL sets the transport scheme to talk to the Consul agent as https
EnableSSL *bool `mapstructure:"ssl"`
EnableSSL *bool `hcl:"ssl"`

// VerifySSL enables or disables SSL verification when the transport scheme
// for the consul api client is https
VerifySSL *bool `mapstructure:"verify_ssl"`
VerifySSL *bool `hcl:"verify_ssl"`

// CAFile is the path to the ca certificate used for Consul communication
CAFile string `mapstructure:"ca_file"`
CAFile string `hcl:"ca_file"`

// CertFile is the path to the certificate for Consul communication
CertFile string `mapstructure:"cert_file"`
CertFile string `hcl:"cert_file"`

// KeyFile is the path to the private key for Consul communication
KeyFile string `mapstructure:"key_file"`
KeyFile string `hcl:"key_file"`

// ServerAutoJoin enables Nomad servers to find peers by querying Consul and
// joining them
ServerAutoJoin *bool `mapstructure:"server_auto_join"`
ServerAutoJoin *bool `hcl:"server_auto_join"`

// ClientAutoJoin enables Nomad servers to find addresses of Nomad servers
// and register with them
ClientAutoJoin *bool `mapstructure:"client_auto_join"`
ClientAutoJoin *bool `hcl:"client_auto_join"`

// ExtraKeysHCL is used by hcl to surface unexpected keys
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
}

// DefaultConsulConfig() returns the canonical defaults for the Nomad
Expand Down
2 changes: 2 additions & 0 deletions nomad/structs/config/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type PluginConfig struct {
Name string `hcl:",key"`
Args []string `hcl:"args"`
Config map[string]interface{} `hcl:"config"`
// ExtraKeysHCL is used by hcl to surface unexpected keys
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
}

func (p *PluginConfig) Merge(o *PluginConfig) *PluginConfig {
Expand Down
Loading

0 comments on commit 84306b0

Please sign in to comment.