Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions cmd/containerd-shim-runhcs-v1/rootfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,10 @@ func parseLegacyRootfsMount(m *types.Mount) (string, []string, error) {
//
// The OCI spec expects:
// layerN, layerN-1, ..., layer0, scratch
var parentLayerPaths []string
for _, option := range m.Options {
if strings.HasPrefix(option, mount.ParentLayerPathsFlag) {
err := json.Unmarshal([]byte(option[len(mount.ParentLayerPathsFlag):]), &parentLayerPaths)
if err != nil {
return "", nil, fmt.Errorf("unmarshal parent layer paths from mount: %v: %w", err, errdefs.ErrFailedPrecondition)
}
// Would perhaps be worthwhile to check for unrecognized options and return an error,
// but since this is a legacy layer mount we don't do that to avoid breaking anyone.
break
}
containerdMount := mount.Mount{Type: m.Type, Source: m.Source, Target: m.Target, Options: m.Options}
parentLayerPaths, err := containerdMount.GetParentPaths()
if err != nil {
return "", nil, fmt.Errorf("failed to get mount's parent layer paths: %v: %w", err, errdefs.ErrFailedPrecondition)
}
return m.Source, parentLayerPaths, nil
}
Expand Down Expand Up @@ -100,7 +93,7 @@ func getLCOWLayers(rootfs []*types.Mount, layerFolders []string) (*layers.LCOWLa
m := rootfs[0]
switch m.Type {
case "lcow-layer":
scratchLayer, parentLayers, err := parseLegacyRootfsMount(rootfs[0])
scratchLayer, parentLayers, err := parseLegacyRootfsMount(m)
if err != nil {
return nil, err
}
Expand Down
12 changes: 3 additions & 9 deletions test/internal/layers/layerfolders.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package layers

import (
"context"
"encoding/json"
"strings"
"testing"

"github.com/containerd/containerd"
Expand Down Expand Up @@ -35,13 +33,9 @@ func FromChainID(ctx context.Context, tb testing.TB, client *containerd.Client,
// 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, err := m.GetParentPaths()
if err != nil {
tb.Fatalf("failed to get mount's parent layer paths: %v", err)
}
layers = append(layers, m.Source)

Expand Down