Simple, fast and easy to use Go library to run helm template without the need of a Helm binary nor its execution as an external command.
fs.FS
(Template charts from FS, embedded, memory...)package main
import (
"context"
"fmt"
"testing/fstest"
"github.com/slok/go-helm-template/helm"
)
// Chart data in memory.
const (
chart = `
apiVersion: v2
name: example-memory
version: 0.1.0
`
configmap = `
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ printf "%s-%s" .Chart.Name .Release.Name | trunc 63 | trimSuffix "-" }}
namespace: {{ .Release.Namespace }}
labels:
{{- with .Values.labels -}}
{{ toYaml . | nindent 4 }}
{{- end }}
data:
something: something
`
)
func main() {
ctx := context.Background()
// Create chart in memory.
chartFS := make(fstest.MapFS)
chartFS["Chart.yaml"] = &fstest.MapFile{Data: []byte(chart)}
chartFS["templates/configmap.yaml"] = &fstest.MapFile{Data: []byte(configmap)}
// Load chart.
chart, err := helm.LoadChart(ctx, chartFS)
if err != nil {
panic(err)
}
// Execute helm template.
result, err := helm.Template(ctx, helm.TemplateConfig{
Chart: chart,
ReleaseName: "test",
Namespace: "no-kube-system",
Values: map[string]interface{}{
"labels": map[string]string{
"example-from": "go-helm-template",
},
},
})
if err != nil {
panic(err)
}
fmt.Println(result)
}
embed.FS
.This library doesn't support anything apart from simple helm template
. dependencies, hooks... and similar fancy features, are not supported.
One of the Helm's most powerful feature (if not the most) is its template system, lots of users only use Helm for this usage.
Not depending on helm as a system dependency, nor requiring to execute an external command, improves the portability and performance of applications that use Helm internally.
embed.FS
.