delete.go 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package supervisor
  2. import (
  3. "time"
  4. "github.com/Sirupsen/logrus"
  5. "github.com/docker/containerd/runtime"
  6. )
  7. type DeleteTask struct {
  8. baseTask
  9. ID string
  10. Status int
  11. PID string
  12. NoEvent bool
  13. }
  14. func (s *Supervisor) delete(t *DeleteTask) error {
  15. if i, ok := s.containers[t.ID]; ok {
  16. start := time.Now()
  17. if err := s.deleteContainer(i.container); err != nil {
  18. logrus.WithField("error", err).Error("containerd: deleting container")
  19. }
  20. if !t.NoEvent {
  21. s.notifySubscribers(Event{
  22. Type: StateExit,
  23. Timestamp: time.Now(),
  24. ID: t.ID,
  25. Status: t.Status,
  26. PID: t.PID,
  27. })
  28. }
  29. ContainersCounter.Dec(1)
  30. ContainerDeleteTimer.UpdateSince(start)
  31. }
  32. return nil
  33. }
  34. func (s *Supervisor) deleteContainer(container runtime.Container) error {
  35. delete(s.containers, container.ID())
  36. return container.Delete()
  37. }