@@ -163,6 +163,8 @@ type HostConfig struct {
163163 Sysctls map [string ]string // List of Namespaced sysctls used for the container
164164 Runtime string // Runtime to use with this container
165165 Devices []string // List of devices to map inside the container
166+ PidMode string // PID namespace to use for the container
167+ Tmpfs []MountPoint `json:",omitempty"` // List of tmpfs (mounts) used for the container
166168}
167169
168170// From https://github.com/moby/moby/blob/v20.10.1/api/types/types.go#L416-L427
@@ -292,6 +294,7 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
292294 // XXX is this always right? what if the container OS is NOT the same as the host OS?
293295 Platform : runtime .GOOS , // for Docker compatibility, this Platform string does NOT contain arch like "/amd64"
294296 }
297+ c .HostConfig = new (HostConfig )
295298 if n .Labels [restart .StatusLabel ] == string (containerd .Running ) {
296299 c .RestartCount , _ = strconv .Atoi (n .Labels [restart .CountLabel ])
297300 }
@@ -332,15 +335,20 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
332335 }
333336 }
334337
338+ var tmpfsMounts []MountPoint
339+
335340 if nerdctlMounts := n .Labels [labels .Mounts ]; nerdctlMounts != "" {
336341 mounts , err := parseMounts (nerdctlMounts )
337342 if err != nil {
338343 return nil , err
339344 }
340345 c .Mounts = mounts
346+ if len (mounts ) > 0 {
347+ tmpfsMounts = filterTmpfsMounts (mounts )
348+ }
341349 }
350+ c .HostConfig .Tmpfs = tmpfsMounts
342351
343- c .HostConfig = new (HostConfig )
344352 if nedctlExtraHosts := n .Labels [labels .ExtraHosts ]; nedctlExtraHosts != "" {
345353 c .HostConfig .ExtraHosts = parseExtraHosts (nedctlExtraHosts )
346354 }
@@ -366,7 +374,7 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
366374 }
367375
368376 // var hostConfigLabel HostConfigLabel
369- hostConfigLabel , err := getHostConfigLabelFromNative (n .Labels )
377+ hostConfigLabel , _ := getHostConfigLabelFromNative (n .Labels )
370378
371379 c .HostConfig .BlkioWeight = hostConfigLabel .BlkioWeight
372380 c .HostConfig .ContainerIDFile = hostConfigLabel .CidFile
@@ -484,6 +492,11 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
484492
485493 c .HostConfig .Devices = hostConfigLabel .DeviceMapping
486494
495+ var pidMode string
496+ if n .Labels [labels .PIDContainer ] != "" {
497+ pidMode = n .Labels [labels .PIDContainer ]
498+ }
499+ c .HostConfig .PidMode = pidMode
487500 return c , nil
488501}
489502
@@ -556,6 +569,18 @@ func mountsFromNative(spMounts []specs.Mount) []MountPoint {
556569 return mountpoints
557570}
558571
572+ // filterTmpfsMounts filters the tmpfs mounts
573+ func filterTmpfsMounts (spMounts []MountPoint ) []MountPoint {
574+ mountpoints := make ([]MountPoint , 0 , len (spMounts ))
575+ for _ , m := range spMounts {
576+ if m .Type == "tmpfs" {
577+ mountpoints = append (mountpoints , m )
578+ }
579+ }
580+
581+ return mountpoints
582+ }
583+
559584func statusFromNative (x containerd.Status , labels map [string ]string ) string {
560585 switch s := x .Status ; s {
561586 case containerd .Stopped :
@@ -805,15 +830,6 @@ func getSysctlFromNative(sp *specs.Spec) (map[string]string, error) {
805830 return res , nil
806831}
807832
808- func parseDeviceMapping (deviceMappingJSON string ) ([]string , error ) {
809- var devices []string
810- err := json .Unmarshal ([]byte (deviceMappingJSON ), & devices )
811- if err != nil {
812- return nil , fmt .Errorf ("failed to parse device mapping: %v" , err )
813- }
814- return devices , nil
815- }
816-
817833type IPAMConfig struct {
818834 Subnet string `json:"Subnet,omitempty"`
819835 Gateway string `json:"Gateway,omitempty"`
0 commit comments