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

Commit

Permalink
Handle helm repo aliases (#274)
Browse files Browse the repository at this point in the history
* Handle helm repo aliases

* Make install test instead

* Also issue generate on directory

* Fix lint error

* Remove unnecessary Generate
  • Loading branch information
timfpark authored and evanlouie committed Nov 7, 2019
1 parent f0bf9b1 commit a889fc1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestGenerateStaticRemoteYAML(t *testing.T) {

expectedLengths := map[string]int{
"keyvault-flexvolume": 5,
"keyvault-sub": 1372,
"keyvault-sub": 1372,
}

assert.Nil(t, err)
Expand All @@ -64,7 +64,6 @@ func TestGenerateStaticRemoteYAML(t *testing.T) {
checkComponentLengthsAgainstExpected(t, components, expectedLengths)
}


func TestGenerateWithHooks(t *testing.T) {
_, err := Generate("../testdata/generate-hooks", []string{"prod"}, false)

Expand Down
16 changes: 16 additions & 0 deletions cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,19 @@ func TestInstallWithoutHelmInitialized(t *testing.T) {
assert.Nil(t, os.Chdir(componentDir))
assert.Nil(t, Install("./"))
}

func TestGenerateHelmRepoAlias(t *testing.T) {
componentDir := "../testdata/repo-alias"
cwd, err := os.Getwd()
assert.Nil(t, err)
defer func() {
assert.Nil(t, os.Chdir(cwd))
assert.Nil(t, util.UninstallComponents(componentDir))
}()

// Change cwd to component directory
assert.Nil(t, os.Chdir(componentDir))
assert.Nil(t, Install("./"))

assert.Nil(t, err)
}
10 changes: 10 additions & 0 deletions generators/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,12 @@ func updateHelmChartDep(chartPath string) (err error) {
addedDepRepoList := []string{}
if _, err := os.Stat(requirementsYamlPath); err == nil {
logger.Info(fmt.Sprintf("requirements.yaml found at '%s', ensuring repositories exist on helm client", requirementsYamlPath))

bytes, err := ioutil.ReadFile(requirementsYamlPath)
if err != nil {
return err
}

requirementsYaml := helmRequirements{}
if err = yaml.Unmarshal(bytes, &requirementsYaml); err != nil {
return err
Expand All @@ -396,11 +398,18 @@ func updateHelmChartDep(chartPath string) (err error) {
logger.Info(emoji.Sprintf(":pencil: Helm dependency repo already present: %v", currentRepo))
continue
}

if !strings.HasPrefix(dep.Repository, "http") {
logger.Info(emoji.Sprintf(":pencil: Skipping non-http helm dependency repo. Found '%v'", dep.Repository))
continue
}

logger.Info(emoji.Sprintf(":pencil: Adding helm dependency repository '%s'", dep.Repository))
randomUUID, err := uuid.NewRandom()
if err != nil {
return err
}

randomRepoName := randomUUID.String()
hd.mu.Lock()
if output, err := exec.Command("helm", "repo", "add", randomRepoName, dep.Repository).CombinedOutput(); err != nil {
Expand All @@ -409,6 +418,7 @@ func updateHelmChartDep(chartPath string) (err error) {
return err
}
hd.mu.Unlock()

addedDepRepoList = append(addedDepRepoList, randomRepoName)
}
}
Expand Down
7 changes: 7 additions & 0 deletions testdata/repo-alias/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: repo-alias
subcomponents:
- name: metricbeat
type: helm
source: https://helm.elastic.co
method: helm
path: metricbeat

0 comments on commit a889fc1

Please sign in to comment.