-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
labels.go
38 lines (35 loc) · 1.14 KB
/
labels.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package estargz
import (
"fmt"
"strings"
ctdlabels "github.com/containerd/containerd/labels"
"github.com/containerd/stargz-snapshotter/estargz"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
)
func SnapshotLabels(ref string, descs []ocispecs.Descriptor, targetIndex int) map[string]string {
if len(descs) < targetIndex {
return nil
}
desc := descs[targetIndex]
labels := make(map[string]string)
for _, k := range []string{estargz.TOCJSONDigestAnnotation, estargz.StoreUncompressedSizeAnnotation} {
labels[k] = desc.Annotations[k]
}
labels["containerd.io/snapshot/remote/stargz.reference"] = ref
labels["containerd.io/snapshot/remote/stargz.digest"] = desc.Digest.String()
var (
layersKey = "containerd.io/snapshot/remote/stargz.layers"
layers string
)
for _, l := range descs[targetIndex:] {
ls := fmt.Sprintf("%s,", l.Digest.String())
// This avoids the label hits the size limitation.
// Skipping layers is allowed here and only affects performance.
if err := ctdlabels.Validate(layersKey, layers+ls); err != nil {
break
}
layers += ls
}
labels[layersKey] = strings.TrimSuffix(layers, ",")
return labels
}