@@ -163,6 +163,8 @@ type HostConfig struct {
163
163
Sysctls map [string ]string // List of Namespaced sysctls used for the container
164
164
Runtime string // Runtime to use with this container
165
165
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
166
168
}
167
169
168
170
// 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) {
292
294
// XXX is this always right? what if the container OS is NOT the same as the host OS?
293
295
Platform : runtime .GOOS , // for Docker compatibility, this Platform string does NOT contain arch like "/amd64"
294
296
}
297
+ c .HostConfig = new (HostConfig )
295
298
if n .Labels [restart .StatusLabel ] == string (containerd .Running ) {
296
299
c .RestartCount , _ = strconv .Atoi (n .Labels [restart .CountLabel ])
297
300
}
@@ -332,15 +335,20 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
332
335
}
333
336
}
334
337
338
+ var tmpfsMounts []MountPoint
339
+
335
340
if nerdctlMounts := n .Labels [labels .Mounts ]; nerdctlMounts != "" {
336
341
mounts , err := parseMounts (nerdctlMounts )
337
342
if err != nil {
338
343
return nil , err
339
344
}
340
345
c .Mounts = mounts
346
+ if len (mounts ) > 0 {
347
+ tmpfsMounts = filterTmpfsMounts (mounts )
348
+ }
341
349
}
350
+ c .HostConfig .Tmpfs = tmpfsMounts
342
351
343
- c .HostConfig = new (HostConfig )
344
352
if nedctlExtraHosts := n .Labels [labels .ExtraHosts ]; nedctlExtraHosts != "" {
345
353
c .HostConfig .ExtraHosts = parseExtraHosts (nedctlExtraHosts )
346
354
}
@@ -366,7 +374,7 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
366
374
}
367
375
368
376
// var hostConfigLabel HostConfigLabel
369
- hostConfigLabel , err := getHostConfigLabelFromNative (n .Labels )
377
+ hostConfigLabel , _ := getHostConfigLabelFromNative (n .Labels )
370
378
371
379
c .HostConfig .BlkioWeight = hostConfigLabel .BlkioWeight
372
380
c .HostConfig .ContainerIDFile = hostConfigLabel .CidFile
@@ -480,6 +488,11 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
480
488
481
489
c .HostConfig .Devices = hostConfigLabel .DeviceMapping
482
490
491
+ var pidMode string
492
+ if n .Labels [labels .PIDContainer ] != "" {
493
+ pidMode = n .Labels [labels .PIDContainer ]
494
+ }
495
+ c .HostConfig .PidMode = pidMode
483
496
return c , nil
484
497
}
485
498
@@ -550,6 +563,18 @@ func mountsFromNative(spMounts []specs.Mount) []MountPoint {
550
563
return mountpoints
551
564
}
552
565
566
+ // filterTmpfsMounts filters the tmpfs mounts
567
+ func filterTmpfsMounts (spMounts []MountPoint ) []MountPoint {
568
+ mountpoints := make ([]MountPoint , 0 , len (spMounts ))
569
+ for _ , m := range spMounts {
570
+ if m .Type == "tmpfs" {
571
+ mountpoints = append (mountpoints , m )
572
+ }
573
+ }
574
+
575
+ return mountpoints
576
+ }
577
+
553
578
func statusFromNative (x containerd.Status , labels map [string ]string ) string {
554
579
switch s := x .Status ; s {
555
580
case containerd .Stopped :
@@ -799,15 +824,6 @@ func getSysctlFromNative(sp *specs.Spec) (map[string]string, error) {
799
824
return res , nil
800
825
}
801
826
802
- func parseDeviceMapping (deviceMappingJSON string ) ([]string , error ) {
803
- var devices []string
804
- err := json .Unmarshal ([]byte (deviceMappingJSON ), & devices )
805
- if err != nil {
806
- return nil , fmt .Errorf ("failed to parse device mapping: %v" , err )
807
- }
808
- return devices , nil
809
- }
810
-
811
827
type IPAMConfig struct {
812
828
Subnet string `json:"Subnet,omitempty"`
813
829
Gateway string `json:"Gateway,omitempty"`
0 commit comments