From 7d899b6c60d75d7c36a7088496df05991a12ad23 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 9 Aug 2016 15:00:50 -0700 Subject: [PATCH] Pass Vault config to client --- client/config/config.go | 6 ++++++ command/agent/agent.go | 1 + nomad/structs/config/consul.go | 11 +++++++++++ nomad/structs/config/vault.go | 11 +++++++++++ nomad/structs/funcs.go | 13 +++++++++++++ 5 files changed, 42 insertions(+) diff --git a/client/config/config.go b/client/config/config.go index 1d50c5669..6ed0670fa 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -118,6 +118,9 @@ type Config struct { // ConsulConfig is this Agent's Consul configuration ConsulConfig *config.ConsulConfig + // VaultConfig is this Agent's Vault configuration + VaultConfig *config.VaultConfig + // StatsCollectionInterval is the interval at which the Nomad client // collects resource usage stats StatsCollectionInterval time.Duration @@ -137,6 +140,9 @@ func (c *Config) Copy() *Config { nc.Node = nc.Node.Copy() nc.Servers = structs.CopySliceString(nc.Servers) nc.Options = structs.CopyMapStringString(nc.Options) + nc.GloballyReservedPorts = structs.CopySliceInt(c.GloballyReservedPorts) + nc.ConsulConfig = c.ConsulConfig.Copy() + nc.VaultConfig = c.VaultConfig.Copy() return nc } diff --git a/command/agent/agent.go b/command/agent/agent.go index 5c2f726d7..753253d67 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -352,6 +352,7 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) { } conf.ConsulConfig = a.config.Consul + conf.VaultConfig = a.config.Vault conf.StatsCollectionInterval = a.config.Telemetry.collectionInterval conf.PublishNodeMetrics = a.config.Telemetry.PublishNodeMetrics conf.PublishAllocationMetrics = a.config.Telemetry.PublishAllocationMetrics diff --git a/nomad/structs/config/consul.go b/nomad/structs/config/consul.go index 7f673a5c4..86d70bf47 100644 --- a/nomad/structs/config/consul.go +++ b/nomad/structs/config/consul.go @@ -188,3 +188,14 @@ func (c *ConsulConfig) ApiConfig() (*consul.Config, error) { return config, nil } + +// Copy returns a copy of this Consul config. +func (c *ConsulConfig) Copy() *ConsulConfig { + if c == nil { + return nil + } + + nc := new(ConsulConfig) + *nc = *c + return nc +} diff --git a/nomad/structs/config/vault.go b/nomad/structs/config/vault.go index dd452e045..b12f7ab6d 100644 --- a/nomad/structs/config/vault.go +++ b/nomad/structs/config/vault.go @@ -131,3 +131,14 @@ func (c *VaultConfig) ApiConfig(readEnv bool) (*vault.Config, error) { return conf, nil } + +// Copy returns a copy of this Vault config. +func (c *VaultConfig) Copy() *VaultConfig { + if c == nil { + return nil + } + + nc := new(VaultConfig) + *nc = *c + return nc +} diff --git a/nomad/structs/funcs.go b/nomad/structs/funcs.go index 57d762701..836e0ce3d 100644 --- a/nomad/structs/funcs.go +++ b/nomad/structs/funcs.go @@ -204,6 +204,19 @@ func CopySliceString(s []string) []string { return c } +func CopySliceInt(s []int) []int { + l := len(s) + if l == 0 { + return nil + } + + c := make([]int, l) + for i, v := range s { + c[i] = v + } + return c +} + func CopySliceConstraints(s []*Constraint) []*Constraint { l := len(s) if l == 0 {