Update go-runc to bd9aef7cf4402a3a8728e3ef83dcca6a5a1be899
Also remove the comment fields in the vndr script, they are too hard to keep up to date and add little value when we have the git commit timestamps Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
fc45d9c119
commit
4fd2478513
3 changed files with 45 additions and 86 deletions
80
vendor/github.com/crosbymichael/go-runc/runc.go
generated
vendored
80
vendor/github.com/crosbymichael/go-runc/runc.go
generated
vendored
|
@ -40,7 +40,7 @@ type Runc struct {
|
|||
|
||||
// List returns all containers created inside the provided runc root directory
|
||||
func (r *Runc) List(context context.Context) ([]*Container, error) {
|
||||
data, err := r.command(context, "list", "--format=json").Output()
|
||||
data, err := Monitor.Output(r.command(context, "list", "--format=json"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func (r *Runc) List(context context.Context) ([]*Container, error) {
|
|||
|
||||
// State returns the state for the container provided by id
|
||||
func (r *Runc) State(context context.Context, id string) (*Container, error) {
|
||||
data, err := r.command(context, "state", id).CombinedOutput()
|
||||
data, err := Monitor.CombinedOutput(r.command(context, "state", id))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %s", err, data)
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ type CreateOpts struct {
|
|||
Detach bool
|
||||
NoPivot bool
|
||||
NoNewKeyring bool
|
||||
ExtraFiles []*os.File
|
||||
}
|
||||
|
||||
func (o *CreateOpts) args() (out []string, err error) {
|
||||
|
@ -94,6 +95,9 @@ func (o *CreateOpts) args() (out []string, err error) {
|
|||
if o.Detach {
|
||||
out = append(out, "--detach")
|
||||
}
|
||||
if o.ExtraFiles != nil {
|
||||
out = append(out, "--preserve-fds", strconv.Itoa(len(o.ExtraFiles)))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
@ -111,14 +115,16 @@ func (r *Runc) Create(context context.Context, id, bundle string, opts *CreateOp
|
|||
if opts != nil && opts.IO != nil {
|
||||
opts.Set(cmd)
|
||||
}
|
||||
cmd.ExtraFiles = opts.ExtraFiles
|
||||
|
||||
if cmd.Stdout == nil && cmd.Stderr == nil {
|
||||
data, err := cmd.CombinedOutput()
|
||||
data, err := Monitor.CombinedOutput(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", err, data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := cmd.Start(); err != nil {
|
||||
if err := Monitor.Start(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
if opts != nil && opts.IO != nil {
|
||||
|
@ -128,36 +134,26 @@ func (r *Runc) Create(context context.Context, id, bundle string, opts *CreateOp
|
|||
}
|
||||
}
|
||||
}
|
||||
return cmd.Wait()
|
||||
_, err := Monitor.Wait(cmd)
|
||||
return err
|
||||
}
|
||||
|
||||
// Start will start an already created container
|
||||
func (r *Runc) Start(context context.Context, id string) error {
|
||||
return runOrError(r.command(context, "start", id))
|
||||
return r.runOrError(r.command(context, "start", id))
|
||||
}
|
||||
|
||||
type ExecOpts struct {
|
||||
IO
|
||||
PidFile string
|
||||
Uid int
|
||||
Gid int
|
||||
Cwd string
|
||||
Tty bool
|
||||
ConsoleSocket *ConsoleSocket
|
||||
Detach bool
|
||||
}
|
||||
|
||||
func (o *ExecOpts) args() (out []string, err error) {
|
||||
out = append(out, "--user", fmt.Sprintf("%d:%d", o.Uid, o.Gid))
|
||||
if o.Tty {
|
||||
out = append(out, "--tty")
|
||||
}
|
||||
if o.ConsoleSocket != nil {
|
||||
out = append(out, "--console-socket", o.ConsoleSocket.Path())
|
||||
}
|
||||
if o.Cwd != "" {
|
||||
out = append(out, "--cwd", o.Cwd)
|
||||
}
|
||||
if o.Detach {
|
||||
out = append(out, "--detach")
|
||||
}
|
||||
|
@ -174,7 +170,7 @@ func (o *ExecOpts) args() (out []string, err error) {
|
|||
// Exec executres and additional process inside the container based on a full
|
||||
// OCI Process specification
|
||||
func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts *ExecOpts) error {
|
||||
f, err := ioutil.TempFile("", "-process")
|
||||
f, err := ioutil.TempFile("", "runc-process")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -197,13 +193,13 @@ func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts
|
|||
opts.Set(cmd)
|
||||
}
|
||||
if cmd.Stdout == nil && cmd.Stderr == nil {
|
||||
data, err := cmd.CombinedOutput()
|
||||
data, err := Monitor.CombinedOutput(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", err, data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := cmd.Start(); err != nil {
|
||||
if err := Monitor.Start(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
if opts != nil && opts.IO != nil {
|
||||
|
@ -213,7 +209,8 @@ func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts
|
|||
}
|
||||
}
|
||||
}
|
||||
return cmd.Wait()
|
||||
_, err = Monitor.Wait(cmd)
|
||||
return err
|
||||
}
|
||||
|
||||
// Run runs the create, start, delete lifecycle of the container
|
||||
|
@ -231,19 +228,15 @@ func (r *Runc) Run(context context.Context, id, bundle string, opts *CreateOpts)
|
|||
if opts != nil {
|
||||
opts.Set(cmd)
|
||||
}
|
||||
if err := cmd.Start(); err != nil {
|
||||
if err := Monitor.Start(cmd); err != nil {
|
||||
return -1, err
|
||||
}
|
||||
status, err := cmd.Process.Wait()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return status.Sys().(syscall.WaitStatus).ExitStatus(), nil
|
||||
return Monitor.Wait(cmd)
|
||||
}
|
||||
|
||||
// Delete deletes the container
|
||||
func (r *Runc) Delete(context context.Context, id string) error {
|
||||
return runOrError(r.command(context, "delete", id))
|
||||
return r.runOrError(r.command(context, "delete", id))
|
||||
}
|
||||
|
||||
// KillOpts specifies options for killing a container and its processes
|
||||
|
@ -266,7 +259,7 @@ func (r *Runc) Kill(context context.Context, id string, sig int, opts *KillOpts)
|
|||
if opts != nil {
|
||||
args = append(args, opts.args()...)
|
||||
}
|
||||
return runOrError(r.command(context, append(args, id, strconv.Itoa(sig))...))
|
||||
return r.runOrError(r.command(context, append(args, id, strconv.Itoa(sig))...))
|
||||
}
|
||||
|
||||
// Stats return the stats for a container like cpu, memory, and io
|
||||
|
@ -278,9 +271,9 @@ func (r *Runc) Stats(context context.Context, id string) (*Stats, error) {
|
|||
}
|
||||
defer func() {
|
||||
rd.Close()
|
||||
cmd.Wait()
|
||||
Monitor.Wait(cmd)
|
||||
}()
|
||||
if err := cmd.Start(); err != nil {
|
||||
if err := Monitor.Start(cmd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var e Event
|
||||
|
@ -297,7 +290,7 @@ func (r *Runc) Events(context context.Context, id string, interval time.Duration
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := cmd.Start(); err != nil {
|
||||
if err := Monitor.Start(cmd); err != nil {
|
||||
rd.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
@ -309,7 +302,7 @@ func (r *Runc) Events(context context.Context, id string, interval time.Duration
|
|||
defer func() {
|
||||
close(c)
|
||||
rd.Close()
|
||||
cmd.Wait()
|
||||
Monitor.Wait(cmd)
|
||||
}()
|
||||
for {
|
||||
var e Event
|
||||
|
@ -330,17 +323,17 @@ func (r *Runc) Events(context context.Context, id string, interval time.Duration
|
|||
|
||||
// Pause the container with the provided id
|
||||
func (r *Runc) Pause(context context.Context, id string) error {
|
||||
return runOrError(r.command(context, "pause", id))
|
||||
return r.runOrError(r.command(context, "pause", id))
|
||||
}
|
||||
|
||||
// Resume the container with the provided id
|
||||
func (r *Runc) Resume(context context.Context, id string) error {
|
||||
return runOrError(r.command(context, "resume", id))
|
||||
return r.runOrError(r.command(context, "resume", id))
|
||||
}
|
||||
|
||||
// Ps lists all the processes inside the container returning their pids
|
||||
func (r *Runc) Ps(context context.Context, id string) ([]int, error) {
|
||||
data, err := r.command(context, "ps", "--format", "json", id).CombinedOutput()
|
||||
data, err := Monitor.CombinedOutput(r.command(context, "ps", "--format", "json", id))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %s", err, data)
|
||||
}
|
||||
|
@ -380,3 +373,18 @@ func (r *Runc) command(context context.Context, args ...string) *exec.Cmd {
|
|||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
// runOrError will run the provided command. If an error is
|
||||
// encountered and neither Stdout or Stderr was set the error and the
|
||||
// stderr of the command will be returned in the format of <error>:
|
||||
// <stderr>
|
||||
func (r *Runc) runOrError(cmd *exec.Cmd) error {
|
||||
if cmd.Stdout != nil || cmd.Stderr != nil {
|
||||
return Monitor.Run(cmd)
|
||||
}
|
||||
data, err := Monitor.CombinedOutput(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", err, data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue