feat: Helmfile renders *.yaml.gotmpl in a K8s manifests/kustomization directory (#1745)
Related to #494 This feature is mostly a built-in alternative to the `incubator/raw` chart without external dependency and has access to helmfile's own template functions and template data. The expected use-case of this feature is to add arbitrary K8s resources to your deployment. Unlike the original issue raised in #494 this doesn't enable you to add arbitary resources to a release. That's another story. But this would be a good foundation for that, too.
This commit is contained in:
parent
85accf7330
commit
f614e8b1bf
2
go.mod
2
go.mod
|
|
@ -28,7 +28,7 @@ require (
|
||||||
github.com/spf13/cobra v1.1.1
|
github.com/spf13/cobra v1.1.1
|
||||||
github.com/tatsushid/go-prettytable v0.0.0-20141013043238-ed2d14c29939
|
github.com/tatsushid/go-prettytable v0.0.0-20141013043238-ed2d14c29939
|
||||||
github.com/urfave/cli v1.22.5
|
github.com/urfave/cli v1.22.5
|
||||||
github.com/variantdev/chartify v0.6.0
|
github.com/variantdev/chartify v0.7.0
|
||||||
github.com/variantdev/dag v0.0.0-20191028002400-bb0b3c785363
|
github.com/variantdev/dag v0.0.0-20191028002400-bb0b3c785363
|
||||||
github.com/variantdev/vals v0.13.0
|
github.com/variantdev/vals v0.13.0
|
||||||
go.uber.org/multierr v1.6.0
|
go.uber.org/multierr v1.6.0
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -573,6 +573,8 @@ github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
|
||||||
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
github.com/variantdev/chartify v0.6.0 h1:QQ00a8Vtuhk6F9jeTZJEXV2g0zRXhYG43xovWZrc3ac=
|
github.com/variantdev/chartify v0.6.0 h1:QQ00a8Vtuhk6F9jeTZJEXV2g0zRXhYG43xovWZrc3ac=
|
||||||
github.com/variantdev/chartify v0.6.0/go.mod h1:qF4XzQlkfH/6k2jAi1hLas+lK4zSCa8kY+r5JdmLA68=
|
github.com/variantdev/chartify v0.6.0/go.mod h1:qF4XzQlkfH/6k2jAi1hLas+lK4zSCa8kY+r5JdmLA68=
|
||||||
|
github.com/variantdev/chartify v0.7.0 h1:LQU9bW734CPTIRRx9AG6rIolqW3GgbqaFZQTOCNOfn8=
|
||||||
|
github.com/variantdev/chartify v0.7.0/go.mod h1:qF4XzQlkfH/6k2jAi1hLas+lK4zSCa8kY+r5JdmLA68=
|
||||||
github.com/variantdev/dag v0.0.0-20191028002400-bb0b3c785363 h1:KrfQBEUn+wEOQ/6UIfoqRDvn+Q/wZridQ7t0G1vQqKE=
|
github.com/variantdev/dag v0.0.0-20191028002400-bb0b3c785363 h1:KrfQBEUn+wEOQ/6UIfoqRDvn+Q/wZridQ7t0G1vQqKE=
|
||||||
github.com/variantdev/dag v0.0.0-20191028002400-bb0b3c785363/go.mod h1:pH1TQsNSLj2uxMo9NNl9zdGy01Wtn+/2MT96BrKmVyE=
|
github.com/variantdev/dag v0.0.0-20191028002400-bb0b3c785363/go.mod h1:pH1TQsNSLj2uxMo9NNl9zdGy01Wtn+/2MT96BrKmVyE=
|
||||||
github.com/variantdev/vals v0.13.0 h1:zdtTBjoWKkUGdFauxETkDVjqWXdjUNwI+ggWcUmpxv8=
|
github.com/variantdev/vals v0.13.0 h1:zdtTBjoWKkUGdFauxETkDVjqWXdjUNwI+ggWcUmpxv8=
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@ package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/roboll/helmfile/pkg/helmexec"
|
|
||||||
"github.com/roboll/helmfile/pkg/remote"
|
|
||||||
"github.com/variantdev/chartify"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/roboll/helmfile/pkg/helmexec"
|
||||||
|
"github.com/roboll/helmfile/pkg/remote"
|
||||||
|
"github.com/variantdev/chartify"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dependency struct {
|
type Dependency struct {
|
||||||
|
|
@ -195,6 +196,8 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp
|
||||||
filesNeedCleaning = append(filesNeedCleaning, generatedFiles...)
|
filesNeedCleaning = append(filesNeedCleaning, generatedFiles...)
|
||||||
|
|
||||||
chartify.Opts.ValuesFiles = generatedFiles
|
chartify.Opts.ValuesFiles = generatedFiles
|
||||||
|
chartify.Opts.TemplateData = st.newReleaseTemplateData(release)
|
||||||
|
chartify.Opts.TemplateFuncs = st.newReleaseTemplateFuncMap(dir)
|
||||||
|
|
||||||
return chartify, clean, nil
|
return chartify, clean, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2428,10 +2428,22 @@ func (st *HelmState) flagsForLint(helm helmexec.Interface, release *ReleaseSpec,
|
||||||
return flags, files, nil
|
return flags, files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) RenderReleaseValuesFileToBytes(release *ReleaseSpec, path string) ([]byte, error) {
|
func (st *HelmState) newReleaseTemplateData(release *ReleaseSpec) releaseTemplateData {
|
||||||
vals := st.Values()
|
vals := st.Values()
|
||||||
templateData := st.createReleaseTemplateData(release, vals)
|
templateData := st.createReleaseTemplateData(release, vals)
|
||||||
|
|
||||||
|
return templateData
|
||||||
|
}
|
||||||
|
|
||||||
|
func (st *HelmState) newReleaseTemplateFuncMap(dir string) template.FuncMap {
|
||||||
|
r := tmpl.NewFileRenderer(st.readFile, dir, nil)
|
||||||
|
|
||||||
|
return r.Context.CreateFuncMap()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (st *HelmState) RenderReleaseValuesFileToBytes(release *ReleaseSpec, path string) ([]byte, error) {
|
||||||
|
templateData := st.newReleaseTemplateData(release)
|
||||||
|
|
||||||
r := tmpl.NewFileRenderer(st.readFile, filepath.Dir(path), templateData)
|
r := tmpl.NewFileRenderer(st.readFile, filepath.Dir(path), templateData)
|
||||||
rawBytes, err := r.RenderToBytes(path)
|
rawBytes, err := r.RenderToBytes(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Context) newTemplate() *template.Template {
|
func (c *Context) CreateFuncMap() template.FuncMap {
|
||||||
aliased := template.FuncMap{}
|
aliased := template.FuncMap{}
|
||||||
|
|
||||||
aliases := map[string]string{
|
aliases := map[string]string{
|
||||||
|
|
@ -27,6 +27,12 @@ func (c *Context) newTemplate() *template.Template {
|
||||||
funcMap[name] = f
|
funcMap[name] = f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return funcMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) newTemplate() *template.Template {
|
||||||
|
funcMap := c.CreateFuncMap()
|
||||||
|
|
||||||
tmpl := template.New("stringTemplate").Funcs(funcMap)
|
tmpl := template.New("stringTemplate").Funcs(funcMap)
|
||||||
if c.preRender {
|
if c.preRender {
|
||||||
tmpl = tmpl.Option("missingkey=zero")
|
tmpl = tmpl.Option("missingkey=zero")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue