@@ -153,6 +153,10 @@ type HostConfig struct {
153153 ContainerIDFile string // File (path) where the containerId is written
154154 GroupAdd []string // GroupAdd specifies additional groups to join
155155 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
156160}
157161
158162// 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) {
409413 c .HostConfig .CPUQuota = cpuSetting .cpuQuota
410414 c .HostConfig .CPUShares = cpuSetting .cpuShares
411415
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
412430 c .State = cs
413431 c .Config = & Config {
414432 Labels : n .Labels ,
@@ -598,6 +616,18 @@ func cpuSettingsFromNative(sp *specs.Spec) (*CPUSettings, error) {
598616 return res , nil
599617}
600618
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+
601631func groupAddFromNative (sp * specs.Spec ) ([]string , error ) {
602632 res := []string {}
603633 if sp .Process != nil && sp .Process .User .AdditionalGids != nil {
@@ -637,6 +667,24 @@ func parseExtraHosts(extraHostsJSON string) []string {
637667 return extraHosts
638668}
639669
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+
640688type IPAMConfig struct {
641689 Subnet string `json:"Subnet,omitempty"`
642690 Gateway string `json:"Gateway,omitempty"`
@@ -667,6 +715,12 @@ type structuredCNI struct {
667715 } `json:"plugins"`
668716}
669717
718+ type MemorySetting struct {
719+ Limit int64 `json:"limit"`
720+ Swap int64 `json:"swap"`
721+ DisableOOMKiller bool `json:"disableOOMKiller"`
722+ }
723+
670724func NetworkFromNative (n * native.Network ) (* Network , error ) {
671725 var res Network
672726
0 commit comments