Skip to content

Commit

Permalink
fix: add helm dependencies with custom CA (argoproj#6003)
Browse files Browse the repository at this point in the history
* fix: add helm dependecies with custom CA

Signed-off-by: Shubham Agarwal <[email protected]>

* fixed go lint error

Signed-off-by: Shubham Agarwal <[email protected]>

* ignore existing repos

Signed-off-by: Shubham Agarwal <[email protected]>

* fix: Enable helm OCI to work for lots of different URLs without having to create a repo for each one

Signed-off-by: May Zhang <[email protected]>

* Revert "fix: Enable helm OCI to work for lots of different URLs without having to create a repo for each one"

This reverts commit a8ae8cf.

* fix: only adding the dependency repo which does not exist in the repo list

Co-authored-by: May Zhang <[email protected]>
  • Loading branch information
Shubhama19 and mayzhang2000 authored Apr 14, 2021
1 parent 8fd6f13 commit 8f53bd5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
56 changes: 55 additions & 1 deletion reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,48 @@ func getHelmRepos(repositories []*v1alpha1.Repository) []helm.HelmRepository {
return repos
}

type dependencies struct {
Dependencies []repositories `yaml:"dependencies"`
}

type repositories struct {
Repository string `yaml:"repository"`
}

func getHelmDependencyRepos(appPath string) ([]*v1alpha1.Repository, error) {
repos := make([]*v1alpha1.Repository, 0)
f, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", appPath, "Chart.yaml"))
if err != nil {
return nil, err
}

d := &dependencies{}
if err = yaml.Unmarshal(f, d); err != nil {
return nil, err
}

for _, r := range d.Dependencies {
if u, err := url.Parse(r.Repository); err == nil && u.Scheme == "https" {
repo := &v1alpha1.Repository{
Repo: r.Repository,
Name: u.Host,
}
repos = append(repos, repo)
}
}

return repos, nil
}

func repoExists(repo string, repos []*v1alpha1.Repository) bool {
for _, r := range repos {
if repo == r.Repo {
return true
}
}
return false
}

func isConcurrencyAllowed(appPath string) bool {
if _, err := os.Stat(path.Join(appPath, allowConcurrencyFile)); err == nil {
return true
Expand Down Expand Up @@ -586,11 +628,23 @@ func helmTemplate(appPath string, repoRoot string, env *v1alpha1.Env, q *apiclie
for i, j := range templateOpts.SetFile {
templateOpts.SetFile[i] = env.Envsubst(j)
}
h, err := helm.NewHelmApp(appPath, getHelmRepos(q.Repos), isLocal, version)

repos, err := getHelmDependencyRepos(appPath)
if err != nil {
return nil, err
}

for _, r := range repos {
if !repoExists(r.Repo, q.Repos) {
q.Repos = append(q.Repos, r)
}
}

h, err := helm.NewHelmApp(appPath, getHelmRepos(q.Repos), isLocal, version)
if err != nil {
return nil, err
}

defer h.Dispose()
err = h.Init()
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,3 +1480,14 @@ func TestTestRepoOCI(t *testing.T) {
assert.Error(t, err)
assert.Equal(t, "OCI Helm repository URL should include hostname and port only", err.Error())
}

func Test_getHelmDependencyRepos(t *testing.T) {
repo1 := "https://charts.bitnami.com/bitnami"
repo2 := "https://eventstore.github.io/EventStore.Charts"

repos, err := getHelmDependencyRepos("../../util/helm/testdata/dependency")
assert.NoError(t, err)
assert.Equal(t, len(repos), 2)
assert.Equal(t, repos[0].Repo, repo1)
assert.Equal(t, repos[1].Repo, repo2)
}

0 comments on commit 8f53bd5

Please sign in to comment.