@@ -18,6 +18,7 @@ package container
18
18
19
19
import (
20
20
"bytes"
21
+ "context"
21
22
"fmt"
22
23
"os"
23
24
"path/filepath"
@@ -27,11 +28,14 @@ import (
27
28
"gotest.tools/v3/assert"
28
29
29
30
"github.com/containerd/cgroups/v3"
31
+ containerd "github.com/containerd/containerd/v2/client"
30
32
"github.com/containerd/continuity/testutil/loopback"
31
33
32
34
"github.com/containerd/nerdctl/v2/pkg/cmd/container"
35
+ "github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
33
36
"github.com/containerd/nerdctl/v2/pkg/testutil"
34
37
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
38
+ "github.com/containerd/nerdctl/v2/pkg/testutil/test"
35
39
)
36
40
37
41
func TestRunCgroupV2 (t * testing.T ) {
@@ -170,6 +174,53 @@ func TestRunCgroupV1(t *testing.T) {
170
174
base .Cmd ("run" , "--rm" , "--cpu-quota" , "42000" , "--cpu-period" , "100000" , "--cpuset-mems" , "0" , "--memory" , "42m" , "--memory-reservation" , "6m" , "--memory-swap" , "100m" , "--memory-swappiness" , "0" , "--pids-limit" , "42" , "--cpu-shares" , "2000" , "--cpuset-cpus" , "0-1" , testutil .AlpineImage , "cat" , quota , period , cpusetMems , memoryLimit , memoryReservation , memorySwap , memorySwappiness , pidsLimit , cpuShare , cpusetCpus ).AssertOutExactly (expected )
171
175
}
172
176
177
+ // TestIssue3781 tests https://github.com/containerd/nerdctl/issues/3781
178
+ func TestIssue3781 (t * testing.T ) {
179
+ t .Parallel ()
180
+ testCase := nerdtest .Setup ()
181
+ testCase .Require = test .Not (nerdtest .Docker )
182
+
183
+ base := testutil .NewBase (t )
184
+ info := base .Info ()
185
+ switch info .CgroupDriver {
186
+ case "none" , "" :
187
+ t .Skip ("test requires cgroup driver" )
188
+ }
189
+ containerName := testutil .Identifier (t )
190
+ base .Cmd ("run" , "-d" , "--name" , containerName , testutil .AlpineImage , "sleep" , "infinity" ).AssertOK ()
191
+ defer func () {
192
+ base .Cmd ("rm" , "-f" , containerName )
193
+ }()
194
+ base .Cmd ("update" , "--cpuset-cpus" , "0-1" , containerName ).AssertOK ()
195
+ addr := base .ContainerdAddress ()
196
+ client , err := containerd .New (addr , containerd .WithDefaultNamespace (testutil .Namespace ))
197
+ assert .NilError (base .T , err )
198
+ ctx := context .Background ()
199
+
200
+ // get container id by container name.
201
+ var cid string
202
+ var args []string
203
+ args = append (args , containerName )
204
+ walker := & containerwalker.ContainerWalker {
205
+ Client : client ,
206
+ OnFound : func (ctx context.Context , found containerwalker.Found ) error {
207
+ if found .MatchCount > 1 {
208
+ return fmt .Errorf ("multiple IDs found with provided prefix: %s" , found .Req )
209
+ }
210
+ cid = found .Container .ID ()
211
+ return nil
212
+ },
213
+ }
214
+ err = walker .WalkAll (ctx , args , true )
215
+ assert .NilError (base .T , err )
216
+
217
+ container , err := client .LoadContainer (ctx , cid )
218
+ assert .NilError (base .T , err )
219
+ spec , err := container .Spec (ctx )
220
+ assert .NilError (base .T , err )
221
+ assert .Equal (t , spec .Linux .Resources .Pids == nil , true )
222
+ }
223
+
173
224
func TestRunDevice (t * testing.T ) {
174
225
if os .Geteuid () != 0 || userns .RunningInUserNS () {
175
226
t .Skip ("test requires the root in the initial user namespace" )
0 commit comments