diff --git a/client/client.go b/client/client.go index cfefef1f6..2cb9dac59 100644 --- a/client/client.go +++ b/client/client.go @@ -265,7 +265,7 @@ func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulServic c.configCopy = c.config.Copy() c.configLock.Unlock() - fingerprintManager := NewFingerprintManager(c.GetConfig, c.config.Node, + fingerprintManager := NewFingerprintManager(c.GetConfig, c.configCopy.Node, c.shutdownCh, c.updateNodeFromFingerprint, c.updateNodeFromDriver, c.logger) @@ -443,7 +443,7 @@ func (c *Client) Leave() error { func (c *Client) GetConfig() *config.Config { c.configLock.Lock() defer c.configLock.Unlock() - return c.config + return c.configCopy } // Datacenter returns the datacenter for the given client diff --git a/nomad/structs/node.go b/nomad/structs/node.go index a4eb91e71..76758fb8e 100644 --- a/nomad/structs/node.go +++ b/nomad/structs/node.go @@ -2,6 +2,8 @@ package structs import ( "time" + + "github.com/hashicorp/nomad/helper" ) // DriverInfo is the current state of a single driver. This is updated @@ -14,6 +16,17 @@ type DriverInfo struct { UpdateTime time.Time } +func (di *DriverInfo) Copy() *DriverInfo { + if di == nil { + return nil + } + + cdi := new(DriverInfo) + *cdi = *di + cdi.Attributes = helper.CopyMapStringString(di.Attributes) + return cdi +} + // MergeHealthCheck merges information from a health check for a drier into a // node's driver info func (di *DriverInfo) MergeHealthCheck(other *DriverInfo) { diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 1fd30e322..60d8f0d80 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1461,6 +1461,7 @@ func (n *Node) Copy() *Node { nn.Meta = helper.CopyMapStringString(nn.Meta) nn.Events = copyNodeEvents(n.Events) nn.DrainStrategy = nn.DrainStrategy.Copy() + nn.Drivers = copyNodeDrivers(n.Drivers) return nn } @@ -1478,6 +1479,20 @@ func copyNodeEvents(events []*NodeEvent) []*NodeEvent { return c } +// copyNodeDrivers is a helper to copy a map of DriverInfo +func copyNodeDrivers(drivers map[string]*DriverInfo) map[string]*DriverInfo { + l := len(drivers) + if l == 0 { + return nil + } + + c := make(map[string]*DriverInfo, l) + for driver, info := range drivers { + c[driver] = info.Copy() + } + return c +} + // TerminalStatus returns if the current status is terminal and // will no longer transition. func (n *Node) TerminalStatus() bool {