Refactor runtime code for code sharing

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2019-07-02 15:51:08 -04:00
parent 2aa8780ce6
commit 6601b406b7
20 changed files with 203 additions and 186 deletions

View File

@@ -36,8 +36,9 @@ import (
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
rproc "github.com/containerd/containerd/runtime/proc"
"github.com/containerd/containerd/runtime/v1/linux/proc"
"github.com/containerd/containerd/pkg/oom"
"github.com/containerd/containerd/pkg/process"
"github.com/containerd/containerd/pkg/stdio"
"github.com/containerd/containerd/runtime/v2/runc"
"github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/containerd/containerd/runtime/v2/shim"
@@ -60,7 +61,7 @@ var (
// New returns a new shim service that can be used via GRPC
func New(ctx context.Context, id string, publisher shim.Publisher, shutdown func()) (shim.Shim, error) {
ep, err := runc.NewOOMEpoller(publisher)
ep, err := oom.New(publisher)
if err != nil {
return nil, err
}
@@ -90,9 +91,9 @@ type service struct {
context context.Context
events chan interface{}
platform rproc.Platform
platform stdio.Platform
ec chan runcC.Exit
ep *runc.Epoller
ep *oom.Epoller
id string
container *runc.Container
@@ -209,7 +210,7 @@ func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error)
if err != nil {
return nil, err
}
r := proc.NewRunc(proc.RuncRoot, path, ns, runtime, "", false)
r := process.NewRunc(process.RuncRoot, path, ns, runtime, "", false)
if err := r.Delete(ctx, s.id, &runcC.DeleteOpts{
Force: true,
}); err != nil {
@@ -590,7 +591,7 @@ func (s *service) checkProcesses(e runcC.Exit) {
for _, p := range container.All() {
if p.Pid() == e.Pid {
if shouldKillAll {
if ip, ok := p.(*proc.Init); ok {
if ip, ok := p.(*process.Init); ok {
// Ensure all children are killed
if err := ip.KillAll(s.context); err != nil {
logrus.WithError(err).WithField("id", ip.ID()).
@@ -635,7 +636,7 @@ func (s *service) getContainerPids(ctx context.Context, id string) ([]uint32, er
if err != nil {
return nil, errdefs.ToGRPC(err)
}
ps, err := p.(*proc.Init).Runtime().Ps(ctx, id)
ps, err := p.(*process.Init).Runtime().Ps(ctx, id)
if err != nil {
return nil, err
}
@@ -670,7 +671,7 @@ func (s *service) getContainer() (*runc.Container, error) {
return container, nil
}
func (s *service) getProcess(execID string) (rproc.Process, error) {
func (s *service) getProcess(execID string) (process.Process, error) {
container, err := s.getContainer()
if err != nil {
return nil, err