Merge pull request #139 from int128/inline-values

Inline values support
This commit is contained in:
KUOKA Yusuke 2018-05-11 14:34:25 +09:00 committed by GitHub
commit fb781be560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 8 deletions

View File

@ -45,7 +45,11 @@ releases:
foo: bar
chart: roboll/vault-secret-manager # the chart being installed to create this release, referenced by `repository/chart` syntax
version: ~1.24.1 # the semver of the chart. range constraint is supported
values: [ vault.yaml ] # value files (--values)
values:
- vault.yaml # value files (--values)
- db: # inline values. Passed via a temporary values file (--values)
username: {{ requiredEnv "DB_USERNAME" }}
password: {{ requiredEnv "DB_PASSWORD" }}
secrets:
- vault_secret.yaml # will attempt to decrypt it using helm-secrets plugin
set: # values (--set)
@ -78,7 +82,7 @@ If the environment variable is unset or empty, the template rendering will fail
## Using environment variables
Environment variables can be used in most places for templating the helmfile. Currently this is supported for `name`, `namespace`, `value` (in set) and `url` (in repositories).
Environment variables can be used in most places for templating the helmfile. Currently this is supported for `name`, `namespace`, `value` (in set), `values` and `url` (in repositories).
Examples:
@ -93,6 +97,10 @@ releases:
- name: {{ requiredEnv "NAME" }}-vault
namespace: {{ requiredEnv "NAME" }}
chart: roboll/vault-secret-manager
values:
- db:
username: {{ requiredEnv "DB_USERNAME" }}
password: {{ requiredEnv "DB_PASSWORD" }}
set:
- name: proxy.domain
value: {{ requiredEnv "PLATFORM_ID" }}.my-domain.com

View File

@ -49,7 +49,7 @@ type ReleaseSpec struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace"`
Labels map[string]string `yaml:"labels"`
Values []string `yaml:"values"`
Values []interface{} `yaml:"values"`
Secrets []string `yaml:"secrets"`
SetValues []SetValue `yaml:"set"`
@ -479,12 +479,28 @@ func flagsForRelease(helm helmexec.Interface, basePath string, release *ReleaseS
flags = append(flags, "--namespace", release.Namespace)
}
for _, value := range release.Values {
path := filepath.Join(basePath, value)
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, err
}
switch typedValue := value.(type) {
case string:
path := filepath.Join(basePath, typedValue)
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, err
}
flags = append(flags, "--values", path)
flags = append(flags, "--values", path)
case map[interface{}]interface{}:
valfile, err := ioutil.TempFile("", "values")
if err != nil {
return nil, err
}
defer valfile.Close()
encoder := yaml.NewEncoder(valfile)
defer encoder.Close()
if err := encoder.Encode(typedValue); err != nil {
return nil, err
}
release.generatedValues = append(release.generatedValues, valfile.Name())
flags = append(flags, "--values", valfile.Name())
}
}
for _, value := range release.Secrets {
path := filepath.Join(basePath, value)