Allow the same release name on different tillerNamespaces (#529)

Closes #528
This commit is contained in:
Patrick Valsecchi 2019-04-02 11:51:11 +02:00 committed by KUOKA Yusuke
parent eb36e93c5a
commit fa95e0dd92
2 changed files with 24 additions and 4 deletions

View File

@ -202,13 +202,20 @@ func (a *App) VisitDesiredStatesWithReleasesFiltered(fileOrDir string, converge
} }
} }
releaseNameCounts := map[string]int{} type Key struct {
TillerNamespace, Name string
}
releaseNameCounts := map[Key]int{}
for _, r := range st.Releases { for _, r := range st.Releases {
releaseNameCounts[r.Name]++ tillerNamespace := st.HelmDefaults.TillerNamespace
if r.TillerNamespace != "" {
tillerNamespace = r.TillerNamespace
}
releaseNameCounts[Key{tillerNamespace, r.Name}]++
} }
for name, c := range releaseNameCounts { for name, c := range releaseNameCounts {
if c > 1 { if c > 1 {
return false, []error{fmt.Errorf("duplicate release \"%s\" found: there were %d releases named \"%s\" matching specified selector", name, c, name)} return false, []error{fmt.Errorf("duplicate release \"%s\" found in \"%s\": there were %d releases named \"%s\" matching specified selector", name.Name, name.TillerNamespace, c, name.Name)}
} }
} }

View File

@ -247,6 +247,8 @@ releases:
chart: stable/prometheus chart: stable/prometheus
`, `,
"/path/to/helmfile.d/b.yaml": ` "/path/to/helmfile.d/b.yaml": `
helmDefaults:
tillerNamespace: zoo
releases: releases:
- name: grafana - name: grafana
chart: stable/grafana chart: stable/grafana
@ -258,6 +260,16 @@ releases:
chart: charts/foo chart: charts/foo
labels: labels:
duplicated: yes duplicated: yes
- name: bar
chart: charts/foo
tillerNamespace: bar1
labels:
duplicatedOK: yes
- name: bar
chart: charts/foo
tillerNamespace: bar2
labels:
duplicatedOK: yes
`, `,
} }
@ -272,7 +284,8 @@ releases:
{label: "name!=", expectedCount: 0, expectErr: true, errMsg: "failed processing /path/to/helmfile.d/a1.yaml: Malformed label: name!=. Expected label in form k=v or k!=v"}, {label: "name!=", expectedCount: 0, expectErr: true, errMsg: "failed processing /path/to/helmfile.d/a1.yaml: Malformed label: name!=. Expected label in form k=v or k!=v"},
{label: "name", expectedCount: 0, expectErr: true, errMsg: "failed processing /path/to/helmfile.d/a1.yaml: Malformed label: name. Expected label in form k=v or k!=v"}, {label: "name", expectedCount: 0, expectErr: true, errMsg: "failed processing /path/to/helmfile.d/a1.yaml: Malformed label: name. Expected label in form k=v or k!=v"},
// See https://github.com/roboll/helmfile/issues/193 // See https://github.com/roboll/helmfile/issues/193
{label: "duplicated=yes", expectedCount: 0, expectErr: true, errMsg: "failed processing /path/to/helmfile.d/b.yaml: duplicate release \"foo\" found: there were 2 releases named \"foo\" matching specified selector"}, {label: "duplicated=yes", expectedCount: 0, expectErr: true, errMsg: "failed processing /path/to/helmfile.d/b.yaml: duplicate release \"foo\" found in \"zoo\": there were 2 releases named \"foo\" matching specified selector"},
{label: "duplicatedOK=yes", expectedCount: 2, expectErr: false},
} }
for _, testcase := range testcases { for _, testcase := range testcases {