Skip to content

Commit 4e69228

Browse files
Wei Fufuweid
authored andcommitted
bugfix: unpack should always set the snapshot gc label
There are two images, A and B. A is based on B. If user pulls A first, then user pulls B. containerd already has the unpacked snapshots in the backend. During unpacking B, the client doesn't set gc snapshot reference label to the config descriptor. That is the problem. The gc module cannot reach the snapshot from the config descriptor. If user removes the image B, the snapshot will be deleted by gc module. That is why we should always set the snapshot gc label to config descriptor. Signed-off-by: Wei Fu <[email protected]> (cherry picked from commit 2d96aad) Signed-off-by: Wei Fu <[email protected]>
1 parent 52bfc9f commit 4e69228

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

image.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,22 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
153153
chain = append(chain, layer.Diff.Digest)
154154
}
155155

156-
if unpacked {
157-
desc, err := i.i.Config(ctx, cs, platforms.Default())
158-
if err != nil {
159-
return err
160-
}
156+
desc, err := i.i.Config(ctx, cs, platforms.Default())
157+
if err != nil {
158+
return err
159+
}
161160

162-
rootfs := identity.ChainID(chain).String()
161+
rootfs := identity.ChainID(chain).String()
163162

164-
cinfo := content.Info{
165-
Digest: desc.Digest,
166-
Labels: map[string]string{
167-
fmt.Sprintf("containerd.io/gc.ref.snapshot.%s", snapshotterName): rootfs,
168-
},
169-
}
170-
if _, err := cs.Update(ctx, cinfo, fmt.Sprintf("labels.containerd.io/gc.ref.snapshot.%s", snapshotterName)); err != nil {
171-
return err
172-
}
163+
cinfo := content.Info{
164+
Digest: desc.Digest,
165+
Labels: map[string]string{
166+
fmt.Sprintf("containerd.io/gc.ref.snapshot.%s", snapshotterName): rootfs,
167+
},
173168
}
174169

175-
return nil
170+
_, err = cs.Update(ctx, cinfo, fmt.Sprintf("labels.containerd.io/gc.ref.snapshot.%s", snapshotterName))
171+
return err
176172
}
177173

178174
func (i *image) getLayers(ctx context.Context, platform string) ([]rootfs.Layer, error) {

0 commit comments

Comments
 (0)