mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
set resources only when specified
when using the compatibility endpoint to create a container, we should only set certain resources when we are provided a value for them or we result in fields with zero values. Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -293,66 +293,61 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig) (*Cont
|
|||||||
// like with start. We believe this is just a difference in podman/compat
|
// like with start. We believe this is just a difference in podman/compat
|
||||||
cliOpts := ContainerCLIOpts{
|
cliOpts := ContainerCLIOpts{
|
||||||
//Attach: nil, // dont need?
|
//Attach: nil, // dont need?
|
||||||
Authfile: "",
|
Authfile: "",
|
||||||
BlkIOWeight: strconv.Itoa(int(cc.HostConfig.BlkioWeight)),
|
CapAdd: append(capAdd, cc.HostConfig.CapAdd...),
|
||||||
BlkIOWeightDevice: nil, // TODO
|
CapDrop: append(cappDrop, cc.HostConfig.CapDrop...),
|
||||||
CapAdd: append(capAdd, cc.HostConfig.CapAdd...),
|
CGroupParent: cc.HostConfig.CgroupParent,
|
||||||
CapDrop: append(cappDrop, cc.HostConfig.CapDrop...),
|
CIDFile: cc.HostConfig.ContainerIDFile,
|
||||||
CGroupParent: cc.HostConfig.CgroupParent,
|
CPUPeriod: uint64(cc.HostConfig.CPUPeriod),
|
||||||
CIDFile: cc.HostConfig.ContainerIDFile,
|
CPUQuota: cc.HostConfig.CPUQuota,
|
||||||
CPUPeriod: uint64(cc.HostConfig.CPUPeriod),
|
CPURTPeriod: uint64(cc.HostConfig.CPURealtimePeriod),
|
||||||
CPUQuota: cc.HostConfig.CPUQuota,
|
CPURTRuntime: cc.HostConfig.CPURealtimeRuntime,
|
||||||
CPURTPeriod: uint64(cc.HostConfig.CPURealtimePeriod),
|
CPUShares: uint64(cc.HostConfig.CPUShares),
|
||||||
CPURTRuntime: cc.HostConfig.CPURealtimeRuntime,
|
|
||||||
CPUShares: uint64(cc.HostConfig.CPUShares),
|
|
||||||
//CPUS: 0, // dont need?
|
//CPUS: 0, // dont need?
|
||||||
CPUSetCPUs: cc.HostConfig.CpusetCpus,
|
CPUSetCPUs: cc.HostConfig.CpusetCpus,
|
||||||
CPUSetMems: cc.HostConfig.CpusetMems,
|
CPUSetMems: cc.HostConfig.CpusetMems,
|
||||||
//Detach: false, // dont need
|
//Detach: false, // dont need
|
||||||
//DetachKeys: "", // dont need
|
//DetachKeys: "", // dont need
|
||||||
Devices: devices,
|
Devices: devices,
|
||||||
DeviceCGroupRule: nil,
|
DeviceCGroupRule: nil,
|
||||||
DeviceReadBPs: readBps,
|
DeviceReadBPs: readBps,
|
||||||
DeviceReadIOPs: readIops,
|
DeviceReadIOPs: readIops,
|
||||||
DeviceWriteBPs: writeBps,
|
DeviceWriteBPs: writeBps,
|
||||||
DeviceWriteIOPs: writeIops,
|
DeviceWriteIOPs: writeIops,
|
||||||
Entrypoint: &entrypoint,
|
Entrypoint: &entrypoint,
|
||||||
Env: cc.Config.Env,
|
Env: cc.Config.Env,
|
||||||
Expose: expose,
|
Expose: expose,
|
||||||
GroupAdd: cc.HostConfig.GroupAdd,
|
GroupAdd: cc.HostConfig.GroupAdd,
|
||||||
Hostname: cc.Config.Hostname,
|
Hostname: cc.Config.Hostname,
|
||||||
ImageVolume: "bind",
|
ImageVolume: "bind",
|
||||||
Init: init,
|
Init: init,
|
||||||
Interactive: cc.Config.OpenStdin,
|
Interactive: cc.Config.OpenStdin,
|
||||||
IPC: string(cc.HostConfig.IpcMode),
|
IPC: string(cc.HostConfig.IpcMode),
|
||||||
Label: stringMaptoArray(cc.Config.Labels),
|
Label: stringMaptoArray(cc.Config.Labels),
|
||||||
LogDriver: cc.HostConfig.LogConfig.Type,
|
LogDriver: cc.HostConfig.LogConfig.Type,
|
||||||
LogOptions: stringMaptoArray(cc.HostConfig.LogConfig.Config),
|
LogOptions: stringMaptoArray(cc.HostConfig.LogConfig.Config),
|
||||||
Memory: strconv.Itoa(int(cc.HostConfig.Memory)),
|
Name: cc.Name,
|
||||||
MemoryReservation: strconv.Itoa(int(cc.HostConfig.MemoryReservation)),
|
OOMScoreAdj: cc.HostConfig.OomScoreAdj,
|
||||||
MemorySwap: strconv.Itoa(int(cc.HostConfig.MemorySwap)),
|
OverrideArch: "",
|
||||||
Name: cc.Name,
|
OverrideOS: "",
|
||||||
OOMScoreAdj: cc.HostConfig.OomScoreAdj,
|
OverrideVariant: "",
|
||||||
OverrideArch: "",
|
PID: string(cc.HostConfig.PidMode),
|
||||||
OverrideOS: "",
|
PIDsLimit: cc.HostConfig.PidsLimit,
|
||||||
OverrideVariant: "",
|
Privileged: cc.HostConfig.Privileged,
|
||||||
PID: string(cc.HostConfig.PidMode),
|
PublishAll: cc.HostConfig.PublishAllPorts,
|
||||||
PIDsLimit: cc.HostConfig.PidsLimit,
|
Quiet: false,
|
||||||
Privileged: cc.HostConfig.Privileged,
|
ReadOnly: cc.HostConfig.ReadonlyRootfs,
|
||||||
PublishAll: cc.HostConfig.PublishAllPorts,
|
ReadOnlyTmpFS: true, // podman default
|
||||||
Quiet: false,
|
Rm: cc.HostConfig.AutoRemove,
|
||||||
ReadOnly: cc.HostConfig.ReadonlyRootfs,
|
SecurityOpt: cc.HostConfig.SecurityOpt,
|
||||||
ReadOnlyTmpFS: true, // podman default
|
StopSignal: cc.Config.StopSignal,
|
||||||
Rm: cc.HostConfig.AutoRemove,
|
StoreageOpt: stringMaptoArray(cc.HostConfig.StorageOpt),
|
||||||
SecurityOpt: cc.HostConfig.SecurityOpt,
|
Sysctl: stringMaptoArray(cc.HostConfig.Sysctls),
|
||||||
ShmSize: strconv.Itoa(int(cc.HostConfig.ShmSize)),
|
Systemd: "true", // podman default
|
||||||
StopSignal: cc.Config.StopSignal,
|
TmpFS: stringMaptoArray(cc.HostConfig.Tmpfs),
|
||||||
StoreageOpt: stringMaptoArray(cc.HostConfig.StorageOpt),
|
TTY: cc.Config.Tty,
|
||||||
Sysctl: stringMaptoArray(cc.HostConfig.Sysctls),
|
|
||||||
Systemd: "true", // podman default
|
|
||||||
TmpFS: stringMaptoArray(cc.HostConfig.Tmpfs),
|
|
||||||
TTY: cc.Config.Tty,
|
|
||||||
//Ulimit: cc.HostConfig.Ulimits, // ask dan, no documented format
|
//Ulimit: cc.HostConfig.Ulimits, // ask dan, no documented format
|
||||||
|
Ulimit: []string{"nproc=4194304:4194304"},
|
||||||
User: cc.Config.User,
|
User: cc.Config.User,
|
||||||
UserNS: string(cc.HostConfig.UsernsMode),
|
UserNS: string(cc.HostConfig.UsernsMode),
|
||||||
UTS: string(cc.HostConfig.UTSMode),
|
UTS: string(cc.HostConfig.UTSMode),
|
||||||
@ -363,10 +358,37 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig) (*Cont
|
|||||||
Net: &netInfo,
|
Net: &netInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(cc.HostConfig.BlkioWeightDevice) > 0 {
|
||||||
|
devices := make([]string, 0, len(cc.HostConfig.BlkioWeightDevice))
|
||||||
|
for _, d := range cc.HostConfig.BlkioWeightDevice {
|
||||||
|
devices = append(devices, d.String())
|
||||||
|
}
|
||||||
|
cliOpts.BlkIOWeightDevice = devices
|
||||||
|
}
|
||||||
|
if cc.HostConfig.BlkioWeight > 0 {
|
||||||
|
cliOpts.BlkIOWeight = strconv.Itoa(int(cc.HostConfig.BlkioWeight))
|
||||||
|
}
|
||||||
|
|
||||||
|
if cc.HostConfig.Memory > 0 {
|
||||||
|
cliOpts.Memory = strconv.Itoa(int(cc.HostConfig.Memory))
|
||||||
|
}
|
||||||
|
|
||||||
|
if cc.HostConfig.MemoryReservation > 0 {
|
||||||
|
cliOpts.MemoryReservation = strconv.Itoa(int(cc.HostConfig.MemoryReservation))
|
||||||
|
}
|
||||||
|
|
||||||
|
if cc.HostConfig.MemorySwap > 0 {
|
||||||
|
cliOpts.MemorySwap = strconv.Itoa(int(cc.HostConfig.MemorySwap))
|
||||||
|
}
|
||||||
|
|
||||||
if cc.Config.StopTimeout != nil {
|
if cc.Config.StopTimeout != nil {
|
||||||
cliOpts.StopTimeout = uint(*cc.Config.StopTimeout)
|
cliOpts.StopTimeout = uint(*cc.Config.StopTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cc.HostConfig.ShmSize > 0 {
|
||||||
|
cliOpts.ShmSize = strconv.Itoa(int(cc.HostConfig.ShmSize))
|
||||||
|
}
|
||||||
|
|
||||||
if cc.HostConfig.KernelMemory > 0 {
|
if cc.HostConfig.KernelMemory > 0 {
|
||||||
cliOpts.KernelMemory = strconv.Itoa(int(cc.HostConfig.KernelMemory))
|
cliOpts.KernelMemory = strconv.Itoa(int(cc.HostConfig.KernelMemory))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user