-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Affinity labels like -e affinity:com.example.type==test
#667
Changes from 3 commits
4f6df97
f388d70
28a358d
77f0ac9
a2dc4b8
dce5d6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,7 +101,7 @@ without specifying them when starting the node. Those tags are sourced from | |
|
|
||
| #### Containers | ||
|
|
||
| You can schedule 2 containers and make the container #2 next to the container #1. | ||
| You can schedule 2 containers and make the container #2 next to the container #1 using it's name or ID. | ||
|
|
||
| ```bash | ||
| $ docker run -d -p 80:80 --name front nginx | ||
|
|
@@ -164,6 +164,33 @@ CONTAINER ID IMAGE COMMAND CREATED | |
|
|
||
| As you can see here, the containers were only scheduled on nodes with the `redis` image already pulled. | ||
|
|
||
| #### Labels | ||
|
|
||
| You can schedule 2 containers and make the container #2 next to the container #1 using it's labels. | ||
|
Contributor
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.
/cc @moxiegirl |
||
|
|
||
| ```bash | ||
| $ docker run -d -p 80:80 --label com.example.type=front nginx | ||
|
Contributor
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. nit: |
||
| 87c4376856a8 | ||
|
|
||
| $ docker ps | ||
| CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NODE NAMES | ||
| 87c4376856a8 nginx:latest "nginx" Less than a second ago running 192.168.0.42:80->80/tcp node-1 trusting_yonath | ||
| ``` | ||
|
|
||
| Using `-e affinity:com.example.type==front` will schedule a container next to the container with label `front`. | ||
|
|
||
| ```bash | ||
| $ docker run -d -e affinity:com.example.type==front logger | ||
| 87c4376856a8 | ||
|
|
||
| $ docker ps | ||
| CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NODE NAMES | ||
| 87c4376856a8 nginx:latest "nginx" Less than a second ago running 192.168.0.42:80->80/tcp node-1 trusting_yonath | ||
| 963841b138d8 logger:latest "logger" Less than a second ago running node-1 happy_hawking | ||
| ``` | ||
|
|
||
| The `logger` container ends up on `node-1` because its affinity with the container `front`. | ||
|
Contributor
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.
/cc @moxiegirl |
||
|
|
||
| #### Expression Syntax | ||
|
|
||
| An affinity or a constraint expression consists of a `key` and a `value`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ func parseExprs(key string, env []string) ([]expr, error) { | |
|
|
||
| // validate key | ||
| // allow alpha-numeric | ||
| matched, err := regexp.MatchString(`^(?i)[a-z_][a-z0-9\-_]+$`, parts[0]) | ||
| matched, err := regexp.MatchString(`^(?i)[a-z_][a-z0-9\-_.]+$`, parts[0]) | ||
|
Contributor
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. A tiny bit unsure about the effect on the regex: Is this being interpreted as a dot or as any character and do we need to escape it?
Contributor
Author
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. I'll test, but I'm not sure it counts as
Contributor
Author
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. Seems good to me |
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load helpers | ||
|
|
||
| function teardown() { | ||
| swarm_manage_cleanup | ||
| stop_docker | ||
| } | ||
|
|
||
|
Contributor
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. Would you mind adding an image affinity test since you already made most of the work?
Contributor
Author
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. yes!
Contributor
Author
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. done |
||
| @test "container affinty" { | ||
| start_docker 2 | ||
| swarm_manage | ||
|
|
||
| run docker_swarm run --name c1 -e constraint:node==node-0 -d busybox:latest sh | ||
| [ "$status" -eq 0 ] | ||
| run docker_swarm run --name c2 -e affinity:container==c1 -d busybox:latest sh | ||
| [ "$status" -eq 0 ] | ||
| run docker_swarm run --name c3 -e affinity:container!=c1 -d busybox:latest sh | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| run docker_swarm inspect c1 | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *'"Name": "node-0"'* ]] | ||
|
|
||
| run docker_swarm inspect c2 | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *'"Name": "node-0"'* ]] | ||
|
|
||
| run docker_swarm inspect c3 | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *'"Name": "node-1"'* ]] | ||
|
Contributor
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. Perhaps match this against
Contributor
Author
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. ok |
||
| } | ||
|
|
||
| @test "label affinity" { | ||
| start_docker 2 | ||
| swarm_manage | ||
|
|
||
| run docker_swarm run --name c1 --label test.label=true -e constraint:node==node-0 -d busybox:latest sh | ||
| [ "$status" -eq 0 ] | ||
| run docker_swarm run --name c2 -e affinity:test.label==true -d busybox:latest sh | ||
| [ "$status" -eq 0 ] | ||
| run docker_swarm run --name c3 -e affinity:test.label!=true -d busybox:latest sh | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| run docker_swarm inspect c1 | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *'"Name": "node-0"'* ]] | ||
|
|
||
| run docker_swarm inspect c2 | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *'"Name": "node-0"'* ]] | ||
|
|
||
| run docker_swarm inspect c3 | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *'"Name": "node-1"'* ]] | ||
|
Contributor
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. Same feedback
Contributor
Author
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. ok |
||
| } | ||
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.
Doc feedback - how about:
/cc @moxiegirl