Fix cpu/memory limits and reservations being reset on service update#1079
Merged
vdemeester merged 2 commits intodocker:masterfrom May 24, 2018
Merged
Fix cpu/memory limits and reservations being reset on service update#1079vdemeester merged 2 commits intodocker:masterfrom
vdemeester merged 2 commits intodocker:masterfrom
Conversation
Before this change:
----------------------------------------------------
Create a service with reservations and limits for memory and cpu:
docker service create --name test \
--limit-memory=100M --limit-cpu=1 \
--reserve-memory=100M --reserve-cpu=1 \
nginx:alpine
Verify the configuration
docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
{
"Limits": {
"NanoCPUs": 1000000000,
"MemoryBytes": 104857600
},
"Reservations": {
"NanoCPUs": 1000000000,
"MemoryBytes": 104857600
}
}
Update just CPU limit and reservation:
docker service update --limit-cpu=2 --reserve-cpu=2 test
Notice that the memory limit and reservation is not preserved:
docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
{
"Limits": {
"NanoCPUs": 2000000000
},
"Reservations": {
"NanoCPUs": 2000000000
}
}
Update just Memory limit and reservation:
docker service update --limit-memory=200M --reserve-memory=200M test
Notice that the CPU limit and reservation is not preserved:
docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
{
"Limits": {
"MemoryBytes": 209715200
},
"Reservations": {
"MemoryBytes": 209715200
}
}
After this change:
----------------------------------------------------
Create a service with reservations and limits for memory and cpu:
docker service create --name test \
--limit-memory=100M --limit-cpu=1 \
--reserve-memory=100M --reserve-cpu=1 \
nginx:alpine
Verify the configuration
docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
{
"Limits": {
"NanoCPUs": 1000000000,
"MemoryBytes": 104857600
},
"Reservations": {
"NanoCPUs": 1000000000,
"MemoryBytes": 104857600
}
}
Update just CPU limit and reservation:
docker service update --limit-cpu=2 --reserve-cpu=2 test
Confirm that the CPU limits/reservations are updated, but memory limit and reservation are preserved:
docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
{
"Limits": {
"NanoCPUs": 2000000000,
"MemoryBytes": 104857600
},
"Reservations": {
"NanoCPUs": 2000000000,
"MemoryBytes": 104857600
}
}
Update just Memory limit and reservation:
docker service update --limit-memory=200M --reserve-memory=200M test
Confirm that the Mempry limits/reservations are updated, but CPU limit and reservation are preserved:
docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
{
"Limits": {
"NanoCPUs": 2000000000,
"MemoryBytes": 209715200
},
"Reservations": {
"NanoCPUs": 2000000000,
"MemoryBytes": 209715200
}
}
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
22c9a9e to
df9a0c7
Compare
mat007
approved these changes
May 24, 2018
| assert.Check(t, is.Equal(spec.TaskTemplate.Resources.Reservations.NanoCPUs, int64(2000000000))) | ||
| assert.Check(t, is.Equal(spec.TaskTemplate.Resources.Reservations.MemoryBytes, int64(104857600))) | ||
|
|
||
| flags = newUpdateCommand(nil).Flags() |
Contributor
There was a problem hiding this comment.
nit: split it into 2 subtests?
Member
Author
There was a problem hiding this comment.
You mean: only change (eg) reservation so that we can catch regressions where changing a reservation would reset limits?
Actually thought about that, don't know why I didn't do that; let me know if you want that updated in this PR
Contributor
There was a problem hiding this comment.
Yep, in case of failure it points directly to the right sub-test. But it's only a small nit, no need to update it 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix cpu/memory limits and reservations being reset on service update
fixes moby/moby#37036
fixes moby/moby#37037
Before this change:
Create a service with reservations and limits for memory and cpu:
docker service create \ --limit-memory=100M \ --limit-cpu=1 \ --reserve-memory=100M \ --reserve-cpu=1 \ --name test \ nginx:alpineVerify the configuration
{ "Limits": { "NanoCPUs": 1000000000, "MemoryBytes": 104857600 }, "Reservations": { "NanoCPUs": 1000000000, "MemoryBytes": 104857600 } }Update just CPU limit and reservation:
docker service update --limit-cpu=2 --reserve-cpu=2 testNotice that the memory limit and reservation is not preserved:
{ "Limits": { "NanoCPUs": 2000000000 }, "Reservations": { "NanoCPUs": 2000000000 } }Update just Memory limit and reservation:
docker service update --limit-memory=200M --reserve-memory=200M testNotice that the CPU limit and reservation is not preserved:
{ "Limits": { "MemoryBytes": 209715200 }, "Reservations": { "MemoryBytes": 209715200 } }After this change:
Create a service with reservations and limits for memory and cpu:
docker service create \ --limit-memory=100M \ --limit-cpu=1 \ --reserve-memory=100M \ --reserve-cpu=1 \ --name test \ nginx:alpineVerify the configuration
{ "Limits": { "NanoCPUs": 1000000000, "MemoryBytes": 104857600 }, "Reservations": { "NanoCPUs": 1000000000, "MemoryBytes": 104857600 } }Update just CPU limit and reservation:
docker service update --limit-cpu=2 --reserve-cpu=2 testConfirm that the CPU limits/reservations are updated, but memory limit and reservation are preserved:
{ "Limits": { "NanoCPUs": 2000000000, "MemoryBytes": 104857600 }, "Reservations": { "NanoCPUs": 2000000000, "MemoryBytes": 104857600 } }Update just Memory limit and reservation:
docker service update --limit-memory=200M --reserve-memory=200M testConfirm that the Mempry limits/reservations are updated, but CPU limit and reservation are preserved:
{ "Limits": { "NanoCPUs": 2000000000, "MemoryBytes": 209715200 }, "Reservations": { "NanoCPUs": 2000000000, "MemoryBytes": 209715200 } }