Add update rpc for resource updates
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
44d6a60e7e
commit
0dd075a47b
7 changed files with 298 additions and 122 deletions
|
@ -48,6 +48,8 @@ type Container interface {
|
|||
Runtime() string
|
||||
// OOM signals the channel if the container received an OOM notification
|
||||
OOM() (OOM, error)
|
||||
// UpdateResource updates the containers resources to new values
|
||||
UpdateResources(*Resource) error
|
||||
}
|
||||
|
||||
type OOM interface {
|
||||
|
@ -213,3 +215,22 @@ func (c *container) RemoveProcess(pid string) error {
|
|||
delete(c.processes, pid)
|
||||
return os.RemoveAll(filepath.Join(c.root, c.id, pid))
|
||||
}
|
||||
|
||||
func (c *container) UpdateResources(r *Resource) error {
|
||||
container, err := c.getLibctContainer()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
config := container.Config()
|
||||
config.Cgroups.Resources.CpuShares = r.CPUShares
|
||||
config.Cgroups.Resources.BlkioWeight = r.BlkioWeight
|
||||
config.Cgroups.Resources.CpuPeriod = r.CPUPeriod
|
||||
config.Cgroups.Resources.CpuQuota = r.CPUQuota
|
||||
config.Cgroups.Resources.CpusetCpus = r.CpusetCpus
|
||||
config.Cgroups.Resources.CpusetMems = r.CpusetMems
|
||||
config.Cgroups.Resources.KernelMemory = r.KernelMemory
|
||||
config.Cgroups.Resources.Memory = r.Memory
|
||||
config.Cgroups.Resources.MemoryReservation = r.MemoryReservation
|
||||
config.Cgroups.Resources.MemorySwap = r.MemorySwap
|
||||
return container.Set(config)
|
||||
}
|
||||
|
|
|
@ -32,6 +32,19 @@ const (
|
|||
|
||||
type State string
|
||||
|
||||
type Resource struct {
|
||||
CPUShares int64
|
||||
BlkioWeight uint16
|
||||
CPUPeriod int64
|
||||
CPUQuota int64
|
||||
CpusetCpus string
|
||||
CpusetMems string
|
||||
KernelMemory int64
|
||||
Memory int64
|
||||
MemoryReservation int64
|
||||
MemorySwap int64
|
||||
}
|
||||
|
||||
const (
|
||||
Paused = State("paused")
|
||||
Stopped = State("stopped")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue