Skip to content

Commit

Permalink
Use if/else for readability, add version check to absChartHome
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Lish committed Mar 31, 2023
1 parent a9981ae commit 380abb9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
30 changes: 14 additions & 16 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,11 +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 @@ -143,10 +143,17 @@ func (p *plugin) errIfIllegalValuesMerge() error {
}

func (p *plugin) absChartHome() string {
var chartHome string
if filepath.IsAbs(p.ChartHome) {
return p.ChartHome
chartHome = p.ChartHome
} else {
chartHome = filepath.Join(p.h.Loader().Root(), p.ChartHome)
}

if p.Version != "" {
return filepath.Join(chartHome, fmt.Sprintf("%s-%s", p.Name, p.Version))
}
return filepath.Join(p.h.Loader().Root(), p.ChartHome)
return chartHome
}

func (p *plugin) runHelmCommand(
Expand Down Expand Up @@ -260,7 +267,7 @@ func (p *plugin) Generate() (rm resmap.ResMap, err error) {
return nil, err
}
var stdout []byte
stdout, err = p.runHelmCommand(p.AsHelmArgs(p.chartPath()))
stdout, err = p.runHelmCommand(p.AsHelmArgs(p.absChartHome()))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -291,7 +298,7 @@ func (p *plugin) pullCommand() []string {
args := []string{
"pull",
"--untar",
"--untardir", p.chartPath(),
"--untardir", p.absChartHome(),
"--repo", p.Repo,
p.Name}
if p.Version != "" {
Expand All @@ -303,7 +310,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.chartPath(), p.Name)
path := filepath.Join(p.absChartHome(), p.Name)
s, err := os.Stat(path)
if err != nil {
return "", false
Expand Down Expand Up @@ -334,12 +341,3 @@ 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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,11 @@ releaseName: %s
rm := th.LoadAndRunGenerator(config)
assert.True(t, len(rm.Resources()) > 0)

chartDir := fmt.Sprintf("charts/%s", tt.chartName)
var chartDir string
if tt.version != "" {
chartDir = fmt.Sprintf("charts/%s-%s/%s", tt.chartName, tt.version, tt.chartName)
} else {
chartDir = fmt.Sprintf("charts/%s", tt.chartName)
}

d, err := th.GetFSys().ReadFile(filepath.Join(th.GetRoot(), chartDir, "Chart.yaml"))
Expand Down

0 comments on commit 380abb9

Please sign in to comment.