Add Cleanup to snapshot API

Cleanup is an optional method a snapshotter may implement.
Cleanup can be used to cleanup resources after a snapshot
has been removed. This function allows a snapshotter to defer
longer resource cleanup until after snapshot removals are
completed. Adding this to the API allows proxy snapshotters
to leverage this enhancement.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2020-01-02 16:38:21 -08:00
parent b95fa01b95
commit 123af61c0b
8 changed files with 354 additions and 70 deletions

View File

@@ -791,18 +791,17 @@ func validateSnapshot(info *snapshots.Info) error {
return nil
}
type cleaner interface {
Cleanup(ctx context.Context) error
}
func (s *snapshotter) garbageCollect(ctx context.Context) (d time.Duration, err error) {
s.l.Lock()
t1 := time.Now()
defer func() {
s.l.Unlock()
if err == nil {
if c, ok := s.Snapshotter.(cleaner); ok {
if c, ok := s.Snapshotter.(snapshots.Cleaner); ok {
err = c.Cleanup(ctx)
if errdefs.IsNotImplemented(err) {
err = nil
}
}
}
if err == nil {