Merge pull request #218 from mumoshu/should-fail-on-duplicate-release-name
fix: helmfile should fail on duplicate release name
This commit is contained in:
		
						commit
						d8aa9f305b
					
				|  | @ -109,6 +109,16 @@ func readFromYaml(content []byte, file string, logger *zap.SugaredLogger) (*Helm | ||||||
| 		state.DeprecatedReleases = []ReleaseSpec{} | 		state.DeprecatedReleases = []ReleaseSpec{} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	releaseNameCounts := map[string]int{} | ||||||
|  | 	for _, r := range state.Releases { | ||||||
|  | 		releaseNameCounts[r.Name] += 1 | ||||||
|  | 	} | ||||||
|  | 	for name, c := range releaseNameCounts { | ||||||
|  | 		if c > 1 { | ||||||
|  | 			return nil, fmt.Errorf("invalid helmfile: duplicate release name found: there were %d releases named \"%s\"", c, name) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	state.logger = logger | 	state.logger = logger | ||||||
| 
 | 
 | ||||||
| 	return &state, nil | 	return &state, nil | ||||||
|  |  | ||||||
|  | @ -164,6 +164,29 @@ func TestReadFromYaml_FilterNegatives(t *testing.T) { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // See https://github.com/roboll/helmfile/issues/193
 | ||||||
|  | func TestReadFromYaml_DuplicateReleaseName(t *testing.T) { | ||||||
|  | 	yamlFile := "example/path/to/yaml/file" | ||||||
|  | 	yamlContent := []byte(`releases: | ||||||
|  | - name: myrelease1 | ||||||
|  |   chart: mychart1 | ||||||
|  |   labels: | ||||||
|  |     stage: pre | ||||||
|  |     foo: bar | ||||||
|  | - name: myrelease1 | ||||||
|  |   chart: mychart2 | ||||||
|  |   labels: | ||||||
|  |     stage: post | ||||||
|  | `) | ||||||
|  | 	_, err := readFromYaml(yamlContent, yamlFile, logger) | ||||||
|  | 	if err == nil { | ||||||
|  | 		t.Error("error expected but not happened") | ||||||
|  | 	} | ||||||
|  | 	if err.Error() != "invalid helmfile: duplicate release name found: there were 2 releases named \"myrelease1\"" { | ||||||
|  | 		t.Errorf("unexpected error happened: %v", err) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func TestLabelParsing(t *testing.T) { | func TestLabelParsing(t *testing.T) { | ||||||
| 	cases := []struct { | 	cases := []struct { | ||||||
| 		labelString    string | 		labelString    string | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue