@@ -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 ,
@@ -596,6 +614,18 @@ func cpuSettingsFromNative(sp *specs.Spec) (*CPUSettings, error) {
596614 return res , nil
597615}
598616
617+ func getCgroupnsFromNative (sp * specs.Spec ) (string , error ) {
618+ res := ""
619+ if sp .Linux != nil && len (sp .Linux .Namespaces ) != 0 {
620+ for _ , ns := range sp .Linux .Namespaces {
621+ if ns .Type == "cgroup" {
622+ res = "private"
623+ }
624+ }
625+ }
626+ return res , nil
627+ }
628+
599629func groupAddFromNative (sp * specs.Spec ) ([]string , error ) {
600630 res := []string {}
601631 if sp .Process != nil && sp .Process .User .AdditionalGids != nil {
@@ -635,6 +665,24 @@ func parseExtraHosts(extraHostsJSON string) []string {
635665 return extraHosts
636666}
637667
668+ func getMemorySettingsFromNative (sp * specs.Spec ) (* MemorySetting , error ) {
669+ res := & MemorySetting {}
670+ if sp .Linux != nil && sp .Linux .Resources != nil && sp .Linux .Resources .Memory != nil {
671+ if sp .Linux .Resources .Memory .DisableOOMKiller != nil {
672+ res .DisableOOMKiller = * sp .Linux .Resources .Memory .DisableOOMKiller
673+ }
674+
675+ if sp .Linux .Resources .Memory .Limit != nil {
676+ res .Limit = * sp .Linux .Resources .Memory .Limit
677+ }
678+
679+ if sp .Linux .Resources .Memory .Swap != nil {
680+ res .Swap = * sp .Linux .Resources .Memory .Swap
681+ }
682+ }
683+ return res , nil
684+ }
685+
638686type IPAMConfig struct {
639687 Subnet string `json:"Subnet,omitempty"`
640688 Gateway string `json:"Gateway,omitempty"`
@@ -665,6 +713,12 @@ type structuredCNI struct {
665713 } `json:"plugins"`
666714}
667715
716+ type MemorySetting struct {
717+ Limit int64 `json:"limit"`
718+ Swap int64 `json:"swap"`
719+ DisableOOMKiller bool `json:"disableOOMKiller"`
720+ }
721+
668722func NetworkFromNative (n * native.Network ) (* Network , error ) {
669723 var res Network
670724
0 commit comments