Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
fixed helm dependency update calls (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlouie authored Jul 12, 2019
1 parent 999376a commit dc5ef78
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
6 changes: 3 additions & 3 deletions core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (c *Component) Write() (err error) {
filename := fmt.Sprintf("component.%s", c.Serialization)
componentPath := path.Join(c.PhysicalPath, filename)

log.Info(emoji.Sprintf(":floppy_disk: Writing %s", componentPath))
log.Info(emoji.Sprintf(":floppy_disk: Writing '%s'", componentPath))

return ioutil.WriteFile(componentPath, marshaledComponent, 0644)
}
Expand Down Expand Up @@ -466,7 +466,7 @@ func (c *Component) GetAccessTokens() (tokens map[string]string, err error) {
// If the file is not found, return an empty map with no error
return map[string]string{}, nil
} else if err != nil {
log.Error(emoji.Sprintf(":no_entry_sign: Error unmarshalling access.yaml in %s", accessYamlPath))
log.Error(emoji.Sprintf(":no_entry_sign: Error unmarshalling access.yaml in '%s'", accessYamlPath))
return nil, err
}

Expand All @@ -475,7 +475,7 @@ func (c *Component) GetAccessTokens() (tokens map[string]string, err error) {
token := os.Getenv(envVar)
if token == "" {
// Give warning that failed to load env var; but continue and attempt clone
msg := fmt.Sprintf("Component %s attempted to load environment variable %s; but is either not set or an empty string. Components with source %s may fail to install", c.Name, envVar, repo)
msg := fmt.Sprintf("Component '%s' attempted to load environment variable '%s'; but is either not set or an empty string. Components with source '%s' may fail to install", c.Name, envVar, repo)
log.Warn(emoji.Sprintf(":no_entry_sign: %s", msg))
} else {
tokens[repo] = token
Expand Down
40 changes: 30 additions & 10 deletions generators/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,17 @@ func (hg *HelmGenerator) Install(c *core.Component) (err error) {
if err = core.CloneRepo(c.Source, c.Version, helmRepoPath, c.Branch); err != nil {
return err
}
// Remove .git
_ = os.RemoveAll(path.Join(helmRepoPath, ".git"))
// Update chart dependencies in chart path -- this is manually done here but automatically done in downloadChart
chartPath, err := hg.getChartPath(c)
if err != nil {
return err
}
_ = updateHelmChartDep(chartPath)
}
}

// Update chart dependencies -- don't fail if error is returned, but throw warning
chartPath, err := hg.getChartPath(c)
if err != nil {
return err
}
log.Info(emoji.Sprintf(":helicopter: Updating helm chart's dependencies for component '%s'", c.Name))
if output, err := exec.Command("helm", "dependency", "update", chartPath).CombinedOutput(); err != nil {
log.Warn(emoji.Sprintf(":no_entry_sign: Updating chart dependencies failed for chart '%s' in component '%s'; run `helm dependency update %s` for more error details.\n%s: %s", c.Name, c.Path, chartPath, err, output))
}

return err
}

Expand Down Expand Up @@ -217,6 +215,9 @@ func (hd *helmDownloader) downloadChart(repo, chart, into string) (err error) {
return err
}

// Update chart dependencies before removing temp repo
_ = updateHelmChartDep(into)

// Remove repository once completed
log.Info(emoji.Sprintf(":bomb: Removing temporary helm repo %s", randomName))
hd.mu.Lock()
Expand All @@ -230,3 +231,22 @@ func (hd *helmDownloader) downloadChart(repo, chart, into string) (err error) {
chartDirectoryInRandomDir := path.Join(randomDir, chart)
return copy.Copy(chartDirectoryInRandomDir, into)
}

// updateHelmChartDep attempts to run `helm dependency update` on chartPath
func updateHelmChartDep(chartPath string) (err error) {
absChartPath := chartPath
if isAbs := filepath.IsAbs(absChartPath); !isAbs {
asAbs, err := filepath.Abs(chartPath)
if err != nil {
return err
}
absChartPath = asAbs
}
log.Info(emoji.Sprintf(":helicopter: Updating helm chart's dependencies for chart in '%s'", absChartPath))
if output, err := exec.Command("helm", "dependency", "update", chartPath).CombinedOutput(); err != nil {
log.Warn(emoji.Sprintf(":no_entry_sign: Updating chart dependencies failed for chart in '%s'; run `helm dependency update %s` for more error details.\n%s: %s", absChartPath, absChartPath, err, output))
return err
}

return err
}

0 comments on commit dc5ef78

Please sign in to comment.