mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #38791 from thaJeztah/update_api_changes
Fix container update resetting pidslimit on older API clients
This commit is contained in:
commit
91d934b41b
2 changed files with 19 additions and 6 deletions
|
@ -425,6 +425,9 @@ func (s *containerRouter) postContainerUpdate(ctx context.Context, w http.Respon
|
||||||
if err := decoder.Decode(&updateConfig); err != nil {
|
if err := decoder.Decode(&updateConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if versions.LessThan(httputils.VersionFromContext(ctx), "1.40") {
|
||||||
|
updateConfig.PidsLimit = nil
|
||||||
|
}
|
||||||
|
|
||||||
hostConfig := &container.HostConfig{
|
hostConfig := &container.HostConfig{
|
||||||
Resources: updateConfig.Resources,
|
Resources: updateConfig.Resources,
|
||||||
|
|
|
@ -9,7 +9,9 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
containertypes "github.com/docker/docker/api/types/container"
|
containertypes "github.com/docker/docker/api/types/container"
|
||||||
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/integration/internal/container"
|
"github.com/docker/docker/integration/internal/container"
|
||||||
|
"github.com/docker/docker/internal/test/request"
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
is "gotest.tools/assert/cmp"
|
is "gotest.tools/assert/cmp"
|
||||||
"gotest.tools/poll"
|
"gotest.tools/poll"
|
||||||
|
@ -108,10 +110,11 @@ func TestUpdatePidsLimit(t *testing.T) {
|
||||||
skip.If(t, !testEnv.DaemonInfo.PidsLimit)
|
skip.If(t, !testEnv.DaemonInfo.PidsLimit)
|
||||||
|
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
client := testEnv.APIClient()
|
apiClient := testEnv.APIClient()
|
||||||
|
oldAPIclient := request.NewAPIClient(t, client.WithVersion("1.24"))
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
cID := container.Run(t, ctx, client)
|
cID := container.Run(t, ctx, apiClient)
|
||||||
|
|
||||||
intPtr := func(i int64) *int64 {
|
intPtr := func(i int64) *int64 {
|
||||||
return &i
|
return &i
|
||||||
|
@ -119,6 +122,7 @@ func TestUpdatePidsLimit(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range []struct {
|
for _, test := range []struct {
|
||||||
desc string
|
desc string
|
||||||
|
oldAPI bool
|
||||||
update *int64
|
update *int64
|
||||||
expect int64
|
expect int64
|
||||||
expectCg string
|
expectCg string
|
||||||
|
@ -126,24 +130,30 @@ func TestUpdatePidsLimit(t *testing.T) {
|
||||||
{desc: "update from none", update: intPtr(32), expect: 32, expectCg: "32"},
|
{desc: "update from none", update: intPtr(32), expect: 32, expectCg: "32"},
|
||||||
{desc: "no change", update: nil, expectCg: "32"},
|
{desc: "no change", update: nil, expectCg: "32"},
|
||||||
{desc: "update lower", update: intPtr(16), expect: 16, expectCg: "16"},
|
{desc: "update lower", update: intPtr(16), expect: 16, expectCg: "16"},
|
||||||
|
{desc: "update on old api ignores value", oldAPI: true, update: intPtr(10), expect: 16, expectCg: "16"},
|
||||||
{desc: "unset limit", update: intPtr(0), expect: 0, expectCg: "max"},
|
{desc: "unset limit", update: intPtr(0), expect: 0, expectCg: "max"},
|
||||||
} {
|
} {
|
||||||
|
c := apiClient
|
||||||
|
if test.oldAPI {
|
||||||
|
c = oldAPIclient
|
||||||
|
}
|
||||||
|
|
||||||
var before types.ContainerJSON
|
var before types.ContainerJSON
|
||||||
if test.update == nil {
|
if test.update == nil {
|
||||||
var err error
|
var err error
|
||||||
before, err = client.ContainerInspect(ctx, cID)
|
before, err = c.ContainerInspect(ctx, cID)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
_, err := client.ContainerUpdate(ctx, cID, containertypes.UpdateConfig{
|
_, err := c.ContainerUpdate(ctx, cID, containertypes.UpdateConfig{
|
||||||
Resources: containertypes.Resources{
|
Resources: containertypes.Resources{
|
||||||
PidsLimit: test.update,
|
PidsLimit: test.update,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
inspect, err := client.ContainerInspect(ctx, cID)
|
inspect, err := c.ContainerInspect(ctx, cID)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Assert(t, inspect.HostConfig.Resources.PidsLimit != nil)
|
assert.Assert(t, inspect.HostConfig.Resources.PidsLimit != nil)
|
||||||
|
|
||||||
|
@ -157,7 +167,7 @@ func TestUpdatePidsLimit(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
|
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
res, err := container.Exec(ctx, client, cID, []string{"cat", "/sys/fs/cgroup/pids/pids.max"})
|
res, err := container.Exec(ctx, c, cID, []string{"cat", "/sys/fs/cgroup/pids/pids.max"})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Assert(t, is.Len(res.Stderr(), 0))
|
assert.Assert(t, is.Len(res.Stderr(), 0))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue