Add golint to test (#255)
* Add a new lint rule to the Makefile Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com> * Fix linter errors Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com> * Allow replacing the default apt mirror Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
4176ba7b52
commit
5624732128
38 changed files with 297 additions and 151 deletions
|
@ -7,6 +7,8 @@ import (
|
|||
"github.com/docker/containerd/specs"
|
||||
)
|
||||
|
||||
// AddProcessTask holds everything necessary to add a process to a
|
||||
// container
|
||||
type AddProcessTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -4,6 +4,7 @@ package supervisor
|
|||
|
||||
import "github.com/docker/containerd/runtime"
|
||||
|
||||
// CreateCheckpointTask holds needed parameters to create a new checkpoint
|
||||
type CreateCheckpointTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
@ -19,6 +20,7 @@ func (s *Supervisor) createCheckpoint(t *CreateCheckpointTask) error {
|
|||
return i.container.Checkpoint(*t.Checkpoint, t.CheckpointDir)
|
||||
}
|
||||
|
||||
// DeleteCheckpointTask holds needed parameters to delete a checkpoint
|
||||
type DeleteCheckpointTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/docker/containerd/runtime"
|
||||
)
|
||||
|
||||
// StartTask holds needed parameters to create a new container
|
||||
type StartTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/docker/containerd/runtime"
|
||||
)
|
||||
|
||||
// DeleteTask holds needed parameters to remove a container
|
||||
type DeleteTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -3,14 +3,18 @@ package supervisor
|
|||
import "errors"
|
||||
|
||||
var (
|
||||
// External errors
|
||||
ErrTaskChanNil = errors.New("containerd: task channel is nil")
|
||||
ErrBundleNotFound = errors.New("containerd: bundle not found")
|
||||
ErrContainerNotFound = errors.New("containerd: container not found")
|
||||
ErrContainerExists = errors.New("containerd: container already exists")
|
||||
ErrProcessNotFound = errors.New("containerd: process not found for container")
|
||||
// ErrContainerNotFound is returned when the container ID passed
|
||||
// for a given operation is invalid
|
||||
ErrContainerNotFound = errors.New("containerd: container not found")
|
||||
// ErrProcessNotFound is returned when the process ID passed for
|
||||
// a given operation is invalid
|
||||
ErrProcessNotFound = errors.New("containerd: process not found for container")
|
||||
// ErrUnknownContainerStatus is returned when the container status
|
||||
// cannot be determined
|
||||
ErrUnknownContainerStatus = errors.New("containerd: unknown container status ")
|
||||
ErrUnknownTask = errors.New("containerd: unknown task type")
|
||||
// ErrUnknownTask is returned when an unknown Task type is
|
||||
// scheduled (should never happen).
|
||||
ErrUnknownTask = errors.New("containerd: unknown task type")
|
||||
|
||||
// Internal errors
|
||||
errShutdown = errors.New("containerd: supervisor is shutdown")
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/docker/containerd/runtime"
|
||||
)
|
||||
|
||||
// ExitTask holds needed parameters to execute the exit task
|
||||
type ExitTask struct {
|
||||
baseTask
|
||||
Process runtime.Process
|
||||
|
@ -56,6 +57,7 @@ func (s *Supervisor) exit(t *ExitTask) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ExecExitTask holds needed parameters to execute the exec exit task
|
||||
type ExecExitTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -2,6 +2,8 @@ package supervisor
|
|||
|
||||
import "github.com/docker/containerd/runtime"
|
||||
|
||||
// GetContainersTask holds needed parameters to retrieve a list of
|
||||
// containers
|
||||
type GetContainersTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -4,11 +4,14 @@ package supervisor
|
|||
|
||||
import "github.com/cloudfoundry/gosigar"
|
||||
|
||||
// Machine holds the current machine cpu count and ram size
|
||||
type Machine struct {
|
||||
Cpus int
|
||||
Memory int64
|
||||
}
|
||||
|
||||
// CollectMachineInformation returns information regarding the current
|
||||
// machine (e.g. CPU count, RAM amount)
|
||||
func CollectMachineInformation() (Machine, error) {
|
||||
m := Machine{}
|
||||
cpu := sigar.CpuList{}
|
||||
|
|
|
@ -3,18 +3,29 @@ package supervisor
|
|||
import "github.com/rcrowley/go-metrics"
|
||||
|
||||
var (
|
||||
ContainerCreateTimer = metrics.NewTimer()
|
||||
ContainerDeleteTimer = metrics.NewTimer()
|
||||
ContainerStartTimer = metrics.NewTimer()
|
||||
ContainerStatsTimer = metrics.NewTimer()
|
||||
ContainersCounter = metrics.NewCounter()
|
||||
// ContainerCreateTimer holds the metrics timer associated with container creation
|
||||
ContainerCreateTimer = metrics.NewTimer()
|
||||
// ContainerDeleteTimer holds the metrics timer associated with container deletion
|
||||
ContainerDeleteTimer = metrics.NewTimer()
|
||||
// ContainerStartTimer holds the metrics timer associated with container start duration
|
||||
ContainerStartTimer = metrics.NewTimer()
|
||||
// ContainerStatsTimer holds the metrics timer associated with container stats generation
|
||||
ContainerStatsTimer = metrics.NewTimer()
|
||||
// ContainersCounter keeps track of the number of active containers
|
||||
ContainersCounter = metrics.NewCounter()
|
||||
// EventSubscriberCounter keeps track of the number of active event subscribers
|
||||
EventSubscriberCounter = metrics.NewCounter()
|
||||
TasksCounter = metrics.NewCounter()
|
||||
ExecProcessTimer = metrics.NewTimer()
|
||||
ExitProcessTimer = metrics.NewTimer()
|
||||
EpollFdCounter = metrics.NewCounter()
|
||||
// TasksCounter keeps track of the number of active supervisor tasks
|
||||
TasksCounter = metrics.NewCounter()
|
||||
// ExecProcessTimer holds the metrics timer associated with container exec
|
||||
ExecProcessTimer = metrics.NewTimer()
|
||||
// ExitProcessTimer holds the metrics timer associated with reporting container exit status
|
||||
ExitProcessTimer = metrics.NewTimer()
|
||||
// EpollFdCounter keeps trac of how many process are being monitored
|
||||
EpollFdCounter = metrics.NewCounter()
|
||||
)
|
||||
|
||||
// Metrics return the list of all available metrics
|
||||
func Metrics() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"container-create-time": ContainerCreateTimer,
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/docker/containerd/runtime"
|
||||
)
|
||||
|
||||
// NewMonitor starts a new process monitor and returns it
|
||||
func NewMonitor() (*Monitor, error) {
|
||||
m := &Monitor{
|
||||
receivers: make(map[int]interface{}),
|
||||
|
@ -24,6 +25,7 @@ func NewMonitor() (*Monitor, error) {
|
|||
return m, nil
|
||||
}
|
||||
|
||||
// Monitor represents a runtime.Process monitor
|
||||
type Monitor struct {
|
||||
m sync.Mutex
|
||||
receivers map[int]interface{}
|
||||
|
@ -32,14 +34,17 @@ type Monitor struct {
|
|||
epollFd int
|
||||
}
|
||||
|
||||
// Exits returns the channel used to notify of a process exit
|
||||
func (m *Monitor) Exits() chan runtime.Process {
|
||||
return m.exits
|
||||
}
|
||||
|
||||
// OOMs returns the channel used to notify of a container exit due to OOM
|
||||
func (m *Monitor) OOMs() chan string {
|
||||
return m.ooms
|
||||
}
|
||||
|
||||
// Monitor adds a process to the list of the one being monitored
|
||||
func (m *Monitor) Monitor(p runtime.Process) error {
|
||||
m.m.Lock()
|
||||
defer m.m.Unlock()
|
||||
|
@ -56,6 +61,7 @@ func (m *Monitor) Monitor(p runtime.Process) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// MonitorOOM adds a container to the list of the ones monitored for OOM
|
||||
func (m *Monitor) MonitorOOM(c runtime.Container) error {
|
||||
m.m.Lock()
|
||||
defer m.m.Unlock()
|
||||
|
@ -76,6 +82,7 @@ func (m *Monitor) MonitorOOM(c runtime.Container) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Close cleans up resources allocated by NewMonitor()
|
||||
func (m *Monitor) Close() error {
|
||||
return syscall.Close(m.epollFd)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
// OOMTask holds needed parameters to report a container OOM
|
||||
type OOMTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -2,6 +2,7 @@ package supervisor
|
|||
|
||||
import "os"
|
||||
|
||||
// SignalTask holds needed parameters to signal a container
|
||||
type SignalTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/docker/containerd/runtime"
|
||||
)
|
||||
|
||||
// StatsTask holds needed parameters to retrieve a container statistics
|
||||
type StatsTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -144,6 +144,7 @@ func readEventLog(s *Supervisor) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Supervisor represents a container supervisor
|
||||
type Supervisor struct {
|
||||
// stateDir is the directory on the system to store container runtime state information.
|
||||
stateDir string
|
||||
|
@ -179,6 +180,7 @@ func (s *Supervisor) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Event represents a container event
|
||||
type Event struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/docker/containerd/runtime"
|
||||
)
|
||||
|
||||
// UpdateTask holds needed parameters to update a container resource constraints
|
||||
type UpdateTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
@ -50,6 +51,8 @@ func (s *Supervisor) updateContainer(t *UpdateTask) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// UpdateProcessTask holds needed parameters to update a container
|
||||
// process terminal size or close its stdin
|
||||
type UpdateProcessTask struct {
|
||||
baseTask
|
||||
ID string
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/docker/containerd/runtime"
|
||||
)
|
||||
|
||||
// Worker interface
|
||||
type Worker interface {
|
||||
Start()
|
||||
}
|
||||
|
@ -22,6 +23,7 @@ type startTask struct {
|
|||
StartResponse chan StartResponse
|
||||
}
|
||||
|
||||
// NewWorker return a new initialized worker
|
||||
func NewWorker(s *Supervisor, wg *sync.WaitGroup) Worker {
|
||||
return &worker{
|
||||
s: s,
|
||||
|
@ -34,6 +36,7 @@ type worker struct {
|
|||
s *Supervisor
|
||||
}
|
||||
|
||||
// Start runs a loop in charge of starting new containers
|
||||
func (w *worker) Start() {
|
||||
defer w.wg.Done()
|
||||
for t := range w.s.startTasks {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue