Merge pull request #457 from crosbymichael/update-go-runc

Update go-runc to afca56d262e694d9056e937a0877a39ab879aeb4
This commit is contained in:
Kenfe-Mickaël Laventure 2017-01-20 13:52:39 -08:00 committed by GitHub
commit 8228996a4a
3 changed files with 67 additions and 29 deletions

View File

@ -1,5 +1,5 @@
# go-runc client for runc; master as of 12/16/2016 # go-runc client for runc; master as of 01/20/2017
github.com/crosbymichael/go-runc 2fdd3cd06f7443a55f6eb14ead2cac507506e718 github.com/crosbymichael/go-runc afca56d262e694d9056e937a0877a39ab879aeb4
# go-metrics client to prometheus; master as of 12/16/2016 # go-metrics client to prometheus; master as of 12/16/2016
github.com/docker/go-metrics 0f35294225552d968a13f9c5bc71a3fa44b2eb87 github.com/docker/go-metrics 0f35294225552d968a13f9c5bc71a3fa44b2eb87
# prometheus client; latest release as of 12/16/2016 # prometheus client; latest release as of 12/16/2016

View File

@ -1,9 +1,14 @@
package runc package runc
type Event struct { type Event struct {
// Type are the event type generated by runc
// If the type is "error" then check the Err field on the event for
// the actual error
Type string `json:"type"` Type string `json:"type"`
ID string `json:"id"` ID string `json:"id"`
Stats *Stats `json:"data,omitempty"` Stats *Stats `json:"data,omitempty"`
// Err has a read error if we were unable to decode the event from runc
Err error `json:"-"`
} }
type Stats struct { type Stats struct {

View File

@ -13,7 +13,6 @@ import (
"time" "time"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
) )
// Format is the type of log formatting options avaliable // Format is the type of log formatting options avaliable
@ -23,14 +22,19 @@ const (
none Format = "" none Format = ""
JSON Format = "json" JSON Format = "json"
Text Format = "text" Text Format = "text"
// DefaultCommand is the default command for Runc
DefaultCommand string = "runc"
) )
// Runc is the client to the runc cli // Runc is the client to the runc cli
type Runc struct { type Runc struct {
Root string //If command is empty, DefaultCommand is used
Debug bool Command string
Log string Root string
LogFormat Format Debug bool
Log string
LogFormat Format
PdeathSignal syscall.Signal
} }
// List returns all containers created inside the provided runc root directory // List returns all containers created inside the provided runc root directory
@ -62,11 +66,11 @@ func (r *Runc) State(context context.Context, id string) (*Container, error) {
type CreateOpts struct { type CreateOpts struct {
IO IO
// PidFile is a path to where a pid file should be created // PidFile is a path to where a pid file should be created
PidFile string PidFile string
Console string ConsoleSocket string
Detach bool Detach bool
NoPivot bool NoPivot bool
NoNewKeyring bool NoNewKeyring bool
} }
type IO struct { type IO struct {
@ -103,8 +107,8 @@ func (o *CreateOpts) args() (out []string) {
if o.PidFile != "" { if o.PidFile != "" {
out = append(out, "--pid-file", o.PidFile) out = append(out, "--pid-file", o.PidFile)
} }
if o.Console != "" { if o.ConsoleSocket != "" {
out = append(out, "--console", o.Console) out = append(out, "--console-socket", o.ConsoleSocket)
} }
if o.NoPivot { if o.NoPivot {
out = append(out, "--no-pivot") out = append(out, "--no-pivot")
@ -138,13 +142,13 @@ func (r *Runc) Start(context context.Context, id string) error {
type ExecOpts struct { type ExecOpts struct {
IO IO
PidFile string PidFile string
Uid int Uid int
Gid int Gid int
Cwd string Cwd string
Tty bool Tty bool
Console string ConsoleSocket string
Detach bool Detach bool
} }
func (o *ExecOpts) args() (out []string) { func (o *ExecOpts) args() (out []string) {
@ -152,8 +156,8 @@ func (o *ExecOpts) args() (out []string) {
if o.Tty { if o.Tty {
out = append(out, "--tty") out = append(out, "--tty")
} }
if o.Console != "" { if o.ConsoleSocket != "" {
out = append(out, "--console", o.Console) out = append(out, "--console-socket", o.ConsoleSocket)
} }
if o.Cwd != "" { if o.Cwd != "" {
out = append(out, "--cwd", o.Cwd) out = append(out, "--cwd", o.Cwd)
@ -217,9 +221,27 @@ func (r *Runc) Delete(context context.Context, id string) error {
return runOrError(r.command(context, "delete", id)) return runOrError(r.command(context, "delete", id))
} }
// KillOpts specifies options for killing a container and its processes
type KillOpts struct {
All bool
}
func (o *KillOpts) args() (out []string) {
if o.All {
out = append(out, "--all")
}
return out
}
// Kill sends the specified signal to the container // Kill sends the specified signal to the container
func (r *Runc) Kill(context context.Context, id string, sig int) error { func (r *Runc) Kill(context context.Context, id string, sig int, opts *KillOpts) error {
return runOrError(r.command(context, "kill", id, strconv.Itoa(sig))) args := []string{
"kill",
}
if opts != nil {
args = append(args, opts.args()...)
}
return runOrError(r.command(context, append(args, id, strconv.Itoa(sig))...))
} }
// Stats return the stats for a container like cpu, memory, and io // Stats return the stats for a container like cpu, memory, and io
@ -270,8 +292,10 @@ func (r *Runc) Events(context context.Context, id string, interval time.Duration
if err == io.EOF { if err == io.EOF {
return return
} }
logrus.WithError(err).Error("runc: decode event") e = Event{
continue Type: "error",
Err: err,
}
} }
c <- &e c <- &e
} }
@ -319,6 +343,15 @@ func (r *Runc) args() (out []string) {
} }
func (r *Runc) command(context context.Context, args ...string) *exec.Cmd { func (r *Runc) command(context context.Context, args ...string) *exec.Cmd {
return exec.CommandContext(context, command := r.Command
"runc", append(r.args(), args...)...) if command == "" {
command = DefaultCommand
}
cmd := exec.CommandContext(context, command, append(r.args(), args...)...)
if r.PdeathSignal != 0 {
cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: r.PdeathSignal,
}
}
return cmd
} }