Skip to content

Commit

Permalink
Extend HelmChart to support helm --set-file
Browse files Browse the repository at this point in the history
  • Loading branch information
dakr0013 committed Oct 15, 2023
1 parent f80d9c4 commit 785e97e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/types/helmchartargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type HelmChart struct {
// addition to either the default values file or the values specified in ValuesFile.
AdditionalValuesFiles []string `json:"additionalValuesFiles,omitempty" yaml:"additionalValuesFiles,omitempty"`

// AdditionalValuesFromFileContent holds value mappings where the value is
// specified in a file. This allows setting values from respective files.
// The file's content will become the value's content.
AdditionalValuesFromFileContent map[string]string `json:"additionalValuesFromFileContent,omitempty" yaml:"additionalValuesFromFileContent,omitempty"`

// ValuesFile is a local file path to a values file to use _instead of_
// the default values that accompanied the chart.
// The default values are in '{ChartHome}/{Name}/values.yaml'.
Expand Down Expand Up @@ -168,6 +173,9 @@ func (h HelmChart) AsHelmArgs(absChartHome string) []string {
for _, valuesFile := range h.AdditionalValuesFiles {
args = append(args, "-f", valuesFile)
}
for key, file := range h.AdditionalValuesFromFileContent {
args = append(args, "--set-file", key+"="+file)
}

for _, apiVer := range h.ApiVersions {
args = append(args, "--api-versions", apiVer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ func (p *plugin) validateArgs() (err error) {
// the additional values filepaths must be relative to the kust root
p.AdditionalValuesFiles[i] = filepath.Join(p.h.Loader().Root(), file)
}
for key, file := range p.AdditionalValuesFromFileContent {
// use Load() to enforce root restrictions
if _, err := p.h.Loader().Load(file); err != nil {
return errors.WrapPrefixf(err, "could not load file specified in AdditionalValuesFromFileContent")
}
// the filepaths must be relative to the kust root
p.AdditionalValuesFromFileContent[key] = filepath.Join(p.h.Loader().Root(), file)
}

if err = p.errIfIllegalValuesMerge(); err != nil {
return err
Expand Down

0 comments on commit 785e97e

Please sign in to comment.