Skip to content

Commit

Permalink
Updated: Fix using same helm chart with different versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Lish committed Mar 22, 2023
1 parent 2dcdc7b commit 936a14c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
20 changes: 17 additions & 3 deletions api/internal/builtins/HelmChartInflationGenerator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ func (p *plugin) validateArgs() (err error) {
// be under the loader root (unless root restrictions are
// disabled).
if p.ValuesFile == "" {
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")

// If the version is specified, use the versioned values file.
if p.Version != "" {
p.ValuesFile = filepath.Join(p.ChartHome, fmt.Sprintf("%s-%s", p.Name, p.Version), p.Name, "values.yaml")
} else {
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")
}
}
for i, file := range p.AdditionalValuesFiles {
Expand Down Expand Up @@ -259,7 +260,7 @@ func (p *plugin) Generate() (rm resmap.ResMap, err error) {
return nil, err
}
var stdout []byte
stdout, err = p.runHelmCommand(p.AsHelmArgs(p.absChartHome()))
stdout, err = p.runHelmCommand(p.AsHelmArgs(p.chartPath()))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -290,7 +291,7 @@ func (p *plugin) pullCommand() []string {
args := []string{
"pull",
"--untar",
"--untardir", p.absChartHome(),
"--untardir", p.chartPath(),
"--repo", p.Repo,
p.Name}
if p.Version != "" {
Expand All @@ -302,7 +303,7 @@ func (p *plugin) pullCommand() []string {
// chartExistsLocally will return true if the chart does exist in
// local chart home.
func (p *plugin) chartExistsLocally() (string, bool) {
path := filepath.Join(p.absChartHome(), p.Name)
path := filepath.Join(p.chartPath(), p.Name)
s, err := os.Stat(path)
if err != nil {
return "", false
Expand Down Expand Up @@ -333,3 +334,12 @@ func (p *plugin) checkHelmVersion() error {
}
return nil
}

// chartPath will return the path to the chart and handle the case where a version
// is specified
func (p *plugin) chartPath() string {
if p.Version != "" {
return filepath.Join(p.absChartHome(), fmt.Sprintf("%s-%s", p.Name, p.Version))
}
return p.absChartHome()
}

0 comments on commit 936a14c

Please sign in to comment.