parent
							
								
									5f1698d0ed
								
							
						
					
					
						commit
						efd26f288a
					
				
							
								
								
									
										15
									
								
								README.md
								
								
								
								
							
							
						
						
									
										15
									
								
								README.md
								
								
								
								
							|  | @ -301,6 +301,21 @@ apiVersions: | |||
| 
 | ||||
| Helmfile uses [Go templates](https://godoc.org/text/template) for templating your helmfile.yaml. While go ships several built-in functions, we have added all of the functions in the [Sprig library](https://godoc.org/github.com/Masterminds/sprig). | ||||
| 
 | ||||
| We also added the following functions: | ||||
| 
 | ||||
| - `requiredEnv` | ||||
| - `exec` | ||||
| - `readFile` | ||||
| - `toYaml` | ||||
| - `fromYaml` | ||||
| - `setValueAtPath` | ||||
| - `requiredEnv` | ||||
| - `get` (Sprig's original `get` is available as `sprigGet`) | ||||
| - `tpl` | ||||
| - `required` | ||||
| - `fetchSecretValue` | ||||
| - `expandSecretRefs` | ||||
| 
 | ||||
| We also added one special template function: `requiredEnv`. | ||||
| The `requiredEnv` function allows you to declare a particular environment variable as required for template rendering. | ||||
| If the environment variable is unset or empty, the template rendering will fail with an error message. | ||||
|  |  | |||
							
								
								
									
										5
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										5
									
								
								go.mod
								
								
								
								
							|  | @ -4,9 +4,8 @@ go 1.14 | |||
| 
 | ||||
| require ( | ||||
| 	github.com/Azure/azure-sdk-for-go v35.0.0+incompatible // indirect | ||||
| 	github.com/Masterminds/goutils v1.1.0 // indirect | ||||
| 	github.com/Masterminds/semver v1.4.2 | ||||
| 	github.com/Masterminds/sprig v2.22.0+incompatible | ||||
| 	github.com/Masterminds/sprig/v3 v3.1.0 | ||||
| 	github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a | ||||
| 	github.com/go-test/deep v1.0.3 | ||||
| 	github.com/golang/mock v1.4.3 | ||||
|  | @ -16,7 +15,6 @@ require ( | |||
| 	github.com/hashicorp/go-retryablehttp v0.6.3 // indirect | ||||
| 	github.com/hashicorp/go-version v1.2.0 | ||||
| 	github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c // indirect | ||||
| 	github.com/huandu/xstrings v1.2.0 // indirect | ||||
| 	github.com/imdario/mergo v0.3.9 | ||||
| 	github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect | ||||
| 	github.com/pierrec/lz4 v2.3.0+incompatible // indirect | ||||
|  | @ -29,7 +27,6 @@ require ( | |||
| 	github.com/variantdev/vals v0.10.0 | ||||
| 	go.uber.org/multierr v1.1.0 | ||||
| 	go.uber.org/zap v1.9.1 | ||||
| 	golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf // indirect | ||||
| 	golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a | ||||
| 	gopkg.in/square/go-jose.v2 v2.4.0 // indirect | ||||
| 	gopkg.in/yaml.v2 v2.2.4 | ||||
|  |  | |||
							
								
								
									
										13
									
								
								go.sum
								
								
								
								
							
							
						
						
									
										13
									
								
								go.sum
								
								
								
								
							|  | @ -114,8 +114,12 @@ github.com/Masterminds/semver v1.4.1 h1:CaDA1wAoM3rj9sAFyyZP37LloExUzxFGYt+DqJ87 | |||
| github.com/Masterminds/semver v1.4.1/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= | ||||
| github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= | ||||
| github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= | ||||
| github.com/Masterminds/semver/v3 v3.1.0 h1:Y2lUDsFKVRSYGojLJ1yLxSXdMmMYTYls0rCvoqmMUQk= | ||||
| github.com/Masterminds/semver/v3 v3.1.0/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= | ||||
| github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60= | ||||
| github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= | ||||
| github.com/Masterminds/sprig/v3 v3.1.0 h1:j7GpgZ7PdFqNsmncycTHsLmVPf5/3wJtlgW9TNDYD9Y= | ||||
| github.com/Masterminds/sprig/v3 v3.1.0/go.mod h1:ONGMf7UfYGAbMXCZmQLy8x3lCDIPrEZE/rU8pmrbihA= | ||||
| github.com/Microsoft/go-winio v0.4.13 h1:Hmi80lzZuI/CaYmlJp/b+FjZdRZhKu9c2mDVqKlLWVs= | ||||
| github.com/Microsoft/go-winio v0.4.13/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= | ||||
| github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= | ||||
|  | @ -358,6 +362,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4 | |||
| github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= | ||||
| github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= | ||||
| github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||
| github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= | ||||
| github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||
| github.com/googleapis/gax-go v2.0.0+incompatible h1:j0GKcs05QVmm7yesiZq2+9cxHkNK9YM6zKx4D2qucQU= | ||||
| github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= | ||||
| github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= | ||||
|  | @ -516,7 +522,10 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= | |||
| github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= | ||||
| github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0= | ||||
| github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= | ||||
| github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs= | ||||
| github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= | ||||
| github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= | ||||
| github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= | ||||
| github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg= | ||||
| github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= | ||||
| github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= | ||||
|  | @ -762,6 +771,8 @@ github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945/go.mod h1:s | |||
| github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= | ||||
| github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= | ||||
| github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= | ||||
| github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= | ||||
| github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= | ||||
| github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= | ||||
| github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= | ||||
| github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= | ||||
|  | @ -891,6 +902,8 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U | |||
| golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||||
| golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIoF2s4qxv0xSSS0BVZUE/ss= | ||||
| golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||||
| golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 h1:bXoxMPcSLOq08zI3/c5dEBT6lE4eh+jOh886GHrn6V8= | ||||
| golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||||
| golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= | ||||
| golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= | ||||
| golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= | ||||
|  |  | |||
|  | @ -2,15 +2,31 @@ package tmpl | |||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"github.com/Masterminds/sprig" | ||||
| 	"github.com/Masterminds/sprig/v3" | ||||
| 	"text/template" | ||||
| ) | ||||
| 
 | ||||
| func (c *Context) newTemplate() *template.Template { | ||||
| 	aliased := template.FuncMap{} | ||||
| 
 | ||||
| 	aliases := map[string]string{ | ||||
| 		"get": "sprigGet", | ||||
| 	} | ||||
| 
 | ||||
| 	funcMap := sprig.TxtFuncMap() | ||||
| 
 | ||||
| 	for orig, alias := range aliases { | ||||
| 		aliased[alias] = funcMap[orig] | ||||
| 	} | ||||
| 
 | ||||
| 	for name, f := range c.createFuncMap() { | ||||
| 		funcMap[name] = f | ||||
| 	} | ||||
| 
 | ||||
| 	for name, f := range aliased { | ||||
| 		funcMap[name] = f | ||||
| 	} | ||||
| 
 | ||||
| 	tmpl := template.New("stringTemplate").Funcs(funcMap) | ||||
| 	if c.preRender { | ||||
| 		tmpl = tmpl.Option("missingkey=zero") | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue