Skip to content

Commit d7e3130

Browse files
authored
Merge pull request #187 from relu/fix-aliased-subcharts-handling
2 parents f60f759 + 960ad88 commit d7e3130

File tree

3 files changed

+73
-66
lines changed

3 files changed

+73
-66
lines changed

controllers/dependency_manager_test.go

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"bytes"
21+
"fmt"
2122
"io/ioutil"
2223
"strings"
2324
"testing"
@@ -31,14 +32,12 @@ import (
3132
var (
3233
helmPackageFile = "testdata/charts/helmchart-0.1.0.tgz"
3334

34-
localDepFixture helmchart.Dependency = helmchart.Dependency{
35-
Name: "helmchart",
36-
Version: "0.1.0",
37-
Repository: "file://../helmchart",
38-
}
39-
remoteDepFixture helmchart.Dependency = helmchart.Dependency{
40-
Name: "helmchart",
41-
Version: "0.1.0",
35+
chartName = "helmchart"
36+
chartVersion = "0.1.0"
37+
chartLocalRepository = "file://../helmchart"
38+
remoteDepFixture helmchart.Dependency = helmchart.Dependency{
39+
Name: chartName,
40+
Version: chartVersion,
4241
Repository: "https://example.com/charts",
4342
}
4443
chartFixture helmchart.Chart = helmchart.Chart{
@@ -58,72 +57,65 @@ func TestBuild_WithEmptyDependencies(t *testing.T) {
5857
}
5958

6059
func TestBuild_WithLocalChart(t *testing.T) {
61-
loc := localDepFixture
62-
chart := chartFixture
63-
dm := DependencyManager{
64-
Chart: &chart,
65-
ChartPath: "testdata/charts/helmchart",
66-
Dependencies: []*DependencyWithRepository{
67-
{
68-
Dependency: &loc,
69-
Repo: nil,
70-
},
71-
},
72-
}
73-
74-
if err := dm.Build(); err != nil {
75-
t.Errorf("Build() expected to not return error: %s", err)
76-
}
77-
78-
deps := dm.Chart.Dependencies()
79-
if len(deps) != 1 {
80-
t.Fatalf("chart expected to have one dependency registered")
81-
}
82-
if deps[0].Metadata.Name != localDepFixture.Name {
83-
t.Errorf("chart dependency has incorrect name, expected: %s, got: %s", localDepFixture.Name, deps[0].Metadata.Name)
84-
}
85-
if deps[0].Metadata.Version != localDepFixture.Version {
86-
t.Errorf("chart dependency has incorrect version, expected: %s, got: %s", localDepFixture.Version, deps[0].Metadata.Version)
87-
}
88-
8960
tests := []struct {
90-
name string
91-
dep helmchart.Dependency
92-
expectError string
61+
name string
62+
dep helmchart.Dependency
63+
wantErr bool
64+
errMsg string
9365
}{
66+
{
67+
name: "valid path",
68+
dep: helmchart.Dependency{
69+
Name: chartName,
70+
Version: chartVersion,
71+
Repository: chartLocalRepository,
72+
},
73+
},
74+
{
75+
name: "valid path",
76+
dep: helmchart.Dependency{
77+
Name: chartName,
78+
Alias: "aliased",
79+
Version: chartVersion,
80+
Repository: chartLocalRepository,
81+
},
82+
},
9483
{
9584
name: "invalid path",
9685
dep: helmchart.Dependency{
97-
Name: "helmchart",
98-
Version: "0.1.0",
86+
Name: chartName,
87+
Version: chartVersion,
9988
Repository: "file://../invalid",
10089
},
101-
expectError: "no such file or directory",
90+
wantErr: true,
91+
errMsg: "no such file or directory",
10292
},
10393
{
10494
name: "invalid version constraint format",
10595
dep: helmchart.Dependency{
106-
Name: "helmchart",
96+
Name: chartName,
10797
Version: "!2.0",
108-
Repository: "file://../helmchart",
98+
Repository: chartLocalRepository,
10999
},
110-
expectError: "has an invalid version/constraint format",
100+
wantErr: true,
101+
errMsg: "has an invalid version/constraint format",
111102
},
112103
{
113104
name: "invalid version",
114105
dep: helmchart.Dependency{
115-
Name: "helmchart",
116-
Version: "1.0.0",
117-
Repository: "file://../helmchart",
106+
Name: chartName,
107+
Version: chartVersion,
108+
Repository: chartLocalRepository,
118109
},
119-
expectError: "can't get a valid version for dependency",
110+
wantErr: true,
111+
errMsg: "can't get a valid version for dependency",
120112
},
121113
}
122114

123115
for _, tt := range tests {
124116
t.Run(tt.name, func(t *testing.T) {
125117
c := chartFixture
126-
dm = DependencyManager{
118+
dm := DependencyManager{
127119
Chart: &c,
128120
ChartPath: "testdata/charts/helmchart",
129121
Dependencies: []*DependencyWithRepository{
@@ -134,13 +126,30 @@ func TestBuild_WithLocalChart(t *testing.T) {
134126
},
135127
}
136128

137-
if err := dm.Build(); err == nil {
129+
err := dm.Build()
130+
deps := dm.Chart.Dependencies()
131+
132+
if (err != nil) && tt.wantErr {
133+
if !strings.Contains(err.Error(), tt.errMsg) {
134+
t.Errorf("Build() expected to return error: %s, got: %s", tt.errMsg, err)
135+
}
136+
if len(deps) > 0 {
137+
t.Fatalf("chart expected to have no dependencies registered")
138+
}
139+
return
140+
} else if err != nil {
138141
t.Errorf("Build() expected to return error")
139-
} else if !strings.Contains(err.Error(), tt.expectError) {
140-
t.Errorf("Build() expected to return error: %s, got: %s", tt.expectError, err)
142+
return
143+
}
144+
145+
if len(deps) == 0 {
146+
t.Fatalf("chart expected to have at least one dependency registered")
147+
}
148+
if deps[0].Metadata.Name != chartName {
149+
t.Errorf("chart dependency has incorrect name, expected: %s, got: %s", chartName, deps[0].Metadata.Name)
141150
}
142-
if len(dm.Chart.Dependencies()) > 0 {
143-
t.Fatalf("chart expected to have no dependencies registered")
151+
if deps[0].Metadata.Version != chartVersion {
152+
t.Errorf("chart dependency has incorrect version, expected: %s, got: %s", chartVersion, deps[0].Metadata.Version)
144153
}
145154
})
146155
}
@@ -153,7 +162,7 @@ func TestBuild_WithRemoteChart(t *testing.T) {
153162
t.Fatal(err)
154163
}
155164
i := repo.NewIndexFile()
156-
i.Add(&helmchart.Metadata{Name: "helmchart", Version: "0.1.0"}, "helmchart-0.1.0.tgz", "http://example.com/charts", "sha256:1234567890")
165+
i.Add(&helmchart.Metadata{Name: chartName, Version: chartVersion}, fmt.Sprintf("%s-%s.tgz", chartName, chartVersion), "http://example.com/charts", "sha256:1234567890")
157166
mg := mockGetter{response: b}
158167
cr := &helm.ChartRepository{
159168
URL: remoteDepFixture.Repository,
@@ -178,11 +187,11 @@ func TestBuild_WithRemoteChart(t *testing.T) {
178187
if len(deps) != 1 {
179188
t.Fatalf("chart expected to have one dependency registered")
180189
}
181-
if deps[0].Metadata.Name != remoteDepFixture.Name {
182-
t.Errorf("chart dependency has incorrect name, expected: %s, got: %s", remoteDepFixture.Name, deps[0].Metadata.Name)
190+
if deps[0].Metadata.Name != chartName {
191+
t.Errorf("chart dependency has incorrect name, expected: %s, got: %s", chartName, deps[0].Metadata.Name)
183192
}
184-
if deps[0].Metadata.Version != remoteDepFixture.Version {
185-
t.Errorf("chart dependency has incorrect version, expected: %s, got: %s", remoteDepFixture.Version, deps[0].Metadata.Version)
193+
if deps[0].Metadata.Version != chartVersion {
194+
t.Errorf("chart dependency has incorrect version, expected: %s, got: %s", chartVersion, deps[0].Metadata.Version)
186195
}
187196

188197
// When repo is not set

controllers/helmchart_controller.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,6 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
446446
isDir := chartFileInfo.IsDir()
447447
switch {
448448
case isDir:
449-
// Load dependencies
450-
if err = chartutil.ProcessDependencies(helmChart, helmChart.Values); err != nil {
451-
err = fmt.Errorf("failed to process chart dependencies: %w", err)
452-
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
453-
}
454-
455449
// Determine chart dependencies
456450
deps := helmChart.Dependencies()
457451
reqs := helmChart.Metadata.Dependencies

controllers/testdata/charts/helmchartwithdeps/Chart.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ dependencies:
2424
- name: helmchart
2525
version: "0.1.0"
2626
repository: "file://../helmchart"
27+
- name: helmchart
28+
alias: aliased
29+
version: "0.1.0"
30+
repository: "file://../helmchart"
2731
- name: grafana
2832
version: ">=5.7.0"
2933
repository: "https://grafana.github.io/helm-charts"

0 commit comments

Comments
 (0)