Skip to content
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

schedulers: check all drivers on node #6227

Merged
merged 2 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions nomad/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ func Node() *structs.Node {
SecretID: uuid.Generate(),
Datacenter: "dc1",
Name: "foobar",
Drivers: map[string]*structs.DriverInfo{
"exec": {
Detected: true,
Healthy: true,
},
"mock_driver": {
Detected: true,
Healthy: true,
},
},
Attributes: map[string]string{
"kernel.name": "linux",
"arch": "x86",
Expand Down
7 changes: 6 additions & 1 deletion scheduler/feasible.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ func (c *DriverChecker) hasDrivers(option *structs.Node) bool {
return false
}

return driverInfo.Detected && driverInfo.Healthy
if driverInfo.Detected && driverInfo.Healthy {
continue
} else {
return false
}
}

value, ok := option.Attributes[driverStr]
Expand All @@ -245,6 +249,7 @@ func (c *DriverChecker) hasDrivers(option *structs.Node) bool {
return false
}
}

return true
}

Expand Down
55 changes: 54 additions & 1 deletion scheduler/feasible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,66 @@ func TestHostVolumeChecker_ReadOnly(t *testing.T) {
}
}

func TestDriverChecker(t *testing.T) {
func TestDriverChecker_DriverInfo(t *testing.T) {
_, ctx := testContext(t)
nodes := []*structs.Node{
mock.Node(),
mock.Node(),
mock.Node(),
}
nodes[0].Drivers["foo"] = &structs.DriverInfo{
Detected: true,
Healthy: true,
}
nodes[1].Drivers["foo"] = &structs.DriverInfo{
Detected: true,
Healthy: false,
}
nodes[2].Drivers["foo"] = &structs.DriverInfo{
Detected: false,
Healthy: false,
}

drivers := map[string]struct{}{
"exec": {},
"foo": {},
}
checker := NewDriverChecker(ctx, drivers)
cases := []struct {
Node *structs.Node
Result bool
}{
{
Node: nodes[0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name the tests or comment the case they cover for easier future reading?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do as a part of a rewrite when we drop compatibility path.

Result: true,
},
{
Node: nodes[1],
Result: false,
},
{
Node: nodes[2],
Result: false,
},
}

for i, c := range cases {
if act := checker.Feasible(c.Node); act != c.Result {
t.Fatalf("case(%d) failed: got %v; want %v", i, act, c.Result)
}
}
}
func TestDriverChecker_Compatibility(t *testing.T) {
_, ctx := testContext(t)
nodes := []*structs.Node{
mock.Node(),
mock.Node(),
mock.Node(),
mock.Node(),
}
for _, n := range nodes {
// force compatibility mode
n.Drivers = nil
}
nodes[0].Attributes["driver.foo"] = "1"
nodes[1].Attributes["driver.foo"] = "0"
Expand Down