Flatten stuff
This commit is contained in:
parent
86ec7e8fd2
commit
412d2b0239
5 changed files with 8 additions and 23 deletions
|
@ -48,7 +48,7 @@ func (s *server) createContainer(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
e := &containerd.CreateContainerEvent{
|
||||
e := &containerd.StartContainerEvent{
|
||||
ID: id,
|
||||
BundlePath: c.BundlePath,
|
||||
Err: make(chan error, 1),
|
||||
|
|
|
@ -4,6 +4,7 @@ type Container interface {
|
|||
ID() string
|
||||
Start() error
|
||||
Pid() (int, error)
|
||||
// Process() Process
|
||||
SetExited(status int)
|
||||
Delete() error
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@ func startSignalHandler(supervisor *containerd.Supervisor, bufferSize int) {
|
|||
logrus.WithField("signal", s).Debug("containerd: received signal")
|
||||
switch s {
|
||||
case syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP:
|
||||
supervisor.Stop()
|
||||
os.Exit(0)
|
||||
case syscall.SIGCHLD:
|
||||
exits, err := reap()
|
||||
|
|
4
event.go
4
event.go
|
@ -18,12 +18,12 @@ func (e *ExitEvent) String() string {
|
|||
return "exit event"
|
||||
}
|
||||
|
||||
type CreateContainerEvent struct {
|
||||
type StartContainerEvent struct {
|
||||
ID string
|
||||
BundlePath string
|
||||
Err chan error
|
||||
}
|
||||
|
||||
func (c *CreateContainerEvent) String() string {
|
||||
func (c *StartContainerEvent) String() string {
|
||||
return "create container"
|
||||
}
|
||||
|
|
|
@ -2,15 +2,9 @@ package containerd
|
|||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
"github.com/rcrowley/go-metrics"
|
||||
)
|
||||
|
||||
var (
|
||||
containerStartTimer = metrics.NewTimer()
|
||||
)
|
||||
|
||||
// NewSupervisor returns an initialized Process supervisor.
|
||||
|
@ -19,7 +13,6 @@ func NewSupervisor(stateDir string, concurrency int) (*Supervisor, error) {
|
|||
return nil, err
|
||||
}
|
||||
// register counters
|
||||
metrics.DefaultRegistry.Register("container-start-time", containerStartTimer)
|
||||
runtime, err := NewRuntime(stateDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -36,6 +29,7 @@ type Supervisor struct {
|
|||
// stateDir is the directory on the system to store container runtime state information.
|
||||
stateDir string
|
||||
|
||||
processes []Process
|
||||
containers map[string]Container
|
||||
|
||||
runtime Runtime
|
||||
|
@ -57,10 +51,8 @@ func (s *Supervisor) Start(events chan Event) error {
|
|||
logrus.WithField("event", evt).Debug("containerd: processing event")
|
||||
switch e := evt.(type) {
|
||||
case *ExitEvent:
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"pid": e.Pid,
|
||||
"status": e.Status,
|
||||
}).Debug("containerd: process exited")
|
||||
logrus.WithFields(logrus.Fields{"pid": e.Pid, "status": e.Status}).
|
||||
Debug("containerd: process exited")
|
||||
container, err := s.getContainerForPid(e.Pid)
|
||||
if err != nil {
|
||||
if err != errNoContainerForPid {
|
||||
|
@ -73,8 +65,7 @@ func (s *Supervisor) Start(events chan Event) error {
|
|||
if err := container.Delete(); err != nil {
|
||||
logrus.WithField("error", err).Error("containerd: deleting container")
|
||||
}
|
||||
case *CreateContainerEvent:
|
||||
start := time.Now()
|
||||
case *StartContainerEvent:
|
||||
container, err := s.runtime.Create(e.ID, e.BundlePath)
|
||||
if err != nil {
|
||||
e.Err <- err
|
||||
|
@ -86,7 +77,6 @@ func (s *Supervisor) Start(events chan Event) error {
|
|||
continue
|
||||
}
|
||||
e.Err <- nil
|
||||
containerStartTimer.UpdateSince(start)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -114,8 +104,3 @@ func (s *Supervisor) getContainerForPid(pid int) (Container, error) {
|
|||
func (s *Supervisor) SendEvent(evt Event) {
|
||||
s.events <- evt
|
||||
}
|
||||
|
||||
// Stop initiates a shutdown of the supervisor killing all processes under supervision.
|
||||
func (s *Supervisor) Stop() {
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue