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:
1 file changed
+20
@@ -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
|
||||
|
||||
Reference in new issue
Block a user