Skip to content

Commit 14e2cf0

Browse files
Support .tpl extensions for values files (#168)
For users who are more accustomed to go templates from helm itself.
1 parent f11c56b commit 14e2cf0

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

pkg/manifests/template/helm.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,16 @@ func (h *helm) valuesFile(svc *console.GetServiceDeploymentForAgent_ServiceDeplo
182182

183183
if strings.HasSuffix(filename, ".liquid") {
184184
data, err = renderLiquid(data, svc)
185-
if err != nil {
186-
return nil, err
187-
}
188185
}
186+
187+
if strings.HasSuffix(filename, ".tpl") {
188+
data, err = renderTpl(data, svc)
189+
}
190+
191+
if err != nil {
192+
return nil, err
193+
}
194+
189195
if err := yaml.Unmarshal(data, &currentMap); err != nil {
190196
return nil, errors.Wrapf(err, "failed to parse %s", filename)
191197
}

pkg/manifests/template/tpl.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package template
2+
3+
import (
4+
"bytes"
5+
"text/template"
6+
7+
"github.com/Masterminds/sprig/v3"
8+
console "github.com/pluralsh/console-client-go"
9+
)
10+
11+
func renderTpl(input []byte, svc *console.GetServiceDeploymentForAgent_ServiceDeployment) ([]byte, error) {
12+
bindings := map[string]interface{}{
13+
"Configuration": configMap(svc),
14+
"Cluster": clusterConfiguration(svc.Cluster),
15+
"Contexts": contexts(svc),
16+
}
17+
18+
tpl, err := template.New("gotpl").Funcs(sprig.TxtFuncMap()).Parse(string(input))
19+
if err != nil {
20+
return nil, err
21+
}
22+
23+
var buffer bytes.Buffer
24+
err = tpl.Execute(&buffer, bindings)
25+
return buffer.Bytes(), err
26+
}

0 commit comments

Comments
 (0)