From 7b67eead059ba98fdf1f18565cc463b24142d275 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 27 Mar 2024 08:02:53 +0100 Subject: [PATCH] merge devices by unique mount path Signed-off-by: Nicolas De Loof --- override/merge_devices_test.go | 84 ++++++++++++++++++++++++++++++++++ override/uncity.go | 1 + 2 files changed, 85 insertions(+) create mode 100644 override/merge_devices_test.go diff --git a/override/merge_devices_test.go b/override/merge_devices_test.go new file mode 100644 index 00000000..1f9be620 --- /dev/null +++ b/override/merge_devices_test.go @@ -0,0 +1,84 @@ +/* + Copyright 2020 The Compose Specification Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package override + +import ( + "testing" +) + +func Test_mergeYamlDevices(t *testing.T) { + assertMergeYaml(t, ` +services: + test: + image: foo + devices: + - '/dev/sda:/dev/sda' + - '/dev/sdb:/dev/sdb' + - '/dev/sdc:/dev/sdc' + - '/dev/sdd:/dev/sdd' +`, ` +services: + test: + devices: + - '/dev/sde:/dev/sde' + - '/dev/sdf:/dev/sdf' + - '/dev/sdg:/dev/sdg' + - '/dev/sdh:/dev/sdh' +`, ` +services: + test: + image: foo + devices: + - '/dev/sda:/dev/sda' + - '/dev/sdb:/dev/sdb' + - '/dev/sdc:/dev/sdc' + - '/dev/sdd:/dev/sdd' + - '/dev/sde:/dev/sde' + - '/dev/sdf:/dev/sdf' + - '/dev/sdg:/dev/sdg' + - '/dev/sdh:/dev/sdh' +`) +} + +func Test_mergeYamlDevicesOverride(t *testing.T) { + assertMergeYaml(t, ` +services: + test: + image: foo + devices: + - '/dev/sda:/dev/sda' + - '/dev/sdb:/dev/sdb' + - '/dev/sdc:/dev/sdc' + - '/dev/sdd:/dev/sdd' +`, ` +services: + test: + devices: + - '/dev/nvme0n1p1:/dev/sda' + - '/dev/nvme1n1p1:/dev/sdb' + - '/dev/nvme2n1p1:/dev/sdc' +`, ` +services: + test: + image: foo + devices: + - '/dev/nvme0n1p1:/dev/sda' + - '/dev/nvme1n1p1:/dev/sdb' + - '/dev/nvme2n1p1:/dev/sdc' + - '/dev/sdd:/dev/sdd' +`) +} diff --git a/override/uncity.go b/override/uncity.go index 9cbc45f4..057b2f28 100644 --- a/override/uncity.go +++ b/override/uncity.go @@ -42,6 +42,7 @@ func init() { unique["services.*.build.labels"] = keyValueIndexer unique["services.*.cap_add"] = keyValueIndexer unique["services.*.cap_drop"] = keyValueIndexer + unique["services.*.devices"] = volumeIndexer unique["services.*.configs"] = mountIndexer("") unique["services.*.deploy.labels"] = keyValueIndexer unique["services.*.dns"] = keyValueIndexer