-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Affinity struct, API and parsing #4512
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1570aaa
Affinity parsing, api and structs
d53a9b9
Remove unused field
63c4b9b
Fix Copy method for job and task to include affinities
dcf1726
Refactor method to return affinity struct, and add extra test at task…
cf3152a
Include affinities in job and task diff, and more test cases
40d0972
Treat set_contains as a synonym of set_contains_all
7bbad35
Fail validation if system job has affinities
63d9691
More review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,42 @@ func TestTaskGroup_Constrain(t *testing.T) { | |
} | ||
} | ||
|
||
func TestTaskGroup_AddAffinity(t *testing.T) { | ||
t.Parallel() | ||
grp := NewTaskGroup("grp1", 1) | ||
|
||
// Add an affinity to the group | ||
out := grp.AddAffinity(NewAffinity("kernel.version", "=", "4.6", 100)) | ||
if n := len(grp.Affinities); n != 1 { | ||
t.Fatalf("expected 1 affinity, got: %d", n) | ||
} | ||
|
||
// Check that the group was returned | ||
if out != grp { | ||
t.Fatalf("expected: %#v, got: %#v", grp, out) | ||
} | ||
|
||
// Add a second affinity | ||
grp.AddAffinity(NewAffinity("${node.affinity}", "=", "dc2", 50)) | ||
expect := []*Affinity{ | ||
{ | ||
LTarget: "kernel.version", | ||
RTarget: "4.6", | ||
Operand: "=", | ||
Weight: 100, | ||
}, | ||
{ | ||
LTarget: "${node.affinity}", | ||
RTarget: "dc2", | ||
Operand: "=", | ||
Weight: 50, | ||
}, | ||
} | ||
if !reflect.DeepEqual(grp.Affinities, expect) { | ||
t.Fatalf("expect: %#v, got: %#v", expect, grp.Constraints) | ||
} | ||
} | ||
|
||
func TestTaskGroup_SetMeta(t *testing.T) { | ||
t.Parallel() | ||
grp := NewTaskGroup("grp1", 1) | ||
|
@@ -232,6 +268,42 @@ func TestTask_Constrain(t *testing.T) { | |
} | ||
} | ||
|
||
func TestTask_AddAffinity(t *testing.T) { | ||
t.Parallel() | ||
task := NewTask("task1", "exec") | ||
|
||
// Add an affinity to the task | ||
out := task.AddAffinity(NewAffinity("kernel.version", "=", "4.6", 100)) | ||
if n := len(task.Affinities); n != 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. require.Len is handy for this https://godoc.org/github.com/stretchr/testify/require#Len |
||
t.Fatalf("expected 1 affinity, got: %d", n) | ||
} | ||
|
||
// Check that the task was returned | ||
if out != task { | ||
t.Fatalf("expected: %#v, got: %#v", task, out) | ||
} | ||
|
||
// Add a second affinity | ||
task.AddAffinity(NewAffinity("${node.datacenter}", "=", "dc2", 50)) | ||
expect := []*Affinity{ | ||
{ | ||
LTarget: "kernel.version", | ||
RTarget: "4.6", | ||
Operand: "=", | ||
Weight: 100, | ||
}, | ||
{ | ||
LTarget: "${node.datacenter}", | ||
RTarget: "dc2", | ||
Operand: "=", | ||
Weight: 50, | ||
}, | ||
} | ||
if !reflect.DeepEqual(task.Affinities, expect) { | ||
t.Fatalf("expect: %#v, got: %#v", expect, task.Affinities) | ||
} | ||
} | ||
|
||
func TestTask_Artifact(t *testing.T) { | ||
t.Parallel() | ||
a := TaskArtifact{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change; just fyi: you can skip repeating the type if it's the same between arguments: