@@ -36,6 +36,7 @@ import (
36
36
"time"
37
37
38
38
"github.com/docker/go-connections/nat"
39
+ "github.com/docker/go-units"
39
40
"github.com/opencontainers/runtime-spec/specs-go"
40
41
41
42
containerd "github.com/containerd/containerd/v2/client"
@@ -161,6 +162,10 @@ type HostConfig struct {
161
162
DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for
162
163
DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for
163
164
OomScoreAdj int // specifies the tune container’s OOM preferences (-1000 to 1000, rootless: 100 to 1000)
165
+ ReadonlyRootfs bool // Is the container root filesystem in read-only
166
+ UTSMode string // UTS namespace to use for the container
167
+ ShmSize int64 // Size of /dev/shm in bytes. The size must be greater than 0.
168
+
164
169
}
165
170
166
171
// From https://github.com/moby/moby/blob/v20.10.1/api/types/types.go#L416-L427
@@ -450,6 +455,17 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
450
455
oomScoreAdj , _ := getOomScoreAdjFromNative (n .Spec .(* specs.Spec ))
451
456
c .HostConfig .OomScoreAdj = oomScoreAdj
452
457
458
+ c .HostConfig .ReadonlyRootfs = false
459
+ if n .Spec .(* specs.Spec ).Root != nil && n .Spec .(* specs.Spec ).Root .Readonly {
460
+ c .HostConfig .ReadonlyRootfs = n .Spec .(* specs.Spec ).Root .Readonly
461
+ }
462
+
463
+ utsMode , _ := getUtsModeFromNative (n .Spec .(* specs.Spec ))
464
+ c .HostConfig .UTSMode = utsMode
465
+
466
+ shmSize , _ := getShmSizeFromNative (n .Spec .(* specs.Spec ))
467
+ c .HostConfig .ShmSize = shmSize
468
+
453
469
c .State = cs
454
470
c .Config = & Config {
455
471
Labels : n .Labels ,
@@ -740,6 +756,39 @@ func getOomScoreAdjFromNative(sp *specs.Spec) (int, error) {
740
756
return res , nil
741
757
}
742
758
759
+ func getUtsModeFromNative (sp * specs.Spec ) (string , error ) {
760
+ if sp .Linux != nil && len (sp .Linux .Namespaces ) > 0 {
761
+ for _ , ns := range sp .Linux .Namespaces {
762
+ if ns .Type == "uts" {
763
+ return "" , nil
764
+ }
765
+ }
766
+ }
767
+ return "host" , nil
768
+ }
769
+
770
+ func getShmSizeFromNative (sp * specs.Spec ) (int64 , error ) {
771
+ var res int64
772
+
773
+ if sp .Mounts != nil && len (sp .Mounts ) > 0 {
774
+ for _ , mount := range sp .Mounts {
775
+ if mount .Destination == "/dev/shm" {
776
+ for _ , option := range mount .Options {
777
+ if strings .HasPrefix (option , "size=" ) {
778
+ sizeStr := strings .TrimPrefix (option , "size=" )
779
+ size , err := units .RAMInBytes (sizeStr )
780
+ if err != nil {
781
+ return 0 , fmt .Errorf ("failed to parse shm size: %v" , err )
782
+ }
783
+ res = size
784
+ }
785
+ }
786
+ }
787
+ }
788
+ }
789
+ return res , nil
790
+ }
791
+
743
792
type IPAMConfig struct {
744
793
Subnet string `json:"Subnet,omitempty"`
745
794
Gateway string `json:"Gateway,omitempty"`
0 commit comments