Skip to content

Commit dd3eedf

Browse files
committed
labels: Add LabelDistributionSource
Add a public const for "containerd.io/distribution.source" in `labels` package and replace hardcoded usages. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 29e10a1 commit dd3eedf

5 files changed

Lines changed: 13 additions & 11 deletions

File tree

integration/client/image_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/containerd/containerd/errdefs"
2828
"github.com/containerd/containerd/images"
2929
imagelist "github.com/containerd/containerd/integration/images"
30+
"github.com/containerd/containerd/labels"
3031
"github.com/containerd/containerd/platforms"
3132
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3233
)
@@ -105,7 +106,7 @@ func TestImagePullWithDistSourceLabel(t *testing.T) {
105106
defer client.ImageService().Delete(ctx, imageName)
106107

107108
cs := client.ContentStore()
108-
key := fmt.Sprintf("containerd.io/distribution.source.%s", source)
109+
key := labels.LabelDistributionSource + "." + source
109110

110111
// only check the target platform
111112
childrenHandler := images.LimitManifests(images.ChildrenHandler(cs), pMatcher, 1)

labels/labels.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ const LabelUncompressed = "containerd.io/uncompressed"
2323
// LabelSharedNamespace is added to a namespace to allow that namespaces
2424
// contents to be shared.
2525
const LabelSharedNamespace = "containerd.io/namespace.shareable"
26+
27+
// LabelDistributionSource is added to content to indicate its origin.
28+
// e.g., "containerd.io/distribution.source.docker.io=library/redis"
29+
const LabelDistributionSource = "containerd.io/distribution.source"

remotes/docker/handler.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ import (
3030
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3131
)
3232

33-
var (
34-
// labelDistributionSource describes the source blob comes from.
35-
labelDistributionSource = "containerd.io/distribution.source"
36-
)
37-
3833
// AppendDistributionSourceLabel updates the label of blob with distribution source.
3934
func AppendDistributionSourceLabel(manager content.Manager, ref string) (images.HandlerFunc, error) {
4035
refspec, err := reference.Parse(ref)
@@ -108,7 +103,7 @@ func appendDistributionSourceLabel(originLabel, repo string) string {
108103
}
109104

110105
func distributionSourceLabelKey(source string) string {
111-
return fmt.Sprintf("%s.%s", labelDistributionSource, source)
106+
return fmt.Sprintf("%s.%s", labels.LabelDistributionSource, source)
112107
}
113108

114109
// selectRepositoryMountCandidate will select the repo which has longest

remotes/docker/handler_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"reflect"
2121
"testing"
2222

23+
"github.com/containerd/containerd/labels"
2324
"github.com/containerd/containerd/reference"
2425
)
2526

@@ -69,7 +70,7 @@ func TestAppendDistributionLabel(t *testing.T) {
6970
}
7071

7172
func TestDistributionSourceLabelKey(t *testing.T) {
72-
expected := "containerd.io/distribution.source.testsource"
73+
expected := labels.LabelDistributionSource + ".testsource"
7374
if got := distributionSourceLabelKey("testsource"); !reflect.DeepEqual(got, expected) {
7475
t.Fatalf("expected %v, but got %v", expected, got)
7576
}
@@ -116,12 +117,12 @@ func TestSelectRepositoryMountCandidate(t *testing.T) {
116117
},
117118
{
118119
refspec: reference.Spec{Locator: "user@host/path"},
119-
source: map[string]string{"containerd.io/distribution.source.host": "foo,path,bar"},
120+
source: map[string]string{labels.LabelDistributionSource + ".host": "foo,path,bar"},
120121
expected: "bar",
121122
},
122123
{
123124
refspec: reference.Spec{Locator: "user@host/path"},
124-
source: map[string]string{"containerd.io/distribution.source.host": "foo,bar,path"},
125+
source: map[string]string{labels.LabelDistributionSource + ".host": "foo,bar,path"},
125126
expected: "bar",
126127
},
127128
} {

remotes/handlers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/containerd/containerd/content"
2929
"github.com/containerd/containerd/errdefs"
3030
"github.com/containerd/containerd/images"
31+
"github.com/containerd/containerd/labels"
3132
"github.com/containerd/containerd/log"
3233
"github.com/containerd/containerd/platforms"
3334
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -367,7 +368,7 @@ func annotateDistributionSourceHandler(f images.HandlerFunc, manager content.Man
367368
}
368369

369370
for k, v := range info.Labels {
370-
if !strings.HasPrefix(k, "containerd.io/distribution.source.") {
371+
if !strings.HasPrefix(k, labels.LabelDistributionSource+".") {
371372
continue
372373
}
373374

0 commit comments

Comments
 (0)