Skip to content

Add support for maximum replicas per node without stack - #1612

Merged
thaJeztah merged 1 commit into
docker:masterfrom
olljanat:replicas-max-per-node-cli
Feb 22, 2019
Merged

Add support for maximum replicas per node without stack#1612
thaJeztah merged 1 commit into
docker:masterfrom
olljanat:replicas-max-per-node-cli

Conversation

@olljanat

@olljanatolljanat commented Jan 14, 2019

Copy link
Copy Markdown
Contributor

- What I did
Added support for maximum replicas per node

Third step to be able solve:

- How I did it
Added new switch --replicas-max-per-node switch to docker service

- How to verify it
Create two services and specify --replicas-max-per-node one of them:

docker service create --detach=true --name web1 --replicas 2 nginx
docker service create --detach=true --name web2 --replicas 2 --replicas-max-per-node 1 nginx

See difference on command outputs:

$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
0inbv7q148nn web1 replicated 2/2 nginx:latest 9kry59rk4ecr web2 replicated 1/2 (max 1 per node) nginx:latest
$ docker service ps --no-trunc web2
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
bf90bhy72o2ry2pj50xh24cfp web2.1 nginx:latest@sha256:b543f6d0983fbc25b9874e22f4fe257a567111da96fd1d8f1b44315f1236398c limint Running Running 34 seconds ago xedop9dwtilok0r56w4g7h5jm web2.2 nginx:latest@sha256:b543f6d0983fbc25b9874e22f4fe257a567111da96fd1d8f1b44315f1236398c Running Pending 35 seconds ago "no suitable node (max replicas per node limit exceed)" 

- Description for the changelog

@codecov-io

codecov-io commented Jan 14, 2019

Copy link
Copy Markdown

Codecov Report

Merging #1612 into master will increase coverage by 0.08%.
The diff coverage is 47.36%.

@@ Coverage Diff @@## master #1612 +/- ##
==========================================
+ Coverage 56.05% 56.14% +0.08% 
==========================================
Files 306 306 Lines 20981 20980 -1 ==========================================
+ Hits 11761 11779 +18 + Misses 8371 8347 -24 - Partials 849 854 +5

@olljanat

Copy link
Copy Markdown
ContributorAuthor

@thaJeztah FYI. I moved non-stack version to this PR as it is already fully working and it easier to debug stack version when there is less stuff.

Can you give first review? I assume that at least some kind of tests are wanted on but which kind of?

Logic is tested on swarmkit and API on Moby.

@olljanat

Copy link
Copy Markdown
ContributorAuthor

@thaJeztah reminder of this one. I really would like get feedback so I can finalize it.

@olljanat

Copy link
Copy Markdown
ContributorAuthor

@vdemeester@thaJeztah PTAL

@cpuguy83cpuguy83 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good but could use some unit tests.

@thaJeztah

Copy link
Copy Markdown
Member

Ah, whoops, thought I reviewed; yes, changes look good, but if you can add a unit test, that'd be great

@olljanat
olljanatforce-pushed the replicas-max-per-node-cli branch 2 times, most recently from 4a9cbcd to 79b5119CompareFebruary 18, 2019 08:03
Comment threadcli/command/service/update_test.go Outdated

@silvin-lubeckisilvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small nit but LGTM otherwise, thank you @olljanat 👍 !

@olljanat
olljanatforce-pushed the replicas-max-per-node-cli branch from 79b5119 to d103bd4CompareFebruary 18, 2019 09:26
@olljanat

Copy link
Copy Markdown
ContributorAuthor

@silvin-lubecki corrected that one and rebased to one commit.

@thaJeztahthaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

apologies for the delay; found some minor issues, and a missing "version" annotation 😊

Comment threadcli/command/service/opts.go Outdated
Comment threadcli/command/service/opts.go
Comment threadcli/command/service/update_test.go Outdated
Comment threaddocs/reference/commandline/service_create.md Outdated
Comment threaddocs/reference/commandline/service_create.md Outdated
@GordonTheTurtle

Copy link
Copy Markdown

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "replicas-max-per-node-cli" git@github.com:olljanat/cli.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842358453696editor openschange each 'pick' to 'edit'save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
@olljanat

Copy link
Copy Markdown
ContributorAuthor

@thaJeztah included changes you suggested and rebased to one commit.

@thaJeztah

Copy link
Copy Markdown
Member

Gave this a spin, and all looks good 😄

We could add some more tests based on the scenarios below, but I'm ok to keep that for a follow-up.

Create a service with max 2 replicas:

docker service create --replicas=2 --replicas-max-per-node=2 --name test nginx:alpine
docker service inspect --format '{{.Spec.TaskTemplate.Placement.MaxReplicas}}'test
2

Update the service (max replicas should keep its value) - this works ok;

docker service update --replicas=1 test
docker service inspect --format '{{.Spec.TaskTemplate.Placement.MaxReplicas}}'test
2

Update the max replicas to 1

docker service update --replicas-max-per-node=1 test
docker service inspect --format '{{.Spec.TaskTemplate.Placement.MaxReplicas}}'test
1

And reset to 0:

docker service update --replicas-max-per-node=0 test
docker service inspect --format '{{.Spec.TaskTemplate.Placement.MaxReplicas}}'test
0

@thaJeztahthaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@thaJeztah
thaJeztah merged commit f1de399 into docker:masterFeb 22, 2019
@GordonTheTurtleGordonTheTurtle added this to the 19.03.0 milestone Feb 22, 2019
@sebastianfelipe

Copy link
Copy Markdown

- What I did
Added support for maximum replicas per node

Third step to be able solve:

- How I did it
Added new switch --replicas-max-per-node switch to docker service

- How to verify it
Create two services and specify --replicas-max-per-node one of them:

docker service create --detach=true --name web1 --replicas 2 nginx
docker service create --detach=true --name web2 --replicas 2 --replicas-max-per-node 1 nginx

See difference on command outputs:

$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
0inbv7q148nn web1 replicated 2/2 nginx:latest 9kry59rk4ecr web2 replicated 1/2 (max 1 per node) nginx:latest
$ docker service ps --no-trunc web2
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
bf90bhy72o2ry2pj50xh24cfp web2.1 nginx:latest@sha256:b543f6d0983fbc25b9874e22f4fe257a567111da96fd1d8f1b44315f1236398c limint Running Running 34 seconds ago xedop9dwtilok0r56w4g7h5jm web2.2 nginx:latest@sha256:b543f6d0983fbc25b9874e22f4fe257a567111da96fd1d8f1b44315f1236398c Running Pending 35 seconds ago "no suitable node (max replicas per node limit exceed)" 

- Description for the changelog

Hi! I would like to link

- What I did
Added support for maximum replicas per node

Third step to be able solve:

- How I did it
Added new switch --replicas-max-per-node switch to docker service

- How to verify it
Create two services and specify --replicas-max-per-node one of them:

docker service create --detach=true --name web1 --replicas 2 nginx
docker service create --detach=true --name web2 --replicas 2 --replicas-max-per-node 1 nginx

See difference on command outputs:

$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
0inbv7q148nn web1 replicated 2/2 nginx:latest 9kry59rk4ecr web2 replicated 1/2 (max 1 per node) nginx:latest
$ docker service ps --no-trunc web2
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
bf90bhy72o2ry2pj50xh24cfp web2.1 nginx:latest@sha256:b543f6d0983fbc25b9874e22f4fe257a567111da96fd1d8f1b44315f1236398c limint Running Running 34 seconds ago xedop9dwtilok0r56w4g7h5jm web2.2 nginx:latest@sha256:b543f6d0983fbc25b9874e22f4fe257a567111da96fd1d8f1b44315f1236398c Running Pending 35 seconds ago "no suitable node (max replicas per node limit exceed)" 

- Description for the changelog

Hi everyone!

I have a tricky issue here. I posted it on Docker Swarm (classicswarm repo -> docker-archive/classicswarm#2979), but I think this is the right place.

Please, read that issue because it is related with this update and it is not working very well when it is needed to update services already running because the "no suitable node" issue, so, is ok, it is necessary, but the implementation blocks updates on docker swarm. Please read the issue.

Thanks,
Sebastián.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@olljanat@codecov-io@thaJeztah@GordonTheTurtle@sebastianfelipe@cpuguy83@silvin-lubecki