2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2015-12-01 19:56:08 +00:00
|
|
|
import (
|
2015-12-19 00:54:02 +00:00
|
|
|
"time"
|
|
|
|
|
2015-12-01 19:56:08 +00:00
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/containerd/runtime"
|
|
|
|
)
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2016-06-03 22:00:49 +00:00
|
|
|
// DeleteTask holds needed parameters to remove a container
|
2016-02-12 01:26:24 +00:00
|
|
|
type DeleteTask struct {
|
2016-02-17 18:55:54 +00:00
|
|
|
baseTask
|
2016-03-12 00:40:42 +00:00
|
|
|
ID string
|
|
|
|
Status int
|
|
|
|
PID string
|
|
|
|
NoEvent bool
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
func (s *Supervisor) delete(t *DeleteTask) error {
|
|
|
|
if i, ok := s.containers[t.ID]; ok {
|
2015-12-19 00:54:02 +00:00
|
|
|
start := time.Now()
|
2016-02-17 18:55:54 +00:00
|
|
|
if err := s.deleteContainer(i.container); err != nil {
|
2015-12-01 18:55:13 +00:00
|
|
|
logrus.WithField("error", err).Error("containerd: deleting container")
|
|
|
|
}
|
2016-03-12 00:40:42 +00:00
|
|
|
if !t.NoEvent {
|
|
|
|
s.notifySubscribers(Event{
|
2016-04-19 11:02:37 +00:00
|
|
|
Type: StateExit,
|
2016-03-12 00:40:42 +00:00
|
|
|
Timestamp: time.Now(),
|
|
|
|
ID: t.ID,
|
|
|
|
Status: t.Status,
|
|
|
|
PID: t.PID,
|
|
|
|
})
|
|
|
|
}
|
2015-12-04 23:12:57 +00:00
|
|
|
ContainersCounter.Dec(1)
|
2015-12-19 00:54:02 +00:00
|
|
|
ContainerDeleteTimer.UpdateSince(start)
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
func (s *Supervisor) deleteContainer(container runtime.Container) error {
|
|
|
|
delete(s.containers, container.ID())
|
2015-12-01 18:55:13 +00:00
|
|
|
return container.Delete()
|
|
|
|
}
|