First alias would be dependency rename

Fixes https://github.com/kubernetes/helm/issues/2508
pull/2534/head
Sushil Kumar 8 years ago
parent 8272360681
commit 541d052202

@ -218,7 +218,7 @@ func ProcessRequirementsTags(reqs *Requirements, cvals Values) {
}
func copyChartAsAlias(charts []*chart.Chart, dependentChart, aliasChart string) *chart.Chart {
func updateChartDependencyAlias(charts []*chart.Chart, dependentChart, aliasChart string, firstAlias bool) *chart.Chart {
var chartFound chart.Chart
for _, existingChart := range charts {
if existingChart == nil {
@ -230,6 +230,10 @@ func copyChartAsAlias(charts []*chart.Chart, dependentChart, aliasChart string)
if existingChart.Metadata.Name != dependentChart {
continue
}
if firstAlias {
existingChart.Metadata.Name = aliasChart
return nil
}
chartFound = *existingChart
newMetadata := *existingChart.Metadata
@ -254,16 +258,22 @@ func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error {
}
for _, req := range reqs.Dependencies {
var firstAlias = true
var dependentChartName = req.Name
for _, alias := range req.Alias {
aliasDependency := copyChartAsAlias(c.Dependencies, req.Name, alias)
aliasDependency := updateChartDependencyAlias(c.Dependencies, dependentChartName, alias, firstAlias)
if firstAlias {
dependentChartName = alias
firstAlias = false
continue
}
if aliasDependency == nil {
break
}
c.Dependencies = append(c.Dependencies, aliasDependency)
origReqName := req.Name
req.Name = alias
reqs.Dependencies = append(reqs.Dependencies, req)
req.Name = origReqName
req.Name = dependentChartName
}
}

@ -321,23 +321,33 @@ func verifyRequirementsImportValues(t *testing.T, c *chart.Chart, v *chart.Confi
}
}
func TestCopyChartAsAlias(t *testing.T) {
func TestUpdateChartDependencyAlias(t *testing.T) {
c, err := Load("testdata/frobnitz")
if err != nil {
t.Fatalf("Failed to load testdata: %s", err)
}
if aliasChart := copyChartAsAlias(c.Dependencies, "mariners", "another-mariner"); aliasChart != nil {
if aliasChart := updateChartDependencyAlias(c.Dependencies, "mariners", "another-mariner", false); aliasChart != nil {
t.Fatalf("expected no chart but got %s", aliasChart.Metadata.Name)
}
aliasChart := copyChartAsAlias(c.Dependencies, "mariner", "another-mariner")
aliasChart := updateChartDependencyAlias(c.Dependencies, "mariner", "another-mariner", false)
if aliasChart == nil {
t.Fatal("Failed to find dependent chart")
}
if aliasChart.Metadata.Name != "another-mariner" {
t.Fatal(`Failed to update chart-name for alias "dependent chart`)
}
//Testing single-alias update, first update and then try same with non-first alias, we should not be able to find chart
if aliasChart := updateChartDependencyAlias(c.Dependencies, "mariner", "another-mariner", true); aliasChart != nil {
t.Fatalf("expected no chart but got %s", aliasChart.Metadata.Name)
}
if aliasChart := updateChartDependencyAlias(c.Dependencies, "mariner", "another-mariner", false); aliasChart != nil {
t.Fatalf("expected no chart but got %s", aliasChart.Metadata.Name)
}
}
func TestDependentChartAliases(t *testing.T) {
@ -371,8 +381,8 @@ func TestDependentChartAliases(t *testing.T) {
expectedDependencyCharts += len(reqmt.Alias)
}
}
if len(c.Dependencies) != expectedDependencyCharts {
t.Fatalf("Expected number of chart dependencies %d, but got %d", expectedDependencyCharts, len(c.Dependencies))
if len(c.Dependencies) != expectedDependencyCharts-1 {
t.Fatalf("Expected number of chart dependencies %d, but got %d", expectedDependencyCharts-1, len(c.Dependencies))
}
}

Loading…
Cancel
Save