mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
fix(helm): local path in requirements.yaml relative to working dir
closes bug: 2103
This commit is contained in:
parent
ea61ace808
commit
e6b79e138b
3 changed files with 30 additions and 24 deletions
|
|
@ -325,14 +325,7 @@ func (m *Manager) getRepoNames(deps []*chartutil.Dependency) (map[string]string,
|
|||
for _, dd := range deps {
|
||||
// if dep chart is from local path, verify the path is valid
|
||||
if strings.HasPrefix(dd.Repository, "file://") {
|
||||
depPath, err := filepath.Abs(strings.TrimPrefix(dd.Repository, "file://"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err = os.Stat(depPath); os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("directory %s not found", depPath)
|
||||
} else if err != nil {
|
||||
if _, err := resolver.GetLocalPath(dd.Repository, m.ChartPath); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -537,17 +530,11 @@ func tarFromLocalDir(chartpath string, name string, repo string, version string)
|
|||
return "", fmt.Errorf("wrong format: chart %s repository %s", name, repo)
|
||||
}
|
||||
|
||||
origPath, err := filepath.Abs(strings.TrimPrefix(repo, "file://"))
|
||||
origPath, err := resolver.GetLocalPath(repo, chartpath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if _, err = os.Stat(origPath); os.IsNotExist(err) {
|
||||
return "", fmt.Errorf("directory %s not found: %s", origPath, err)
|
||||
} else if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ch, err := chartutil.LoadDir(origPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
|||
|
|
@ -58,14 +58,8 @@ func (r *Resolver) Resolve(reqs *chartutil.Requirements, repoNames map[string]st
|
|||
missing := []string{}
|
||||
for i, d := range reqs.Dependencies {
|
||||
if strings.HasPrefix(d.Repository, "file://") {
|
||||
depPath, err := filepath.Abs(strings.TrimPrefix(d.Repository, "file://"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err = os.Stat(depPath); os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("directory %s not found", depPath)
|
||||
} else if err != nil {
|
||||
if _, err := GetLocalPath(d.Repository, r.chartpath); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -136,3 +130,28 @@ func HashReq(req *chartutil.Requirements) (string, error) {
|
|||
s, err := provenance.Digest(bytes.NewBuffer(data))
|
||||
return "sha256:" + s, err
|
||||
}
|
||||
|
||||
// GetLocalPath generates absolute local path when use
|
||||
// "file://" in repository of requirements
|
||||
func GetLocalPath(repo string, chartpath string) (string, error) {
|
||||
var depPath string
|
||||
var err error
|
||||
p := strings.TrimPrefix(repo, "file://")
|
||||
|
||||
// root path is absolute
|
||||
if strings.HasPrefix(p, "/") {
|
||||
if depPath, err = filepath.Abs(p); err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
depPath = filepath.Join(chartpath, p)
|
||||
}
|
||||
|
||||
if _, err = os.Stat(depPath); os.IsNotExist(err) {
|
||||
return "", fmt.Errorf("directory %s not found", depPath)
|
||||
} else if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return depPath, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,12 +81,12 @@ func TestResolve(t *testing.T) {
|
|||
name: "repo from valid local path",
|
||||
req: &chartutil.Requirements{
|
||||
Dependencies: []*chartutil.Dependency{
|
||||
{Name: "signtest", Repository: "file://../../cmd/helm/testdata/testcharts/signtest", Version: "0.1.0"},
|
||||
{Name: "signtest", Repository: "file://../../../../cmd/helm/testdata/testcharts/signtest", Version: "0.1.0"},
|
||||
},
|
||||
},
|
||||
expect: &chartutil.RequirementsLock{
|
||||
Dependencies: []*chartutil.Dependency{
|
||||
{Name: "signtest", Repository: "file://../../cmd/helm/testdata/testcharts/signtest", Version: "0.1.0"},
|
||||
{Name: "signtest", Repository: "file://../../../../cmd/helm/testdata/testcharts/signtest", Version: "0.1.0"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue