Merge pull request #4984 from hashicorp/b-client-update-driver
client: update driver info on new driver fingerprint
This commit is contained in:
commit
3d166e6e9c
|
@ -1156,7 +1156,6 @@ func (c *Client) updateNodeFromDriver(name string, info *structs.DriverInfo) *st
|
||||||
if !hadDriver {
|
if !hadDriver {
|
||||||
// If the driver info has not yet been set, do that here
|
// If the driver info has not yet been set, do that here
|
||||||
hasChanged = true
|
hasChanged = true
|
||||||
c.config.Node.Drivers[name] = info
|
|
||||||
for attrName, newVal := range info.Attributes {
|
for attrName, newVal := range info.Attributes {
|
||||||
c.config.Node.Attributes[attrName] = newVal
|
c.config.Node.Attributes[attrName] = newVal
|
||||||
}
|
}
|
||||||
|
@ -1165,11 +1164,11 @@ func (c *Client) updateNodeFromDriver(name string, info *structs.DriverInfo) *st
|
||||||
// The driver info has already been set, fix it up
|
// The driver info has already been set, fix it up
|
||||||
if oldVal.Detected != info.Detected {
|
if oldVal.Detected != info.Detected {
|
||||||
hasChanged = true
|
hasChanged = true
|
||||||
c.config.Node.Drivers[name].Detected = info.Detected
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldVal.Healthy != info.Healthy || oldVal.HealthDescription != info.HealthDescription {
|
if oldVal.Healthy != info.Healthy || oldVal.HealthDescription != info.HealthDescription {
|
||||||
hasChanged = true
|
hasChanged = true
|
||||||
|
|
||||||
if info.HealthDescription != "" {
|
if info.HealthDescription != "" {
|
||||||
event := &structs.NodeEvent{
|
event := &structs.NodeEvent{
|
||||||
Subsystem: "Driver",
|
Subsystem: "Driver",
|
||||||
|
@ -1188,6 +1187,7 @@ func (c *Client) updateNodeFromDriver(name string, info *structs.DriverInfo) *st
|
||||||
}
|
}
|
||||||
|
|
||||||
hasChanged = true
|
hasChanged = true
|
||||||
|
|
||||||
if newVal == "" {
|
if newVal == "" {
|
||||||
delete(c.config.Node.Attributes, attrName)
|
delete(c.config.Node.Attributes, attrName)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1207,6 +1207,7 @@ func (c *Client) updateNodeFromDriver(name string, info *structs.DriverInfo) *st
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasChanged {
|
if hasChanged {
|
||||||
|
c.config.Node.Drivers[name] = info
|
||||||
c.config.Node.Drivers[name].UpdateTime = time.Now()
|
c.config.Node.Drivers[name].UpdateTime = time.Now()
|
||||||
c.updateNodeLocked()
|
c.updateNodeLocked()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1183,3 +1183,80 @@ func TestClient_computeAllocatedDeviceStats(t *testing.T) {
|
||||||
|
|
||||||
assert.EqualValues(t, expected, result)
|
assert.EqualValues(t, expected, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_updateNodeFromDriverUpdatesAll(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
client, cleanup := TestClient(t, nil)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
// initial update
|
||||||
|
{
|
||||||
|
info := &structs.DriverInfo{
|
||||||
|
Detected: true,
|
||||||
|
Healthy: false,
|
||||||
|
HealthDescription: "not healthy at start",
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"node.mock.testattr1": "val1",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
n := client.updateNodeFromDriver("mock", info)
|
||||||
|
|
||||||
|
updatedInfo := *n.Drivers["mock"]
|
||||||
|
// compare without update time
|
||||||
|
updatedInfo.UpdateTime = info.UpdateTime
|
||||||
|
assert.EqualValues(t, updatedInfo, *info)
|
||||||
|
|
||||||
|
// check node attributes
|
||||||
|
assert.Equal(t, "val1", n.Attributes["node.mock.testattr1"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// initial update
|
||||||
|
{
|
||||||
|
info := &structs.DriverInfo{
|
||||||
|
Detected: true,
|
||||||
|
Healthy: true,
|
||||||
|
HealthDescription: "healthy",
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"node.mock.testattr1": "val2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
n := client.updateNodeFromDriver("mock", info)
|
||||||
|
|
||||||
|
updatedInfo := *n.Drivers["mock"]
|
||||||
|
// compare without update time
|
||||||
|
updatedInfo.UpdateTime = info.UpdateTime
|
||||||
|
assert.EqualValues(t, updatedInfo, *info)
|
||||||
|
|
||||||
|
// check node attributes are updated
|
||||||
|
assert.Equal(t, "val2", n.Attributes["node.mock.testattr1"])
|
||||||
|
|
||||||
|
// update once more with the same info, updateTime shouldn't change
|
||||||
|
un := client.updateNodeFromDriver("mock", info)
|
||||||
|
assert.EqualValues(t, n, un)
|
||||||
|
}
|
||||||
|
|
||||||
|
// update once more to unhealthy because why not
|
||||||
|
{
|
||||||
|
info := &structs.DriverInfo{
|
||||||
|
Detected: true,
|
||||||
|
Healthy: false,
|
||||||
|
HealthDescription: "lost track",
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"node.mock.testattr1": "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
n := client.updateNodeFromDriver("mock", info)
|
||||||
|
|
||||||
|
updatedInfo := *n.Drivers["mock"]
|
||||||
|
// compare without update time
|
||||||
|
updatedInfo.UpdateTime = info.UpdateTime
|
||||||
|
assert.EqualValues(t, updatedInfo, *info)
|
||||||
|
|
||||||
|
// check node attributes are updated
|
||||||
|
assert.Equal(t, "", n.Attributes["node.mock.testattr1"])
|
||||||
|
|
||||||
|
// update once more with the same info, updateTime shouldn't change
|
||||||
|
un := client.updateNodeFromDriver("mock", info)
|
||||||
|
assert.EqualValues(t, n, un)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue