mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-21 09:31:38 +02:00
fix: two releases using the same chart in different version fails (#1685)
* fix: two releases using the same chart in different version fails Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
@@ -10,7 +10,6 @@ func TestGetUnresolvedDependenciess(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
helmState *HelmState
|
||||
wantErr bool
|
||||
expectfile string
|
||||
expectDeps *UnresolvedDependencies
|
||||
}{
|
||||
@@ -21,21 +20,34 @@ func TestGetUnresolvedDependenciess(t *testing.T) {
|
||||
ReleaseSetSpec: ReleaseSetSpec{
|
||||
Releases: []ReleaseSpec{
|
||||
{
|
||||
Name: "foo",
|
||||
Chart: "charts/abc",
|
||||
Version: "0.1.0",
|
||||
Name: "foo",
|
||||
Chart: "chartsa/abc",
|
||||
Version: "0.1.0",
|
||||
Namespace: "ns1",
|
||||
},
|
||||
{
|
||||
Name: "empty",
|
||||
Chart: "chartsb/empty",
|
||||
Namespace: "ns2",
|
||||
},
|
||||
{
|
||||
Name: "empty",
|
||||
Chart: "chartsb/empty",
|
||||
},
|
||||
},
|
||||
Repositories: []RepositorySpec{
|
||||
{
|
||||
Name: "charts",
|
||||
Name: "chartsa",
|
||||
URL: "localhost:5000/aaa",
|
||||
OCI: true,
|
||||
},
|
||||
{
|
||||
Name: "chartsb",
|
||||
URL: "localhost:5000/bbb",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
expectfile: "helmfile",
|
||||
expectDeps: &UnresolvedDependencies{
|
||||
deps: map[string][]unresolvedChartDependency{
|
||||
@@ -44,6 +56,77 @@ func TestGetUnresolvedDependenciess(t *testing.T) {
|
||||
ChartName: "abc",
|
||||
Repository: "oci://localhost:5000/aaa",
|
||||
VersionConstraint: "0.1.0",
|
||||
Alias: "ns1-foo",
|
||||
},
|
||||
},
|
||||
"empty": {
|
||||
{
|
||||
ChartName: "empty",
|
||||
Repository: "localhost:5000/bbb",
|
||||
Alias: "ns2-empty",
|
||||
},
|
||||
{
|
||||
ChartName: "empty",
|
||||
Repository: "localhost:5000/bbb",
|
||||
Alias: "-empty",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "duplicate charts are differentiated by alias",
|
||||
helmState: &HelmState{
|
||||
FilePath: "helmfile.yaml",
|
||||
ReleaseSetSpec: ReleaseSetSpec{
|
||||
Releases: []ReleaseSpec{
|
||||
{
|
||||
Name: "foo",
|
||||
Chart: "myrepo/abc",
|
||||
Version: "> 0.2.0",
|
||||
Namespace: "ns1",
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
Chart: "myrepo/abc",
|
||||
Version: "0.1.0",
|
||||
Namespace: "ns2",
|
||||
},
|
||||
{
|
||||
Name: "baz",
|
||||
Chart: "myrepo/abc",
|
||||
Version: "0.3.0",
|
||||
},
|
||||
},
|
||||
Repositories: []RepositorySpec{
|
||||
{
|
||||
Name: "myrepo",
|
||||
URL: "localhost:5000/aaa",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectfile: "helmfile",
|
||||
expectDeps: &UnresolvedDependencies{
|
||||
deps: map[string][]unresolvedChartDependency{
|
||||
"abc": {
|
||||
{
|
||||
ChartName: "abc",
|
||||
Repository: "localhost:5000/aaa",
|
||||
VersionConstraint: "> 0.2.0",
|
||||
Alias: "ns1-foo",
|
||||
},
|
||||
{
|
||||
ChartName: "abc",
|
||||
Repository: "localhost:5000/aaa",
|
||||
VersionConstraint: "0.1.0",
|
||||
Alias: "ns2-bar",
|
||||
},
|
||||
{
|
||||
ChartName: "abc",
|
||||
Repository: "localhost:5000/aaa",
|
||||
VersionConstraint: "0.3.0",
|
||||
Alias: "-baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -53,82 +136,30 @@ func TestGetUnresolvedDependenciess(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
f, ds, err := getUnresolvedDependenciess(tt.helmState)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err, "getUnresolvedDependenciess() error = nil, wantErr")
|
||||
} else {
|
||||
require.NoErrorf(t, err, "getUnresolvedDependenciess() want no error, got %v", err)
|
||||
}
|
||||
f, ds := getUnresolvedDependenciess(tt.helmState)
|
||||
require.Equalf(t, tt.expectfile, f, "getUnresolvedDependenciess() expect file %s, got %s", tt.expectfile, f)
|
||||
require.Equalf(t, tt.expectDeps, ds, "getUnresolvedDependenciess() expect deps %v, got %v", tt.expectDeps, ds)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestContains(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
dep unresolvedChartDependency
|
||||
deps map[string][]unresolvedChartDependency
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "existing dependency with right item",
|
||||
dep: unresolvedChartDependency{
|
||||
ChartName: "abc",
|
||||
Repository: "oci://localhost:5000/aaa",
|
||||
VersionConstraint: "0.1.0",
|
||||
},
|
||||
deps: map[string][]unresolvedChartDependency{
|
||||
"abc": {
|
||||
{
|
||||
ChartName: "abc",
|
||||
Repository: "oci://localhost:5000/aaa",
|
||||
VersionConstraint: "0.1.0",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "existing dependency with empty item",
|
||||
dep: unresolvedChartDependency{
|
||||
ChartName: "ghi",
|
||||
Repository: "oci://localhost:5000/aaa",
|
||||
VersionConstraint: "0.1.0",
|
||||
},
|
||||
deps: map[string][]unresolvedChartDependency{
|
||||
"ghi": {},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "non-existing dependency",
|
||||
dep: unresolvedChartDependency{
|
||||
ChartName: "def",
|
||||
Repository: "oci://localhost:5000/bbb",
|
||||
VersionConstraint: "0.2.0",
|
||||
},
|
||||
deps: map[string][]unresolvedChartDependency{
|
||||
"abc": {
|
||||
{
|
||||
ChartName: "abc",
|
||||
Repository: "oci://localhost:5000/aaa",
|
||||
VersionConstraint: "0.1.0",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
func TestChartDependenciesAlias(t *testing.T) {
|
||||
type testCase struct {
|
||||
releaseName string
|
||||
namespace string
|
||||
expected string
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
d := &UnresolvedDependencies{
|
||||
deps: tt.deps,
|
||||
}
|
||||
actual := d.contains(tt.dep)
|
||||
require.Equal(t, tt.expected, actual)
|
||||
})
|
||||
testCases := []testCase{
|
||||
{"release1", "n1", "n1-release1"},
|
||||
{"release2", "n2", "n2-release2"},
|
||||
{"empty", "", "-empty"},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
result := chartDependenciesAlias(tc.namespace, tc.releaseName)
|
||||
if result != tc.expected {
|
||||
t.Errorf("Expected %s, but got %s", tc.expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user