cmd/snapshots: add gc.root to created snapshots

This adds gc.root label to snapshots created with prepare and commit via
the CLI. WIthout this, created snapshots get immediately garbage
collected. There may be a better solution but this seems to be a solid
stop gap.

We may also need to add more functionality around snapshot labeling for
the CLI but current use cases are unclear.

Signed-off-by: Stephen J Day <stevvooe@gmail.com>
This commit is contained in:
Stephen J Day 2018-05-03 07:09:38 +02:00
parent cfba048bec
commit ed72059fac
No known key found for this signature in database
GPG Key ID: 67B3DED84EDC823F

View File

@ -304,7 +304,11 @@ var prepareCommand = cli.Command{
defer cancel() defer cancel()
snapshotter := client.SnapshotService(context.GlobalString("snapshotter")) snapshotter := client.SnapshotService(context.GlobalString("snapshotter"))
mounts, err := snapshotter.Prepare(ctx, key, parent) labels := map[string]string{
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
}
mounts, err := snapshotter.Prepare(ctx, key, parent, snapshots.WithLabels(labels))
if err != nil { if err != nil {
return err return err
} }
@ -404,7 +408,10 @@ var commitCommand = cli.Command{
} }
defer cancel() defer cancel()
snapshotter := client.SnapshotService(context.GlobalString("snapshotter")) snapshotter := client.SnapshotService(context.GlobalString("snapshotter"))
return snapshotter.Commit(ctx, key, active) labels := map[string]string{
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
}
return snapshotter.Commit(ctx, key, active, snapshots.WithLabels(labels))
}, },
} }