MCPcopy
hub / github.com/containerd/containerd / AppendDistributionSourceLabel

Function AppendDistributionSourceLabel

core/remotes/docker/handler.go:34–77  ·  view source on GitHub ↗

AppendDistributionSourceLabel updates the label of blob with distribution source.

(manager content.Manager, ref string)

Source from the content-addressed store, hash-verified

32
33// AppendDistributionSourceLabel updates the label of blob with distribution source.
34func AppendDistributionSourceLabel(manager content.Manager, ref string) (images.HandlerFunc, error) {
35 refspec, err := reference.Parse(ref)
36 if err != nil {
37 return nil, err
38 }
39
40 u, err := url.Parse("dummy://" + refspec.Locator)
41 if err != nil {
42 return nil, err
43 }
44
45 source, repo := u.Hostname(), strings.TrimPrefix(u.Path, "/")
46 return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
47 info, err := manager.Info(ctx, desc.Digest)
48 if err != nil {
49 return nil, err
50 }
51
52 key := distributionSourceLabelKey(source)
53
54 originLabel := ""
55 if info.Labels != nil {
56 originLabel = info.Labels[key]
57 }
58 value := appendDistributionSourceLabel(originLabel, repo)
59
60 // The repo name has been limited under 256 and the distribution
61 // label might hit the limitation of label size, when blob data
62 // is used as the very, very common layer.
63 if err := labels.Validate(key, value); err != nil {
64 log.G(ctx).Warnf("skip to append distribution label: %s", err)
65 return nil, nil
66 }
67
68 info = content.Info{
69 Digest: desc.Digest,
70 Labels: map[string]string{
71 key: value,
72 },
73 }
74 _, err = manager.Update(ctx, info, fmt.Sprintf("labels.%s", key))
75 return nil, err
76 }, nil
77}
78
79func appendDistributionSourceLabel(originLabel, repo string) string {
80 repos := []string{}

Callers 2

fetchMethod · 0.92
pullMethod · 0.92

Calls 7

ParseFunction · 0.92
ValidateFunction · 0.92
HostnameMethod · 0.65
InfoMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…