Skip to content

Commit

Permalink
Support constraint on platform architecture and OS.
Browse files Browse the repository at this point in the history
Signed-off-by: Dong Chen <dongluo.chen@docker.com>
  • Loading branch information
dongluochen committed Oct 22, 2016
1 parent 8cf1a54 commit de2d329
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -56,6 +56,8 @@ Some of *SwarmKit*'s main features are:
| node.id | node's ID | `node.id == 2ivku8v2gvtg4`|
| node.hostname | node's hostname | `node.hostname != node-2`|
| node.role | node's manager or worker role | `node.role == manager`|
| node.platform.os | node's operating system | `node.platform.os == linux`|
| node.platform.arch | node's architecture | `node.platform.arch == x86_64`|
| node.labels | node's labels added by cluster admins | `node.labels.security == high`|
| engine.labels | Docker Engine's labels | `engine.labels.operatingsystem == ubuntu 14.04`|

Expand Down
20 changes: 20 additions & 0 deletions manager/constraint/constraint.go
Expand Up @@ -125,6 +125,26 @@ func NodeMatches(constraints []Constraint, n *api.Node) bool {
if !constraint.Match(n.Spec.Role.String()) {
return false
}
case strings.EqualFold(constraint.key, "node.platform.os"):
if n.Description == nil || n.Description.Platform == nil {
if !constraint.Match("") {
return false
}
continue
}
if !constraint.Match(n.Description.Platform.OS) {
return false
}
case strings.EqualFold(constraint.key, "node.platform.arch"):
if n.Description == nil || n.Description.Platform == nil {
if !constraint.Match("") {
return false
}
continue
}
if !constraint.Match(n.Description.Platform.Architecture) {
return false
}

// node labels constraint in form like 'node.labels.key==value'
case len(constraint.key) > len(nodeLabelPrefix) && strings.EqualFold(constraint.key[:len(nodeLabelPrefix)], nodeLabelPrefix):
Expand Down
35 changes: 35 additions & 0 deletions manager/scheduler/constraint_test.go
Expand Up @@ -158,6 +158,41 @@ func TestNodeRole(t *testing.T) {
assert.False(t, f.Check(ni))
}

func TestNodePlatform(t *testing.T) {
setupEnv()
f := ConstraintFilter{}
task1.Spec.Placement = &api.Placement{
Constraints: []string{"node.platform.os == linux"},
}
require.True(t, f.SetTask(task1))
//node info doesn't have platform yet
assert.False(t, f.Check(ni))

ni.Node.Description.Platform = &api.Platform{
Architecture: "x86_64",
OS: "linux",
}
assert.True(t, f.Check(ni))

ni.Node.Description.Platform = &api.Platform{
Architecture: "x86_64",
OS: "windows",
}
assert.False(t, f.Check(ni))

task1.Spec.Placement = &api.Placement{
Constraints: []string{"node.platform.arch == amd64"},
}
require.True(t, f.SetTask(task1))
assert.False(t, f.Check(ni))

task1.Spec.Placement = &api.Placement{
Constraints: []string{"node.platform.arch != amd64"},
}
require.True(t, f.SetTask(task1))
assert.True(t, f.Check(ni))
}

func TestNodeLabel(t *testing.T) {
setupEnv()
f := ConstraintFilter{}
Expand Down

0 comments on commit de2d329

Please sign in to comment.