Comment more packages to pass go lint

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-10-02 11:50:18 -04:00
parent 33e974ce99
commit 451421b615
54 changed files with 255 additions and 121 deletions

View File

@@ -15,6 +15,7 @@ import (
"github.com/pkg/errors"
)
// loadBundle loads an existing bundle from disk
func loadBundle(id, path, workdir string) *bundle {
return &bundle{
id: id,
@@ -71,6 +72,7 @@ type bundle struct {
type shimOpt func(*bundle, string, *runcopts.RuncOptions) (client.Config, client.ClientOpt)
// ShimRemote is a shimOpt for connecting and starting a remote shim
func ShimRemote(shim, daemonAddress, cgroup string, debug bool, exitHandler func()) shimOpt {
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
return b.shimConfig(ns, ropts),
@@ -78,12 +80,14 @@ func ShimRemote(shim, daemonAddress, cgroup string, debug bool, exitHandler func
}
}
// ShimLocal is a shimOpt for using an in process shim implementation
func ShimLocal(exchange *events.Exchange) shimOpt {
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
return b.shimConfig(ns, ropts), client.WithLocal(exchange)
}
}
// ShimConnect is a shimOpt for connecting to an existing remote shim
func ShimConnect() shimOpt {
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))

View File

@@ -11,15 +11,20 @@ import (
"github.com/containerd/containerd/runtime"
)
// Process implements a linux process
type Process struct {
id string
t *Task
}
// ID of the process
func (p *Process) ID() string {
return p.id
}
// Kill sends the provided signal to the underlying process
//
// Unable to kill all processes in the task using this method on a process
func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
_, err := p.t.shim.Kill(ctx, &shim.KillRequest{
Signal: signal,
@@ -31,6 +36,7 @@ func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
return err
}
// State of process
func (p *Process) State(ctx context.Context) (runtime.State, error) {
// use the container status for the status of the process
response, err := p.t.shim.State(ctx, &shim.StateRequest{
@@ -63,6 +69,7 @@ func (p *Process) State(ctx context.Context) (runtime.State, error) {
}, nil
}
// ResizePty changes the side of the process's PTY to the provided width and height
func (p *Process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
_, err := p.t.shim.ResizePty(ctx, &shim.ResizePtyRequest{
ID: p.id,
@@ -75,6 +82,7 @@ func (p *Process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error
return err
}
// CloseIO closes the provided IO pipe for the process
func (p *Process) CloseIO(ctx context.Context) error {
_, err := p.t.shim.CloseIO(ctx, &shim.CloseIORequest{
ID: p.id,
@@ -86,6 +94,7 @@ func (p *Process) CloseIO(ctx context.Context) error {
return nil
}
// Start the process
func (p *Process) Start(ctx context.Context) error {
_, err := p.t.shim.Start(ctx, &shim.StartRequest{
ID: p.id,
@@ -96,6 +105,7 @@ func (p *Process) Start(ctx context.Context) error {
return nil
}
// Wait on the process to exit and return the exit status and timestamp
func (p *Process) Wait(ctx context.Context) (*runtime.Exit, error) {
r, err := p.t.shim.Wait(ctx, &shim.WaitRequest{
ID: p.id,

View File

@@ -52,7 +52,7 @@ func init() {
Type: plugin.RuntimePlugin,
ID: "linux",
Init: New,
Requires: []plugin.PluginType{
Requires: []plugin.Type{
plugin.TaskMonitorPlugin,
plugin.MetadataPlugin,
},
@@ -65,6 +65,7 @@ func init() {
var _ = (runtime.Runtime)(&Runtime{})
// Config options for the runtime
type Config struct {
// Shim is a path or name of binary implementing the Shim GRPC API
Shim string `toml:"shim"`
@@ -78,6 +79,7 @@ type Config struct {
ShimDebug bool `toml:"shim_debug"`
}
// New returns a configured runtime
func New(ic *plugin.InitContext) (interface{}, error) {
if err := os.MkdirAll(ic.Root, 0711); err != nil {
return nil, err
@@ -117,6 +119,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
return r, nil
}
// Runtime for a linux based system
type Runtime struct {
root string
state string
@@ -130,10 +133,12 @@ type Runtime struct {
config *Config
}
// ID of the runtime
func (r *Runtime) ID() string {
return pluginID
}
// Create a new task
func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts) (_ runtime.Task, err error) {
namespace, err := namespaces.NamespaceRequired(ctx)
if err != nil {
@@ -265,6 +270,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
return t, nil
}
// Delete a task removing all on disk state
func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, error) {
namespace, err := namespaces.NamespaceRequired(ctx)
if err != nil {
@@ -305,6 +311,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er
}, nil
}
// Tasks returns all tasks known to the runtime
func (r *Runtime) Tasks(ctx context.Context) ([]runtime.Task, error) {
return r.tasks.GetAll(ctx)
}
@@ -330,6 +337,7 @@ func (r *Runtime) restoreTasks(ctx context.Context) ([]*Task, error) {
return o, nil
}
// Get a specific task by task id
func (r *Runtime) Get(ctx context.Context, id string) (runtime.Task, error) {
return r.tasks.Get(ctx, id)
}
@@ -491,6 +499,5 @@ func (r *Runtime) getRuncOptions(ctx context.Context, id string) (*runcopts.Runc
return ropts, nil
}
return nil, nil
}

View File

@@ -27,6 +27,7 @@ import (
"google.golang.org/grpc"
)
// ClientOpt is an option for a shim client configuration
type ClientOpt func(context.Context, Config) (shim.ShimClient, io.Closer, error)
// WithStart executes a new shim process
@@ -180,6 +181,7 @@ func WithLocal(publisher events.Publisher) func(context.Context, Config) (shim.S
}
}
// Config contains shim specific configuration
type Config struct {
Path string
Namespace string
@@ -202,6 +204,7 @@ func New(ctx context.Context, config Config, opt ClientOpt) (*Client, error) {
}, nil
}
// Client is a shim client containing the connection to a shim
type Client struct {
shim.ShimClient
@@ -233,6 +236,7 @@ func (c *Client) KillShim(ctx context.Context) error {
return c.signalShim(ctx, unix.SIGKILL)
}
// Close the cient connection
func (c *Client) Close() error {
if c.c == nil {
return nil

View File

@@ -27,6 +27,7 @@ import (
"github.com/pkg/errors"
)
// InitPidFile name of the file that contains the init pid
const InitPidFile = "init.pid"
type initProcess struct {

View File

@@ -29,6 +29,7 @@ import (
var empty = &google_protobuf.Empty{}
// RuncRoot is the path to the root runc state directory
const RuncRoot = "/run/containerd/runc"
// NewService returns a new shim service that can be used via GRPC
@@ -65,6 +66,7 @@ type platform interface {
close() error
}
// Service is the shim implementation of a remote shim over GRPC
type Service struct {
mu sync.Mutex
@@ -80,6 +82,7 @@ type Service struct {
bundle string
}
// Create a new initial process and container with the underlying OCI runtime
func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*shimapi.CreateTaskResponse, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -110,6 +113,7 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*sh
}, nil
}
// Start a process
func (s *Service) Start(ctx context.Context, r *shimapi.StartRequest) (*shimapi.StartResponse, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -139,6 +143,7 @@ func (s *Service) Start(ctx context.Context, r *shimapi.StartRequest) (*shimapi.
}, nil
}
// Delete the initial process and container
func (s *Service) Delete(ctx context.Context, r *google_protobuf.Empty) (*shimapi.DeleteResponse, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -165,6 +170,7 @@ func (s *Service) Delete(ctx context.Context, r *google_protobuf.Empty) (*shimap
}, nil
}
// DeleteProcess deletes an exec'd process
func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessRequest) (*shimapi.DeleteResponse, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -186,6 +192,7 @@ func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessReq
}, nil
}
// Exec an additional process inside the container
func (s *Service) Exec(ctx context.Context, r *shimapi.ExecProcessRequest) (*google_protobuf.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -212,6 +219,7 @@ func (s *Service) Exec(ctx context.Context, r *shimapi.ExecProcessRequest) (*goo
return empty, nil
}
// ResizePty of a process
func (s *Service) ResizePty(ctx context.Context, r *shimapi.ResizePtyRequest) (*google_protobuf.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -232,6 +240,7 @@ func (s *Service) ResizePty(ctx context.Context, r *shimapi.ResizePtyRequest) (*
return empty, nil
}
// State returns runtime state information for a process
func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.StateResponse, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -271,6 +280,7 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.
}, nil
}
// Pause the container
func (s *Service) Pause(ctx context.Context, r *google_protobuf.Empty) (*google_protobuf.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -287,6 +297,7 @@ func (s *Service) Pause(ctx context.Context, r *google_protobuf.Empty) (*google_
return empty, nil
}
// Resume the container
func (s *Service) Resume(ctx context.Context, r *google_protobuf.Empty) (*google_protobuf.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -303,6 +314,7 @@ func (s *Service) Resume(ctx context.Context, r *google_protobuf.Empty) (*google
return empty, nil
}
// Kill a process with the provided signal
func (s *Service) Kill(ctx context.Context, r *shimapi.KillRequest) (*google_protobuf.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -327,6 +339,7 @@ func (s *Service) Kill(ctx context.Context, r *shimapi.KillRequest) (*google_pro
return empty, nil
}
// ListPids returns all pids inside the container
func (s *Service) ListPids(ctx context.Context, r *shimapi.ListPidsRequest) (*shimapi.ListPidsResponse, error) {
pids, err := s.getContainerPids(ctx, r.ID)
if err != nil {
@@ -337,6 +350,7 @@ func (s *Service) ListPids(ctx context.Context, r *shimapi.ListPidsRequest) (*sh
}, nil
}
// CloseIO of a process
func (s *Service) CloseIO(ctx context.Context, r *shimapi.CloseIORequest) (*google_protobuf.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -352,6 +366,7 @@ func (s *Service) CloseIO(ctx context.Context, r *shimapi.CloseIORequest) (*goog
return empty, nil
}
// Checkpoint the container
func (s *Service) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) (*google_protobuf.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -368,12 +383,14 @@ func (s *Service) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskReque
return empty, nil
}
// ShimInfo returns shim information such as the shim's pid
func (s *Service) ShimInfo(ctx context.Context, r *google_protobuf.Empty) (*shimapi.ShimInfoResponse, error) {
return &shimapi.ShimInfoResponse{
ShimPid: uint32(os.Getpid()),
}, nil
}
// Update a running container
func (s *Service) Update(ctx context.Context, r *shimapi.UpdateTaskRequest) (*google_protobuf.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -387,6 +404,7 @@ func (s *Service) Update(ctx context.Context, r *shimapi.UpdateTaskRequest) (*go
return empty, nil
}
// Wait for a process to exit
func (s *Service) Wait(ctx context.Context, r *shimapi.WaitRequest) (*shimapi.WaitResponse, error) {
s.mu.Lock()
p := s.processes[r.ID]

View File

@@ -16,6 +16,7 @@ import (
"github.com/gogo/protobuf/types"
)
// Task on a linux based system
type Task struct {
id string
pid int
@@ -45,10 +46,12 @@ func newTask(id, namespace string, pid int, shim *client.Client, monitor runtime
}, nil
}
// ID of the task
func (t *Task) ID() string {
return t.id
}
// Info returns task information about the runtime and namespace
func (t *Task) Info() runtime.TaskInfo {
return runtime.TaskInfo{
ID: t.id,
@@ -57,6 +60,7 @@ func (t *Task) Info() runtime.TaskInfo {
}
}
// Start the task
func (t *Task) Start(ctx context.Context) error {
hasCgroup := t.cg != nil
r, err := t.shim.Start(ctx, &shim.StartRequest{
@@ -79,6 +83,7 @@ func (t *Task) Start(ctx context.Context) error {
return nil
}
// State returns runtime information for the task
func (t *Task) State(ctx context.Context) (runtime.State, error) {
response, err := t.shim.State(ctx, &shim.StateRequest{
ID: t.id,
@@ -114,6 +119,7 @@ func (t *Task) State(ctx context.Context) (runtime.State, error) {
}, nil
}
// Pause the task and all processes
func (t *Task) Pause(ctx context.Context) error {
_, err := t.shim.Pause(ctx, empty)
if err != nil {
@@ -122,6 +128,7 @@ func (t *Task) Pause(ctx context.Context) error {
return err
}
// Resume the task and all processes
func (t *Task) Resume(ctx context.Context) error {
if _, err := t.shim.Resume(ctx, empty); err != nil {
return errdefs.FromGRPC(err)
@@ -129,6 +136,9 @@ func (t *Task) Resume(ctx context.Context) error {
return nil
}
// Kill the task using the provided signal
//
// Optionally send the signal to all processes that are a child of the task
func (t *Task) Kill(ctx context.Context, signal uint32, all bool) error {
if _, err := t.shim.Kill(ctx, &shim.KillRequest{
ID: t.id,
@@ -140,6 +150,7 @@ func (t *Task) Kill(ctx context.Context, signal uint32, all bool) error {
return nil
}
// Exec creates a new process inside the task
func (t *Task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) {
request := &shim.ExecProcessRequest{
ID: id,
@@ -158,6 +169,7 @@ func (t *Task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runt
}, nil
}
// Pids returns all system level process ids running inside the task
func (t *Task) Pids(ctx context.Context) ([]uint32, error) {
resp, err := t.shim.ListPids(ctx, &shim.ListPidsRequest{
ID: t.id,
@@ -168,6 +180,7 @@ func (t *Task) Pids(ctx context.Context) ([]uint32, error) {
return resp.Pids, nil
}
// ResizePty changes the side of the task's PTY to the provided width and height
func (t *Task) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
_, err := t.shim.ResizePty(ctx, &shim.ResizePtyRequest{
ID: t.id,
@@ -180,6 +193,7 @@ func (t *Task) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
return err
}
// CloseIO closes the provided IO on the task
func (t *Task) CloseIO(ctx context.Context) error {
_, err := t.shim.CloseIO(ctx, &shim.CloseIORequest{
ID: t.id,
@@ -191,6 +205,7 @@ func (t *Task) CloseIO(ctx context.Context) error {
return err
}
// Checkpoint creates a system level dump of the task and process information that can be later restored
func (t *Task) Checkpoint(ctx context.Context, path string, options *types.Any) error {
r := &shim.CheckpointTaskRequest{
Path: path,
@@ -202,6 +217,7 @@ func (t *Task) Checkpoint(ctx context.Context, path string, options *types.Any)
return nil
}
// DeleteProcess removes the provided process from the task and deletes all on disk state
func (t *Task) DeleteProcess(ctx context.Context, id string) (*runtime.Exit, error) {
r, err := t.shim.DeleteProcess(ctx, &shim.DeleteProcessRequest{
ID: id,
@@ -216,6 +232,7 @@ func (t *Task) DeleteProcess(ctx context.Context, id string) (*runtime.Exit, err
}, nil
}
// Update changes runtime information of a running task
func (t *Task) Update(ctx context.Context, resources *types.Any) error {
if _, err := t.shim.Update(ctx, &shim.UpdateTaskRequest{
Resources: resources,
@@ -225,6 +242,7 @@ func (t *Task) Update(ctx context.Context, resources *types.Any) error {
return nil
}
// Process returns a specific process inside the task by the process id
func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error) {
// TODO: verify process exists for container
return &Process{
@@ -233,6 +251,7 @@ func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error)
}, nil
}
// Metrics returns runtime specific system level metric information for the task
func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
stats, err := t.cg.Stat(cgroups.IgnoreNotExist)
if err != nil {
@@ -241,10 +260,12 @@ func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
return stats, nil
}
// Cgroup returns the underlying cgroup for a linux task
func (t *Task) Cgroup() cgroups.Cgroup {
return t.cg
}
// Wait for the task to exit returning the status and timestamp
func (t *Task) Wait(ctx context.Context) (*runtime.Exit, error) {
r, err := t.shim.Wait(ctx, &shim.WaitRequest{
ID: t.id,