diff --git a/cmd/helm/testdata/output/install-chart-with-alt-delim.txt b/cmd/helm/testdata/output/install-chart-with-alt-delim.txt index 3a9c330eb..d3d1b6acf 100644 --- a/cmd/helm/testdata/output/install-chart-with-alt-delim.txt +++ b/cmd/helm/testdata/output/install-chart-with-alt-delim.txt @@ -1,6 +1,6 @@ --- # Source: chart-with-alt-delim/templates/alt-configmap.yaml -# helm: delim=[[,]] +# helm: delim=[,] apiVersion: v1 kind: ConfigMap metadata: @@ -9,7 +9,6 @@ data: myvalue: "Hello {{world}}" --- # Source: chart-with-alt-delim/templates/normal-configmap.yaml -# helm: delim=[[,]] apiVersion: v1 kind: ConfigMap metadata: diff --git a/cmd/helm/testdata/testcharts/chart-with-alt-delim/templates/alt-configmap.yaml b/cmd/helm/testdata/testcharts/chart-with-alt-delim/templates/alt-configmap.yaml index 42b6cc2dc..e2706c098 100644 --- a/cmd/helm/testdata/testcharts/chart-with-alt-delim/templates/alt-configmap.yaml +++ b/cmd/helm/testdata/testcharts/chart-with-alt-delim/templates/alt-configmap.yaml @@ -1,4 +1,4 @@ -# helm: delim=[[,]] +# helm: delim=[,] apiVersion: v1 kind: ConfigMap metadata: diff --git a/cmd/helm/testdata/testcharts/chart-with-alt-delim/templates/normal-configmap.yaml b/cmd/helm/testdata/testcharts/chart-with-alt-delim/templates/normal-configmap.yaml index b64a83c5d..4ec537db5 100644 --- a/cmd/helm/testdata/testcharts/chart-with-alt-delim/templates/normal-configmap.yaml +++ b/cmd/helm/testdata/testcharts/chart-with-alt-delim/templates/normal-configmap.yaml @@ -1,4 +1,3 @@ -# helm: delim=[[,]] apiVersion: v1 kind: ConfigMap metadata: diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 00494f9d7..86f8fb55a 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -83,6 +83,15 @@ func RenderWithClient(chrt *chart.Chart, values chartutil.Values, config *rest.C }.Render(chrt, values) } +var magicCommentsRegexp = regexp.MustCompile(`^#\s*helm:\s*(?:(\w+)=([^\s]*))*`) + +type templateOpts struct { + // Left template delimiter + delimL string + // Right template delimiter + delimR string +} + // renderable is an object that can be rendered. type renderable struct { // tpl is the current template. @@ -91,6 +100,8 @@ type renderable struct { vals chartutil.Values // namespace prefix to the templates of the current chart basePath string + // template engine options + opts templateOpts } const warnStartDelim = "HELM_ERR_START" @@ -230,7 +241,7 @@ func (e Engine) renderWithReferences(tpls, referenceTpls map[string]renderable) for _, filename := range keys { r := tpls[filename] - if _, err := t.New(filename).Parse(r.tpl); err != nil { + if _, err := t.New(filename).Delims(r.opts.delimL, r.opts.delimR).Parse(r.tpl); err != nil { return map[string]string{}, cleanupParseError(filename, err) } } @@ -380,6 +391,7 @@ func recAllTpls(c *chart.Chart, templates map[string]renderable, vals chartutil. templates[path.Join(newParentID, t.Name)] = renderable{ tpl: string(t.Data), vals: next, + opts: readTemplateMagicComments(string(t.Data)), basePath: path.Join(newParentID, "templates"), } } @@ -399,3 +411,17 @@ func isTemplateValid(ch *chart.Chart, templateName string) bool { func isLibraryChart(c *chart.Chart) bool { return strings.EqualFold(c.Metadata.Type, "library") } + +func readTemplateMagicComments(templateBody string) templateOpts { + templateOpts := templateOpts{} + matches := magicCommentsRegexp.FindAllSubmatch([]byte(templateBody), -1) + for _, match := range matches { + if (strings.EqualFold(string(match[1]), "delim")) { + delim := strings.SplitN(string(match[2]), ",", 2) + templateOpts.delimL = strings.Repeat(delim[0], 2) + templateOpts.delimR = strings.Repeat(delim[1], 2) + } + } + + return templateOpts + }