Skip to content

Commit 072aa64

Browse files
committed
merge devices by unique mount path
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent cc11b36 commit 072aa64

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

override/merge_devices_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright 2020 The Compose Specification Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package override
18+
19+
import (
20+
"testing"
21+
)
22+
23+
func Test_mergeYamlDevices(t *testing.T) {
24+
assertMergeYaml(t, `
25+
services:
26+
test:
27+
image: foo
28+
devices:
29+
- '/dev/sda:/dev/sda'
30+
- '/dev/sdb:/dev/sdb'
31+
- '/dev/sdc:/dev/sdc'
32+
- '/dev/sdd:/dev/sdd'
33+
`, `
34+
services:
35+
test:
36+
devices:
37+
- '/dev/sde:/dev/sde'
38+
- '/dev/sdf:/dev/sdf'
39+
- '/dev/sdg:/dev/sdg'
40+
- '/dev/sdh:/dev/sdh'
41+
`, `
42+
services:
43+
test:
44+
image: foo
45+
devices:
46+
- '/dev/sda:/dev/sda'
47+
- '/dev/sdb:/dev/sdb'
48+
- '/dev/sdc:/dev/sdc'
49+
- '/dev/sdd:/dev/sdd'
50+
- '/dev/sde:/dev/sde'
51+
- '/dev/sdf:/dev/sdf'
52+
- '/dev/sdg:/dev/sdg'
53+
- '/dev/sdh:/dev/sdh'
54+
`)
55+
}
56+
57+
func Test_mergeYamlDevicesOverride(t *testing.T) {
58+
assertMergeYaml(t, `
59+
services:
60+
test:
61+
image: foo
62+
devices:
63+
- '/dev/sda:/dev/sda'
64+
- '/dev/sdb:/dev/sdb'
65+
- '/dev/sdc:/dev/sdc'
66+
- '/dev/sdd:/dev/sdd'
67+
`, `
68+
services:
69+
test:
70+
devices:
71+
- '/dev/nvme0n1p1:/dev/sda'
72+
- '/dev/nvme1n1p1:/dev/sdb'
73+
- '/dev/nvme2n1p1:/dev/sdc'
74+
`, `
75+
services:
76+
test:
77+
image: foo
78+
devices:
79+
- '/dev/nvme0n1p1:/dev/sda'
80+
- '/dev/nvme1n1p1:/dev/sdb'
81+
- '/dev/nvme2n1p1:/dev/sdc'
82+
- '/dev/sdd:/dev/sdd'
83+
`)
84+
}

override/uncity.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func init() {
4242
unique["services.*.build.labels"] = keyValueIndexer
4343
unique["services.*.cap_add"] = keyValueIndexer
4444
unique["services.*.cap_drop"] = keyValueIndexer
45+
unique["services.*.devices"] = volumeIndexer
4546
unique["services.*.configs"] = mountIndexer("")
4647
unique["services.*.deploy.labels"] = keyValueIndexer
4748
unique["services.*.dns"] = keyValueIndexer

0 commit comments

Comments
 (0)