From a889fc1cb3441b3e2bcd9ad8373b689641fcbf00 Mon Sep 17 00:00:00 2001 From: Tim Park Date: Thu, 7 Nov 2019 13:34:24 -0800 Subject: [PATCH] Handle helm repo aliases (#274) * Handle helm repo aliases * Make install test instead * Also issue generate on directory * Fix lint error * Remove unnecessary Generate --- cmd/generate_test.go | 3 +-- cmd/install_test.go | 16 ++++++++++++++++ generators/helm.go | 10 ++++++++++ testdata/repo-alias/component.yaml | 7 +++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 testdata/repo-alias/component.yaml diff --git a/cmd/generate_test.go b/cmd/generate_test.go index 5f66539..47d2d55 100644 --- a/cmd/generate_test.go +++ b/cmd/generate_test.go @@ -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) @@ -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) diff --git a/cmd/install_test.go b/cmd/install_test.go index 4f832f2..f9023fa 100644 --- a/cmd/install_test.go +++ b/cmd/install_test.go @@ -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) +} diff --git a/generators/helm.go b/generators/helm.go index 2871070..8b2cd63 100644 --- a/generators/helm.go +++ b/generators/helm.go @@ -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 @@ -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 { @@ -409,6 +418,7 @@ func updateHelmChartDep(chartPath string) (err error) { return err } hd.mu.Unlock() + addedDepRepoList = append(addedDepRepoList, randomRepoName) } } diff --git a/testdata/repo-alias/component.yaml b/testdata/repo-alias/component.yaml new file mode 100644 index 0000000..7eea233 --- /dev/null +++ b/testdata/repo-alias/component.yaml @@ -0,0 +1,7 @@ +name: repo-alias +subcomponents: +- name: metricbeat + type: helm + source: https://helm.elastic.co + method: helm + path: metricbeat