Skip to content

Commit 39a2d5e

Browse files
committed
feat(helm): add local path support for deps in requirements.yaml
fix change requests
1 parent d72ff65 commit 39a2d5e

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

docs/helm/helm_dependency.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ appending '/index.yaml' to the URL, it should be able to retrieve the chart
3939
repository's index. Note: 'repository' cannot be a repository alias. It must be
4040
a URL.
4141

42+
Starting from 2.2.0, repository can be defined as the path to the directory of
43+
the dependency charts stored locally. The path should start with a prefix of "file://".
44+
For example,
45+
# requirements.yaml
46+
dependencies:
47+
- name: nginx
48+
version: "1.2.3"
49+
repository: "file://../depedency_chart/nginx"
50+
If the dependency chart is retrieved locally, it is not required to have the repository
51+
added to helm by "helm add repo". Version matching is also supported for this case.
4252

4353
### Options inherited from parent commands
4454

pkg/downloader/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,13 @@ func (m *Manager) getRepoNames(deps []*chartutil.Dependency) (map[string]string,
313313
for _, dd := range deps {
314314
// if dep chart is from local path, verify the path is valid
315315
if strings.HasPrefix(dd.Repository, "file://") {
316-
depPath, err := filepath.Abs(dd.Repository[7:])
316+
depPath, err := filepath.Abs(strings.TrimPrefix(dd.Repository, "file://"))
317317
if err != nil {
318318
return nil, err
319319
}
320320

321321
if _, err = os.Stat(depPath); os.IsNotExist(err) {
322-
return nil, fmt.Errorf("directory %s not found: %s", depPath, err)
322+
return nil, fmt.Errorf("directory %s not found", depPath)
323323
}
324324

325325
fmt.Fprintf(m.Out, "Repository from local path: %s\n", dd.Repository)

pkg/resolver/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (r *Resolver) Resolve(reqs *chartutil.Requirements, repoNames map[string]st
5858
missing := []string{}
5959
for i, d := range reqs.Dependencies {
6060
if strings.HasPrefix(d.Repository, "file://") {
61-
depPath, err := filepath.Abs(d.Repository[7:])
61+
depPath, err := filepath.Abs(strings.TrimPrefix(d.Repository, "file://"))
6262
if err != nil {
6363
return nil, err
6464
}

pkg/resolver/resolver_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,20 @@ func TestResolve(t *testing.T) {
7878
},
7979
},
8080
{
81-
name: "repo from local invalid path",
81+
name: "repo from valid local path",
82+
req: &chartutil.Requirements{
83+
Dependencies: []*chartutil.Dependency{
84+
{Name: "signtest", Repository: "file://../testdata/testcharts/signtest", Version: "0.1.0"},
85+
},
86+
},
87+
expect: &chartutil.RequirementsLock{
88+
Dependencies: []*chartutil.Dependency{
89+
{Name: "signtest", Repository: "file://../testdata/testcharts/signtest", Version: "0.1.0"},
90+
},
91+
},
92+
},
93+
{
94+
name: "repo from invalid local path",
8295
req: &chartutil.Requirements{
8396
Dependencies: []*chartutil.Dependency{
8497
{Name: "notexist", Repository: "file://../testdata/notexist", Version: "0.1.0"},

0 commit comments

Comments
 (0)