|
|
@ -32,6 +32,8 @@ import (
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/chart"
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/chart"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const recursionMaxNums = 1000
|
|
|
|
|
|
|
|
|
|
|
|
// Engine is an implementation of 'cmd/tiller/environment'.Engine that uses Go templates.
|
|
|
|
// Engine is an implementation of 'cmd/tiller/environment'.Engine that uses Go templates.
|
|
|
|
type Engine struct {
|
|
|
|
type Engine struct {
|
|
|
|
// FuncMap contains the template functions that will be passed to each
|
|
|
|
// FuncMap contains the template functions that will be passed to each
|
|
|
@ -145,21 +147,22 @@ func (e *Engine) alterFuncMap(t *template.Template, referenceTpls map[string]ren
|
|
|
|
funcMap[k] = v
|
|
|
|
funcMap[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
includedNames := make([]string, 0)
|
|
|
|
includedNames := make(map[string]int)
|
|
|
|
|
|
|
|
|
|
|
|
// Add the 'include' function here so we can close over t.
|
|
|
|
// Add the 'include' function here so we can close over t.
|
|
|
|
funcMap["include"] = func(name string, data interface{}) (string, error) {
|
|
|
|
funcMap["include"] = func(name string, data interface{}) (string, error) {
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
for _, n := range includedNames {
|
|
|
|
if v, ok := includedNames[name]; ok {
|
|
|
|
if n == name {
|
|
|
|
if v > recursionMaxNums {
|
|
|
|
return "", errors.Wrapf(fmt.Errorf("unable to excute template"), "rendering template has a nested reference name: %s", name)
|
|
|
|
return "", errors.Wrapf(fmt.Errorf("unable to execute template"), "rendering template has a nested reference name: %s", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
includedNames[name]++
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
includedNames[name] = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
includedNames = append(includedNames, name)
|
|
|
|
|
|
|
|
if err := t.ExecuteTemplate(buf, name, data); err != nil {
|
|
|
|
if err := t.ExecuteTemplate(buf, name, data); err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
includedNames = includedNames[:len(includedNames)-1]
|
|
|
|
|
|
|
|
return buf.String(), nil
|
|
|
|
return buf.String(), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|