Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Set labels for pending containers #1451

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
6 changes: 4 additions & 2 deletions cluster/swarm/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ type pendingContainer struct {

func (p *pendingContainer) ToContainer() *cluster.Container {
container := &cluster.Container{
Container: dockerclient.Container{},
Config: p.Config,
Container: dockerclient.Container{
Labels: p.Config.Labels,
},
Config: p.Config,
Info: dockerclient.ContainerInfo{
HostConfig: &dockerclient.HostConfig{},
},
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
FROM dockerswarm/dind:1.9.0

# Install dependencies.
RUN apt-get update && apt-get install -y --no-install-recommends git file \
RUN apt-get update && apt-get install -y --no-install-recommends git file parallel \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install golang
Expand Down
15 changes: 15 additions & 0 deletions test/integration/affinities.bats
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ function teardown() {
[[ "${output}" != *'"Name": "node-1"'* ]]
}

@test "label affinity in parallel" {
start_docker_with_busybox 2
swarm_manage

# Run 3 tests in parallel. One of them must fail.
run parallel docker -H "${SWARM_HOSTS[0]}" run --label test.label=true -e affinity:test.label!=true -d busybox:latest ::: sh sh sh
[ "$status" -ne 0 ]
[[ "${output}" == *'unable to find a node that satisfies test.label!=true'* ]]

# Only 2 containers should have succeeded.
run docker_swarm ps -q
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 2 ]
}

@test "soft affinity" {
start_docker_with_busybox 2

Expand Down