mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
helm values on inflator config - builtin
Signed-off-by: Petr Michalec <epcim@apealive.net>
This commit is contained in:
@@ -6,12 +6,15 @@ package builtins
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/imdario/mergo"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
@@ -62,6 +65,9 @@ func (p *HelmChartInflationGeneratorPlugin) Config(h *resmap.PluginHelpers, conf
|
|||||||
if p.Values == "" {
|
if p.Values == "" {
|
||||||
p.Values = path.Join(p.ChartHome, p.ChartName, "values.yaml")
|
p.Values = path.Join(p.ChartHome, p.ChartName, "values.yaml")
|
||||||
}
|
}
|
||||||
|
if p.ValuesMerge == "" {
|
||||||
|
p.ValuesMerge = "override"
|
||||||
|
}
|
||||||
// runHelmCommand will run `helm` command with args provided. Return stdout
|
// runHelmCommand will run `helm` command with args provided. Return stdout
|
||||||
// and error if there is any.
|
// and error if there is any.
|
||||||
p.runHelmCommand = func(args []string) ([]byte, error) {
|
p.runHelmCommand = func(args []string) ([]byte, error) {
|
||||||
@@ -88,6 +94,21 @@ func (p *HelmChartInflationGeneratorPlugin) Config(h *resmap.PluginHelpers, conf
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EncodeValues for writing
|
||||||
|
func (p *HelmChartInflationGeneratorPlugin) EncodeValues(w io.Writer) error {
|
||||||
|
d, err := yaml.Marshal(p.ValuesLocal)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = w.Write(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
// Generate implements generator
|
// Generate implements generator
|
||||||
func (p *HelmChartInflationGeneratorPlugin) Generate() (resmap.ResMap, error) {
|
func (p *HelmChartInflationGeneratorPlugin) Generate() (resmap.ResMap, error) {
|
||||||
// cleanup
|
// cleanup
|
||||||
@@ -104,6 +125,50 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (resmap.ResMap, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// values
|
||||||
|
if len(p.ValuesLocal) > 0 {
|
||||||
|
fn := path.Join(p.ChartHome, p.ChartName, "kustomize-values.yaml")
|
||||||
|
vf, err := os.Create(fn)
|
||||||
|
defer vf.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// override, merge, none
|
||||||
|
if p.ValuesMerge == "none" || p.ValuesMerge == "no" || p.ValuesMerge == "false" {
|
||||||
|
p.Values = fn
|
||||||
|
} else {
|
||||||
|
pValues, err := ioutil.ReadFile(p.Values)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
chValues := make(map[string]interface{})
|
||||||
|
err = yaml.Unmarshal(pValues, &chValues)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if p.ValuesMerge == "override" {
|
||||||
|
err = mergo.Merge(&chValues, p.ValuesLocal, mergo.WithOverride)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if p.ValuesMerge == "merge" {
|
||||||
|
err = mergo.Merge(&chValues, p.ValuesLocal)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.ValuesLocal = chValues
|
||||||
|
p.Values = fn
|
||||||
|
}
|
||||||
|
err = p.EncodeValues(vf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
vf.Sync()
|
||||||
|
}
|
||||||
|
|
||||||
// render the charts
|
// render the charts
|
||||||
stdout, err := p.runHelmCommand(p.getTemplateCommandArgs())
|
stdout, err := p.runHelmCommand(p.getTemplateCommandArgs())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user