Merge pull request #74 from aaronlehmann/tolerate-missing-resources

Avoid panic when spec file is missing sections under Resources
This commit is contained in:
Michael Crosby 2016-01-15 16:26:16 -08:00
commit fbb69b2fa0

View file

@ -626,6 +626,7 @@ 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 != nil {
if r.Memory.Limit != nil { if r.Memory.Limit != nil {
c.Memory = int64(*r.Memory.Limit) c.Memory = int64(*r.Memory.Limit)
} }
@ -641,6 +642,8 @@ func (rt *libcontainerRuntime) createCgroupConfig(name string, spec *specs.Linux
if r.Memory.Swappiness != nil { if r.Memory.Swappiness != nil {
c.MemorySwappiness = int64(*r.Memory.Swappiness) c.MemorySwappiness = int64(*r.Memory.Swappiness)
} }
}
if r.CPU != nil {
if r.CPU.Shares != nil { if r.CPU.Shares != nil {
c.CpuShares = int64(*r.CPU.Shares) c.CpuShares = int64(*r.CPU.Shares)
} }
@ -662,12 +665,15 @@ func (rt *libcontainerRuntime) createCgroupConfig(name string, spec *specs.Linux
if r.CPU.Mems != nil { if r.CPU.Mems != nil {
c.CpusetMems = *r.CPU.Mems c.CpusetMems = *r.CPU.Mems
} }
}
if r.BlockIO != nil {
if r.BlockIO.Weight != nil { if r.BlockIO.Weight != nil {
c.BlkioWeight = *r.BlockIO.Weight c.BlkioWeight = *r.BlockIO.Weight
} }
if r.BlockIO.LeafWeight != nil { if r.BlockIO.LeafWeight != nil {
c.BlkioLeafWeight = *r.BlockIO.LeafWeight 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)
c.BlkioWeightDevice = append(c.BlkioWeightDevice, weightDevice) c.BlkioWeightDevice = append(c.BlkioWeightDevice, weightDevice)
@ -695,6 +701,7 @@ func (rt *libcontainerRuntime) createCgroupConfig(name string, spec *specs.Linux
}) })
} }
c.OomKillDisable = r.DisableOOMKiller != nil && *r.DisableOOMKiller c.OomKillDisable = r.DisableOOMKiller != nil && *r.DisableOOMKiller
if r.Network != nil {
c.NetClsClassid = r.Network.ClassID c.NetClsClassid = r.Network.ClassID
for _, m := range r.Network.Priorities { for _, m := range r.Network.Priorities {
c.NetPrioIfpriomap = append(c.NetPrioIfpriomap, &configs.IfPrioMap{ c.NetPrioIfpriomap = append(c.NetPrioIfpriomap, &configs.IfPrioMap{
@ -702,6 +709,7 @@ func (rt *libcontainerRuntime) createCgroupConfig(name string, spec *specs.Linux
Priority: int64(m.Priority), Priority: int64(m.Priority),
}) })
} }
}
return cr, nil return cr, nil
} }