Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88401ba

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 c1f49fa commit 88401ba

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

image.go

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

173-
if unpacked {
174-
desc, err := i.i.Config(ctx, cs, i.platform)
175-
if err != nil {
176-
return err
177-
}
173+
desc, err := i.i.Config(ctx, cs, i.platform)
174+
if err != nil {
175+
return err
176+
}
178177

179-
rootfs := identity.ChainID(chain).String()
178+
rootfs := identity.ChainID(chain).String()
180179

181-
cinfo := content.Info{
182-
Digest: desc.Digest,
183-
Labels: map[string]string{
184-
fmt.Sprintf("containerd.io/gc.ref.snapshot.%s", snapshotterName): rootfs,
185-
},
186-
}
187-
if _, err := cs.Update(ctx, cinfo, fmt.Sprintf("labels.containerd.io/gc.ref.snapshot.%s", snapshotterName)); err != nil {
188-
return err
189-
}
180+
cinfo := content.Info{
181+
Digest: desc.Digest,
182+
Labels: map[string]string{
183+
fmt.Sprintf("containerd.io/gc.ref.snapshot.%s", snapshotterName): rootfs,
184+
},
190185
}
191186

192-
return nil
187+
_, err = cs.Update(ctx, cinfo, fmt.Sprintf("labels.containerd.io/gc.ref.snapshot.%s", snapshotterName))
188+
return err
193189
}
194190

195191
func (i *image) getLayers(ctx context.Context, platform platforms.MatchComparer) ([]rootfs.Layer, error) {

0 commit comments

Comments
 (0)