@@ -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 ,
@@ -602,6 +620,18 @@ func cpuSettingsFromNative(sp *specs.Spec) (*CPUSettings, error) {
602620 return res , nil
603621}
604622
623+ func getCgroupnsFromNative (sp * specs.Spec ) (string , error ) {
624+ res := ""
625+ if sp .Linux != nil && len (sp .Linux .Namespaces ) != 0 {
626+ for _ , ns := range sp .Linux .Namespaces {
627+ if ns .Type == "cgroup" {
628+ res = "private"
629+ }
630+ }
631+ }
632+ return res , nil
633+ }
634+
605635func groupAddFromNative (sp * specs.Spec ) ([]string , error ) {
606636 res := []string {}
607637 if sp .Process != nil && sp .Process .User .AdditionalGids != nil {
@@ -641,6 +671,24 @@ func parseExtraHosts(extraHostsJSON string) []string {
641671 return extraHosts
642672}
643673
674+ func getMemorySettingsFromNative (sp * specs.Spec ) (* MemorySetting , error ) {
675+ res := & MemorySetting {}
676+ if sp .Linux != nil && sp .Linux .Resources != nil && sp .Linux .Resources .Memory != nil {
677+ if sp .Linux .Resources .Memory .DisableOOMKiller != nil {
678+ res .DisableOOMKiller = * sp .Linux .Resources .Memory .DisableOOMKiller
679+ }
680+
681+ if sp .Linux .Resources .Memory .Limit != nil {
682+ res .Limit = * sp .Linux .Resources .Memory .Limit
683+ }
684+
685+ if sp .Linux .Resources .Memory .Swap != nil {
686+ res .Swap = * sp .Linux .Resources .Memory .Swap
687+ }
688+ }
689+ return res , nil
690+ }
691+
644692type IPAMConfig struct {
645693 Subnet string `json:"Subnet,omitempty"`
646694 Gateway string `json:"Gateway,omitempty"`
@@ -671,6 +719,12 @@ type structuredCNI struct {
671719 } `json:"plugins"`
672720}
673721
722+ type MemorySetting struct {
723+ Limit int64 `json:"limit"`
724+ Swap int64 `json:"swap"`
725+ DisableOOMKiller bool `json:"disableOOMKiller"`
726+ }
727+
674728func NetworkFromNative (n * native.Network ) (* Network , error ) {
675729 var res Network
676730
0 commit comments