Skip to content

Commit 36e5548

Browse files
committed
Remove namepsaces and id imports from shim
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent a7343b0 commit 36e5548

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

linux/proc/init.go

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"time"
1616

1717
"github.com/containerd/console"
18-
"github.com/containerd/containerd/identifiers"
1918
"github.com/containerd/containerd/linux/runctypes"
2019
shimapi "github.com/containerd/containerd/linux/shim/v1"
2120
"github.com/containerd/containerd/log"
@@ -61,13 +60,26 @@ type Init struct {
6160
IoGID int
6261
}
6362

63+
// NewRunc returns a new runc instance for a process
64+
func NewRunc(root, path, namespace, runtime, criu string, systemd bool) *runc.Runc {
65+
if root == "" {
66+
root = RuncRoot
67+
}
68+
return &runc.Runc{
69+
Command: runtime,
70+
Log: filepath.Join(path, "log.json"),
71+
LogFormat: runc.JSON,
72+
PdeathSignal: syscall.SIGKILL,
73+
Root: filepath.Join(root, namespace),
74+
Criu: criu,
75+
SystemdCgroup: systemd,
76+
}
77+
}
78+
6479
// New returns a new init process
6580
func New(context context.Context, path, workDir, runtimeRoot, namespace, criu string, systemdCgroup bool, platform Platform, r *shimapi.CreateTaskRequest) (*Init, error) {
6681
var success bool
6782

68-
if err := identifiers.Validate(r.ID); err != nil {
69-
return nil, errors.Wrapf(err, "invalid task id")
70-
}
7183
var options runctypes.CreateOptions
7284
if r.Options != nil {
7385
v, err := typeurl.UnmarshalAny(r.Options)
@@ -99,19 +111,7 @@ func New(context context.Context, path, workDir, runtimeRoot, namespace, criu st
99111
return nil, errors.Wrapf(err, "failed to mount rootfs component %v", m)
100112
}
101113
}
102-
root := runtimeRoot
103-
if root == "" {
104-
root = RuncRoot
105-
}
106-
runtime := &runc.Runc{
107-
Command: r.Runtime,
108-
Log: filepath.Join(path, "log.json"),
109-
LogFormat: runc.JSON,
110-
PdeathSignal: syscall.SIGKILL,
111-
Root: filepath.Join(root, namespace),
112-
Criu: criu,
113-
SystemdCgroup: systemdCgroup,
114-
}
114+
runtime := NewRunc(runtimeRoot, path, namespace, r.Runtime, criu, systemdCgroup)
115115
p := &Init{
116116
id: r.ID,
117117
bundle: r.Bundle,
@@ -339,9 +339,6 @@ func (p *Init) Runtime() *runc.Runc {
339339

340340
// Exec returns a new exec'd process
341341
func (p *Init) Exec(context context.Context, path string, r *shimapi.ExecProcessRequest) (Process, error) {
342-
if err := identifiers.Validate(r.ID); err != nil {
343-
return nil, errors.Wrapf(err, "invalid exec id")
344-
}
345342
// process exec request
346343
var spec specs.Process
347344
if err := json.Unmarshal(r.Spec.Value, &spec); err != nil {

linux/shim/service.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/containerd/containerd/linux/runctypes"
2020
shimapi "github.com/containerd/containerd/linux/shim/v1"
2121
"github.com/containerd/containerd/log"
22-
"github.com/containerd/containerd/namespaces"
2322
"github.com/containerd/containerd/reaper"
2423
"github.com/containerd/containerd/runtime"
2524
runc "github.com/containerd/go-runc"
@@ -47,15 +46,15 @@ func NewService(config Config, publisher events.Publisher) (*Service, error) {
4746
if config.Namespace == "" {
4847
return nil, fmt.Errorf("shim namespace cannot be empty")
4948
}
50-
context := namespaces.WithNamespace(context.Background(), config.Namespace)
51-
context = log.WithLogger(context, logrus.WithFields(logrus.Fields{
49+
ctx := context.Background()
50+
ctx = log.WithLogger(ctx, logrus.WithFields(logrus.Fields{
5251
"namespace": config.Namespace,
5352
"path": config.Path,
5453
"pid": os.Getpid(),
5554
}))
5655
s := &Service{
5756
config: config,
58-
context: context,
57+
context: ctx,
5958
processes: make(map[string]proc.Process),
6059
events: make(chan interface{}, 128),
6160
ec: reaper.Default.Subscribe(),

linux/task.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/containerd/containerd/api/types/task"
1414
"github.com/containerd/containerd/errdefs"
1515
"github.com/containerd/containerd/events/exchange"
16+
"github.com/containerd/containerd/identifiers"
1617
"github.com/containerd/containerd/linux/shim/client"
1718
shim "github.com/containerd/containerd/linux/shim/v1"
1819
"github.com/containerd/containerd/runtime"
@@ -167,6 +168,9 @@ func (t *Task) Kill(ctx context.Context, signal uint32, all bool) error {
167168

168169
// Exec creates a new process inside the task
169170
func (t *Task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) {
171+
if err := identifiers.Validate(id); err != nil {
172+
return nil, errors.Wrapf(err, "invalid exec id")
173+
}
170174
request := &shim.ExecProcessRequest{
171175
ID: id,
172176
Stdin: opts.IO.Stdin,

reaper/reaper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// ErrNoSuchProcess is returned when the process no longer exists
1616
var ErrNoSuchProcess = errors.New("no such process")
1717

18-
const bufferSize = 2048
18+
const bufferSize = 1024
1919

2020
// Reap should be called when the process receives an SIGCHLD. Reap will reap
2121
// all exited processes and close their wait channels

0 commit comments

Comments
 (0)