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:
baude
2020-10-23 09:16:41 -05:00
parent 0f0d857f6c
commit 5d3042c4fb

View File

@ -294,8 +294,6 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig) (*Cont
cliOpts := ContainerCLIOpts{ cliOpts := ContainerCLIOpts{
//Attach: nil, // dont need? //Attach: nil, // dont need?
Authfile: "", Authfile: "",
BlkIOWeight: strconv.Itoa(int(cc.HostConfig.BlkioWeight)),
BlkIOWeightDevice: nil, // TODO
CapAdd: append(capAdd, cc.HostConfig.CapAdd...), CapAdd: append(capAdd, cc.HostConfig.CapAdd...),
CapDrop: append(cappDrop, cc.HostConfig.CapDrop...), CapDrop: append(cappDrop, cc.HostConfig.CapDrop...),
CGroupParent: cc.HostConfig.CgroupParent, CGroupParent: cc.HostConfig.CgroupParent,
@ -328,9 +326,6 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig) (*Cont
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)),
MemoryReservation: strconv.Itoa(int(cc.HostConfig.MemoryReservation)),
MemorySwap: strconv.Itoa(int(cc.HostConfig.MemorySwap)),
Name: cc.Name, Name: cc.Name,
OOMScoreAdj: cc.HostConfig.OomScoreAdj, OOMScoreAdj: cc.HostConfig.OomScoreAdj,
OverrideArch: "", OverrideArch: "",
@ -345,7 +340,6 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig) (*Cont
ReadOnlyTmpFS: true, // podman default ReadOnlyTmpFS: true, // podman default
Rm: cc.HostConfig.AutoRemove, Rm: cc.HostConfig.AutoRemove,
SecurityOpt: cc.HostConfig.SecurityOpt, SecurityOpt: cc.HostConfig.SecurityOpt,
ShmSize: strconv.Itoa(int(cc.HostConfig.ShmSize)),
StopSignal: cc.Config.StopSignal, StopSignal: cc.Config.StopSignal,
StoreageOpt: stringMaptoArray(cc.HostConfig.StorageOpt), StoreageOpt: stringMaptoArray(cc.HostConfig.StorageOpt),
Sysctl: stringMaptoArray(cc.HostConfig.Sysctls), Sysctl: stringMaptoArray(cc.HostConfig.Sysctls),
@ -353,6 +347,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig) (*Cont
TmpFS: stringMaptoArray(cc.HostConfig.Tmpfs), TmpFS: stringMaptoArray(cc.HostConfig.Tmpfs),
TTY: cc.Config.Tty, 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))
} }