inspect: add pull identity to track origin registry repo

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Tonis Tiigi committed 2026-01-16 08:07:21 -08:00
1 parent 3540989c71
commit 0adfe6c856
1 file changed
+20
+20
View File
@@ -11,6 +11,7 @@ import (
"time"
c8dimages "github.com/containerd/containerd/v2/core/images"
"github.com/containerd/containerd/v2/pkg/labels"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/log"
"github.com/containerd/platforms"
@@ -152,6 +153,8 @@ func (i *ImageService) imageIdentity(ctx context.Context, dgst digest.Digest) (*
}
identity := &imagetypes.Identity{}
seenRepos := make(map[string]struct{})
for k, v := range info.Labels {
if ref, ok := strings.CutPrefix(k, exporter.BuildRefLabel); ok {
var val exporter.BuildRefLabelValue
@@ -166,6 +169,23 @@ func (i *ImageService) imageIdentity(ctx context.Context, dgst digest.Digest) (*
})
}
}
if registry, ok := strings.CutPrefix(k, labels.LabelDistributionSource+"."); ok {
for repo := range strings.SplitSeq(v, ",") {
ref, err := reference.ParseNormalizedNamed(registry + "/" + repo)
if err != nil {
log.G(ctx).WithError(err).Error("failed to parse image name as reference")
continue
}
name := ref.Name()
if _, ok := seenRepos[name]; ok {
continue
}
seenRepos[name] = struct{}{}
identity.Pull = append(identity.Pull, imagetypes.PullIdentity{
Repository: name,
})
}
}
}
// return nil if there is no identity information