Remove errdefs and shimapi types from proc package

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-11-09 16:47:55 -05:00
parent 9abde39bf7
commit c81788b129
7 changed files with 87 additions and 29 deletions

View File

@@ -6,7 +6,7 @@ import (
"context"
"github.com/containerd/console"
shimapi "github.com/containerd/containerd/linux/shim/v1"
google_protobuf "github.com/gogo/protobuf/types"
"github.com/pkg/errors"
)
@@ -21,11 +21,11 @@ func (s *deletedState) Resume(ctx context.Context) error {
return errors.Errorf("cannot resume a deleted process")
}
func (s *deletedState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
func (s *deletedState) Update(context context.Context, r *google_protobuf.Any) error {
return errors.Errorf("cannot update a deleted process")
}
func (s *deletedState) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) error {
func (s *deletedState) Checkpoint(ctx context.Context, r *CheckpointConfig) error {
return errors.Errorf("cannot checkpoint a deleted process")
}

View File

@@ -16,12 +16,12 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd/linux/runctypes"
shimapi "github.com/containerd/containerd/linux/shim/v1"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount"
"github.com/containerd/fifo"
runc "github.com/containerd/go-runc"
"github.com/containerd/typeurl"
google_protobuf "github.com/gogo/protobuf/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)
@@ -78,7 +78,7 @@ func NewRunc(root, path, namespace, runtime, criu string, systemd bool) *runc.Ru
}
// 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 *CreateConfig) (*Init, error) {
var success bool
var options runctypes.CreateOptions
@@ -347,7 +347,7 @@ func (p *Init) Runtime() *runc.Runc {
}
// 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 *ExecConfig) (Process, error) {
// process exec request
var spec specs.Process
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
return e, nil
}
func (p *Init) checkpoint(context context.Context, r *shimapi.CheckpointTaskRequest) error {
func (p *Init) checkpoint(context context.Context, r *CheckpointConfig) error {
var options runctypes.CheckpointOptions
if r.Options != nil {
v, err := typeurl.UnmarshalAny(r.Options)
@@ -405,9 +405,9 @@ func (p *Init) checkpoint(context context.Context, r *shimapi.CheckpointTaskRequ
return nil
}
func (p *Init) update(context context.Context, r *shimapi.UpdateTaskRequest) error {
func (p *Init) update(context context.Context, r *google_protobuf.Any) error {
var resources specs.LinuxResources
if err := json.Unmarshal(r.Resources.Value, &resources); err != nil {
if err := json.Unmarshal(r.Value, &resources); err != nil {
return err
}
return p.runtime.Update(context, p.id, &resources)

View File

@@ -9,9 +9,9 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd/errdefs"
shimapi "github.com/containerd/containerd/linux/shim/v1"
"github.com/containerd/fifo"
runc "github.com/containerd/go-runc"
google_protobuf "github.com/gogo/protobuf/types"
"github.com/pkg/errors"
)
@@ -20,8 +20,8 @@ type initState interface {
Pause(context.Context) error
Resume(context.Context) error
Update(context.Context, *shimapi.UpdateTaskRequest) error
Checkpoint(context.Context, *shimapi.CheckpointTaskRequest) error
Update(context.Context, *google_protobuf.Any) error
Checkpoint(context.Context, *CheckpointConfig) error
}
type createdState struct {
@@ -56,14 +56,14 @@ func (s *createdState) Resume(ctx context.Context) error {
return errors.Errorf("cannot resume task in created state")
}
func (s *createdState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
func (s *createdState) Update(context context.Context, r *google_protobuf.Any) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
return s.p.update(context, r)
}
func (s *createdState) Checkpoint(context context.Context, r *shimapi.CheckpointTaskRequest) error {
func (s *createdState) Checkpoint(context context.Context, r *CheckpointConfig) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
@@ -146,14 +146,14 @@ func (s *createdCheckpointState) Resume(ctx context.Context) error {
return errors.Errorf("cannot resume task in created state")
}
func (s *createdCheckpointState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
func (s *createdCheckpointState) Update(context context.Context, r *google_protobuf.Any) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
return s.p.update(context, r)
}
func (s *createdCheckpointState) Checkpoint(context context.Context, r *shimapi.CheckpointTaskRequest) error {
func (s *createdCheckpointState) Checkpoint(context context.Context, r *CheckpointConfig) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
@@ -259,14 +259,14 @@ func (s *runningState) Resume(ctx context.Context) error {
return errors.Errorf("cannot resume a running process")
}
func (s *runningState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
func (s *runningState) Update(context context.Context, r *google_protobuf.Any) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
return s.p.update(context, r)
}
func (s *runningState) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) error {
func (s *runningState) Checkpoint(ctx context.Context, r *CheckpointConfig) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
@@ -345,14 +345,14 @@ func (s *pausedState) Resume(ctx context.Context) error {
return s.transition("running")
}
func (s *pausedState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
func (s *pausedState) Update(context context.Context, r *google_protobuf.Any) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
return s.p.update(context, r)
}
func (s *pausedState) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) error {
func (s *pausedState) Checkpoint(ctx context.Context, r *CheckpointConfig) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
@@ -427,14 +427,14 @@ func (s *stoppedState) Resume(ctx context.Context) error {
return errors.Errorf("cannot resume a stopped container")
}
func (s *stoppedState) Update(context context.Context, r *shimapi.UpdateTaskRequest) error {
func (s *stoppedState) Update(context context.Context, r *google_protobuf.Any) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
return errors.Errorf("cannot update a stopped container")
}
func (s *stoppedState) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) error {
func (s *stoppedState) Checkpoint(ctx context.Context, r *CheckpointConfig) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()

37
linux/proc/types.go Normal file
View File

@@ -0,0 +1,37 @@
package proc
import (
containerd_types "github.com/containerd/containerd/api/types"
google_protobuf "github.com/gogo/protobuf/types"
)
// CreateConfig hold task creation configuration
type CreateConfig struct {
ID string
Bundle string
Runtime string
Rootfs []*containerd_types.Mount
Terminal bool
Stdin string
Stdout string
Stderr string
Checkpoint string
ParentCheckpoint string
Options *google_protobuf.Any
}
// ExecConfig holds exec creation configuration
type ExecConfig struct {
ID string
Terminal bool
Stdin string
Stdout string
Stderr string
Spec *google_protobuf.Any
}
// CheckpointConfig holds task checkpoint configuration
type CheckpointConfig struct {
Path string
Options *google_protobuf.Any
}

View File

@@ -10,7 +10,6 @@ import (
"time"
"github.com/containerd/containerd/errdefs"
shimapi "github.com/containerd/containerd/linux/shim/v1"
runc "github.com/containerd/go-runc"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
@@ -81,6 +80,6 @@ func checkKillError(err error) error {
return errors.Wrapf(err, "unknown error after kill")
}
func hasNoIO(r *shimapi.CreateTaskRequest) bool {
func hasNoIO(r *CreateConfig) bool {
return r.Stdin == "" && r.Stdout == "" && r.Stderr == ""
}