server: implement update container resources

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-09-28 10:52:56 +02:00
parent 7d7024999b
commit c25530ac0b
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
6 changed files with 107 additions and 5 deletions

View file

@ -549,6 +549,25 @@ func (r *Runtime) ExecSync(c *Container, command []string, timeout int64) (resp
}, nil
}
// UpdateContainer updates container resources
func (r *Runtime) UpdateContainer(c *Container, res *rspec.LinuxResources) error {
cmd := exec.Command(r.Path(c), "update", "--resources", "-", c.id)
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
jsonResources, err := json.Marshal(res)
if err != nil {
return err
}
cmd.Stdin = bytes.NewReader(jsonResources)
if err := cmd.Run(); err != nil {
return fmt.Errorf("updating resources for container %q failed: %v %v (%v)", c.id, stderr.String(), stdout.String(), err)
}
return nil
}
func waitContainerStop(ctx context.Context, c *Container, timeout time.Duration) error {
done := make(chan struct{})
// we could potentially re-use "done" channel to exit the loop on timeout