Add container monitor plugin type for restart
Adds a plugin type for container monitor. Rename the task monitor type to avoid confusion. Add config migration for new plugin types to pass existing migration tests. Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
		| @@ -19,12 +19,15 @@ | ||||
| package cgroups | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"github.com/containerd/cgroups/v3" | ||||
| 	v1 "github.com/containerd/containerd/v2/core/metrics/cgroups/v1" | ||||
| 	v2 "github.com/containerd/containerd/v2/core/metrics/cgroups/v2" | ||||
| 	"github.com/containerd/containerd/v2/core/runtime" | ||||
| 	"github.com/containerd/containerd/v2/pkg/events" | ||||
| 	"github.com/containerd/containerd/v2/plugins" | ||||
| 	"github.com/containerd/containerd/v2/version" | ||||
| 	"github.com/containerd/platforms" | ||||
| 	"github.com/containerd/plugin" | ||||
| 	"github.com/containerd/plugin/registry" | ||||
| @@ -45,6 +48,20 @@ func init() { | ||||
| 			plugins.EventPlugin, | ||||
| 		}, | ||||
| 		Config: &Config{}, | ||||
| 		ConfigMigration: func(ctx context.Context, configVersion int, pluginConfigs map[string]interface{}) error { | ||||
| 			if configVersion >= version.ConfigVersion { | ||||
| 				return nil | ||||
| 			} | ||||
| 			// Previous plugin name | ||||
| 			const pluginName = "io.containerd.monitor.v1.cgroups" | ||||
| 			c, ok := pluginConfigs[pluginName] | ||||
| 			if ok { | ||||
| 				pluginConfigs[string(plugins.TaskMonitorPlugin)+".cgroups"] = c | ||||
| 				delete(pluginConfigs, pluginName) | ||||
| 			} | ||||
|  | ||||
| 			return nil | ||||
| 		}, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -28,6 +28,7 @@ import ( | ||||
| 	"github.com/containerd/containerd/v2/internal/tomlext" | ||||
| 	"github.com/containerd/containerd/v2/pkg/namespaces" | ||||
| 	"github.com/containerd/containerd/v2/plugins" | ||||
| 	"github.com/containerd/containerd/v2/version" | ||||
| 	"github.com/containerd/log" | ||||
| 	"github.com/containerd/plugin" | ||||
| 	"github.com/containerd/plugin/registry" | ||||
| @@ -41,7 +42,7 @@ type Config struct { | ||||
|  | ||||
| func init() { | ||||
| 	registry.Register(&plugin.Registration{ | ||||
| 		Type: plugins.InternalPlugin, | ||||
| 		Type: plugins.ContainerMonitorPlugin, | ||||
| 		Requires: []plugin.Type{ | ||||
| 			plugins.EventPlugin, | ||||
| 			plugins.ServicePlugin, | ||||
| @@ -62,6 +63,19 @@ func init() { | ||||
| 			go m.run(tomlext.ToStdTime(ic.Config.(*Config).Interval)) | ||||
| 			return m, nil | ||||
| 		}, | ||||
| 		ConfigMigration: func(ctx context.Context, configVersion int, pluginConfigs map[string]interface{}) error { | ||||
| 			if configVersion >= version.ConfigVersion { | ||||
| 				return nil | ||||
| 			} | ||||
| 			const pluginName = string(plugins.InternalPlugin) + ".restart" | ||||
| 			c, ok := pluginConfigs[pluginName] | ||||
| 			if ok { | ||||
| 				pluginConfigs[string(plugins.ContainerMonitorPlugin)+".restart"] = c | ||||
| 				delete(pluginConfigs, pluginName) | ||||
| 			} | ||||
|  | ||||
| 			return nil | ||||
| 		}, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -38,7 +38,9 @@ const ( | ||||
| 	// SnapshotPlugin implements a snapshotter | ||||
| 	SnapshotPlugin plugin.Type = "io.containerd.snapshotter.v1" | ||||
| 	// TaskMonitorPlugin implements a task monitor | ||||
| 	TaskMonitorPlugin plugin.Type = "io.containerd.monitor.v1" | ||||
| 	TaskMonitorPlugin plugin.Type = "io.containerd.monitor.task.v1" | ||||
| 	// TaskMonitorPlugin implements a container monitor | ||||
| 	ContainerMonitorPlugin plugin.Type = "io.containerd.monitor.container.v1" | ||||
| 	// DiffPlugin implements a differ | ||||
| 	DiffPlugin plugin.Type = "io.containerd.differ.v1" | ||||
| 	// MetadataPlugin implements a metadata store | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Derek McGowan
					Derek McGowan