Skip to content

Commit a0696b2

Browse files
authored
Merge pull request #3374 from crosbymichael/runtime
Refactor runtime package for code usage
2 parents dce11a2 + 6601b40 commit a0696b2

20 files changed

Lines changed: 203 additions & 186 deletions

File tree

cmd/containerd-shim/main_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import (
3737

3838
"github.com/containerd/containerd/events"
3939
"github.com/containerd/containerd/namespaces"
40+
"github.com/containerd/containerd/pkg/process"
4041
shimlog "github.com/containerd/containerd/runtime/v1"
41-
"github.com/containerd/containerd/runtime/v1/linux/proc"
4242
"github.com/containerd/containerd/runtime/v1/shim"
4343
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
4444
"github.com/containerd/ttrpc"
@@ -73,7 +73,7 @@ func init() {
7373
flag.StringVar(&socketFlag, "socket", "", "abstract socket path to serve")
7474
flag.StringVar(&addressFlag, "address", "", "grpc address back to main containerd")
7575
flag.StringVar(&workdirFlag, "workdir", "", "path used to storge large temporary data")
76-
flag.StringVar(&runtimeRootFlag, "runtime-root", proc.RuncRoot, "root directory for the runtime")
76+
flag.StringVar(&runtimeRootFlag, "runtime-root", process.RuncRoot, "root directory for the runtime")
7777
flag.StringVar(&criuFlag, "criu", "", "path to criu binary")
7878
flag.BoolVar(&systemdCgroupFlag, "systemd-cgroup", false, "set runtime to use systemd-cgroup")
7979
// currently, the `containerd publish` utility is embedded in the daemon binary.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
limitations under the License.
1717
*/
1818

19-
package runc
19+
package oom
2020

2121
import (
2222
"context"
@@ -30,9 +30,9 @@ import (
3030
"golang.org/x/sys/unix"
3131
)
3232

33-
// NewOOMEpoller returns an epoll implementation that listens to OOM events
33+
// New returns an epoll implementation that listens to OOM events
3434
// from a container's cgroups.
35-
func NewOOMEpoller(publisher shim.Publisher) (*Epoller, error) {
35+
func New(publisher shim.Publisher) (*Epoller, error) {
3636
fd, err := unix.EpollCreate1(unix.EPOLL_CLOEXEC)
3737
if err != nil {
3838
return nil, err
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
limitations under the License.
1717
*/
1818

19-
package proc
19+
package process
2020

2121
import (
2222
"context"
2323

2424
"github.com/containerd/console"
2525
"github.com/containerd/containerd/errdefs"
26-
"github.com/containerd/containerd/runtime/proc"
2726
google_protobuf "github.com/gogo/protobuf/types"
2827
"github.com/pkg/errors"
2928
)
@@ -67,6 +66,6 @@ func (s *deletedState) SetExited(status int) {
6766
// no op
6867
}
6968

70-
func (s *deletedState) Exec(ctx context.Context, path string, r *ExecConfig) (proc.Process, error) {
69+
func (s *deletedState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
7170
return nil, errors.Errorf("cannot exec in a deleted state")
7271
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
limitations under the License.
1717
*/
1818

19-
package proc
19+
package process
2020

2121
import (
2222
"context"
@@ -32,7 +32,7 @@ import (
3232

3333
"github.com/containerd/console"
3434
"github.com/containerd/containerd/errdefs"
35-
"github.com/containerd/containerd/runtime/proc"
35+
"github.com/containerd/containerd/pkg/stdio"
3636
"github.com/containerd/fifo"
3737
runc "github.com/containerd/go-runc"
3838
specs "github.com/opencontainers/runtime-spec/specs-go"
@@ -53,7 +53,7 @@ type execProcess struct {
5353
pid safePid
5454
closers []io.Closer
5555
stdin io.Closer
56-
stdio proc.Stdio
56+
stdio stdio.Stdio
5757
path string
5858
spec specs.Process
5959

@@ -161,7 +161,7 @@ func (e *execProcess) Stdin() io.Closer {
161161
return e.stdin
162162
}
163163

164-
func (e *execProcess) Stdio() proc.Stdio {
164+
func (e *execProcess) Stdio() stdio.Stdio {
165165
return e.stdio
166166
}
167167

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
limitations under the License.
1717
*/
1818

19-
package proc
19+
package process
2020

2121
import (
2222
"context"
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
limitations under the License.
1717
*/
1818

19-
package proc
19+
package process
2020

2121
import (
2222
"context"
@@ -33,7 +33,7 @@ import (
3333
"github.com/containerd/console"
3434
"github.com/containerd/containerd/log"
3535
"github.com/containerd/containerd/mount"
36-
"github.com/containerd/containerd/runtime/proc"
36+
"github.com/containerd/containerd/pkg/stdio"
3737
"github.com/containerd/fifo"
3838
runc "github.com/containerd/go-runc"
3939
google_protobuf "github.com/gogo/protobuf/types"
@@ -59,15 +59,15 @@ type Init struct {
5959
id string
6060
Bundle string
6161
console console.Console
62-
Platform proc.Platform
62+
Platform stdio.Platform
6363
io *processIO
6464
runtime *runc.Runc
6565
status int
6666
exited time.Time
6767
pid safePid
6868
closers []io.Closer
6969
stdin io.Closer
70-
stdio proc.Stdio
70+
stdio stdio.Stdio
7171
Rootfs string
7272
IoUID int
7373
IoGID int
@@ -93,7 +93,7 @@ func NewRunc(root, path, namespace, runtime, criu string, systemd bool) *runc.Ru
9393
}
9494

9595
// New returns a new process
96-
func New(id string, runtime *runc.Runc, stdio proc.Stdio) *Init {
96+
func New(id string, runtime *runc.Runc, stdio stdio.Stdio) *Init {
9797
p := &Init{
9898
id: id,
9999
runtime: runtime,
@@ -381,15 +381,15 @@ func (p *Init) Runtime() *runc.Runc {
381381
}
382382

383383
// Exec returns a new child process
384-
func (p *Init) Exec(ctx context.Context, path string, r *ExecConfig) (proc.Process, error) {
384+
func (p *Init) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
385385
p.mu.Lock()
386386
defer p.mu.Unlock()
387387

388388
return p.initState.Exec(ctx, path, r)
389389
}
390390

391391
// exec returns a new exec'd process
392-
func (p *Init) exec(ctx context.Context, path string, r *ExecConfig) (proc.Process, error) {
392+
func (p *Init) exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
393393
// process exec request
394394
var spec specs.Process
395395
if err := json.Unmarshal(r.Spec.Value, &spec); err != nil {
@@ -402,7 +402,7 @@ func (p *Init) exec(ctx context.Context, path string, r *ExecConfig) (proc.Proce
402402
path: path,
403403
parent: p,
404404
spec: spec,
405-
stdio: proc.Stdio{
405+
stdio: stdio.Stdio{
406406
Stdin: r.Stdin,
407407
Stdout: r.Stdout,
408408
Stderr: r.Stderr,
@@ -468,7 +468,7 @@ func (p *Init) update(ctx context.Context, r *google_protobuf.Any) error {
468468
}
469469

470470
// Stdio of the process
471-
func (p *Init) Stdio() proc.Stdio {
471+
func (p *Init) Stdio() stdio.Stdio {
472472
return p.stdio
473473
}
474474

@@ -488,7 +488,7 @@ func (p *Init) runtimeError(rErr error, msg string) error {
488488
}
489489
}
490490

491-
func withConditionalIO(c proc.Stdio) runc.IOOpt {
491+
func withConditionalIO(c stdio.Stdio) runc.IOOpt {
492492
return func(o *runc.IOOption) {
493493
o.OpenStdin = c.Stdin != ""
494494
o.OpenStdout = c.Stdout != ""
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
limitations under the License.
1717
*/
1818

19-
package proc
19+
package process
2020

2121
import (
2222
"context"
2323

24-
"github.com/containerd/containerd/runtime/proc"
2524
runc "github.com/containerd/go-runc"
2625
google_protobuf "github.com/gogo/protobuf/types"
2726
"github.com/pkg/errors"
@@ -35,7 +34,7 @@ type initState interface {
3534
Resume(context.Context) error
3635
Update(context.Context, *google_protobuf.Any) error
3736
Checkpoint(context.Context, *CheckpointConfig) error
38-
Exec(context.Context, string, *ExecConfig) (proc.Process, error)
37+
Exec(context.Context, string, *ExecConfig) (Process, error)
3938
Kill(context.Context, uint32, bool) error
4039
SetExited(int)
4140
}
@@ -100,7 +99,7 @@ func (s *createdState) SetExited(status int) {
10099
}
101100
}
102101

103-
func (s *createdState) Exec(ctx context.Context, path string, r *ExecConfig) (proc.Process, error) {
102+
func (s *createdState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
104103
return s.p.exec(ctx, path, r)
105104
}
106105

@@ -208,7 +207,7 @@ func (s *createdCheckpointState) SetExited(status int) {
208207
}
209208
}
210209

211-
func (s *createdCheckpointState) Exec(ctx context.Context, path string, r *ExecConfig) (proc.Process, error) {
210+
func (s *createdCheckpointState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
212211
return nil, errors.Errorf("cannot exec in a created state")
213212
}
214213

@@ -268,7 +267,7 @@ func (s *runningState) SetExited(status int) {
268267
}
269268
}
270269

271-
func (s *runningState) Exec(ctx context.Context, path string, r *ExecConfig) (proc.Process, error) {
270+
func (s *runningState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
272271
return s.p.exec(ctx, path, r)
273272
}
274273

@@ -332,7 +331,7 @@ func (s *pausedState) SetExited(status int) {
332331
}
333332
}
334333

335-
func (s *pausedState) Exec(ctx context.Context, path string, r *ExecConfig) (proc.Process, error) {
334+
func (s *pausedState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
336335
return nil, errors.Errorf("cannot exec in a paused state")
337336
}
338337

@@ -385,6 +384,6 @@ func (s *stoppedState) SetExited(status int) {
385384
// no op
386385
}
387386

388-
func (s *stoppedState) Exec(ctx context.Context, path string, r *ExecConfig) (proc.Process, error) {
387+
func (s *stoppedState) Exec(ctx context.Context, path string, r *ExecConfig) (Process, error) {
389388
return nil, errors.Errorf("cannot exec in a stopped state")
390389
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
limitations under the License.
1717
*/
1818

19-
package proc
19+
package process
2020

2121
import (
2222
"context"
@@ -32,7 +32,7 @@ import (
3232

3333
"github.com/containerd/containerd/log"
3434
"github.com/containerd/containerd/namespaces"
35-
"github.com/containerd/containerd/runtime/proc"
35+
"github.com/containerd/containerd/pkg/stdio"
3636
"github.com/containerd/fifo"
3737
runc "github.com/containerd/go-runc"
3838
"github.com/pkg/errors"
@@ -50,7 +50,7 @@ type processIO struct {
5050

5151
uri *url.URL
5252
copy bool
53-
stdio proc.Stdio
53+
stdio stdio.Stdio
5454
}
5555

5656
func (p *processIO) Close() error {
@@ -76,7 +76,7 @@ func (p *processIO) Copy(ctx context.Context, wg *sync.WaitGroup) error {
7676
return nil
7777
}
7878

79-
func createIO(ctx context.Context, id string, ioUID, ioGID int, stdio proc.Stdio) (*processIO, error) {
79+
func createIO(ctx context.Context, id string, ioUID, ioGID int, stdio stdio.Stdio) (*processIO, error) {
8080
pio := &processIO{
8181
stdio: stdio,
8282
}
Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,17 @@
1414
limitations under the License.
1515
*/
1616

17-
package proc
17+
package process
1818

1919
import (
2020
"context"
2121
"io"
22-
"sync"
2322
"time"
2423

2524
"github.com/containerd/console"
25+
"github.com/containerd/containerd/pkg/stdio"
2626
)
2727

28-
// Stdio of a process
29-
type Stdio struct {
30-
Stdin string
31-
Stdout string
32-
Stderr string
33-
Terminal bool
34-
}
35-
36-
// IsNull returns true if the stdio is not defined
37-
func (s Stdio) IsNull() bool {
38-
return s.Stdin == "" && s.Stdout == "" && s.Stderr == ""
39-
}
40-
4128
// Process on a system
4229
type Process interface {
4330
// ID returns the id for the process
@@ -51,7 +38,7 @@ type Process interface {
5138
// Stdin returns the process STDIN
5239
Stdin() io.Closer
5340
// Stdio returns io information for the container
54-
Stdio() Stdio
41+
Stdio() stdio.Stdio
5542
// Status returns the process status
5643
Status(context.Context) (string, error)
5744
// Wait blocks until the process has exited
@@ -67,12 +54,3 @@ type Process interface {
6754
// SetExited sets the exit status for the process
6855
SetExited(status int)
6956
}
70-
71-
// Platform handles platform-specific behavior that may differs across
72-
// platform implementations
73-
type Platform interface {
74-
CopyConsole(ctx context.Context, console console.Console, stdin, stdout, stderr string,
75-
wg *sync.WaitGroup) (console.Console, error)
76-
ShutdownConsole(ctx context.Context, console console.Console) error
77-
Close() error
78-
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package proc
17+
package process
1818

1919
import (
2020
google_protobuf "github.com/gogo/protobuf/types"

0 commit comments

Comments
 (0)