Move label filter to snapshots package

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
ktock
2019-12-25 10:21:57 +09:00
parent 4ccb7aa221
commit 493a36de95
4 changed files with 31 additions and 31 deletions

View File

@@ -25,6 +25,11 @@ import (
"github.com/containerd/containerd/mount"
)
const (
inheritedLabelsPrefix = "containerd.io/snapshot/"
labelSnapshotRef = "containerd.io/snapshot.ref"
)
// Kind identifies the kind of snapshot.
type Kind uint8
@@ -346,3 +351,20 @@ func WithLabels(labels map[string]string) Opt {
return nil
}
}
// FilterInheritedLabels filters the provided labels by removing any key which
// isn't a snapshot label. Snapshot labels have a prefix of "containerd.io/snapshot/"
// or are the "containerd.io/snapshot.ref" label.
func FilterInheritedLabels(labels map[string]string) map[string]string {
if labels == nil {
return nil
}
filtered := make(map[string]string)
for k, v := range labels {
if k == labelSnapshotRef || strings.HasPrefix(k, inheritedLabelsPrefix) {
filtered[k] = v
}
}
return filtered
}