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
596f16fb
Commit
596f16fb
authored
6 years ago
by
Lang Martin
Browse files
Options
Download
Email Patches
Plain Diff
fingerprint Constraints and Affinities have Equals, as set
parent
7857ac59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nomad/job_endpoint.go
+2
-2
nomad/job_endpoint.go
nomad/structs/structs.go
+63
-35
nomad/structs/structs.go
with
65 additions
and
37 deletions
+65
-37
nomad/job_endpoint.go
+
2
-
2
View file @
596f16fb
...
...
@@ -263,7 +263,7 @@ func setImplicitConstraints(j *structs.Job) {
found
:=
false
for
_
,
c
:=
range
tg
.
Constraints
{
if
c
.
Equal
(
vaultConstraint
)
{
if
c
.
Equal
s
(
vaultConstraint
)
{
found
=
true
break
}
...
...
@@ -288,7 +288,7 @@ func setImplicitConstraints(j *structs.Job) {
found
:=
false
for
_
,
c
:=
range
tg
.
Constraints
{
if
c
.
Equal
(
sigConstraint
)
{
if
c
.
Equal
s
(
sigConstraint
)
{
found
=
true
break
}
...
...
This diff is collapsed.
Click to expand it.
nomad/structs/structs.go
+
63
-
35
View file @
596f16fb
...
...
@@ -2126,11 +2126,11 @@ type RequestedDevice struct {
// Constraints are a set of constraints to apply when selecting the device
// to use.
Constraints
[]
*
Constraint
Constraints
Constraint
s
// Affinities are a set of affinites to apply when selecting the device
// to use.
Affinities
[]
*
Affinit
y
Affinities
Affinit
ies
}
func
(
r
*
RequestedDevice
)
Equals
(
o
*
RequestedDevice
)
bool
{
...
...
@@ -2140,30 +2140,10 @@ func (r *RequestedDevice) Equals(o *RequestedDevice) bool {
if
r
==
nil
||
o
==
nil
{
return
false
}
if
!
(
r
.
Name
==
o
.
Name
&&
r
.
Count
==
o
.
Count
)
{
return
false
}
// r.Constraints == o.Constraints, order sensitive
if
len
(
r
.
Constraints
)
!=
len
(
o
.
Constraints
)
{
return
false
}
for
i
,
c
:=
range
r
.
Constraints
{
if
!
c
.
Equal
(
o
.
Constraints
[
i
])
{
return
false
}
}
// r.Affinities == o.Affinities, order sensitive
if
len
(
r
.
Affinities
)
!=
len
(
o
.
Affinities
)
{
return
false
}
for
i
,
a
:=
range
r
.
Affinities
{
if
!
a
.
Equal
(
o
.
Affinities
[
i
])
{
return
false
}
}
return
true
return
r
.
Name
==
o
.
Name
&&
r
.
Count
==
o
.
Count
&&
r
.
Constraints
.
Equals
(
&
o
.
Constraints
)
&&
r
.
Affinities
.
Equals
(
&
o
.
Affinities
)
}
func
(
r
*
RequestedDevice
)
Copy
()
*
RequestedDevice
{
...
...
@@ -6515,10 +6495,11 @@ type Constraint struct {
}
// Equal checks if two constraints are equal
func
(
c
*
Constraint
)
Equal
(
o
*
Constraint
)
bool
{
return
c
.
LTarget
==
o
.
LTarget
&&
c
.
RTarget
==
o
.
RTarget
&&
c
.
Operand
==
o
.
Operand
func
(
c
*
Constraint
)
Equals
(
o
*
Constraint
)
bool
{
return
c
==
o
||
c
.
LTarget
==
o
.
LTarget
&&
c
.
RTarget
==
o
.
RTarget
&&
c
.
Operand
==
o
.
Operand
}
func
(
c
*
Constraint
)
Copy
()
*
Constraint
{
...
...
@@ -6594,6 +6575,29 @@ func (c *Constraint) Validate() error {
return
mErr
.
ErrorOrNil
()
}
type
Constraints
[]
*
Constraint
// Equals compares Constraints as a set
func
(
xs
*
Constraints
)
Equals
(
ys
*
Constraints
)
bool
{
if
xs
==
ys
{
return
true
}
if
xs
==
nil
||
ys
==
nil
{
return
false
}
if
len
(
*
xs
)
!=
len
(
*
ys
)
{
return
false
}
for
_
,
x
:=
range
*
xs
{
for
_
,
y
:=
range
*
ys
{
if
!
x
.
Equals
(
y
)
{
return
false
}
}
}
return
true
}
// Affinity is used to score placement options based on a weight
type
Affinity
struct
{
LTarget
string
// Left-hand target
...
...
@@ -6604,11 +6608,12 @@ type Affinity struct {
}
// Equal checks if two affinities are equal
func
(
a
*
Affinity
)
Equal
(
o
*
Affinity
)
bool
{
return
a
.
LTarget
==
o
.
LTarget
&&
a
.
RTarget
==
o
.
RTarget
&&
a
.
Operand
==
o
.
Operand
&&
a
.
Weight
==
o
.
Weight
func
(
a
*
Affinity
)
Equals
(
o
*
Affinity
)
bool
{
return
a
==
o
||
a
.
LTarget
==
o
.
LTarget
&&
a
.
RTarget
==
o
.
RTarget
&&
a
.
Operand
==
o
.
Operand
&&
a
.
Weight
==
o
.
Weight
}
func
(
a
*
Affinity
)
Copy
()
*
Affinity
{
...
...
@@ -6689,6 +6694,29 @@ type Spread struct {
str
string
}
type
Affinities
[]
*
Affinity
// Equals compares Affinities as a set
func
(
xs
*
Affinities
)
Equals
(
ys
*
Affinities
)
bool
{
if
xs
==
ys
{
return
true
}
if
xs
==
nil
||
ys
==
nil
{
return
false
}
if
len
(
*
xs
)
!=
len
(
*
ys
)
{
return
false
}
for
_
,
x
:=
range
*
xs
{
for
_
,
y
:=
range
*
ys
{
if
!
x
.
Equals
(
y
)
{
return
false
}
}
}
return
true
}
func
(
s
*
Spread
)
Copy
()
*
Spread
{
if
s
==
nil
{
return
nil
...
...
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