mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 09:55:44 +03:00
Fix copying drivers
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user