mirror of
https://github.com/helm/helm.git
synced 2026-08-07 16:41:27 +00:00
fix(engine): support chart template recursion
This commit is contained in:
@@ -104,13 +104,16 @@ func (e *Engine) render(tpls map[string]string, v interface{}) (map[string]strin
|
||||
// allTemplates returns all templates for a chart and its dependencies.
|
||||
func allTemplates(c *chart.Chart) map[string]string {
|
||||
templates := map[string]string{}
|
||||
recAllTpls(c, templates)
|
||||
return templates
|
||||
}
|
||||
|
||||
func recAllTpls(c *chart.Chart, templates map[string]string) {
|
||||
for _, child := range c.Dependencies {
|
||||
for _, t := range child.Templates {
|
||||
templates[t.Name] = string(t.Data)
|
||||
}
|
||||
recAllTpls(child, templates)
|
||||
}
|
||||
for _, t := range c.Templates {
|
||||
templates[t.Name] = string(t.Data)
|
||||
}
|
||||
return templates
|
||||
|
||||
}
|
||||
|
||||
@@ -90,16 +90,23 @@ func TestAllTemplates(t *testing.T) {
|
||||
{Name: "bar", Data: []byte("bar")},
|
||||
},
|
||||
Dependencies: []*chart.Chart{
|
||||
{Templates: []*chart.Template{
|
||||
{Name: "pinky", Data: []byte("pinky")},
|
||||
{Name: "brain", Data: []byte("brain")},
|
||||
}},
|
||||
{
|
||||
Templates: []*chart.Template{
|
||||
{Name: "pinky", Data: []byte("pinky")},
|
||||
{Name: "brain", Data: []byte("brain")},
|
||||
},
|
||||
Dependencies: []*chart.Chart{
|
||||
{Templates: []*chart.Template{
|
||||
{Name: "innermost", Data: []byte("innermost")},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
tpls := allTemplates(ch1)
|
||||
if len(tpls) != 4 {
|
||||
t.Errorf("Expected 4 charts, got %d", len(tpls))
|
||||
if len(tpls) != 5 {
|
||||
t.Errorf("Expected 5 charts, got %d", len(tpls))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,9 +119,11 @@ func TestRenderDependency(t *testing.T) {
|
||||
{Name: "outer", Data: []byte(toptpl)},
|
||||
},
|
||||
Dependencies: []*chart.Chart{
|
||||
{Templates: []*chart.Template{
|
||||
{Name: "inner", Data: []byte(deptpl)},
|
||||
}},
|
||||
{
|
||||
Templates: []*chart.Template{
|
||||
{Name: "inner", Data: []byte(deptpl)},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user