Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

stage1: improve duplicate mount-volume detection #3666

Merged
merged 4 commits into from
May 8, 2017
Merged
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
5 changes: 3 additions & 2 deletions stage0/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ func deduplicateMPs(mounts []schema.Mount) []schema.Mount {
var res []schema.Mount
seen := make(map[string]struct{})
for _, m := range mounts {
if _, ok := seen[m.Path]; !ok {
cleanPath := path.Clean(m.Path)
if _, ok := seen[cleanPath]; !ok {
res = append(res, m)
seen[m.Path] = struct{}{}
seen[cleanPath] = struct{}{}
}
}
return res
Expand Down
9 changes: 9 additions & 0 deletions stage1/common/types/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ func LoadPod(root string, uuid *types.UUID, rp *RuntimePod) (*Pod, error) {
}
p.Manifest = pm

// ensure volumes names are unique
volNames := make(map[types.ACName]bool, len(pm.Volumes))
for _, vol := range pm.Volumes {
if volNames[vol.Name] {
return nil, fmt.Errorf("duplicate volume name %q", vol.Name)
}
volNames[vol.Name] = true
}

for i, app := range p.Manifest.Apps {
impath := common.ImageManifestPath(p.Root, app.Name)
buf, err := ioutil.ReadFile(impath)
Expand Down
11 changes: 8 additions & 3 deletions stage1_fly/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,16 @@ func evaluateMounts(rfs string, app string, p *stage1commontypes.Pod) ([]flyMoun
// Check if we have a mount for this volume
tuple, exists := namedVolumeMounts[v.Name]
if !exists {
return nil, fmt.Errorf("missing mount for volume %q", v.Name)
} else if tuple.M.Volume != v.Name {
// assertion regarding the implementation, should never happen
diag.Printf("skipping unused volume %q", v.Name)
continue
}

// Assertion regarding the implementation, should never happen
if tuple.M.Volume != v.Name {
return nil, fmt.Errorf("mismatched volume:mount pair: %q != %q", v.Name, tuple.M.Volume)
}

// Augment and replace mount entry, adding volume info
namedVolumeMounts[v.Name] = volumeMountTuple{V: v, M: tuple.M}
diag.Printf("adding %+v", namedVolumeMounts[v.Name])
}
Expand Down
21 changes: 2 additions & 19 deletions tests/rkt_volume_mount_fly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package main

import (
"fmt"
"testing"
)

Expand All @@ -28,22 +27,6 @@ func TestVolumeMount(t *testing.T) {
volumeMountTestCasesRecursivePodManifest,
volumeMountTestCasesNonRecursivePodManifest,
volumeMountTestCasesNonRecursive,
{
{
"CLI: duplicate mount given",
[]imagePatch{
{
"rkt-test-run-read-file.aci",
[]string{fmt.Sprintf("--exec=/inspect --read-file --file-name %s", mountFilePath)},
},
},
fmt.Sprintf(
"--volume=test1,kind=host,source=%s --mount volume=test1,target=%s --volume=test2,kind=host,source=%s --mount volume=test1,target=%s",
volDir, mountDir,
volDir, mountDir,
),
nil,
`run: can't evaluate mounts: missing mount for volume "test2"`,
},
}}).Execute(t)
volumeMountTestCasesDuplicateVolume,
}).Execute(t)
}
3 changes: 2 additions & 1 deletion tests/rkt_volume_mount_generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestVolumeMount(t *testing.T) {
volumeMountTestCasesRecursivePodManifest,
volumeMountTestCasesNonRecursivePodManifest,
volumeMountTestCasesNonRecursive,
volumeMountTestCasesDuplicateVolume,
{
{
"CLI: duplicate mount given",
Expand All @@ -40,7 +41,7 @@ func TestVolumeMount(t *testing.T) {
fmt.Sprintf(
"--volume=test1,kind=host,source=%s --mount volume=test1,target=%s --volume=test2,kind=host,source=%s --mount volume=test1,target=%s",
volDir, mountDir,
volDir, mountDir,
volDir, mountDir+"/",
),
nil,
innerFileContent,
Expand Down
15 changes: 15 additions & 0 deletions tests/rkt_volume_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ var (
outerFileContent,
},
}

volumeMountTestCasesDuplicateVolume = []volumeMountTestCase{
{
"CLI: duplicate volume name",
[]imagePatch{
{"rkt-test-run-pod-manifest-duplicate-mount.aci", []string{}},
},
fmt.Sprintf(
"--volume=test,kind=host,source=%s --mount volume=test,target=%s --volume=test,kind=empty --mount volume=test,target=%s",
volDir, mountDir, path.Join(mountDir, "dup"),
),
nil,
"duplicate volume name",
},
}
)

func NewTestVolumeMount(volumeMountTestCases [][]volumeMountTestCase) testutils.Test {
Expand Down