Add synchronous image delete
Synchronous image delete provides an option image delete to wait until the next garbage collection deletes after an image is removed before returning success to the caller. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package images
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
eventstypes "github.com/containerd/containerd/api/events"
|
||||
imagesapi "github.com/containerd/containerd/api/services/images/v1"
|
||||
@@ -22,26 +24,38 @@ func init() {
|
||||
ID: "images",
|
||||
Requires: []plugin.Type{
|
||||
plugin.MetadataPlugin,
|
||||
plugin.GCPlugin,
|
||||
},
|
||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
m, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewService(m.(*metadata.DB), ic.Events), nil
|
||||
g, err := ic.Get(plugin.GCPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewService(m.(*metadata.DB), g.(gcScheduler), ic.Events), nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type gcScheduler interface {
|
||||
ScheduleAndWait(gocontext.Context) (metadata.GCStats, error)
|
||||
}
|
||||
|
||||
type service struct {
|
||||
db *metadata.DB
|
||||
gc gcScheduler
|
||||
publisher events.Publisher
|
||||
}
|
||||
|
||||
// NewService returns the GRPC image server
|
||||
func NewService(db *metadata.DB, publisher events.Publisher) imagesapi.ImagesServer {
|
||||
func NewService(db *metadata.DB, gc gcScheduler, publisher events.Publisher) imagesapi.ImagesServer {
|
||||
return &service{
|
||||
db: db,
|
||||
gc: gc,
|
||||
publisher: publisher,
|
||||
}
|
||||
}
|
||||
@@ -162,6 +176,12 @@ func (s *service) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if req.Sync {
|
||||
if _, err := s.gc.ScheduleAndWait(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &ptypes.Empty{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user