Merge pull request #1416 from WeiZhang555/dont-save-cgroups-to-state-file

cgroups: remove duplicate fields from state
This commit is contained in:
Peng Tao 2019-04-02 16:09:33 +08:00 committed by GitHub
commit d76eddf41e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 26 deletions

View File

@ -281,36 +281,36 @@ func (s *Sandbox) cpuResources() *specs.LinuxCPU {
continue continue
} }
if c.state.Resources.CPU == nil { if c.config.Resources.CPU == nil {
continue continue
} }
if c.state.Resources.CPU.Shares != nil { if c.config.Resources.CPU.Shares != nil {
shares = uint64(math.Max(float64(*c.state.Resources.CPU.Shares), float64(shares))) shares = uint64(math.Max(float64(*c.config.Resources.CPU.Shares), float64(shares)))
} }
if c.state.Resources.CPU.Quota != nil { if c.config.Resources.CPU.Quota != nil {
quota += *c.state.Resources.CPU.Quota quota += *c.config.Resources.CPU.Quota
} }
if c.state.Resources.CPU.Period != nil { if c.config.Resources.CPU.Period != nil {
period = uint64(math.Max(float64(*c.state.Resources.CPU.Period), float64(period))) period = uint64(math.Max(float64(*c.config.Resources.CPU.Period), float64(period)))
} }
if c.state.Resources.CPU.Cpus != "" { if c.config.Resources.CPU.Cpus != "" {
cpu.Cpus += c.state.Resources.CPU.Cpus + "," cpu.Cpus += c.config.Resources.CPU.Cpus + ","
} }
if c.state.Resources.CPU.RealtimeRuntime != nil { if c.config.Resources.CPU.RealtimeRuntime != nil {
realtimeRuntime += *c.state.Resources.CPU.RealtimeRuntime realtimeRuntime += *c.config.Resources.CPU.RealtimeRuntime
} }
if c.state.Resources.CPU.RealtimePeriod != nil { if c.config.Resources.CPU.RealtimePeriod != nil {
realtimePeriod += *c.state.Resources.CPU.RealtimePeriod realtimePeriod += *c.config.Resources.CPU.RealtimePeriod
} }
if c.state.Resources.CPU.Mems != "" { if c.config.Resources.CPU.Mems != "" {
cpu.Mems += c.state.Resources.CPU.Mems + "," cpu.Mems += c.config.Resources.CPU.Mems + ","
} }
} }

View File

@ -1326,7 +1326,7 @@ func (c *Container) newCgroups() error {
return fmt.Errorf("Could not create cgroup for %v: %v", c.state.CgroupPath, err) return fmt.Errorf("Could not create cgroup for %v: %v", c.state.CgroupPath, err)
} }
c.state.Resources = resources c.config.Resources = resources
// Add shim into cgroup // Add shim into cgroup
if c.process.Pid > 0 { if c.process.Pid > 0 {
@ -1390,8 +1390,8 @@ func (c *Container) updateCgroups(resources specs.LinuxResources) error {
} }
// store new resources // store new resources
c.state.Resources = r c.config.Resources = r
if err := c.store.Store(store.State, c.state); err != nil { if err := c.storeContainer(); err != nil {
return err return err
} }

View File

@ -8,8 +8,6 @@ package types
import ( import (
"fmt" "fmt"
"strings" "strings"
specs "github.com/opencontainers/runtime-spec/specs-go"
) )
// StateString is a string representing a sandbox state. // StateString is a string representing a sandbox state.
@ -50,12 +48,6 @@ type State struct {
// CgroupPath is the cgroup hierarchy where sandbox's processes // CgroupPath is the cgroup hierarchy where sandbox's processes
// including the hypervisor are placed. // including the hypervisor are placed.
CgroupPath string `json:"cgroupPath,omitempty"` CgroupPath string `json:"cgroupPath,omitempty"`
// Resources contains the resources assigned to the container.
// When a container is created resources specified in the config json
// are used, those resources change when a container is updated but
// the config json is not updated.
Resources specs.LinuxResources `json:"resources,omitempty"`
} }
// Valid checks that the sandbox state is valid. // Valid checks that the sandbox state is valid.