@@ -153,6 +153,10 @@ type HostConfig struct {
153
153
ContainerIDFile string // File (path) where the containerId is written
154
154
GroupAdd []string // GroupAdd specifies additional groups to join
155
155
IpcMode string // IPC namespace to use for the container
156
+ CgroupnsMode string // Cgroup namespace mode to use for the container
157
+ Memory int64 // Memory limit (in bytes)
158
+ MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
159
+ OomKillDisable bool // specifies whether to disable OOM Killer
156
160
}
157
161
158
162
// From https://github.com/moby/moby/blob/v20.10.1/api/types/types.go#L416-L427
@@ -409,6 +413,20 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
409
413
c .HostConfig .CPUQuota = cpuSetting .cpuQuota
410
414
c .HostConfig .CPUShares = cpuSetting .cpuShares
411
415
416
+ cgroupNamespace , err := getCgroupnsFromNative (n .Spec .(* specs.Spec ))
417
+ if err != nil {
418
+ return nil , fmt .Errorf ("failed to Decode cgroupNamespace: %v" , err )
419
+ }
420
+ c .HostConfig .CgroupnsMode = cgroupNamespace
421
+
422
+ memorySettings , err := getMemorySettingsFromNative (n .Spec .(* specs.Spec ))
423
+ if err != nil {
424
+ return nil , fmt .Errorf ("failed to Decode memory Settings: %v" , err )
425
+ }
426
+
427
+ c .HostConfig .OomKillDisable = memorySettings .DisableOOMKiller
428
+ c .HostConfig .Memory = memorySettings .Limit
429
+ c .HostConfig .MemorySwap = memorySettings .Swap
412
430
c .State = cs
413
431
c .Config = & Config {
414
432
Labels : n .Labels ,
@@ -598,6 +616,18 @@ func cpuSettingsFromNative(sp *specs.Spec) (*CPUSettings, error) {
598
616
return res , nil
599
617
}
600
618
619
+ func getCgroupnsFromNative (sp * specs.Spec ) (string , error ) {
620
+ res := ""
621
+ if sp .Linux != nil && len (sp .Linux .Namespaces ) != 0 {
622
+ for _ , ns := range sp .Linux .Namespaces {
623
+ if ns .Type == "cgroup" {
624
+ res = "private"
625
+ }
626
+ }
627
+ }
628
+ return res , nil
629
+ }
630
+
601
631
func groupAddFromNative (sp * specs.Spec ) ([]string , error ) {
602
632
res := []string {}
603
633
if sp .Process != nil && sp .Process .User .AdditionalGids != nil {
@@ -637,6 +667,24 @@ func parseExtraHosts(extraHostsJSON string) []string {
637
667
return extraHosts
638
668
}
639
669
670
+ func getMemorySettingsFromNative (sp * specs.Spec ) (* MemorySetting , error ) {
671
+ res := & MemorySetting {}
672
+ if sp .Linux != nil && sp .Linux .Resources != nil && sp .Linux .Resources .Memory != nil {
673
+ if sp .Linux .Resources .Memory .DisableOOMKiller != nil {
674
+ res .DisableOOMKiller = * sp .Linux .Resources .Memory .DisableOOMKiller
675
+ }
676
+
677
+ if sp .Linux .Resources .Memory .Limit != nil {
678
+ res .Limit = * sp .Linux .Resources .Memory .Limit
679
+ }
680
+
681
+ if sp .Linux .Resources .Memory .Swap != nil {
682
+ res .Swap = * sp .Linux .Resources .Memory .Swap
683
+ }
684
+ }
685
+ return res , nil
686
+ }
687
+
640
688
type IPAMConfig struct {
641
689
Subnet string `json:"Subnet,omitempty"`
642
690
Gateway string `json:"Gateway,omitempty"`
@@ -667,6 +715,12 @@ type structuredCNI struct {
667
715
} `json:"plugins"`
668
716
}
669
717
718
+ type MemorySetting struct {
719
+ Limit int64 `json:"limit"`
720
+ Swap int64 `json:"swap"`
721
+ DisableOOMKiller bool `json:"disableOOMKiller"`
722
+ }
723
+
670
724
func NetworkFromNative (n * native.Network ) (* Network , error ) {
671
725
var res Network
672
726
0 commit comments