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

Commit

Permalink
Helm race condition fixes (#210)
Browse files Browse the repository at this point in the history
- Fixed some possible race condition issues around helm template
- Version bump to 0.14.0
  • Loading branch information
evanlouie authored Jul 2, 2019
1 parent b2b4ffb commit de0a74e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var versionCmd = &cobra.Command{

// PrintVersion prints the current version of Fabrikate being used.
func PrintVersion() {
log.Println("fab version 0.13.1")
log.Println("fab version 0.14.0")
}

func init() {
Expand Down
24 changes: 10 additions & 14 deletions generators/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,40 +70,38 @@ func (hg *HelmGenerator) Generate(component *core.Component) (manifest string, e
return "", err
}

// Get chart path based on helm_repo location
helmRepoPath := hg.makeHelmRepoPath(component)
absHelmRepoPath, err := filepath.Abs(helmRepoPath)
if err != nil {
return "", err
}

chartPath := path.Join(absHelmRepoPath, component.Path)

// Write helm config to temporary file in tmp folder
uuid, err := uuid.NewRandom()
if err != nil {
return "", err
}

overriddenValuesFileName := fmt.Sprintf("overriddenValues-%s.yaml", uuid.String())
absOverriddenPath := path.Join(chartPath, overriddenValuesFileName)

log.Debugf("Writing config %s to %s\n", configYaml, absOverriddenPath)
err = ioutil.WriteFile(absOverriddenPath, configYaml, 0644)
overriddenValuesFileName := fmt.Sprintf("%s.yaml", uuid.String())
absOverriddenPath := path.Join(os.TempDir(), overriddenValuesFileName)
log.Debugf(emoji.Sprintf(":pencil: Writing config %s to %s\n", configYaml, absOverriddenPath))
err = ioutil.WriteFile(absOverriddenPath, configYaml, 0777)
if err != nil {
return "", err
}

name := component.Name

// Default to `default` namespace unless provided
namespace := "default"
if component.Config.Namespace != "" {
namespace = component.Config.Namespace
}

output, err := exec.Command("helm", "template", chartPath, "--values", absOverriddenPath, "--name", name, "--namespace", namespace).Output()

// Run `helm template` on the chart using the config stored in temp dir
output, err := exec.Command("helm", "template", chartPath, "--values", absOverriddenPath, "--name", component.Name, "--namespace", namespace).Output()
if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
log.Errorf("helm template failed with: %s\n", ee.Stderr)
_ = os.RemoveAll(absOverriddenPath)
return "", err
}
}
Expand All @@ -118,8 +116,6 @@ func (hg *HelmGenerator) Generate(component *core.Component) (manifest string, e
stringManifests, err = addNamespaceToManifests(stringManifests, component.Config.Namespace)
}

_ = os.RemoveAll(absOverriddenPath)

return stringManifests, err
}

Expand Down

0 comments on commit de0a74e

Please sign in to comment.