From 6910678c21428150a91c5e50903985857422eb4d Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 27 Feb 2017 13:42:37 -0800 Subject: [PATCH] Allow random UUID --- client/client.go | 2 +- client/config/config.go | 4 ++++ command/agent/agent.go | 1 + command/agent/config-test-fixtures/basic.hcl | 1 + command/agent/config.go | 7 +++++++ command/agent/config_parse.go | 1 + command/agent/config_parse_test.go | 1 + demo/vagrant/client2.hcl | 1 + website/source/docs/agent/configuration/client.html.md | 3 +++ 9 files changed, 20 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 22e2f24d1..43357f4eb 100644 --- a/client/client.go +++ b/client/client.go @@ -639,7 +639,7 @@ func (c *Client) getAllocRunners() map[string]*AllocRunner { func (c *Client) nodeID() (id, secret string, err error) { var hostID string hostInfo, err := host.Info() - if err == nil && helper.IsUUID(hostInfo.HostID) { + if !c.config.NoHostUUID && err == nil && helper.IsUUID(hostInfo.HostID) { hostID = hostInfo.HostID } else { // Generate a random hostID if no constant ID is available on diff --git a/client/config/config.go b/client/config/config.go index 54936ec0b..02f17c873 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -165,6 +165,10 @@ type Config struct { // LogLevel is the level of the logs to putout LogLevel string + + // NoHostUUID disables using the host's UUID and will force generation of a + // random UUID. + NoHostUUID bool } func (c *Config) Copy() *Config { diff --git a/command/agent/agent.go b/command/agent/agent.go index bfecfec7d..61d1985c0 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -312,6 +312,7 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) { conf.GCInterval = a.config.Client.GCInterval conf.GCDiskUsageThreshold = a.config.Client.GCDiskUsageThreshold conf.GCInodeUsageThreshold = a.config.Client.GCInodeUsageThreshold + conf.NoHostUUID = a.config.Client.NoHostUUID return conf, nil } diff --git a/command/agent/config-test-fixtures/basic.hcl b/command/agent/config-test-fixtures/basic.hcl index 3ad81148b..8974fdf35 100644 --- a/command/agent/config-test-fixtures/basic.hcl +++ b/command/agent/config-test-fixtures/basic.hcl @@ -56,6 +56,7 @@ client { gc_interval = "6s" gc_disk_usage_threshold = 82 gc_inode_usage_threshold = 91 + no_host_uuid = true } server { enabled = true diff --git a/command/agent/config.go b/command/agent/config.go index 9412e4567..ccb5db560 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -209,6 +209,10 @@ type ClientConfig struct { // GCInodeUsageThreshold is the inode usage threshold beyond which the Nomad // client triggers GC of the terminal allocations GCInodeUsageThreshold float64 `mapstructure:"gc_inode_usage_threshold"` + + // NoHostUUID disables using the host's UUID and will force generation of a + // random UUID. + NoHostUUID bool `mapstructure:"no_host_uuid"` } // ServerConfig is configuration specific to the server mode @@ -931,6 +935,9 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig { if b.GCInodeUsageThreshold != 0 { result.GCInodeUsageThreshold = b.GCInodeUsageThreshold } + if b.NoHostUUID { + result.NoHostUUID = b.NoHostUUID + } // Add the servers result.Servers = append(result.Servers, b.Servers...) diff --git a/command/agent/config_parse.go b/command/agent/config_parse.go index 35229d805..ea2e4e0fa 100644 --- a/command/agent/config_parse.go +++ b/command/agent/config_parse.go @@ -344,6 +344,7 @@ func parseClient(result **ClientConfig, list *ast.ObjectList) error { "gc_interval", "gc_disk_usage_threshold", "gc_inode_usage_threshold", + "no_host_uuid", } if err := checkHCLKeys(listVal, valid); err != nil { return err diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index ba9016d7a..f0da05e7f 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -73,6 +73,7 @@ func TestConfig_Parse(t *testing.T) { GCInterval: 6 * time.Second, GCDiskUsageThreshold: 82, GCInodeUsageThreshold: 91, + NoHostUUID: true, }, Server: &ServerConfig{ Enabled: true, diff --git a/demo/vagrant/client2.hcl b/demo/vagrant/client2.hcl index 31b74ad1d..9889ebe7c 100644 --- a/demo/vagrant/client2.hcl +++ b/demo/vagrant/client2.hcl @@ -7,6 +7,7 @@ data_dir = "/tmp/client2" # Enable the client client { enabled = true + no_host_uuid = true # For demo assume we are talking to server1. For production, # this should be like "nomad.service.consul:4647" and a system diff --git a/website/source/docs/agent/configuration/client.html.md b/website/source/docs/agent/configuration/client.html.md index 019dea757..77aa64e77 100644 --- a/website/source/docs/agent/configuration/client.html.md +++ b/website/source/docs/agent/configuration/client.html.md @@ -92,6 +92,9 @@ client { - `gc_inode_usage_threshold` `(float: 70)` - Specifies the inode usage percent which Nomad tries to maintain by garbage collecting terminal allocations. +- `no_host_uuid` `(bool: false)` - Force the UUID generated by the client to be + randomly generated and not be based on the host's UUID. + ### `chroot_env` Parameters Drivers based on [isolated fork/exec](/docs/drivers/exec.html) implement file