Remove namepsaces and id imports from shim
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
a7343b0773
commit
36e5548e76
@ -15,7 +15,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
"github.com/containerd/containerd/identifiers"
|
|
||||||
"github.com/containerd/containerd/linux/runctypes"
|
"github.com/containerd/containerd/linux/runctypes"
|
||||||
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
@ -61,13 +60,26 @@ type Init struct {
|
|||||||
IoGID int
|
IoGID int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRunc returns a new runc instance for a process
|
||||||
|
func NewRunc(root, path, namespace, runtime, criu string, systemd bool) *runc.Runc {
|
||||||
|
if root == "" {
|
||||||
|
root = RuncRoot
|
||||||
|
}
|
||||||
|
return &runc.Runc{
|
||||||
|
Command: runtime,
|
||||||
|
Log: filepath.Join(path, "log.json"),
|
||||||
|
LogFormat: runc.JSON,
|
||||||
|
PdeathSignal: syscall.SIGKILL,
|
||||||
|
Root: filepath.Join(root, namespace),
|
||||||
|
Criu: criu,
|
||||||
|
SystemdCgroup: systemd,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// New returns a new init process
|
// New returns a new init process
|
||||||
func New(context context.Context, path, workDir, runtimeRoot, namespace, criu string, systemdCgroup bool, platform Platform, r *shimapi.CreateTaskRequest) (*Init, error) {
|
func New(context context.Context, path, workDir, runtimeRoot, namespace, criu string, systemdCgroup bool, platform Platform, r *shimapi.CreateTaskRequest) (*Init, error) {
|
||||||
var success bool
|
var success bool
|
||||||
|
|
||||||
if err := identifiers.Validate(r.ID); err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "invalid task id")
|
|
||||||
}
|
|
||||||
var options runctypes.CreateOptions
|
var options runctypes.CreateOptions
|
||||||
if r.Options != nil {
|
if r.Options != nil {
|
||||||
v, err := typeurl.UnmarshalAny(r.Options)
|
v, err := typeurl.UnmarshalAny(r.Options)
|
||||||
@ -99,19 +111,7 @@ func New(context context.Context, path, workDir, runtimeRoot, namespace, criu st
|
|||||||
return nil, errors.Wrapf(err, "failed to mount rootfs component %v", m)
|
return nil, errors.Wrapf(err, "failed to mount rootfs component %v", m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root := runtimeRoot
|
runtime := NewRunc(runtimeRoot, path, namespace, r.Runtime, criu, systemdCgroup)
|
||||||
if root == "" {
|
|
||||||
root = RuncRoot
|
|
||||||
}
|
|
||||||
runtime := &runc.Runc{
|
|
||||||
Command: r.Runtime,
|
|
||||||
Log: filepath.Join(path, "log.json"),
|
|
||||||
LogFormat: runc.JSON,
|
|
||||||
PdeathSignal: syscall.SIGKILL,
|
|
||||||
Root: filepath.Join(root, namespace),
|
|
||||||
Criu: criu,
|
|
||||||
SystemdCgroup: systemdCgroup,
|
|
||||||
}
|
|
||||||
p := &Init{
|
p := &Init{
|
||||||
id: r.ID,
|
id: r.ID,
|
||||||
bundle: r.Bundle,
|
bundle: r.Bundle,
|
||||||
@ -339,9 +339,6 @@ func (p *Init) Runtime() *runc.Runc {
|
|||||||
|
|
||||||
// Exec returns a new exec'd process
|
// Exec returns a new exec'd process
|
||||||
func (p *Init) Exec(context context.Context, path string, r *shimapi.ExecProcessRequest) (Process, error) {
|
func (p *Init) Exec(context context.Context, path string, r *shimapi.ExecProcessRequest) (Process, error) {
|
||||||
if err := identifiers.Validate(r.ID); err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "invalid exec id")
|
|
||||||
}
|
|
||||||
// process exec request
|
// process exec request
|
||||||
var spec specs.Process
|
var spec specs.Process
|
||||||
if err := json.Unmarshal(r.Spec.Value, &spec); err != nil {
|
if err := json.Unmarshal(r.Spec.Value, &spec); err != nil {
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"github.com/containerd/containerd/linux/runctypes"
|
"github.com/containerd/containerd/linux/runctypes"
|
||||||
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/namespaces"
|
|
||||||
"github.com/containerd/containerd/reaper"
|
"github.com/containerd/containerd/reaper"
|
||||||
"github.com/containerd/containerd/runtime"
|
"github.com/containerd/containerd/runtime"
|
||||||
runc "github.com/containerd/go-runc"
|
runc "github.com/containerd/go-runc"
|
||||||
@ -47,15 +46,15 @@ func NewService(config Config, publisher events.Publisher) (*Service, error) {
|
|||||||
if config.Namespace == "" {
|
if config.Namespace == "" {
|
||||||
return nil, fmt.Errorf("shim namespace cannot be empty")
|
return nil, fmt.Errorf("shim namespace cannot be empty")
|
||||||
}
|
}
|
||||||
context := namespaces.WithNamespace(context.Background(), config.Namespace)
|
ctx := context.Background()
|
||||||
context = log.WithLogger(context, logrus.WithFields(logrus.Fields{
|
ctx = log.WithLogger(ctx, logrus.WithFields(logrus.Fields{
|
||||||
"namespace": config.Namespace,
|
"namespace": config.Namespace,
|
||||||
"path": config.Path,
|
"path": config.Path,
|
||||||
"pid": os.Getpid(),
|
"pid": os.Getpid(),
|
||||||
}))
|
}))
|
||||||
s := &Service{
|
s := &Service{
|
||||||
config: config,
|
config: config,
|
||||||
context: context,
|
context: ctx,
|
||||||
processes: make(map[string]proc.Process),
|
processes: make(map[string]proc.Process),
|
||||||
events: make(chan interface{}, 128),
|
events: make(chan interface{}, 128),
|
||||||
ec: reaper.Default.Subscribe(),
|
ec: reaper.Default.Subscribe(),
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/containerd/containerd/api/types/task"
|
"github.com/containerd/containerd/api/types/task"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/events/exchange"
|
"github.com/containerd/containerd/events/exchange"
|
||||||
|
"github.com/containerd/containerd/identifiers"
|
||||||
"github.com/containerd/containerd/linux/shim/client"
|
"github.com/containerd/containerd/linux/shim/client"
|
||||||
shim "github.com/containerd/containerd/linux/shim/v1"
|
shim "github.com/containerd/containerd/linux/shim/v1"
|
||||||
"github.com/containerd/containerd/runtime"
|
"github.com/containerd/containerd/runtime"
|
||||||
@ -167,6 +168,9 @@ func (t *Task) Kill(ctx context.Context, signal uint32, all bool) error {
|
|||||||
|
|
||||||
// Exec creates a new process inside the task
|
// Exec creates a new process inside the task
|
||||||
func (t *Task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) {
|
func (t *Task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) {
|
||||||
|
if err := identifiers.Validate(id); err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "invalid exec id")
|
||||||
|
}
|
||||||
request := &shim.ExecProcessRequest{
|
request := &shim.ExecProcessRequest{
|
||||||
ID: id,
|
ID: id,
|
||||||
Stdin: opts.IO.Stdin,
|
Stdin: opts.IO.Stdin,
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
// ErrNoSuchProcess is returned when the process no longer exists
|
// ErrNoSuchProcess is returned when the process no longer exists
|
||||||
var ErrNoSuchProcess = errors.New("no such process")
|
var ErrNoSuchProcess = errors.New("no such process")
|
||||||
|
|
||||||
const bufferSize = 2048
|
const bufferSize = 1024
|
||||||
|
|
||||||
// Reap should be called when the process receives an SIGCHLD. Reap will reap
|
// Reap should be called when the process receives an SIGCHLD. Reap will reap
|
||||||
// all exited processes and close their wait channels
|
// all exited processes and close their wait channels
|
||||||
|
Loading…
Reference in New Issue
Block a user