Skip to content

Commit 7aedc2e

Browse files
committed
fix: pin repoTag image only (#21)
Signed-off-by: Zllinc <2965202581@qq.com>
1 parent 9505bd2 commit 7aedc2e

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎pkg/cri/server/helpers.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ const (
9090

9191
// runtimeRunhcsV1 is the runtime type for runhcs.
9292
runtimeRunhcsV1 = "io.containerd.runhcs.v1"
93+
94+
// DevboxSnapshotter is the name of the devbox snapshotter.
95+
DevboxSnapshotter = "devbox"
9396
)
9497

9598
// makeSandboxName generates sandbox name from sandbox metadata. The name

‎pkg/cri/server/image_pull.go‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,6 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
160160

161161
labels := c.getLabels(ctx, ref)
162162

163-
// if snapshotter is devbox, add the pinned image label
164-
if snapshotter == "devbox" {
165-
if labels == nil {
166-
labels = map[string]string{}
167-
}
168-
labels[crilabels.PinnedImageLabelKey] = crilabels.PinnedImageLabelValue
169-
}
170-
171163
pullOpts := []containerd.RemoteOpt{
172164
containerd.WithSchema1Conversion, //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
173165
containerd.WithResolver(resolver),
@@ -209,11 +201,28 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
209201
imageID := configDesc.Digest.String()
210202

211203
repoDigest, repoTag := getRepoDigestAndTag(namedRef, image.Target().Digest, isSchema1)
204+
205+
// Iterate over imageID, repoTag, and repoDigest
212206
for _, r := range []string{imageID, repoTag, repoDigest} {
213207
if r == "" {
214208
continue
215209
}
216-
if err := c.createImageReference(ctx, r, image.Target(), labels); err != nil {
210+
211+
// Create a copy of labels for each reference to avoid modifying the original map
212+
var imageLabels map[string]string
213+
if r == repoTag && snapshotter == DevboxSnapshotter {
214+
// Only add pin label for repoTag when snapshotter is devbox
215+
imageLabels = make(map[string]string)
216+
for k, v := range labels {
217+
imageLabels[k] = v
218+
}
219+
imageLabels[crilabels.PinnedImageLabelKey] = crilabels.PinnedImageLabelValue
220+
} else {
221+
// For imageID and repoDigest, use labels as-is (no pin label)
222+
imageLabels = labels
223+
}
224+
225+
if err := c.createImageReference(ctx, r, image.Target(), imageLabels); err != nil {
217226
return nil, fmt.Errorf("failed to create image reference %q: %w", r, err)
218227
}
219228
// Update image store to reflect the newest state in containerd.

0 commit comments

Comments
 (0)