From 30d6e1b9e21410067f58d3752c731ccda2dd309e Mon Sep 17 00:00:00 2001 From: aiordache Date: Fri, 8 Jan 2021 16:11:37 +0100 Subject: [PATCH] override inherited secret mounts Signed-off-by: aiordache --- local/compose/create.go | 10 ++++++++++ local/compose/util.go | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/local/compose/create.go b/local/compose/create.go index 1dd717c19..62f834cd4 100644 --- a/local/compose/create.go +++ b/local/compose/create.go @@ -310,6 +310,16 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, inherit if definedSecret.External.External { return nil, fmt.Errorf("unsupported external secret %s", definedSecret.Name) } + + if contains(inherited, target) { + // remove inherited mount + pos := indexOf(inherited, target) + if pos >= 0 { + mounts = append(mounts[:pos], mounts[pos+1]) + inherited = append(inherited[:pos], inherited[pos+1]) + } + } + mount, err := buildMount(p, types.ServiceVolumeConfig{ Type: types.VolumeTypeBind, Source: definedSecret.File, diff --git a/local/compose/util.go b/local/compose/util.go index dd9cbbcfe..b0af71cac 100644 --- a/local/compose/util.go +++ b/local/compose/util.go @@ -38,3 +38,12 @@ func contains(slice []string, item string) bool { } return false } + +func indexOf(slice []string, item string) int { + for i, v := range slice { + if v == item { + return i + } + } + return -1 +}