Merge pull request #1127 from sameo/topic/typo
linux: Make containerd less runc specific
This commit is contained in:
commit
193750e1a5
@ -85,8 +85,8 @@ func newExecProcess(context context.Context, path string, r *shimapi.ExecProcess
|
|||||||
}
|
}
|
||||||
spec.Terminal = r.Terminal
|
spec.Terminal = r.Terminal
|
||||||
|
|
||||||
if err := parent.runc.Exec(context, parent.id, spec, opts); err != nil {
|
if err := parent.runtime.Exec(context, parent.id, spec, opts); err != nil {
|
||||||
return nil, parent.runcError(err, "runc exec failed")
|
return nil, parent.runtimeError(err, "OCI runtime exec failed")
|
||||||
}
|
}
|
||||||
if r.Stdin != "" {
|
if r.Stdin != "" {
|
||||||
sc, err := fifo.OpenFifo(context, r.Stdin, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
|
sc, err := fifo.OpenFifo(context, r.Stdin, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
|
||||||
@ -114,7 +114,7 @@ func newExecProcess(context context.Context, path string, r *shimapi.ExecProcess
|
|||||||
copyWaitGroup.Wait()
|
copyWaitGroup.Wait()
|
||||||
pid, err := runc.ReadPidFile(opts.PidFile)
|
pid, err := runc.ReadPidFile(opts.PidFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to retrieve runc exec pid")
|
return nil, errors.Wrap(err, "failed to retrieve OCI runtime exec pid")
|
||||||
}
|
}
|
||||||
e.pid = pid
|
e.pid = pid
|
||||||
return e, nil
|
return e, nil
|
||||||
|
@ -42,7 +42,7 @@ type initProcess struct {
|
|||||||
bundle string
|
bundle string
|
||||||
console console.Console
|
console console.Console
|
||||||
io runc.IO
|
io runc.IO
|
||||||
runc *runc.Runc
|
runtime *runc.Runc
|
||||||
status int
|
status int
|
||||||
exited time.Time
|
exited time.Time
|
||||||
pid int
|
pid int
|
||||||
@ -82,7 +82,7 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
|||||||
p := &initProcess{
|
p := &initProcess{
|
||||||
id: r.ID,
|
id: r.ID,
|
||||||
bundle: r.Bundle,
|
bundle: r.Bundle,
|
||||||
runc: runtime,
|
runtime: runtime,
|
||||||
stdinPath: r.Stdin,
|
stdinPath: r.Stdin,
|
||||||
stdoutPath: r.Stdout,
|
stdoutPath: r.Stdout,
|
||||||
stderrPath: r.Stderr,
|
stderrPath: r.Stderr,
|
||||||
@ -95,13 +95,13 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
|||||||
)
|
)
|
||||||
if r.Terminal {
|
if r.Terminal {
|
||||||
if socket, err = runc.NewConsoleSocket(filepath.Join(path, "pty.sock")); err != nil {
|
if socket, err = runc.NewConsoleSocket(filepath.Join(path, "pty.sock")); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create runc console socket")
|
return nil, errors.Wrap(err, "failed to create OCI runtime console socket")
|
||||||
}
|
}
|
||||||
defer os.Remove(socket.Path())
|
defer os.Remove(socket.Path())
|
||||||
} else {
|
} else {
|
||||||
// TODO: get uid/gid
|
// TODO: get uid/gid
|
||||||
if io, err = runc.NewPipeIO(0, 0); err != nil {
|
if io, err = runc.NewPipeIO(0, 0); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create runc io pipes")
|
return nil, errors.Wrap(err, "failed to create OCI runtime io pipes")
|
||||||
}
|
}
|
||||||
p.io = io
|
p.io = io
|
||||||
}
|
}
|
||||||
@ -119,8 +119,8 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
|||||||
Detach: true,
|
Detach: true,
|
||||||
NoSubreaper: true,
|
NoSubreaper: true,
|
||||||
}
|
}
|
||||||
if _, err := p.runc.Restore(context, r.ID, r.Bundle, opts); err != nil {
|
if _, err := p.runtime.Restore(context, r.ID, r.Bundle, opts); err != nil {
|
||||||
return nil, p.runcError(err, "runc restore failed")
|
return nil, p.runtimeError(err, "OCI runtime restore failed")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
opts := &runc.CreateOpts{
|
opts := &runc.CreateOpts{
|
||||||
@ -132,8 +132,8 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
|||||||
if socket != nil {
|
if socket != nil {
|
||||||
opts.ConsoleSocket = socket
|
opts.ConsoleSocket = socket
|
||||||
}
|
}
|
||||||
if err := p.runc.Create(context, r.ID, r.Bundle, opts); err != nil {
|
if err := p.runtime.Create(context, r.ID, r.Bundle, opts); err != nil {
|
||||||
return nil, p.runcError(err, "runc create failed")
|
return nil, p.runtimeError(err, "OCI runtime create failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if r.Stdin != "" {
|
if r.Stdin != "" {
|
||||||
@ -163,7 +163,7 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
|||||||
copyWaitGroup.Wait()
|
copyWaitGroup.Wait()
|
||||||
pid, err := runc.ReadPidFile(pidFile)
|
pid, err := runc.ReadPidFile(pidFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to retrieve runc container pid")
|
return nil, errors.Wrap(err, "failed to retrieve OCI runtime container pid")
|
||||||
}
|
}
|
||||||
p.pid = pid
|
p.pid = pid
|
||||||
return p, nil
|
return p, nil
|
||||||
@ -183,9 +183,9 @@ func (p *initProcess) ExitedAt() time.Time {
|
|||||||
|
|
||||||
// ContainerStatus return the state of the container (created, running, paused, stopped)
|
// ContainerStatus return the state of the container (created, running, paused, stopped)
|
||||||
func (p *initProcess) ContainerStatus(ctx context.Context) (string, error) {
|
func (p *initProcess) ContainerStatus(ctx context.Context) (string, error) {
|
||||||
c, err := p.runc.State(ctx, p.id)
|
c, err := p.runtime.State(ctx, p.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", p.runcError(err, "runc state failed")
|
return "", p.runtimeError(err, "OCI runtime state failed")
|
||||||
}
|
}
|
||||||
return c.Status, nil
|
return c.Status, nil
|
||||||
}
|
}
|
||||||
@ -193,8 +193,8 @@ func (p *initProcess) ContainerStatus(ctx context.Context) (string, error) {
|
|||||||
func (p *initProcess) Start(context context.Context) error {
|
func (p *initProcess) Start(context context.Context) error {
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
defer p.mu.Unlock()
|
defer p.mu.Unlock()
|
||||||
err := p.runc.Start(context, p.id)
|
err := p.runtime.Start(context, p.id)
|
||||||
return p.runcError(err, "runc start failed")
|
return p.runtimeError(err, "OCI runtime start failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) Exited(status int) {
|
func (p *initProcess) Exited(status int) {
|
||||||
@ -214,14 +214,14 @@ func (p *initProcess) Delete(context context.Context) error {
|
|||||||
}
|
}
|
||||||
p.killAll(context)
|
p.killAll(context)
|
||||||
p.Wait()
|
p.Wait()
|
||||||
err = p.runc.Delete(context, p.id, nil)
|
err = p.runtime.Delete(context, p.id, nil)
|
||||||
if p.io != nil {
|
if p.io != nil {
|
||||||
for _, c := range p.closers {
|
for _, c := range p.closers {
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
p.io.Close()
|
p.io.Close()
|
||||||
}
|
}
|
||||||
return p.runcError(err, "runc delete failed")
|
return p.runtimeError(err, "OCI runtime delete failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) Resize(ws console.WinSize) error {
|
func (p *initProcess) Resize(ws console.WinSize) error {
|
||||||
@ -232,27 +232,27 @@ func (p *initProcess) Resize(ws console.WinSize) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) Pause(context context.Context) error {
|
func (p *initProcess) Pause(context context.Context) error {
|
||||||
err := p.runc.Pause(context, p.id)
|
err := p.runtime.Pause(context, p.id)
|
||||||
return p.runcError(err, "runc pause failed")
|
return p.runtimeError(err, "OCI runtime pause failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) Resume(context context.Context) error {
|
func (p *initProcess) Resume(context context.Context) error {
|
||||||
err := p.runc.Resume(context, p.id)
|
err := p.runtime.Resume(context, p.id)
|
||||||
return p.runcError(err, "runc resume failed")
|
return p.runtimeError(err, "OCI runtime resume failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) Kill(context context.Context, signal uint32, all bool) error {
|
func (p *initProcess) Kill(context context.Context, signal uint32, all bool) error {
|
||||||
err := p.runc.Kill(context, p.id, int(signal), &runc.KillOpts{
|
err := p.runtime.Kill(context, p.id, int(signal), &runc.KillOpts{
|
||||||
All: all,
|
All: all,
|
||||||
})
|
})
|
||||||
return checkKillError(err)
|
return checkKillError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) killAll(context context.Context) error {
|
func (p *initProcess) killAll(context context.Context) error {
|
||||||
err := p.runc.Kill(context, p.id, int(syscall.SIGKILL), &runc.KillOpts{
|
err := p.runtime.Kill(context, p.id, int(syscall.SIGKILL), &runc.KillOpts{
|
||||||
All: true,
|
All: true,
|
||||||
})
|
})
|
||||||
return p.runcError(err, "runc killall failed")
|
return p.runtimeError(err, "OCI runtime killall failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) Signal(sig int) error {
|
func (p *initProcess) Signal(sig int) error {
|
||||||
@ -276,7 +276,7 @@ func (p *initProcess) Checkpoint(context context.Context, r *shimapi.CheckpointT
|
|||||||
}
|
}
|
||||||
work := filepath.Join(p.bundle, "work")
|
work := filepath.Join(p.bundle, "work")
|
||||||
defer os.RemoveAll(work)
|
defer os.RemoveAll(work)
|
||||||
if err := p.runc.Checkpoint(context, p.id, &runc.CheckpointOpts{
|
if err := p.runtime.Checkpoint(context, p.id, &runc.CheckpointOpts{
|
||||||
WorkDir: work,
|
WorkDir: work,
|
||||||
ImagePath: r.Path,
|
ImagePath: r.Path,
|
||||||
AllowOpenTCP: options.OpenTcp,
|
AllowOpenTCP: options.OpenTcp,
|
||||||
@ -299,11 +299,11 @@ func (p *initProcess) Update(context context.Context, r *shimapi.UpdateTaskReque
|
|||||||
if err := json.Unmarshal(r.Resources.Value, &resources); err != nil {
|
if err := json.Unmarshal(r.Resources.Value, &resources); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return p.runc.Update(context, p.id, &resources)
|
return p.runtime.Update(context, p.id, &resources)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(mlaventure): move to runc package?
|
// TODO(mlaventure): move to runc package?
|
||||||
func getLastRuncError(r *runc.Runc) (string, error) {
|
func getLastRuntimeError(r *runc.Runc) (string, error) {
|
||||||
if r.Log == "" {
|
if r.Log == "" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
@ -335,15 +335,15 @@ func getLastRuncError(r *runc.Runc) (string, error) {
|
|||||||
return errMsg, nil
|
return errMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) runcError(rErr error, msg string) error {
|
func (p *initProcess) runtimeError(rErr error, msg string) error {
|
||||||
if rErr == nil {
|
if rErr == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
rMsg, err := getLastRuncError(p.runc)
|
rMsg, err := getLastRuntimeError(p.runtime)
|
||||||
switch {
|
switch {
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return errors.Wrapf(rErr, "%s: %s (%s)", msg, "unable to retrieve runc error", err.Error())
|
return errors.Wrapf(rErr, "%s: %s (%s)", msg, "unable to retrieve OCI runtime error", err.Error())
|
||||||
case rMsg == "":
|
case rMsg == "":
|
||||||
return errors.Wrap(rErr, msg)
|
return errors.Wrap(rErr, msg)
|
||||||
default:
|
default:
|
||||||
|
@ -383,7 +383,7 @@ func (s *Service) waitExit(p process, pid int, cmd *reaper.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) getContainerPids(ctx context.Context, id string) ([]uint32, error) {
|
func (s *Service) getContainerPids(ctx context.Context, id string) ([]uint32, error) {
|
||||||
p, err := s.initProcess.runc.Ps(ctx, id)
|
p, err := s.initProcess.runtime.Ps(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user