Skip to content

Commit 7f5d7ff

Browse files
committed
Update snapshots docs with garbage collector label
Signed-off-by: Oliver Stenbom <[email protected]>
1 parent f35c352 commit 7f5d7ff

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

snapshots/snapshotter.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,13 @@ func (u *Usage) Add(other Usage) {
160160
// layerPath, tmpDir := getLayerPath(), mkTmpDir() // just a path to layer tar file.
161161
//
162162
// We start by using a Snapshotter to Prepare a new snapshot transaction, using a
163-
// key and descending from the empty parent "":
163+
// key and descending from the empty parent "". To prevent our layer from being
164+
// garbage collected during unpacking, we add the `containerd.io/gc.root` label:
164165
//
165-
// mounts, err := snapshotter.Prepare(ctx, key, "")
166+
// noGcOpt := snapshotter.WithLabels(map[string]string{
167+
// "containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
168+
// })
169+
// mounts, err := snapshotter.Prepare(ctx, key, "", noGcOpt)
166170
// if err != nil { ... }
167171
//
168172
// We get back a list of mounts from Snapshotter.Prepare, with the key identifying
@@ -191,23 +195,21 @@ func (u *Usage) Add(other Usage) {
191195
//
192196
// Now that we've verified and unpacked our layer, we commit the active
193197
// snapshot to a name. For this example, we are just going to use the layer
194-
// digest, but in practice, this will probably be the ChainID:
198+
// digest, but in practice, this will probably be the ChainID. This also removes
199+
// the active snapshot:
195200
//
196-
// if err := snapshotter.Commit(ctx, digest.String(), key); err != nil { ... }
201+
// if err := snapshotter.Commit(ctx, digest.String(), key, noGcOpt); err != nil { ... }
197202
//
198203
// Now, we have a layer in the Snapshotter that can be accessed with the digest
199-
// provided during commit. Once you have committed the snapshot, the active
200-
// snapshot can be removed with the following:
201-
//
202-
// snapshotter.Remove(ctx, key)
204+
// provided during commit.
203205
//
204206
// Importing the Next Layer
205207
//
206208
// Making a layer depend on the above is identical to the process described
207209
// above except that the parent is provided as parent when calling
208210
// Manager.Prepare, assuming a clean, unique key identifier:
209211
//
210-
// mounts, err := snapshotter.Prepare(ctx, key, parentDigest)
212+
// mounts, err := snapshotter.Prepare(ctx, key, parentDigest, noGcOpt)
211213
//
212214
// We then mount, apply and commit, as we did above. The new snapshot will be
213215
// based on the content of the previous one.

0 commit comments

Comments
 (0)