5624732128
* 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>
43 lines
921 B
Go
43 lines
921 B
Go
package supervisor
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/docker/containerd/runtime"
|
|
)
|
|
|
|
// DeleteTask holds needed parameters to remove a container
|
|
type DeleteTask struct {
|
|
baseTask
|
|
ID string
|
|
Status int
|
|
PID string
|
|
NoEvent bool
|
|
}
|
|
|
|
func (s *Supervisor) delete(t *DeleteTask) error {
|
|
if i, ok := s.containers[t.ID]; ok {
|
|
start := time.Now()
|
|
if err := s.deleteContainer(i.container); err != nil {
|
|
logrus.WithField("error", err).Error("containerd: deleting container")
|
|
}
|
|
if !t.NoEvent {
|
|
s.notifySubscribers(Event{
|
|
Type: StateExit,
|
|
Timestamp: time.Now(),
|
|
ID: t.ID,
|
|
Status: t.Status,
|
|
PID: t.PID,
|
|
})
|
|
}
|
|
ContainersCounter.Dec(1)
|
|
ContainerDeleteTimer.UpdateSince(start)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *Supervisor) deleteContainer(container runtime.Container) error {
|
|
delete(s.containers, container.ID())
|
|
return container.Delete()
|
|
}
|