Skip to content

Commit 541d052

Browse files
Sushil KumarSushil Kumar
Sushil Kumar
authored and
Sushil Kumar
committed
First alias would be dependency rename
Fixes helm#2508
1 parent 8272360 commit 541d052

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

pkg/chartutil/requirements.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func ProcessRequirementsTags(reqs *Requirements, cvals Values) {
218218

219219
}
220220

221-
func copyChartAsAlias(charts []*chart.Chart, dependentChart, aliasChart string) *chart.Chart {
221+
func updateChartDependencyAlias(charts []*chart.Chart, dependentChart, aliasChart string, firstAlias bool) *chart.Chart {
222222
var chartFound chart.Chart
223223
for _, existingChart := range charts {
224224
if existingChart == nil {
@@ -230,6 +230,10 @@ func copyChartAsAlias(charts []*chart.Chart, dependentChart, aliasChart string)
230230
if existingChart.Metadata.Name != dependentChart {
231231
continue
232232
}
233+
if firstAlias {
234+
existingChart.Metadata.Name = aliasChart
235+
return nil
236+
}
233237

234238
chartFound = *existingChart
235239
newMetadata := *existingChart.Metadata
@@ -254,16 +258,22 @@ func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error {
254258
}
255259

256260
for _, req := range reqs.Dependencies {
261+
var firstAlias = true
262+
var dependentChartName = req.Name
257263
for _, alias := range req.Alias {
258-
aliasDependency := copyChartAsAlias(c.Dependencies, req.Name, alias)
264+
aliasDependency := updateChartDependencyAlias(c.Dependencies, dependentChartName, alias, firstAlias)
265+
if firstAlias {
266+
dependentChartName = alias
267+
firstAlias = false
268+
continue
269+
}
259270
if aliasDependency == nil {
260271
break
261272
}
262273
c.Dependencies = append(c.Dependencies, aliasDependency)
263-
origReqName := req.Name
264274
req.Name = alias
265275
reqs.Dependencies = append(reqs.Dependencies, req)
266-
req.Name = origReqName
276+
req.Name = dependentChartName
267277
}
268278
}
269279

pkg/chartutil/requirements_test.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -321,23 +321,33 @@ func verifyRequirementsImportValues(t *testing.T, c *chart.Chart, v *chart.Confi
321321
}
322322
}
323323

324-
func TestCopyChartAsAlias(t *testing.T) {
324+
func TestUpdateChartDependencyAlias(t *testing.T) {
325325
c, err := Load("testdata/frobnitz")
326326
if err != nil {
327327
t.Fatalf("Failed to load testdata: %s", err)
328328
}
329329

330-
if aliasChart := copyChartAsAlias(c.Dependencies, "mariners", "another-mariner"); aliasChart != nil {
330+
if aliasChart := updateChartDependencyAlias(c.Dependencies, "mariners", "another-mariner", false); aliasChart != nil {
331331
t.Fatalf("expected no chart but got %s", aliasChart.Metadata.Name)
332332
}
333333

334-
aliasChart := copyChartAsAlias(c.Dependencies, "mariner", "another-mariner")
334+
aliasChart := updateChartDependencyAlias(c.Dependencies, "mariner", "another-mariner", false)
335335
if aliasChart == nil {
336336
t.Fatal("Failed to find dependent chart")
337337
}
338338
if aliasChart.Metadata.Name != "another-mariner" {
339339
t.Fatal(`Failed to update chart-name for alias "dependent chart`)
340340
}
341+
342+
//Testing single-alias update, first update and then try same with non-first alias, we should not be able to find chart
343+
if aliasChart := updateChartDependencyAlias(c.Dependencies, "mariner", "another-mariner", true); aliasChart != nil {
344+
t.Fatalf("expected no chart but got %s", aliasChart.Metadata.Name)
345+
}
346+
347+
if aliasChart := updateChartDependencyAlias(c.Dependencies, "mariner", "another-mariner", false); aliasChart != nil {
348+
t.Fatalf("expected no chart but got %s", aliasChart.Metadata.Name)
349+
}
350+
341351
}
342352

343353
func TestDependentChartAliases(t *testing.T) {
@@ -371,8 +381,8 @@ func TestDependentChartAliases(t *testing.T) {
371381
expectedDependencyCharts += len(reqmt.Alias)
372382
}
373383
}
374-
if len(c.Dependencies) != expectedDependencyCharts {
375-
t.Fatalf("Expected number of chart dependencies %d, but got %d", expectedDependencyCharts, len(c.Dependencies))
384+
if len(c.Dependencies) != expectedDependencyCharts-1 {
385+
t.Fatalf("Expected number of chart dependencies %d, but got %d", expectedDependencyCharts-1, len(c.Dependencies))
376386
}
377387

378388
}

0 commit comments

Comments
 (0)