|
@@ -53,6 +53,9 @@ func withRlimits(daemon *Daemon, daemonCfg *dconfig.Config, c *container.Contain
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ if s.Process == nil {
|
|
|
+ s.Process = &specs.Process{}
|
|
|
+ }
|
|
|
s.Process.Rlimits = rlimits
|
|
|
return nil
|
|
|
}
|
|
@@ -113,6 +116,9 @@ func withRootless(daemon *Daemon, daemonCfg *dconfig.Config) coci.SpecOpts {
|
|
|
// WithOOMScore sets the oom score
|
|
|
func WithOOMScore(score *int) coci.SpecOpts {
|
|
|
return func(ctx context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
|
|
|
+ if s.Process == nil {
|
|
|
+ s.Process = &specs.Process{}
|
|
|
+ }
|
|
|
s.Process.OOMScoreAdj = score
|
|
|
return nil
|
|
|
}
|
|
@@ -121,6 +127,12 @@ func WithOOMScore(score *int) coci.SpecOpts {
|
|
|
// WithSelinux sets the selinux labels
|
|
|
func WithSelinux(c *container.Container) coci.SpecOpts {
|
|
|
return func(ctx context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
|
|
|
+ if s.Process == nil {
|
|
|
+ s.Process = &specs.Process{}
|
|
|
+ }
|
|
|
+ if s.Linux == nil {
|
|
|
+ s.Linux = &specs.Linux{}
|
|
|
+ }
|
|
|
s.Process.SelinuxLabel = c.GetProcessLabel()
|
|
|
s.Linux.MountLabel = c.MountLabel
|
|
|
return nil
|
|
@@ -151,6 +163,9 @@ func WithApparmor(c *container.Container) coci.SpecOpts {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
+ if s.Process == nil {
|
|
|
+ s.Process = &specs.Process{}
|
|
|
+ }
|
|
|
s.Process.ApparmorProfile = appArmorProfile
|
|
|
}
|
|
|
return nil
|
|
@@ -213,6 +228,10 @@ func getUser(c *container.Container, username string) (specs.User, error) {
|
|
|
}
|
|
|
|
|
|
func setNamespace(s *specs.Spec, ns specs.LinuxNamespace) {
|
|
|
+ if s.Linux == nil {
|
|
|
+ s.Linux = &specs.Linux{}
|
|
|
+ }
|
|
|
+
|
|
|
for i, n := range s.Linux.Namespaces {
|
|
|
if n.Type == ns.Type {
|
|
|
s.Linux.Namespaces[i] = ns
|
|
@@ -606,6 +625,9 @@ func withMounts(daemon *Daemon, daemonCfg *configStore, c *container.Container)
|
|
|
}
|
|
|
rootpg := mountPropagationMap[s.Linux.RootfsPropagation]
|
|
|
if rootpg != mount.SHARED && rootpg != mount.RSHARED {
|
|
|
+ if s.Linux == nil {
|
|
|
+ s.Linux = &specs.Linux{}
|
|
|
+ }
|
|
|
s.Linux.RootfsPropagation = mountPropagationReverseMap[mount.SHARED]
|
|
|
}
|
|
|
case mount.SLAVE, mount.RSLAVE:
|
|
@@ -634,6 +656,9 @@ func withMounts(daemon *Daemon, daemonCfg *configStore, c *container.Container)
|
|
|
if !fallback {
|
|
|
rootpg := mountPropagationMap[s.Linux.RootfsPropagation]
|
|
|
if rootpg != mount.SHARED && rootpg != mount.RSHARED && rootpg != mount.SLAVE && rootpg != mount.RSLAVE {
|
|
|
+ if s.Linux == nil {
|
|
|
+ s.Linux = &specs.Linux{}
|
|
|
+ }
|
|
|
s.Linux.RootfsPropagation = mountPropagationReverseMap[mount.RSLAVE]
|
|
|
}
|
|
|
}
|
|
@@ -706,8 +731,10 @@ func withMounts(daemon *Daemon, daemonCfg *configStore, c *container.Container)
|
|
|
clearReadOnly(&s.Mounts[i])
|
|
|
}
|
|
|
}
|
|
|
- s.Linux.ReadonlyPaths = nil
|
|
|
- s.Linux.MaskedPaths = nil
|
|
|
+ if s.Linux != nil {
|
|
|
+ s.Linux.ReadonlyPaths = nil
|
|
|
+ s.Linux.MaskedPaths = nil
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// TODO: until a kernel/mount solution exists for handling remount in a user namespace,
|
|
@@ -753,6 +780,9 @@ func withCommonOptions(daemon *Daemon, daemonCfg *dconfig.Config, c *container.C
|
|
|
if len(cwd) == 0 {
|
|
|
cwd = "/"
|
|
|
}
|
|
|
+ if s.Process == nil {
|
|
|
+ s.Process = &specs.Process{}
|
|
|
+ }
|
|
|
s.Process.Args = append([]string{c.Path}, c.Args...)
|
|
|
|
|
|
// only add the custom init if it is specified and the container is running in its
|
|
@@ -829,6 +859,9 @@ func withCgroups(daemon *Daemon, daemonCfg *dconfig.Config, c *container.Contain
|
|
|
} else {
|
|
|
cgroupsPath = filepath.Join(parent, c.ID)
|
|
|
}
|
|
|
+ if s.Linux == nil {
|
|
|
+ s.Linux = &specs.Linux{}
|
|
|
+ }
|
|
|
s.Linux.CgroupsPath = cgroupsPath
|
|
|
|
|
|
// the rest is only needed for CPU RT controller
|
|
@@ -929,8 +962,14 @@ func WithDevices(daemon *Daemon, c *container.Container) coci.SpecOpts {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if s.Linux == nil {
|
|
|
+ s.Linux = &specs.Linux{}
|
|
|
+ }
|
|
|
+ if s.Linux.Resources == nil {
|
|
|
+ s.Linux.Resources = &specs.LinuxResources{}
|
|
|
+ }
|
|
|
s.Linux.Devices = append(s.Linux.Devices, devs...)
|
|
|
- s.Linux.Resources.Devices = devPermissions
|
|
|
+ s.Linux.Resources.Devices = append(s.Linux.Resources.Devices, devPermissions...)
|
|
|
|
|
|
for _, req := range c.HostConfig.DeviceRequests {
|
|
|
if err := daemon.handleDevice(req, s); err != nil {
|
|
@@ -971,27 +1010,28 @@ func WithResources(c *container.Container) coci.SpecOpts {
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- blkioWeight := r.BlkioWeight
|
|
|
|
|
|
- specResources := &specs.LinuxResources{
|
|
|
- Memory: memoryRes,
|
|
|
- CPU: cpuRes,
|
|
|
- BlockIO: &specs.LinuxBlockIO{
|
|
|
- Weight: &blkioWeight,
|
|
|
- WeightDevice: weightDevices,
|
|
|
- ThrottleReadBpsDevice: readBpsDevice,
|
|
|
- ThrottleWriteBpsDevice: writeBpsDevice,
|
|
|
- ThrottleReadIOPSDevice: readIOpsDevice,
|
|
|
- ThrottleWriteIOPSDevice: writeIOpsDevice,
|
|
|
- },
|
|
|
- Pids: getPidsLimit(r),
|
|
|
+ if s.Linux == nil {
|
|
|
+ s.Linux = &specs.Linux{}
|
|
|
}
|
|
|
-
|
|
|
- if s.Linux.Resources != nil && len(s.Linux.Resources.Devices) > 0 {
|
|
|
- specResources.Devices = s.Linux.Resources.Devices
|
|
|
+ if s.Linux.Resources == nil {
|
|
|
+ s.Linux.Resources = &specs.LinuxResources{}
|
|
|
+ }
|
|
|
+ s.Linux.Resources.Memory = memoryRes
|
|
|
+ s.Linux.Resources.CPU = cpuRes
|
|
|
+ s.Linux.Resources.BlockIO = &specs.LinuxBlockIO{
|
|
|
+ WeightDevice: weightDevices,
|
|
|
+ ThrottleReadBpsDevice: readBpsDevice,
|
|
|
+ ThrottleWriteBpsDevice: writeBpsDevice,
|
|
|
+ ThrottleReadIOPSDevice: readIOpsDevice,
|
|
|
+ ThrottleWriteIOPSDevice: writeIOpsDevice,
|
|
|
+ }
|
|
|
+ if r.BlkioWeight != 0 {
|
|
|
+ w := r.BlkioWeight
|
|
|
+ s.Linux.Resources.BlockIO.Weight = &w
|
|
|
}
|
|
|
+ s.Linux.Resources.Pids = getPidsLimit(r)
|
|
|
|
|
|
- s.Linux.Resources = specResources
|
|
|
return nil
|
|
|
}
|
|
|
}
|
|
@@ -999,6 +1039,15 @@ func WithResources(c *container.Container) coci.SpecOpts {
|
|
|
// WithSysctls sets the container's sysctls
|
|
|
func WithSysctls(c *container.Container) coci.SpecOpts {
|
|
|
return func(ctx context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
|
|
|
+ if len(c.HostConfig.Sysctls) == 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ if s.Linux == nil {
|
|
|
+ s.Linux = &specs.Linux{}
|
|
|
+ }
|
|
|
+ if s.Linux.Sysctl == nil {
|
|
|
+ s.Linux.Sysctl = make(map[string]string)
|
|
|
+ }
|
|
|
// We merge the sysctls injected above with the HostConfig (latter takes
|
|
|
// precedence for backwards-compatibility reasons).
|
|
|
for k, v := range c.HostConfig.Sysctls {
|
|
@@ -1011,6 +1060,9 @@ func WithSysctls(c *container.Container) coci.SpecOpts {
|
|
|
// WithUser sets the container's user
|
|
|
func WithUser(c *container.Container) coci.SpecOpts {
|
|
|
return func(ctx context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
|
|
|
+ if s.Process == nil {
|
|
|
+ s.Process = &specs.Process{}
|
|
|
+ }
|
|
|
var err error
|
|
|
s.Process.User, err = getUser(c, c.Config.User)
|
|
|
return err
|