@@ -357,6 +357,172 @@ var _ = Describe("Container Create API ", func() {
357
357
Expect (rr .Body ).Should (MatchJSON (jsonResponse ))
358
358
})
359
359
360
+ It ("should set CPUPeriod create options for resources" , func () {
361
+ body := []byte (`{
362
+ "Image": "test-image",
363
+ "HostConfig": {
364
+ "CpuPeriod": 100000
365
+ }
366
+ }` )
367
+ req , _ := http .NewRequest (http .MethodPost , "/containers/create" , bytes .NewReader (body ))
368
+
369
+ // expected create options
370
+ createOpt .CPUPeriod = 100000
371
+
372
+ service .EXPECT ().Create (gomock .Any (), "test-image" , nil , equalTo (createOpt ), equalTo (netOpt )).Return (
373
+ cid , nil )
374
+
375
+ // handler should return success message with 201 status code.
376
+ h .create (rr , req )
377
+ Expect (rr ).Should (HaveHTTPStatus (http .StatusCreated ))
378
+ Expect (rr .Body ).Should (MatchJSON (jsonResponse ))
379
+ })
380
+
381
+ It ("should set CpuQuota create options for resources" , func () {
382
+ body := []byte (`{
383
+ "Image": "test-image",
384
+ "HostConfig": {
385
+ "CpuQuota": 50000
386
+ }
387
+ }` )
388
+ req , _ := http .NewRequest (http .MethodPost , "/containers/create" , bytes .NewReader (body ))
389
+
390
+ // expected create options
391
+ createOpt .CPUQuota = 50000
392
+ service .EXPECT ().Create (gomock .Any (), "test-image" , nil , equalTo (createOpt ), equalTo (netOpt )).Return (
393
+ cid , nil )
394
+
395
+ // handler should return success message with 201 status code.
396
+ h .create (rr , req )
397
+ Expect (rr ).Should (HaveHTTPStatus (http .StatusCreated ))
398
+ Expect (rr .Body ).Should (MatchJSON (jsonResponse ))
399
+ })
400
+
401
+ It ("should set CpuQuota to -1 by default" , func () {
402
+ body := []byte (`{
403
+ "Image": "test-image"
404
+ }` )
405
+ req , _ := http .NewRequest (http .MethodPost , "/containers/create" , bytes .NewReader (body ))
406
+
407
+ // expected create options
408
+ createOpt .CPUQuota = - 1
409
+ service .EXPECT ().Create (gomock .Any (), "test-image" , nil , equalTo (createOpt ), equalTo (netOpt )).Return (
410
+ cid , nil )
411
+
412
+ // handler should return success message with 201 status code.
413
+ h .create (rr , req )
414
+ Expect (rr ).Should (HaveHTTPStatus (http .StatusCreated ))
415
+ Expect (rr .Body ).Should (MatchJSON (jsonResponse ))
416
+ })
417
+
418
+ It ("should set MemoryReservation, MemorySwap and MemorySwappiness create options for resources" , func () {
419
+ body := []byte (`{
420
+ "Image": "test-image",
421
+ "HostConfig": {
422
+ "MemoryReservation": 209710,
423
+ "MemorySwap": 514288000,
424
+ "MemorySwappiness": 25
425
+ }
426
+ }` )
427
+ req , _ := http .NewRequest (http .MethodPost , "/containers/create" , bytes .NewReader (body ))
428
+
429
+ // expected create options
430
+ createOpt .MemoryReservation = "209710"
431
+ createOpt .MemorySwap = "514288000"
432
+ createOpt .MemorySwappiness64 = 25
433
+ service .EXPECT ().Create (gomock .Any (), "test-image" , nil , equalTo (createOpt ), equalTo (netOpt )).Return (
434
+ cid , nil )
435
+
436
+ // handler should return success message with 201 status code.
437
+ h .create (rr , req )
438
+ Expect (rr ).Should (HaveHTTPStatus (http .StatusCreated ))
439
+ Expect (rr .Body ).Should (MatchJSON (jsonResponse ))
440
+ })
441
+
442
+ It ("should set CapDrop option" , func () {
443
+ body := []byte (`{
444
+ "Image": "test-image",
445
+ "HostConfig": {
446
+ "CapDrop": ["MKNOD"]
447
+ }
448
+ }` )
449
+ req , _ := http .NewRequest (http .MethodPost , "/containers/create" , bytes .NewReader (body ))
450
+
451
+ // expected create options
452
+ createOpt .CapDrop = []string {"MKNOD" }
453
+
454
+ service .EXPECT ().Create (gomock .Any (), "test-image" , nil , equalTo (createOpt ), equalTo (netOpt )).Return (
455
+ cid , nil )
456
+
457
+ // handler should return success message with 201 status code.
458
+ h .create (rr , req )
459
+ Expect (rr ).Should (HaveHTTPStatus (http .StatusCreated ))
460
+ Expect (rr .Body ).Should (MatchJSON (jsonResponse ))
461
+ })
462
+
463
+ It ("should set Privileged option" , func () {
464
+ body := []byte (`{
465
+ "Image": "test-image",
466
+ "HostConfig": {
467
+ "Privileged": true
468
+ }
469
+ }` )
470
+ req , _ := http .NewRequest (http .MethodPost , "/containers/create" , bytes .NewReader (body ))
471
+
472
+ // expected create options
473
+ createOpt .Privileged = true
474
+
475
+ service .EXPECT ().Create (gomock .Any (), "test-image" , nil , equalTo (createOpt ), equalTo (netOpt )).Return (
476
+ cid , nil )
477
+
478
+ // handler should return success message with 201 status code.
479
+ h .create (rr , req )
480
+ Expect (rr ).Should (HaveHTTPStatus (http .StatusCreated ))
481
+ Expect (rr .Body ).Should (MatchJSON (jsonResponse ))
482
+ })
483
+
484
+ It ("should set Ulimit option" , func () {
485
+ body := []byte (`{
486
+ "Image": "test-image",
487
+ "HostConfig": {
488
+ "Ulimits": [{"Name": "nofile", "Soft": 1024, "Hard": 2048},{"Name": "nproc", "Soft": 1024, "Hard": 4048}]
489
+ }
490
+ }` )
491
+ req , _ := http .NewRequest (http .MethodPost , "/containers/create" , bytes .NewReader (body ))
492
+
493
+ // expected create options
494
+ createOpt .Ulimit = []string {"nofile=1024:2048" , "nproc=1024:4048" }
495
+
496
+ service .EXPECT ().Create (gomock .Any (), "test-image" , nil , equalTo (createOpt ), equalTo (netOpt )).Return (
497
+ cid , nil )
498
+
499
+ // handler should return success message with 201 status code.
500
+ h .create (rr , req )
501
+ Expect (rr ).Should (HaveHTTPStatus (http .StatusCreated ))
502
+ Expect (rr .Body ).Should (MatchJSON (jsonResponse ))
503
+ })
504
+
505
+ It ("should set PidLimit option" , func () {
506
+ body := []byte (`{
507
+ "Image": "test-image",
508
+ "HostConfig": {
509
+ "PidsLimit": 200
510
+ }
511
+ }` )
512
+ req , _ := http .NewRequest (http .MethodPost , "/containers/create" , bytes .NewReader (body ))
513
+
514
+ // expected create options
515
+ createOpt .PidsLimit = 200
516
+
517
+ service .EXPECT ().Create (gomock .Any (), "test-image" , nil , equalTo (createOpt ), equalTo (netOpt )).Return (
518
+ cid , nil )
519
+
520
+ // handler should return success message with 201 status code.
521
+ h .create (rr , req )
522
+ Expect (rr ).Should (HaveHTTPStatus (http .StatusCreated ))
523
+ Expect (rr .Body ).Should (MatchJSON (jsonResponse ))
524
+ })
525
+
360
526
It ("should return 404 if the image was not found" , func () {
361
527
body := []byte (`{"Image": "test-image"}` )
362
528
req , _ := http .NewRequest (http .MethodPost , "/containers/create" , bytes .NewReader (body ))
@@ -542,17 +708,18 @@ func getDefaultCreateOpt(conf config.Config) types.ContainerCreateOptions {
542
708
MemorySwappiness64 : - 1 , // nerdctl default.
543
709
PidsLimit : - 1 , // nerdctl default.
544
710
Cgroupns : defaults .CgroupnsMode (), // nerdctl default.
711
+ Ulimit : []string {},
545
712
// #endregion
546
713
547
714
// #region for user flags
548
- User : "" ,
549
- GroupAdd : []string {}, // nerdctl default.
715
+ User : "" ,
550
716
// #endregion
551
717
552
718
// #region for security flags
553
719
SecurityOpt : []string {}, // nerdctl default.
554
720
CapAdd : []string {}, // nerdctl default.
555
721
CapDrop : []string {}, // nerdctl default.
722
+ Privileged : false ,
556
723
// #endregion
557
724
558
725
// #region for runtime flags
0 commit comments