X Tutup
Skip to content

Commit c81788b

Browse files
committed
Remove errdefs and shimapi types from proc package
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent 9abde39 commit c81788b

File tree

7 files changed

+87
-29
lines changed

7 files changed

+87
-29
lines changed

linux/proc/deleted_state.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"context"
77

88
"github.com/containerd/console"
9-
shimapi "github.com/containerd/containerd/linux/shim/v1"
9+
google_protobuf "github.com/gogo/protobuf/types"
1010
"github.com/pkg/errors"
1111
)
1212

@@ -21,11 +21,11 @@ func (s *deletedState) Resume(ctx context.Context) error {
2121
return errors.Errorf("cannot resume a deleted process")
2222
}
2323

24-
func (s *deletedState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
24+
func (s *deletedState) Update(context context.Context, r *google_protobuf.Any) error {
2525
return errors.Errorf("cannot update a deleted process")
2626
}
2727

28-
func (s *deletedState) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) error {
28+
func (s *deletedState) Checkpoint(ctx context.Context, r *CheckpointConfig) error {
2929
return errors.Errorf("cannot checkpoint a deleted process")
3030
}
3131

linux/proc/init.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import (
1616

1717
"github.com/containerd/console"
1818
"github.com/containerd/containerd/linux/runctypes"
19-
shimapi "github.com/containerd/containerd/linux/shim/v1"
2019
"github.com/containerd/containerd/log"
2120
"github.com/containerd/containerd/mount"
2221
"github.com/containerd/fifo"
2322
runc "github.com/containerd/go-runc"
2423
"github.com/containerd/typeurl"
24+
google_protobuf "github.com/gogo/protobuf/types"
2525
specs "github.com/opencontainers/runtime-spec/specs-go"
2626
"github.com/pkg/errors"
2727
)
@@ -78,7 +78,7 @@ func NewRunc(root, path, namespace, runtime, criu string, systemd bool) *runc.Ru
7878
}
7979

8080
// New returns a new init process
81-
func New(context context.Context, path, workDir, runtimeRoot, namespace, criu string, systemdCgroup bool, platform Platform, r *shimapi.CreateTaskRequest) (*Init, error) {
81+
func New(context context.Context, path, workDir, runtimeRoot, namespace, criu string, systemdCgroup bool, platform Platform, r *CreateConfig) (*Init, error) {
8282
var success bool
8383

8484
var options runctypes.CreateOptions
@@ -347,7 +347,7 @@ func (p *Init) Runtime() *runc.Runc {
347347
}
348348

349349
// Exec returns a new exec'd process
350-
func (p *Init) Exec(context context.Context, path string, r *shimapi.ExecProcessRequest) (Process, error) {
350+
func (p *Init) Exec(context context.Context, path string, r *ExecConfig) (Process, error) {
351351
// process exec request
352352
var spec specs.Process
353353
if err := json.Unmarshal(r.Spec.Value, &spec); err != nil {
@@ -372,7 +372,7 @@ func (p *Init) Exec(context context.Context, path string, r *shimapi.ExecProcess
372372
return e, nil
373373
}
374374

375-
func (p *Init) checkpoint(context context.Context, r *shimapi.CheckpointTaskRequest) error {
375+
func (p *Init) checkpoint(context context.Context, r *CheckpointConfig) error {
376376
var options runctypes.CheckpointOptions
377377
if r.Options != nil {
378378
v, err := typeurl.UnmarshalAny(r.Options)
@@ -405,9 +405,9 @@ func (p *Init) checkpoint(context context.Context, r *shimapi.CheckpointTaskRequ
405405
return nil
406406
}
407407

408-
func (p *Init) update(context context.Context, r *shimapi.UpdateTaskRequest) error {
408+
func (p *Init) update(context context.Context, r *google_protobuf.Any) error {
409409
var resources specs.LinuxResources
410-
if err := json.Unmarshal(r.Resources.Value, &resources); err != nil {
410+
if err := json.Unmarshal(r.Value, &resources); err != nil {
411411
return err
412412
}
413413
return p.runtime.Update(context, p.id, &resources)

linux/proc/init_state.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
"github.com/containerd/console"
1111
"github.com/containerd/containerd/errdefs"
12-
shimapi "github.com/containerd/containerd/linux/shim/v1"
1312
"github.com/containerd/fifo"
1413
runc "github.com/containerd/go-runc"
14+
google_protobuf "github.com/gogo/protobuf/types"
1515
"github.com/pkg/errors"
1616
)
1717

@@ -20,8 +20,8 @@ type initState interface {
2020

2121
Pause(context.Context) error
2222
Resume(context.Context) error
23-
Update(context.Context, *shimapi.UpdateTaskRequest) error
24-
Checkpoint(context.Context, *shimapi.CheckpointTaskRequest) error
23+
Update(context.Context, *google_protobuf.Any) error
24+
Checkpoint(context.Context, *CheckpointConfig) error
2525
}
2626

2727
type createdState struct {
@@ -56,14 +56,14 @@ func (s *createdState) Resume(ctx context.Context) error {
5656
return errors.Errorf("cannot resume task in created state")
5757
}
5858

59-
func (s *createdState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
59+
func (s *createdState) Update(context context.Context, r *google_protobuf.Any) error {
6060
s.p.mu.Lock()
6161
defer s.p.mu.Unlock()
6262

6363
return s.p.update(context, r)
6464
}
6565

66-
func (s *createdState) Checkpoint(context context.Context, r *shimapi.CheckpointTaskRequest) error {
66+
func (s *createdState) Checkpoint(context context.Context, r *CheckpointConfig) error {
6767
s.p.mu.Lock()
6868
defer s.p.mu.Unlock()
6969

@@ -146,14 +146,14 @@ func (s *createdCheckpointState) Resume(ctx context.Context) error {
146146
return errors.Errorf("cannot resume task in created state")
147147
}
148148

149-
func (s *createdCheckpointState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
149+
func (s *createdCheckpointState) Update(context context.Context, r *google_protobuf.Any) error {
150150
s.p.mu.Lock()
151151
defer s.p.mu.Unlock()
152152

153153
return s.p.update(context, r)
154154
}
155155

156-
func (s *createdCheckpointState) Checkpoint(context context.Context, r *shimapi.CheckpointTaskRequest) error {
156+
func (s *createdCheckpointState) Checkpoint(context context.Context, r *CheckpointConfig) error {
157157
s.p.mu.Lock()
158158
defer s.p.mu.Unlock()
159159

@@ -259,14 +259,14 @@ func (s *runningState) Resume(ctx context.Context) error {
259259
return errors.Errorf("cannot resume a running process")
260260
}
261261

262-
func (s *runningState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
262+
func (s *runningState) Update(context context.Context, r *google_protobuf.Any) error {
263263
s.p.mu.Lock()
264264
defer s.p.mu.Unlock()
265265

266266
return s.p.update(context, r)
267267
}
268268

269-
func (s *runningState) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) error {
269+
func (s *runningState) Checkpoint(ctx context.Context, r *CheckpointConfig) error {
270270
s.p.mu.Lock()
271271
defer s.p.mu.Unlock()
272272

@@ -345,14 +345,14 @@ func (s *pausedState) Resume(ctx context.Context) error {
345345
return s.transition("running")
346346
}
347347

348-
func (s *pausedState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
348+
func (s *pausedState) Update(context context.Context, r *google_protobuf.Any) error {
349349
s.p.mu.Lock()
350350
defer s.p.mu.Unlock()
351351

352352
return s.p.update(context, r)
353353
}
354354

355-
func (s *pausedState) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) error {
355+
func (s *pausedState) Checkpoint(ctx context.Context, r *CheckpointConfig) error {
356356
s.p.mu.Lock()
357357
defer s.p.mu.Unlock()
358358

@@ -427,14 +427,14 @@ func (s *stoppedState) Resume(ctx context.Context) error {
427427
return errors.Errorf("cannot resume a stopped container")
428428
}
429429

430-
func (s *stoppedState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
430+
func (s *stoppedState) Update(context context.Context, r *google_protobuf.Any) error {
431431
s.p.mu.Lock()
432432
defer s.p.mu.Unlock()
433433

434434
return errors.Errorf("cannot update a stopped container")
435435
}
436436

437-
func (s *stoppedState) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) error {
437+
func (s *stoppedState) Checkpoint(ctx context.Context, r *CheckpointConfig) error {
438438
s.p.mu.Lock()
439439
defer s.p.mu.Unlock()
440440

linux/proc/types.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package proc
2+
3+
import (
4+
containerd_types "github.com/containerd/containerd/api/types"
5+
google_protobuf "github.com/gogo/protobuf/types"
6+
)
7+
8+
// CreateConfig hold task creation configuration
9+
type CreateConfig struct {
10+
ID string
11+
Bundle string
12+
Runtime string
13+
Rootfs []*containerd_types.Mount
14+
Terminal bool
15+
Stdin string
16+
Stdout string
17+
Stderr string
18+
Checkpoint string
19+
ParentCheckpoint string
20+
Options *google_protobuf.Any
21+
}
22+
23+
// ExecConfig holds exec creation configuration
24+
type ExecConfig struct {
25+
ID string
26+
Terminal bool
27+
Stdin string
28+
Stdout string
29+
Stderr string
30+
Spec *google_protobuf.Any
31+
}
32+
33+
// CheckpointConfig holds task checkpoint configuration
34+
type CheckpointConfig struct {
35+
Path string
36+
Options *google_protobuf.Any
37+
}

linux/proc/utils.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/containerd/containerd/errdefs"
13-
shimapi "github.com/containerd/containerd/linux/shim/v1"
1413
runc "github.com/containerd/go-runc"
1514
"github.com/pkg/errors"
1615
"golang.org/x/sys/unix"
@@ -81,6 +80,6 @@ func checkKillError(err error) error {
8180
return errors.Wrapf(err, "unknown error after kill")
8281
}
8382

84-
func hasNoIO(r *shimapi.CreateTaskRequest) bool {
83+
func hasNoIO(r *CreateConfig) bool {
8584
return r.Stdin == "" && r.Stdout == "" && r.Stderr == ""
8685
}

linux/shim/service.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,19 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*sh
9696
s.config.Criu,
9797
s.config.SystemdCgroup,
9898
s.platform,
99-
r,
99+
&proc.CreateConfig{
100+
ID: r.ID,
101+
Bundle: r.Bundle,
102+
Runtime: r.Runtime,
103+
Rootfs: r.Rootfs,
104+
Terminal: r.Terminal,
105+
Stdin: r.Stdin,
106+
Stdout: r.Stdout,
107+
Stderr: r.Stderr,
108+
Checkpoint: r.Checkpoint,
109+
ParentCheckpoint: r.ParentCheckpoint,
110+
Options: r.Options,
111+
},
100112
)
101113
if err != nil {
102114
return nil, errdefs.ToGRPC(err)
@@ -185,7 +197,14 @@ func (s *Service) Exec(ctx context.Context, r *shimapi.ExecProcessRequest) (*goo
185197
return nil, errdefs.ToGRPCf(errdefs.ErrFailedPrecondition, "container must be created")
186198
}
187199

188-
process, err := p.(*proc.Init).Exec(ctx, s.config.Path, r)
200+
process, err := p.(*proc.Init).Exec(ctx, s.config.Path, &proc.ExecConfig{
201+
ID: r.ID,
202+
Terminal: r.Terminal,
203+
Stdin: r.Stdin,
204+
Stdout: r.Stdout,
205+
Stderr: r.Stderr,
206+
Spec: r.Spec,
207+
})
189208
if err != nil {
190209
return nil, errdefs.ToGRPC(err)
191210
}
@@ -362,7 +381,10 @@ func (s *Service) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskReque
362381
if p == nil {
363382
return nil, errdefs.ToGRPCf(errdefs.ErrFailedPrecondition, "container must be created")
364383
}
365-
if err := p.(*proc.Init).Checkpoint(ctx, r); err != nil {
384+
if err := p.(*proc.Init).Checkpoint(ctx, &proc.CheckpointConfig{
385+
Path: r.Path,
386+
Options: r.Options,
387+
}); err != nil {
366388
return nil, errdefs.ToGRPC(err)
367389
}
368390
return empty, nil
@@ -383,7 +405,7 @@ func (s *Service) Update(ctx context.Context, r *shimapi.UpdateTaskRequest) (*go
383405
if p == nil {
384406
return nil, errdefs.ToGRPCf(errdefs.ErrFailedPrecondition, "container must be created")
385407
}
386-
if err := p.(*proc.Init).Update(ctx, r); err != nil {
408+
if err := p.(*proc.Init).Update(ctx, r.Resources); err != nil {
387409
return nil, errdefs.ToGRPC(err)
388410
}
389411
return empty, nil

linux/shim/service_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
package shim
44

55
import (
6+
"context"
67
"io"
78
"sync"
89
"syscall"
910

1011
"github.com/containerd/console"
1112
"github.com/containerd/fifo"
12-
"golang.org/x/net/context"
1313
)
1414

1515
type unixPlatform struct {

0 commit comments

Comments
 (0)
X Tutup