Move lease manager plugin to separate package
Create lease plugin type to separate lease manager from services plugin. This allows other service plugins to depend on the lease manager. Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
parent
98260e1b18
commit
fe8da6dcaf
@ -21,6 +21,7 @@ import (
|
|||||||
_ "github.com/containerd/containerd/diff/walking/plugin"
|
_ "github.com/containerd/containerd/diff/walking/plugin"
|
||||||
_ "github.com/containerd/containerd/events/plugin"
|
_ "github.com/containerd/containerd/events/plugin"
|
||||||
_ "github.com/containerd/containerd/gc/scheduler"
|
_ "github.com/containerd/containerd/gc/scheduler"
|
||||||
|
_ "github.com/containerd/containerd/leases/plugin"
|
||||||
_ "github.com/containerd/containerd/runtime/restart/monitor"
|
_ "github.com/containerd/containerd/runtime/restart/monitor"
|
||||||
_ "github.com/containerd/containerd/runtime/v2"
|
_ "github.com/containerd/containerd/runtime/v2"
|
||||||
_ "github.com/containerd/containerd/services/containers"
|
_ "github.com/containerd/containerd/services/containers"
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package leases
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -23,15 +23,15 @@ import (
|
|||||||
"github.com/containerd/containerd/leases"
|
"github.com/containerd/containerd/leases"
|
||||||
"github.com/containerd/containerd/metadata"
|
"github.com/containerd/containerd/metadata"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/services"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.ServicePlugin,
|
Type: plugin.LeasePlugin,
|
||||||
ID: services.LeasesService,
|
ID: "manager",
|
||||||
Requires: []plugin.Type{
|
Requires: []plugin.Type{
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
|
plugin.GCPlugin,
|
||||||
},
|
},
|
||||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
m, err := ic.Get(plugin.MetadataPlugin)
|
m, err := ic.Get(plugin.MetadataPlugin)
|
@ -113,19 +113,26 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
|
|
||||||
// getServicesOpts get service options from plugin context.
|
// getServicesOpts get service options from plugin context.
|
||||||
func getServicesOpts(ic *plugin.InitContext) ([]containerd.ServicesOpt, error) {
|
func getServicesOpts(ic *plugin.InitContext) ([]containerd.ServicesOpt, error) {
|
||||||
|
var opts []containerd.ServicesOpt
|
||||||
|
for t, fn := range map[plugin.Type]func(interface{}) containerd.ServicesOpt{
|
||||||
|
plugin.EventPlugin: func(i interface{}) containerd.ServicesOpt {
|
||||||
|
return containerd.WithEventService(i.(containerd.EventService))
|
||||||
|
},
|
||||||
|
plugin.LeasePlugin: func(i interface{}) containerd.ServicesOpt {
|
||||||
|
return containerd.WithLeasesService(i.(leases.Manager))
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
i, err := ic.Get(t)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get %q plugin: %w", t, err)
|
||||||
|
}
|
||||||
|
opts = append(opts, fn(i))
|
||||||
|
}
|
||||||
|
|
||||||
plugins, err := ic.GetByType(plugin.ServicePlugin)
|
plugins, err := ic.GetByType(plugin.ServicePlugin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get service plugin: %w", err)
|
return nil, fmt.Errorf("failed to get service plugin: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ep, err := ic.Get(plugin.EventPlugin)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get event plugin: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := []containerd.ServicesOpt{
|
|
||||||
containerd.WithEventService(ep.(containerd.EventService)),
|
|
||||||
}
|
|
||||||
for s, fn := range map[string]func(interface{}) containerd.ServicesOpt{
|
for s, fn := range map[string]func(interface{}) containerd.ServicesOpt{
|
||||||
services.ContentService: func(s interface{}) containerd.ServicesOpt {
|
services.ContentService: func(s interface{}) containerd.ServicesOpt {
|
||||||
return containerd.WithContentStore(s.(content.Store))
|
return containerd.WithContentStore(s.(content.Store))
|
||||||
@ -148,9 +155,6 @@ func getServicesOpts(ic *plugin.InitContext) ([]containerd.ServicesOpt, error) {
|
|||||||
services.NamespacesService: func(s interface{}) containerd.ServicesOpt {
|
services.NamespacesService: func(s interface{}) containerd.ServicesOpt {
|
||||||
return containerd.WithNamespaceClient(s.(namespaces.NamespacesClient))
|
return containerd.WithNamespaceClient(s.(namespaces.NamespacesClient))
|
||||||
},
|
},
|
||||||
services.LeasesService: func(s interface{}) containerd.ServicesOpt {
|
|
||||||
return containerd.WithLeasesService(s.(leases.Manager))
|
|
||||||
},
|
|
||||||
services.IntrospectionService: func(s interface{}) containerd.ServicesOpt {
|
services.IntrospectionService: func(s interface{}) containerd.ServicesOpt {
|
||||||
return containerd.WithIntrospectionClient(s.(introspectionapi.IntrospectionClient))
|
return containerd.WithIntrospectionClient(s.(introspectionapi.IntrospectionClient))
|
||||||
},
|
},
|
||||||
|
@ -76,6 +76,8 @@ const (
|
|||||||
GCPlugin Type = "io.containerd.gc.v1"
|
GCPlugin Type = "io.containerd.gc.v1"
|
||||||
// EventPlugin implements event handling
|
// EventPlugin implements event handling
|
||||||
EventPlugin Type = "io.containerd.event.v1"
|
EventPlugin Type = "io.containerd.event.v1"
|
||||||
|
// LeasePlugin implements lease manager
|
||||||
|
LeasePlugin Type = "io.containerd.lease.v1"
|
||||||
// TracingProcessorPlugin implements a open telemetry span processor
|
// TracingProcessorPlugin implements a open telemetry span processor
|
||||||
TracingProcessorPlugin Type = "io.containerd.tracing.processor.v1"
|
TracingProcessorPlugin Type = "io.containerd.tracing.processor.v1"
|
||||||
)
|
)
|
||||||
|
@ -98,12 +98,12 @@ func TestContainerdPlugin(t *testing.T) {
|
|||||||
Type: GRPCPlugin,
|
Type: GRPCPlugin,
|
||||||
ID: "leases",
|
ID: "leases",
|
||||||
Requires: []Type{
|
Requires: []Type{
|
||||||
ServicePlugin,
|
LeasePlugin,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
Register(&Registration{
|
Register(&Registration{
|
||||||
Type: ServicePlugin,
|
Type: LeasePlugin,
|
||||||
ID: services.LeasesService,
|
ID: "manager",
|
||||||
Requires: []Type{
|
Requires: []Type{
|
||||||
MetadataPlugin,
|
MetadataPlugin,
|
||||||
},
|
},
|
||||||
@ -250,7 +250,6 @@ func TestContainerdPlugin(t *testing.T) {
|
|||||||
"io.containerd.service.v1.introspection-service",
|
"io.containerd.service.v1.introspection-service",
|
||||||
"io.containerd.service.v1.namespaces-service",
|
"io.containerd.service.v1.namespaces-service",
|
||||||
"io.containerd.service.v1.containers-service",
|
"io.containerd.service.v1.containers-service",
|
||||||
"io.containerd.service.v1.leases-service",
|
|
||||||
"io.containerd.differ.v1.walking",
|
"io.containerd.differ.v1.walking",
|
||||||
"io.containerd.service.v1.diff-service",
|
"io.containerd.service.v1.diff-service",
|
||||||
"io.containerd.service.v1.snapshots-service",
|
"io.containerd.service.v1.snapshots-service",
|
||||||
@ -259,6 +258,7 @@ func TestContainerdPlugin(t *testing.T) {
|
|||||||
"io.containerd.grpc.v1.content",
|
"io.containerd.grpc.v1.content",
|
||||||
"io.containerd.grpc.v1.containers",
|
"io.containerd.grpc.v1.containers",
|
||||||
"io.containerd.grpc.v1.events",
|
"io.containerd.grpc.v1.events",
|
||||||
|
"io.containerd.lease.v1.manager",
|
||||||
"io.containerd.grpc.v1.leases",
|
"io.containerd.grpc.v1.leases",
|
||||||
"io.containerd.grpc.v1.diff",
|
"io.containerd.grpc.v1.diff",
|
||||||
"io.containerd.grpc.v1.snapshots",
|
"io.containerd.grpc.v1.snapshots",
|
||||||
|
@ -91,19 +91,26 @@ func init() {
|
|||||||
|
|
||||||
// getServicesOpts get service options from plugin context.
|
// getServicesOpts get service options from plugin context.
|
||||||
func getServicesOpts(ic *plugin.InitContext) ([]containerd.ServicesOpt, error) {
|
func getServicesOpts(ic *plugin.InitContext) ([]containerd.ServicesOpt, error) {
|
||||||
|
var opts []containerd.ServicesOpt
|
||||||
|
for t, fn := range map[plugin.Type]func(interface{}) containerd.ServicesOpt{
|
||||||
|
plugin.EventPlugin: func(i interface{}) containerd.ServicesOpt {
|
||||||
|
return containerd.WithEventService(i.(containerd.EventService))
|
||||||
|
},
|
||||||
|
plugin.LeasePlugin: func(i interface{}) containerd.ServicesOpt {
|
||||||
|
return containerd.WithLeasesService(i.(leases.Manager))
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
i, err := ic.Get(t)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get %q plugin: %w", t, err)
|
||||||
|
}
|
||||||
|
opts = append(opts, fn(i))
|
||||||
|
}
|
||||||
|
|
||||||
plugins, err := ic.GetByType(plugin.ServicePlugin)
|
plugins, err := ic.GetByType(plugin.ServicePlugin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get service plugin: %w", err)
|
return nil, fmt.Errorf("failed to get service plugin: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ep, err := ic.Get(plugin.EventPlugin)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get event plugin: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := []containerd.ServicesOpt{
|
|
||||||
containerd.WithEventService(ep.(containerd.EventService)),
|
|
||||||
}
|
|
||||||
for s, fn := range map[string]func(interface{}) containerd.ServicesOpt{
|
for s, fn := range map[string]func(interface{}) containerd.ServicesOpt{
|
||||||
services.ContentService: func(s interface{}) containerd.ServicesOpt {
|
services.ContentService: func(s interface{}) containerd.ServicesOpt {
|
||||||
return containerd.WithContentStore(s.(content.Store))
|
return containerd.WithContentStore(s.(content.Store))
|
||||||
@ -126,9 +133,6 @@ func getServicesOpts(ic *plugin.InitContext) ([]containerd.ServicesOpt, error) {
|
|||||||
services.NamespacesService: func(s interface{}) containerd.ServicesOpt {
|
services.NamespacesService: func(s interface{}) containerd.ServicesOpt {
|
||||||
return containerd.WithNamespaceClient(s.(namespacesapi.NamespacesClient))
|
return containerd.WithNamespaceClient(s.(namespacesapi.NamespacesClient))
|
||||||
},
|
},
|
||||||
services.LeasesService: func(s interface{}) containerd.ServicesOpt {
|
|
||||||
return containerd.WithLeasesService(s.(leases.Manager))
|
|
||||||
},
|
|
||||||
} {
|
} {
|
||||||
p := plugins[s]
|
p := plugins[s]
|
||||||
if p == nil {
|
if p == nil {
|
||||||
|
@ -18,13 +18,11 @@ package leases
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
|
|
||||||
api "github.com/containerd/containerd/api/services/leases/v1"
|
api "github.com/containerd/containerd/api/services/leases/v1"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/leases"
|
"github.com/containerd/containerd/leases"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/services"
|
|
||||||
ptypes "github.com/gogo/protobuf/types"
|
ptypes "github.com/gogo/protobuf/types"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
@ -34,18 +32,10 @@ func init() {
|
|||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "leases",
|
ID: "leases",
|
||||||
Requires: []plugin.Type{
|
Requires: []plugin.Type{
|
||||||
plugin.ServicePlugin,
|
plugin.LeasePlugin,
|
||||||
},
|
},
|
||||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
plugins, err := ic.GetByType(plugin.ServicePlugin)
|
i, err := ic.GetByID(plugin.LeasePlugin, "manager")
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
p, ok := plugins[services.LeasesService]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("leases service not found")
|
|
||||||
}
|
|
||||||
i, err := p.Instance()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,6 @@ const (
|
|||||||
TasksService = "tasks-service"
|
TasksService = "tasks-service"
|
||||||
// NamespacesService is id of namespaces service.
|
// NamespacesService is id of namespaces service.
|
||||||
NamespacesService = "namespaces-service"
|
NamespacesService = "namespaces-service"
|
||||||
// LeasesService is id of leases service.
|
|
||||||
LeasesService = "leases-service"
|
|
||||||
// DiffService is id of diff service.
|
// DiffService is id of diff service.
|
||||||
DiffService = "diff-service"
|
DiffService = "diff-service"
|
||||||
// IntrospectionService is the id of introspection service
|
// IntrospectionService is the id of introspection service
|
||||||
|
Loading…
Reference in New Issue
Block a user