-
Notifications
You must be signed in to change notification settings - Fork 238
/
layerfolders.go
49 lines (40 loc) · 1.47 KB
/
layerfolders.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
39
40
41
42
43
44
45
46
47
48
49
//go:build windows
package layers
import (
"context"
"encoding/json"
"strings"
"testing"
"github.com/containerd/containerd"
"github.com/containerd/containerd/mount"
testctrd "github.com/Microsoft/hcsshim/test/internal/containerd"
)
// FromImage returns thee layer paths of a given image, pulling it if necessary
func FromImage(ctx context.Context, tb testing.TB, client *containerd.Client, ref, platform, snapshotter string) []string {
tb.Helper()
chainID := testctrd.PullImage(ctx, tb, client, ref, platform)
return FromChainID(ctx, tb, client, chainID, snapshotter)
}
// FromChainID returns thee layer paths of a given image chain ID
func FromChainID(ctx context.Context, tb testing.TB, client *containerd.Client, chainID, snapshotter string) []string {
tb.Helper()
ms := testctrd.CreateViewSnapshot(ctx, tb, client, snapshotter, chainID, chainID+"view")
if len(ms) != 1 {
tb.Fatalf("Rootfs does not contain exactly 1 mount for the root file system")
}
return FromMount(ctx, tb, ms[0])
}
// FromMount returns the layer paths of a given mount
func FromMount(_ context.Context, tb testing.TB, m mount.Mount) (layers []string) {
tb.Helper()
for _, option := range m.Options {
if strings.HasPrefix(option, mount.ParentLayerPathsFlag) {
err := json.Unmarshal([]byte(option[len(mount.ParentLayerPathsFlag):]), &layers)
if err != nil {
tb.Fatalf("failed to unmarshal parent layer paths from mount: %v", err)
}
}
}
layers = append(layers, m.Source)
return layers
}