Skip to content

Commit 96f649e

Browse files
committed
[Fix] 🐛 Memory Limit Error at Instances Restart / noCard Mode mayooot#10
1 parent f9fc4b1 commit 96f649e

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.23
44

55
require (
66
github.com/commander-cli/cmd v1.6.0
7-
github.com/docker/docker v27.5.1+incompatible
7+
github.com/docker/docker v28.0.1+incompatible
88
github.com/docker/go-connections v0.4.0
99
github.com/gin-gonic/gin v1.10.0
1010
github.com/judwhite/go-svc v1.2.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
2525
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2626
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
2727
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
28-
github.com/docker/docker v27.5.1+incompatible h1:4PYU5dnBYqRQi0294d1FBECqT9ECWeQAIfE8q4YnPY8=
29-
github.com/docker/docker v27.5.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
28+
github.com/docker/docker v28.0.1+incompatible h1:FCHjSRdXhNRFjlHMTv4jUNlIBbTeRjrWfeFuJp7jpo0=
29+
github.com/docker/docker v28.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
3030
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
3131
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
3232
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=

internal/services/replicaset.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"time"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/container"
1514
"github.com/docker/docker/api/types/filters"
1615
"github.com/docker/docker/api/types/network"
@@ -224,7 +223,7 @@ func (rs *ReplicaSetService) ExecuteContainer(name string, exec *models.Containe
224223
}
225224

226225
ctx := context.Background()
227-
execCreate, err := docker.Cli.ContainerExecCreate(ctx, fmt.Sprintf("%s-%d", name, version), types.ExecConfig{
226+
execCreate, err := docker.Cli.ContainerExecCreate(ctx, fmt.Sprintf("%s-%d", name, version), container.ExecOptions{
228227
AttachStderr: true,
229228
AttachStdout: true,
230229
Detach: true,
@@ -236,7 +235,7 @@ func (rs *ReplicaSetService) ExecuteContainer(name string, exec *models.Containe
236235
return resp, errors.Wrapf(err, "docker.ContainerExecCreate failed, name: %s, spec: %+v", name, exec)
237236
}
238237

239-
hijackedResp, err := docker.Cli.ContainerExecAttach(ctx, execCreate.ID, types.ExecStartCheck{})
238+
hijackedResp, err := docker.Cli.ContainerExecAttach(ctx, execCreate.ID, container.ExecAttachOptions{})
240239
defer hijackedResp.Close()
241240
if err != nil {
242241
return resp, errors.Wrapf(err, "docker.ContainerExecAttach failed, name: %s, spec: %+v", name, exec)
@@ -445,7 +444,9 @@ func (rs *ReplicaSetService) patchGpu(name string, spec *models.GpuPatch, info *
445444
name, len(uuids), uuids)
446445
}
447446
if spec.GpuCount == 0 {
448-
info.HostConfig.Resources = container.Resources{}
447+
info.HostConfig.Resources = container.Resources{
448+
Memory: info.HostConfig.Memory,
449+
}
449450
} else {
450451
uuids, err = schedulers.GpuScheduler.Apply(spec.GpuCount)
451452
if err != nil {
@@ -704,6 +705,12 @@ func (rs *ReplicaSetService) RestartContainer(name string) (id, newContainerName
704705
return id, newContainerName, errors.WithMessage(err, "services.containerCpusetCpus failed")
705706
}
706707

708+
// get memory info
709+
memory, err := rs.containerMemory(ctrVersionName)
710+
if err != nil {
711+
return id, newContainerName, errors.WithMessage(err, "services.containerMemory failed")
712+
}
713+
707714
// get creation info from etcd
708715
infoBytes, err := etcd.GetValue(etcd.Containers, name)
709716
if err != nil {
@@ -742,6 +749,11 @@ func (rs *ReplicaSetService) RestartContainer(name string) (id, newContainerName
742749
info.HostConfig.Resources.CpusetCpus = availableCpus
743750
}
744751

752+
// check whether the container is using memory
753+
if memory != 0 {
754+
info.HostConfig.Resources.Memory = memory
755+
}
756+
745757
// create a container to replace the old one
746758
id, newContainerName, kv, err := rs.runContainer(ctx, name, info, true)
747759
if err != nil {

utils/copy.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66

77
"github.com/commander-cli/cmd"
8-
"github.com/docker/docker/api/types"
98
"github.com/docker/docker/api/types/container"
109
"github.com/docker/docker/api/types/network"
1110
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -102,7 +101,7 @@ func moveVolumeData(src, dest string) error {
102101
return errors.Wrapf(err, "docker.ContainerStart failed, container: %s", resp.ID)
103102
}
104103

105-
execCreate, err := docker.Cli.ContainerExecCreate(ctx, resp.ID, types.ExecConfig{
104+
execCreate, err := docker.Cli.ContainerExecCreate(ctx, resp.ID, container.ExecOptions{
106105
AttachStderr: true,
107106
AttachStdout: true,
108107
Detach: true,
@@ -114,7 +113,7 @@ func moveVolumeData(src, dest string) error {
114113
return errors.Wrapf(err, "docker.ContainerExecCreate failed, container: %s", resp.ID)
115114
}
116115

117-
err = docker.Cli.ContainerExecStart(ctx, execCreate.ID, types.ExecStartCheck{})
116+
err = docker.Cli.ContainerExecStart(ctx, execCreate.ID, container.ExecStartOptions{})
118117
if err != nil {
119118
return errors.Wrapf(err, "docker.ContainerExecAttach failed, container: %s", resp.ID)
120119
}

0 commit comments

Comments
 (0)