Add support for memory swap settings for services#51114
Conversation
|
Throwing this up as a draft for right now because I'm still dealing with the bit rot a bit. |
f0b5ae0 to
71fcf94
Compare
|
Removed the section of integration tests which exec'd into the container to check that memory swappiness was actually set. If memory swappiness is set on the container config, we should trust that it is set on the container, and the test of that is a different test entirely. |
9ed391c to
d71c18d
Compare
|
This test passes locally on my machine, but fails in CI. I'm not sure why. |
d71c18d to
e2158c7
Compare
| if service.TaskTemplate.Resources != nil { | ||
| if service.TaskTemplate.Resources.SwapBytes != nil { | ||
| // Setting services' swap size wasn't supported before | ||
| // API version 1.40 |
There was a problem hiding this comment.
| // API version 1.40 | |
| // API version 1.52 |
e33ae68 to
cba4404
Compare
austinvazquez
left a comment
There was a problem hiding this comment.
Just a minor comment to touchup API v1.52 swagger as well.
| type: "integer" | ||
| format: "int64" |
There was a problem hiding this comment.
We probably should add that the minimum is -1, and add nullable and omit empty;
| type: "integer" | |
| format: "int64" | |
| type: "integer" | |
| format: "int64" | |
| minimum: -1 | |
| x-nullable: true | |
| x-omitempty: true |
❓ ❓ ❓ do we need pointers though? Given that we have explicit -1 means "unset previous", would that already give enough information to distinguish "don't set" if the value is 0? (int-pointers can be finicky to deal with)
If a non-pointer value would work for us, we could change it, and remove the x-nullable;
| type: "integer" | |
| format: "int64" | |
| type: "integer" | |
| format: "int64" | |
| minimum: -1 | |
| x-omitempty: true |
There was a problem hiding this comment.
In this case, -1 isn't "set default" it's "set unlimited". The null pointer is "set-default".
There was a problem hiding this comment.
Ah, right, so
-1means unlimitednilmeans "default" (memory x 2 total)0means disable (no swap)1means1 byte(ormemory+1 byte- I never know 😂) -1probably not an acceptable (or not a "sensible") value, but that's a separate topic 😂
api/types/swarm/task.go
Outdated
| // Amount of swap in bytes - can only be used together with a memory limit | ||
| // -1 means unlimited | ||
| // a null pointer keeps the default behaviour of granting twice the memory | ||
| // amount in swap | ||
| SwapBytes *int64 |
There was a problem hiding this comment.
| // Amount of swap in bytes - can only be used together with a memory limit | |
| // -1 means unlimited | |
| // a null pointer keeps the default behaviour of granting twice the memory | |
| // amount in swap | |
| SwapBytes *int64 | |
| // Amount of swap in bytes - can only be used together with a memory limit | |
| // -1 means unlimited. A null pointer keeps the default behaviour of granting | |
| // twice the memory amount in swap. | |
| SwapBytes *int64 `json:"SwapBytes,omitzero"` |
Or (see my other comment)
| // Amount of swap in bytes - can only be used together with a memory limit | |
| // -1 means unlimited | |
| // a null pointer keeps the default behaviour of granting twice the memory | |
| // amount in swap | |
| SwapBytes *int64 | |
| // Amount of swap in bytes - can only be used together with a memory limit | |
| // -1 means unlimited. A zero value keeps the default behaviour of granting | |
| // twice the memory amount in swap. | |
| SwapBytes int64 `json:"SwapBytes,omitzero"` |
| type: "integer" | ||
| format: "int64" |
There was a problem hiding this comment.
| type: "integer" | |
| format: "int64" | |
| format: "int64" | |
| minimum: -1 | |
| maximum: 100 | |
| x-nullable: true | |
| x-omitempty: true |
api/types/swarm/task.go
Outdated
| // Tune container memory swappiness (0 to 100) - if not specified, defaults | ||
| // to the container OS's default - generally 60, or the value predefined in | ||
| // the image; set to -1 to unset a previously set value | ||
| MemorySwappiness *int64 |
There was a problem hiding this comment.
| MemorySwappiness *int64 | |
| MemorySwappiness *int64 `json:"MemorySwappiness,omitzero"` |
Or (if we don't need a pointer)
| MemorySwappiness *int64 | |
| MemorySwappiness int64 `json:"MemorySwappiness,omitzero"` |
There was a problem hiding this comment.
LOL, it could even be an int8, but from a quick look; looks like Swagger only knows about int32 and int64, so probably not worth changing?
| return resources | ||
| } | ||
|
|
||
| func int64PointerFromGRPC(v *gogotypes.Int64Value) *int64 { |
There was a problem hiding this comment.
Unrelated to this PR, but wondering what our chances are to move away from gogo-protobuf; would it be possible?
There was a problem hiding this comment.
It would be possible. It would not be pleasant.
| } else if swapBytes >= 0 { | ||
| // resources.MemorySwap is actually the sum of the memory + the swap | ||
| resources.MemorySwap = resources.Memory + swapBytes |
There was a problem hiding this comment.
Ah, I guess this was the problem, so 0 is a valid value for this one? :sadpanda:
(if there's still a way to handle this without pointers, I'm still all ears though!)
There was a problem hiding this comment.
☝️ I guess an explicit SwapEnable / SwapDisable could be an option for that, but not sure if we did elsewhere.
cba4404 to
c2e008c
Compare
|
Updated with requested changes to swagger.yaml, v1.52.yaml, and the json annotations. |
c2e008c to
d64d445
Compare
|
Solved the conflict in CHANGELOG.md |
d64d445 to
544f200
Compare
| if versions.LessThan(cliVersion, "1.52") { | ||
| if service.TaskTemplate.Resources != nil { | ||
| service.TaskTemplate.Resources.SwapBytes = nil | ||
| service.TaskTemplate.Resources.MemorySwappiness = nil | ||
| } | ||
| } |
There was a problem hiding this comment.
Unrelated, but I wonder if we ever described / documented the behavior when using an older client to update a service;
- create service with (say) a v29 client, and set swap options
- update service with (say) a v25 client
- 💥 swap options are gone
Don't know what a good solution is for that (other than versioning the spec with some schema version and returning warnings if features are set that are not supported in the API version)
There was a problem hiding this comment.
This is the case with any of the settings gated behind the API version.
|
OHMAN; before I forget and blame myself; I see there was a pending thing on the other PR; #37872 (comment)
And there was a related PR; But I honestly forgot the details (it's been a while) |
With integration tests Relevant Swarmkit PR: moby/swarmkit#2816 (updated the vendored version of Swarkit to that) Signed-off-by: Jean Rouge <[email protected]> Updated for latest master, fixed bitrot. Signed-off-by: Drew Erny <[email protected]>
544f200 to
3a90dd8
Compare
|
I think it's not worthwhile to chase down the path proposed in the old PR -- the gains in cleanliness are outweighed by the increased scope of change. |
service create/service update#25303- What I did
Updated #37872 to the latest master branch.
- How I did it
- How to verify it
Comes with integration tests!
- Human readable description for the release notes