Merge pull request #74 from aaronlehmann/tolerate-missing-resources
Avoid panic when spec file is missing sections under Resources
This commit is contained in:
commit
fbb69b2fa0
1 changed files with 53 additions and 45 deletions
|
@ -626,47 +626,53 @@ func (rt *libcontainerRuntime) createCgroupConfig(name string, spec *specs.Linux
|
||||||
}
|
}
|
||||||
cr.Resources = c
|
cr.Resources = c
|
||||||
r := spec.Linux.Resources
|
r := spec.Linux.Resources
|
||||||
if r.Memory.Limit != nil {
|
if r.Memory != nil {
|
||||||
c.Memory = int64(*r.Memory.Limit)
|
if r.Memory.Limit != nil {
|
||||||
|
c.Memory = int64(*r.Memory.Limit)
|
||||||
|
}
|
||||||
|
if r.Memory.Reservation != nil {
|
||||||
|
c.MemoryReservation = int64(*r.Memory.Reservation)
|
||||||
|
}
|
||||||
|
if r.Memory.Swap != nil {
|
||||||
|
c.MemorySwap = int64(*r.Memory.Swap)
|
||||||
|
}
|
||||||
|
if r.Memory.Kernel != nil {
|
||||||
|
c.KernelMemory = int64(*r.Memory.Kernel)
|
||||||
|
}
|
||||||
|
if r.Memory.Swappiness != nil {
|
||||||
|
c.MemorySwappiness = int64(*r.Memory.Swappiness)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if r.Memory.Reservation != nil {
|
if r.CPU != nil {
|
||||||
c.MemoryReservation = int64(*r.Memory.Reservation)
|
if r.CPU.Shares != nil {
|
||||||
|
c.CpuShares = int64(*r.CPU.Shares)
|
||||||
|
}
|
||||||
|
if r.CPU.Quota != nil {
|
||||||
|
c.CpuQuota = int64(*r.CPU.Quota)
|
||||||
|
}
|
||||||
|
if r.CPU.Period != nil {
|
||||||
|
c.CpuPeriod = int64(*r.CPU.Period)
|
||||||
|
}
|
||||||
|
if r.CPU.RealtimeRuntime != nil {
|
||||||
|
c.CpuRtRuntime = int64(*r.CPU.RealtimeRuntime)
|
||||||
|
}
|
||||||
|
if r.CPU.RealtimePeriod != nil {
|
||||||
|
c.CpuRtPeriod = int64(*r.CPU.RealtimePeriod)
|
||||||
|
}
|
||||||
|
if r.CPU.Cpus != nil {
|
||||||
|
c.CpusetCpus = *r.CPU.Cpus
|
||||||
|
}
|
||||||
|
if r.CPU.Mems != nil {
|
||||||
|
c.CpusetMems = *r.CPU.Mems
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if r.Memory.Swap != nil {
|
if r.BlockIO != nil {
|
||||||
c.MemorySwap = int64(*r.Memory.Swap)
|
if r.BlockIO.Weight != nil {
|
||||||
}
|
c.BlkioWeight = *r.BlockIO.Weight
|
||||||
if r.Memory.Kernel != nil {
|
}
|
||||||
c.KernelMemory = int64(*r.Memory.Kernel)
|
if r.BlockIO.LeafWeight != nil {
|
||||||
}
|
c.BlkioLeafWeight = *r.BlockIO.LeafWeight
|
||||||
if r.Memory.Swappiness != nil {
|
}
|
||||||
c.MemorySwappiness = int64(*r.Memory.Swappiness)
|
|
||||||
}
|
|
||||||
if r.CPU.Shares != nil {
|
|
||||||
c.CpuShares = int64(*r.CPU.Shares)
|
|
||||||
}
|
|
||||||
if r.CPU.Quota != nil {
|
|
||||||
c.CpuQuota = int64(*r.CPU.Quota)
|
|
||||||
}
|
|
||||||
if r.CPU.Period != nil {
|
|
||||||
c.CpuPeriod = int64(*r.CPU.Period)
|
|
||||||
}
|
|
||||||
if r.CPU.RealtimeRuntime != nil {
|
|
||||||
c.CpuRtRuntime = int64(*r.CPU.RealtimeRuntime)
|
|
||||||
}
|
|
||||||
if r.CPU.RealtimePeriod != nil {
|
|
||||||
c.CpuRtPeriod = int64(*r.CPU.RealtimePeriod)
|
|
||||||
}
|
|
||||||
if r.CPU.Cpus != nil {
|
|
||||||
c.CpusetCpus = *r.CPU.Cpus
|
|
||||||
}
|
|
||||||
if r.CPU.Mems != nil {
|
|
||||||
c.CpusetMems = *r.CPU.Mems
|
|
||||||
}
|
|
||||||
if r.BlockIO.Weight != nil {
|
|
||||||
c.BlkioWeight = *r.BlockIO.Weight
|
|
||||||
}
|
|
||||||
if r.BlockIO.LeafWeight != nil {
|
|
||||||
c.BlkioLeafWeight = *r.BlockIO.LeafWeight
|
|
||||||
}
|
}
|
||||||
for _, wd := range r.BlockIO.WeightDevice {
|
for _, wd := range r.BlockIO.WeightDevice {
|
||||||
weightDevice := configs.NewWeightDevice(wd.Major, wd.Minor, *wd.Weight, *wd.LeafWeight)
|
weightDevice := configs.NewWeightDevice(wd.Major, wd.Minor, *wd.Weight, *wd.LeafWeight)
|
||||||
|
@ -695,12 +701,14 @@ func (rt *libcontainerRuntime) createCgroupConfig(name string, spec *specs.Linux
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
c.OomKillDisable = r.DisableOOMKiller != nil && *r.DisableOOMKiller
|
c.OomKillDisable = r.DisableOOMKiller != nil && *r.DisableOOMKiller
|
||||||
c.NetClsClassid = r.Network.ClassID
|
if r.Network != nil {
|
||||||
for _, m := range r.Network.Priorities {
|
c.NetClsClassid = r.Network.ClassID
|
||||||
c.NetPrioIfpriomap = append(c.NetPrioIfpriomap, &configs.IfPrioMap{
|
for _, m := range r.Network.Priorities {
|
||||||
Interface: m.Name,
|
c.NetPrioIfpriomap = append(c.NetPrioIfpriomap, &configs.IfPrioMap{
|
||||||
Priority: int64(m.Priority),
|
Interface: m.Name,
|
||||||
})
|
Priority: int64(m.Priority),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cr, nil
|
return cr, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue