Skip to content

Commit 3e76008

Browse files
committed
fix: use canonical image name in tag service only to preserve original repo name
1 parent c3e9747 commit 3e76008

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

internal/storage/containerd/blob.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func (b *blobStore) Resume(ctx context.Context, id string) (distribution.BlobWri
121121
func (b *blobStore) Mount(ctx context.Context, sourceRepo reference.Named, dgst digest.Digest) (
122122
distribution.Descriptor, error,
123123
) {
124-
// We could implement cross-repository mounting here by checking if the blob exists
125-
// and creating a reference to it, but for now we'll keep it simple.
124+
// We could implement cross-repository mounting here by checking if the blob exists and returning its descriptor.
125+
// The content in containerd is not repository-namespaced. But for now we'll keep it simple.
126126
return distribution.Descriptor{}, distribution.ErrUnsupported
127127
}
128128

internal/storage/containerd/registry.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ func (n *registry) Scope() distribution.Scope {
2424

2525
// Repository returns an instance of repository for the given name.
2626
func (n *registry) Repository(_ context.Context, name reference.Named) (distribution.Repository, error) {
27-
canonicalName, err := reference.ParseNormalizedNamed(name.String())
28-
if err != nil {
29-
return nil, err
30-
}
31-
return newRepository(n.client.client, canonicalName), nil
27+
return newRepository(n.client.client, name), nil
3228
}
3329

3430
// Repositories returns a list of repositories.

internal/storage/containerd/repository.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package containerd
22

33
import (
44
"context"
5+
56
"github.com/containerd/containerd/v2/client"
67
"github.com/distribution/distribution/v3"
78
"github.com/distribution/reference"
@@ -49,8 +50,10 @@ func (r *repository) Blobs(_ context.Context) distribution.BlobStore {
4950

5051
// Tags returns the tag service for the repository backed by the containerd image store.
5152
func (r *repository) Tags(_ context.Context) distribution.TagService {
53+
// Shouldn't return an error as r.name is a valid reference.
54+
canonicalRepo, _ := reference.ParseNormalizedNamed(r.name.String())
5255
return &tagService{
53-
client: r.client,
54-
repo: r.name,
56+
client: r.client,
57+
canonicalRepo: canonicalRepo,
5558
}
5659
}

internal/storage/containerd/tags.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package containerd
33
import (
44
"context"
55
"fmt"
6-
"github.com/sirupsen/logrus"
76
"strings"
87

8+
"github.com/sirupsen/logrus"
9+
910
"github.com/containerd/containerd/v2/client"
1011
"github.com/containerd/containerd/v2/core/images"
1112
"github.com/containerd/errdefs"
@@ -15,15 +16,18 @@ import (
1516

1617
// tagService implements distribution.TagService backed by the containerd image store.
1718
type tagService struct {
18-
client *client.Client
19-
repo reference.Named
19+
client *client.Client
20+
canonicalRepo reference.Named
2021
}
2122

2223
// Get retrieves an image descriptor by its tag from the containerd image store.
2324
func (t *tagService) Get(ctx context.Context, tag string) (distribution.Descriptor, error) {
24-
ref, err := reference.WithTag(t.repo, tag)
25+
ref, err := reference.WithTag(t.canonicalRepo, tag)
2526
if err != nil {
26-
return distribution.Descriptor{}, err
27+
return distribution.Descriptor{}, distribution.ErrManifestUnknown{
28+
Name: t.canonicalRepo.Name(),
29+
Tag: tag,
30+
}
2731
}
2832

2933
img, err := t.client.ImageService().Get(ctx, ref.String())
@@ -52,7 +56,7 @@ func (t *tagService) Get(ctx context.Context, tag string) (distribution.Descript
5256
// It also sets garbage collection labels on the image content in the containerd content store to prevent it from being
5357
// deleted by garbage collection.
5458
func (t *tagService) Tag(ctx context.Context, tag string, desc distribution.Descriptor) error {
55-
ref, err := reference.WithTag(t.repo, tag)
59+
ref, err := reference.WithTag(t.canonicalRepo, tag)
5660
if err != nil {
5761
return err
5862
}
@@ -116,7 +120,7 @@ func (t *tagService) Tag(ctx context.Context, tag string, desc distribution.Desc
116120
// TODO:
117121
func (t *tagService) Untag(ctx context.Context, tag string) error {
118122
// Construct the full reference
119-
ref := fmt.Sprintf("%s:%s", t.repo.String(), tag)
123+
ref := fmt.Sprintf("%s:%s", t.canonicalRepo.String(), tag)
120124

121125
// Delete the image reference
122126
err := t.client.ImageService().Delete(ctx, ref)
@@ -138,7 +142,7 @@ func (t *tagService) All(ctx context.Context) ([]string, error) {
138142
}
139143

140144
// Filter by repository name
141-
repoName := t.repo.String()
145+
repoName := t.canonicalRepo.String()
142146
var tags []string
143147

144148
for _, img := range images {
@@ -162,7 +166,7 @@ func (t *tagService) Lookup(ctx context.Context, desc distribution.Descriptor) (
162166
}
163167

164168
// Find tags that point to this descriptor
165-
repoName := t.repo.String()
169+
repoName := t.canonicalRepo.String()
166170
var tags []string
167171

168172
for _, img := range images {

0 commit comments

Comments
 (0)