Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
84bd433c
Commit
84bd433c
authored
6 years ago
by
Lang Martin
Browse files
Options
Download
Email Patches
Plain Diff
add client updateNodeResources to merge but preserve manual config
parent
68978252
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/client.go
+27
-21
client/client.go
with
27 additions
and
21 deletions
+27
-21
client/client.go
+
27
-
21
View file @
84bd433c
...
...
@@ -1227,14 +1227,12 @@ func (c *Client) updateNodeFromFingerprint(response *fingerprint.FingerprintResp
}
// COMPAT(0.10): Remove in 0.10
if
response
.
Resources
!=
nil
&&
!
resourcesAreEqual
(
c
.
config
.
Node
.
Resources
,
response
.
Resources
)
{
if
updateResources
(
c
.
config
,
response
.
Resources
)
{
nodeHasChanged
=
true
c
.
config
.
Node
.
Resources
.
Merge
(
response
.
Resources
)
}
if
response
.
NodeResources
!=
nil
&&
!
c
.
config
.
Node
.
NodeResources
.
Equals
(
response
.
NodeResources
)
{
if
update
NodeResources
(
c
.
config
,
response
.
NodeResources
)
{
nodeHasChanged
=
true
c
.
config
.
Node
.
NodeResources
.
Merge
(
response
.
NodeResources
)
}
if
nodeHasChanged
{
...
...
@@ -1244,31 +1242,39 @@ func (c *Client) updateNodeFromFingerprint(response *fingerprint.FingerprintResp
return
c
.
configCopy
.
Node
}
// resourcesAreEqual is a temporary function to compare whether resources are
// equal. We can use this until we change fingerprinters to set pointers on a
// return type.
func
resourcesAreEqual
(
first
,
second
*
structs
.
Resources
)
bool
{
if
first
.
CPU
!=
second
.
CPU
{
// updateNodeResources modifies the client NodeResources, returns whether it did so
func
updateNodeResources
(
c
*
config
.
Config
,
up
*
structs
.
NodeResources
)
bool
{
if
up
==
nil
{
return
false
}
if
first
.
MemoryMB
!=
second
.
MemoryMB
{
return
false
if
c
.
NetworkInterface
!=
""
||
c
.
NetworkSpeed
!=
0
{
// - if a network is configured, keep it
// - the update may contain a change to an automatically
// assigned interface (eg, via the AWS plugin)
// - the update should reflect the active
// fingerprinted network
up
.
Networks
=
c
.
Node
.
NodeResources
.
Networks
}
if
first
.
DiskMB
!=
second
.
DiskMB
{
if
c
.
Node
.
NodeResources
.
Equals
(
up
)
{
return
false
}
if
len
(
first
.
Networks
)
!=
len
(
second
.
Networks
)
{
c
.
Node
.
NodeResources
.
Merge
(
up
)
return
true
}
// COMPAT(0.10): Remove in 0.10
// updateResources is updateNodeResources for the Resources type
func
updateResources
(
c
*
config
.
Config
,
up
*
structs
.
Resources
)
bool
{
if
up
==
nil
{
return
false
}
for
i
,
e
:=
range
first
.
Networks
{
if
len
(
second
.
Networks
)
<
i
{
return
false
}
f
:=
second
.
Networks
[
i
]
if
!
e
.
Equals
(
f
)
{
return
false
}
if
c
.
NetworkInterface
!=
""
||
c
.
NetworkSpeed
!=
0
{
up
.
Networks
=
c
.
Node
.
Resources
.
Networks
}
if
c
.
Node
.
Resources
.
Equals
(
up
)
{
return
false
}
c
.
Node
.
Resources
.
Merge
(
up
)
return
true
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment