Allow WithServices to use custom implementations

Before this change, for several of the services that `WithServices`
handles, only the grpc client is supported.
Now, for instance, one can use an `images.Store` directly instead of
only an `imagesapi.StoreSlient`.

Some of the methods have been renamed to satisfy the difference between
using a grpc `<Foo>Client` vs the main interface.

I did not see a good candidate for TaskService so have left that mostly
unchanged.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2021-07-09 23:30:40 +00:00
parent 0dcffc3ee1
commit 0a8802df67
3 changed files with 58 additions and 23 deletions

View File

@ -127,28 +127,28 @@ func getServicesOpts(ic *plugin.InitContext) ([]containerd.ServicesOpt, error) {
return containerd.WithContentStore(s.(content.Store)) return containerd.WithContentStore(s.(content.Store))
}, },
services.ImagesService: func(s interface{}) containerd.ServicesOpt { services.ImagesService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithImageService(s.(images.ImagesClient)) return containerd.WithImageClient(s.(images.ImagesClient))
}, },
services.SnapshotsService: func(s interface{}) containerd.ServicesOpt { services.SnapshotsService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithSnapshotters(s.(map[string]snapshots.Snapshotter)) return containerd.WithSnapshotters(s.(map[string]snapshots.Snapshotter))
}, },
services.ContainersService: func(s interface{}) containerd.ServicesOpt { services.ContainersService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithContainerService(s.(containers.ContainersClient)) return containerd.WithContainerClient(s.(containers.ContainersClient))
}, },
services.TasksService: func(s interface{}) containerd.ServicesOpt { services.TasksService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithTaskService(s.(tasks.TasksClient)) return containerd.WithTaskClient(s.(tasks.TasksClient))
}, },
services.DiffService: func(s interface{}) containerd.ServicesOpt { services.DiffService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithDiffService(s.(diff.DiffClient)) return containerd.WithDiffClient(s.(diff.DiffClient))
}, },
services.NamespacesService: func(s interface{}) containerd.ServicesOpt { services.NamespacesService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithNamespaceService(s.(namespaces.NamespacesClient)) return containerd.WithNamespaceClient(s.(namespaces.NamespacesClient))
}, },
services.LeasesService: func(s interface{}) containerd.ServicesOpt { services.LeasesService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithLeasesService(s.(leases.Manager)) return containerd.WithLeasesService(s.(leases.Manager))
}, },
services.IntrospectionService: func(s interface{}) containerd.ServicesOpt { services.IntrospectionService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithIntrospectionService(s.(introspectionapi.IntrospectionClient)) return containerd.WithIntrospectionClient(s.(introspectionapi.IntrospectionClient))
}, },
} { } {
p := plugins[s] p := plugins[s]

View File

@ -103,22 +103,22 @@ func getServicesOpts(ic *plugin.InitContext) ([]containerd.ServicesOpt, error) {
return containerd.WithContentStore(s.(content.Store)) return containerd.WithContentStore(s.(content.Store))
}, },
services.ImagesService: func(s interface{}) containerd.ServicesOpt { services.ImagesService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithImageService(s.(images.ImagesClient)) return containerd.WithImageClient(s.(images.ImagesClient))
}, },
services.SnapshotsService: func(s interface{}) containerd.ServicesOpt { services.SnapshotsService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithSnapshotters(s.(map[string]snapshots.Snapshotter)) return containerd.WithSnapshotters(s.(map[string]snapshots.Snapshotter))
}, },
services.ContainersService: func(s interface{}) containerd.ServicesOpt { services.ContainersService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithContainerService(s.(containers.ContainersClient)) return containerd.WithContainerClient(s.(containers.ContainersClient))
}, },
services.TasksService: func(s interface{}) containerd.ServicesOpt { services.TasksService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithTaskService(s.(tasks.TasksClient)) return containerd.WithTaskClient(s.(tasks.TasksClient))
}, },
services.DiffService: func(s interface{}) containerd.ServicesOpt { services.DiffService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithDiffService(s.(diff.DiffClient)) return containerd.WithDiffClient(s.(diff.DiffClient))
}, },
services.NamespacesService: func(s interface{}) containerd.ServicesOpt { services.NamespacesService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithNamespaceService(s.(namespacesapi.NamespacesClient)) return containerd.WithNamespaceClient(s.(namespacesapi.NamespacesClient))
}, },
services.LeasesService: func(s interface{}) containerd.ServicesOpt { services.LeasesService: func(s interface{}) containerd.ServicesOpt {
return containerd.WithLeasesService(s.(leases.Manager)) return containerd.WithLeasesService(s.(leases.Manager))

View File

@ -55,13 +55,20 @@ func WithContentStore(contentStore content.Store) ServicesOpt {
} }
} }
// WithImageService sets the image service. // WithImageClient sets the image service to use using an images client.
func WithImageService(imageService imagesapi.ImagesClient) ServicesOpt { func WithImageClient(imageService imagesapi.ImagesClient) ServicesOpt {
return func(s *services) { return func(s *services) {
s.imageStore = NewImageStoreFromClient(imageService) s.imageStore = NewImageStoreFromClient(imageService)
} }
} }
// WithImageStore sets the image store.
func WithImageStore(imageStore images.Store) ServicesOpt {
return func(s *services) {
s.imageStore = imageStore
}
}
// WithSnapshotters sets the snapshotters. // WithSnapshotters sets the snapshotters.
func WithSnapshotters(snapshotters map[string]snapshots.Snapshotter) ServicesOpt { func WithSnapshotters(snapshotters map[string]snapshots.Snapshotter) ServicesOpt {
return func(s *services) { return func(s *services) {
@ -72,27 +79,41 @@ func WithSnapshotters(snapshotters map[string]snapshots.Snapshotter) ServicesOpt
} }
} }
// WithContainerService sets the container service. // WithContainerClient sets the container service to use using a containers client.
func WithContainerService(containerService containersapi.ContainersClient) ServicesOpt { func WithContainerClient(containerService containersapi.ContainersClient) ServicesOpt {
return func(s *services) { return func(s *services) {
s.containerStore = NewRemoteContainerStore(containerService) s.containerStore = NewRemoteContainerStore(containerService)
} }
} }
// WithTaskService sets the task service. // WithContainerStore sets the container store.
func WithTaskService(taskService tasks.TasksClient) ServicesOpt { func WithContainerStore(containerStore containers.Store) ServicesOpt {
return func(s *services) {
s.containerStore = containerStore
}
}
// WithTaskClient sets the task service to use from a tasks client.
func WithTaskClient(taskService tasks.TasksClient) ServicesOpt {
return func(s *services) { return func(s *services) {
s.taskService = taskService s.taskService = taskService
} }
} }
// WithDiffService sets the diff service. // WithDiffClient sets the diff service to use from a diff client.
func WithDiffService(diffService diff.DiffClient) ServicesOpt { func WithDiffClient(diffService diff.DiffClient) ServicesOpt {
return func(s *services) { return func(s *services) {
s.diffService = NewDiffServiceFromClient(diffService) s.diffService = NewDiffServiceFromClient(diffService)
} }
} }
// WithDiffService sets the diff store.
func WithDiffService(diffService DiffService) ServicesOpt {
return func(s *services) {
s.diffService = diffService
}
}
// WithEventService sets the event service. // WithEventService sets the event service.
func WithEventService(eventService EventService) ServicesOpt { func WithEventService(eventService EventService) ServicesOpt {
return func(s *services) { return func(s *services) {
@ -100,13 +121,20 @@ func WithEventService(eventService EventService) ServicesOpt {
} }
} }
// WithNamespaceService sets the namespace service. // WithNamespaceClient sets the namespace service using a namespaces client.
func WithNamespaceService(namespaceService namespacesapi.NamespacesClient) ServicesOpt { func WithNamespaceClient(namespaceService namespacesapi.NamespacesClient) ServicesOpt {
return func(s *services) { return func(s *services) {
s.namespaceStore = NewNamespaceStoreFromClient(namespaceService) s.namespaceStore = NewNamespaceStoreFromClient(namespaceService)
} }
} }
// WithNamespaceService sets the namespace service.
func WithNamespaceService(namespaceService namespaces.Store) ServicesOpt {
return func(s *services) {
s.namespaceStore = namespaceService
}
}
// WithLeasesService sets the lease service. // WithLeasesService sets the lease service.
func WithLeasesService(leasesService leases.Manager) ServicesOpt { func WithLeasesService(leasesService leases.Manager) ServicesOpt {
return func(s *services) { return func(s *services) {
@ -114,9 +142,16 @@ func WithLeasesService(leasesService leases.Manager) ServicesOpt {
} }
} }
// WithIntrospectionService sets the introspection service. // WithIntrospectionClient sets the introspection service using an introspection client.
func WithIntrospectionService(in introspectionapi.IntrospectionClient) ServicesOpt { func WithIntrospectionClient(in introspectionapi.IntrospectionClient) ServicesOpt {
return func(s *services) { return func(s *services) {
s.introspectionService = introspection.NewIntrospectionServiceFromClient(in) s.introspectionService = introspection.NewIntrospectionServiceFromClient(in)
} }
} }
// WithIntrospectionService sets the introspection service.
func WithIntrospectionService(in introspection.Service) ServicesOpt {
return func(s *services) {
s.introspectionService = in
}
}