Add comments and fix common lint issues

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-10-20 11:46:19 -04:00
parent 9bd1dc78cb
commit 5fd0415985
15 changed files with 60 additions and 38 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/gogo/protobuf/types"
)
// TaskInfo provides task specific information
type TaskInfo struct {
ID string
Runtime string
@@ -14,6 +15,7 @@ type TaskInfo struct {
Namespace string
}
// Process is a runtime object for an executing process inside a container
type Process interface {
ID() string
// State returns the process state
@@ -30,6 +32,7 @@ type Process interface {
Wait(context.Context) (*Exit, error)
}
// Task is the runtime object for an executing container
type Task interface {
Process
@@ -55,27 +58,37 @@ type Task interface {
Metrics(context.Context) (interface{}, error)
}
// ExecOpts provides additional options for additional processes running in a task
type ExecOpts struct {
Spec *types.Any
IO IO
}
// ConsoleSize of a pty or windows terminal
type ConsoleSize struct {
Width uint32
Height uint32
}
// Status is the runtime status of a task and/or process
type Status int
const (
// CreatedStatus when a process has been created
CreatedStatus Status = iota + 1
// RunningStatus when a process is running
RunningStatus
// StoppedStatus when a process has stopped
StoppedStatus
// DeletedStatus when a process has been deleted
DeletedStatus
// PausedStatus when a process is paused
PausedStatus
// PausingStatus when a process is currently pausing
PausingStatus
)
// State information for a process
type State struct {
// Status is the current status of the container
Status Status
@@ -93,6 +106,7 @@ type State struct {
Terminal bool
}
// ProcessInfo holds platform specific process information
type ProcessInfo struct {
// Pid is the process ID
Pid uint32

View File

@@ -9,21 +9,26 @@ import (
)
var (
ErrTaskNotExists = errors.New("task does not exist")
// ErrTaskNotExists is returned when a task does not exist
ErrTaskNotExists = errors.New("task does not exist")
// ErrTaskAlreadyExists is returned when a task already exists
ErrTaskAlreadyExists = errors.New("task already exists")
)
// NewTaskList returns a new TaskList
func NewTaskList() *TaskList {
return &TaskList{
tasks: make(map[string]map[string]Task),
}
}
// TaskList holds and provides locking around tasks
type TaskList struct {
mu sync.Mutex
tasks map[string]map[string]Task
}
// Get a task
func (l *TaskList) Get(ctx context.Context, id string) (Task, error) {
l.mu.Lock()
defer l.mu.Unlock()
@@ -42,6 +47,7 @@ func (l *TaskList) Get(ctx context.Context, id string) (Task, error) {
return t, nil
}
// GetAll tasks under a namespace
func (l *TaskList) GetAll(ctx context.Context) ([]Task, error) {
namespace, err := namespaces.NamespaceRequired(ctx)
if err != nil {
@@ -58,6 +64,7 @@ func (l *TaskList) GetAll(ctx context.Context) ([]Task, error) {
return o, nil
}
// Add a task
func (l *TaskList) Add(ctx context.Context, t Task) error {
namespace, err := namespaces.NamespaceRequired(ctx)
if err != nil {
@@ -66,6 +73,7 @@ func (l *TaskList) Add(ctx context.Context, t Task) error {
return l.AddWithNamespace(namespace, t)
}
// AddWithNamespace adds a task with the provided namespace
func (l *TaskList) AddWithNamespace(namespace string, t Task) error {
l.mu.Lock()
defer l.mu.Unlock()
@@ -81,6 +89,7 @@ func (l *TaskList) AddWithNamespace(namespace string, t Task) error {
return nil
}
// Delete a task
func (l *TaskList) Delete(ctx context.Context, t Task) {
l.mu.Lock()
defer l.mu.Unlock()