Added filters to snapshots API

Signed-off-by: bpopovschi <zyqsempai@mail.ru>
This commit is contained in:
bpopovschi
2019-10-02 12:24:29 +03:00
committed by Derek McGowan
parent c59561a08e
commit e8c14c07c6
12 changed files with 162 additions and 74 deletions

View File

@@ -186,7 +186,7 @@ func (b *snapshotter) usage(ctx context.Context, key string) (snapshots.Usage, e
}
// Walk the committed snapshots.
func (b *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
func (b *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error, filters ...string) error {
ctx, t, err := b.ms.TransactionContext(ctx, false)
if err != nil {
return err

View File

@@ -312,7 +312,7 @@ func (s *Snapshotter) removeDevice(ctx context.Context, key string) error {
}
// Walk iterates through all metadata Info for the stored snapshots and calls the provided function for each.
func (s *Snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
func (s *Snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error, filters ...string) error {
log.G(ctx).Debug("walk")
return s.withTransaction(ctx, false, func(ctx context.Context) error {
return storage.WalkInfo(ctx, fn)

View File

@@ -241,7 +241,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
}
// Walk the committed snapshots.
func (s *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
func (s *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error, filters ...string) error {
log.G(ctx).Debug("Starting Walk")
ctx, t, err := s.ms.TransactionContext(ctx, false)
if err != nil {

View File

@@ -232,7 +232,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
}
// Walk the committed snapshots.
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error, filters ...string) error {
ctx, t, err := o.ms.TransactionContext(ctx, false)
if err != nil {
return err

View File

@@ -283,7 +283,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
}
// Walk the committed snapshots.
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error, filters ...string) error {
ctx, t, err := o.ms.TransactionContext(ctx, false)
if err != nil {
return err

View File

@@ -153,7 +153,7 @@ func (p *proxySnapshotter) Remove(ctx context.Context, key string) error {
return errdefs.FromGRPC(err)
}
func (p *proxySnapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
func (p *proxySnapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error, filters ...string) error {
sc, err := p.client.List(ctx, &snapshotsapi.ListSnapshotsRequest{
Snapshotter: p.snapshotterName,
})

View File

@@ -315,8 +315,11 @@ type Snapshotter interface {
Remove(ctx context.Context, key string) error
// Walk all snapshots in the snapshotter. For each snapshot in the
// snapshotter, the function will be called.
Walk(ctx context.Context, fn func(context.Context, Info) error) error
// snapshotter, the function will be called, unless filters were used.
// Zero or more filters may be provided as strings. Only events that match
// *any* of the provided filters will be sent on the channel. The filters use
// the standard containerd filters package syntax.
Walk(ctx context.Context, fn func(context.Context, Info) error, filters ...string) error
// Close releases the internal resources.
//

View File

@@ -238,7 +238,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
}
// Walk the committed snapshots.
func (s *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
func (s *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error, filters ...string) error {
ctx, t, err := s.ms.TransactionContext(ctx, false)
if err != nil {
return err