Add monitor plugin loading
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
1005d1dba9
commit
ddbeb9f936
4 changed files with 88 additions and 6 deletions
54
plugin/monitor.go
Normal file
54
plugin/monitor.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package plugin
|
||||
|
||||
import "github.com/docker/containerd"
|
||||
|
||||
// ContainerMonitor provides an interface for monitoring of containers within containerd
|
||||
type ContainerMonitor interface {
|
||||
// Monitor adds the provided container to the monitor
|
||||
Monitor(containerd.Container) error
|
||||
// Stop stops and removes the provided container from the monitor
|
||||
Stop(containerd.Container) error
|
||||
}
|
||||
|
||||
func NewMultiContainerMonitor(monitors ...ContainerMonitor) ContainerMonitor {
|
||||
return &multiContainerMonitor{
|
||||
monitors: monitors,
|
||||
}
|
||||
}
|
||||
|
||||
func NewNoopMonitor() ContainerMonitor {
|
||||
return &noopContainerMonitor{}
|
||||
}
|
||||
|
||||
type noopContainerMonitor struct {
|
||||
}
|
||||
|
||||
func (mm *noopContainerMonitor) Monitor(c containerd.Container) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *noopContainerMonitor) Stop(c containerd.Container) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type multiContainerMonitor struct {
|
||||
monitors []ContainerMonitor
|
||||
}
|
||||
|
||||
func (mm *multiContainerMonitor) Monitor(c containerd.Container) error {
|
||||
for _, m := range mm.monitors {
|
||||
if err := m.Monitor(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *multiContainerMonitor) Stop(c containerd.Container) error {
|
||||
for _, m := range mm.monitors {
|
||||
if err := m.Stop(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -18,6 +18,7 @@ const (
|
|||
RuntimePlugin PluginType = iota + 1
|
||||
GRPCPlugin
|
||||
SnapshotPlugin
|
||||
ContainerMonitorPlugin
|
||||
)
|
||||
|
||||
type Registration struct {
|
||||
|
@ -26,6 +27,7 @@ type Registration struct {
|
|||
Init func(*InitContext) (interface{}, error)
|
||||
}
|
||||
|
||||
// TODO(@crosbymichael): how to we keep this struct from growing but support dependency injection for loaded plugins?
|
||||
type InitContext struct {
|
||||
Root string
|
||||
State string
|
||||
|
@ -34,6 +36,7 @@ type InitContext struct {
|
|||
Snapshotter snapshot.Snapshotter
|
||||
Config interface{}
|
||||
Context context.Context
|
||||
Monitor ContainerMonitor
|
||||
}
|
||||
|
||||
type Service interface {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue