Merge pull request #2067 from qwangrepos/issue-2056

Fix helm dep list reporting wrong status
pull/2061/head
Matt Butcher 8 years ago committed by GitHub
commit 12e87b7e7d

@ -21,6 +21,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/Masterminds/semver"
"github.com/gosuri/uitable" "github.com/gosuri/uitable"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -140,8 +141,14 @@ func (l *dependencyListCmd) run() error {
} }
func (l *dependencyListCmd) dependencyStatus(dep *chartutil.Dependency) string { func (l *dependencyListCmd) dependencyStatus(dep *chartutil.Dependency) string {
filename := fmt.Sprintf("%s-%s.tgz", dep.Name, dep.Version) filename := fmt.Sprintf("%s-%s.tgz", dep.Name, "*")
archive := filepath.Join(l.chartpath, "charts", filename) archives, err := filepath.Glob(filepath.Join(l.chartpath, "charts", filename))
if err != nil {
return "bad pattern"
} else if len(archives) > 1 {
return "too many matches"
} else if len(archives) == 1 {
archive := archives[0]
if _, err := os.Stat(archive); err == nil { if _, err := os.Stat(archive); err == nil {
c, err := chartutil.Load(archive) c, err := chartutil.Load(archive)
if err != nil { if err != nil {
@ -152,10 +159,24 @@ func (l *dependencyListCmd) dependencyStatus(dep *chartutil.Dependency) string {
} }
if c.Metadata.Version != dep.Version { if c.Metadata.Version != dep.Version {
constraint, err := semver.NewConstraint(dep.Version)
if err != nil {
return "invalid version"
}
v, err := semver.NewVersion(c.Metadata.Version)
if err != nil {
return "invalid version"
}
if constraint.Check(v) {
return "ok"
}
return "wrong version" return "wrong version"
} }
return "ok" return "ok"
} }
}
folder := filepath.Join(l.chartpath, "charts", dep.Name) folder := filepath.Join(l.chartpath, "charts", dep.Name)
if fi, err := os.Stat(folder); err != nil { if fi, err := os.Stat(folder); err != nil {
@ -174,6 +195,19 @@ func (l *dependencyListCmd) dependencyStatus(dep *chartutil.Dependency) string {
} }
if c.Metadata.Version != dep.Version { if c.Metadata.Version != dep.Version {
constraint, err := semver.NewConstraint(dep.Version)
if err != nil {
return "invalid version"
}
v, err := semver.NewVersion(c.Metadata.Version)
if err != nil {
return "invalid version"
}
if constraint.Check(v) {
return "unpacked"
}
return "wrong version" return "wrong version"
} }

@ -42,7 +42,10 @@ func TestDependencyListCmd(t *testing.T) {
{ {
name: "Requirements in chart dir", name: "Requirements in chart dir",
args: []string{"testdata/testcharts/reqtest"}, args: []string{"testdata/testcharts/reqtest"},
expect: "NAME \tVERSION\tREPOSITORY \tSTATUS \nreqsubchart \t0.1.0 \thttps://example.com/charts\tunpacked\nreqsubchart2\t0.2.0 \thttps://example.com/charts\tunpacked\n", expect: "NAME \tVERSION\tREPOSITORY \tSTATUS \n" +
"reqsubchart \t0.1.0 \thttps://example.com/charts\tunpacked\n" +
"reqsubchart2\t0.2.0 \thttps://example.com/charts\tunpacked\n" +
"reqsubchart3\t>=0.1.0\thttps://example.com/charts\tok \n\n",
}, },
{ {
name: "Requirements in chart archive", name: "Requirements in chart archive",

@ -5,3 +5,6 @@ dependencies:
- name: reqsubchart2 - name: reqsubchart2
version: 0.2.0 version: 0.2.0
repository: "https://example.com/charts" repository: "https://example.com/charts"
- name: reqsubchart3
version: ">=0.1.0"
repository: "https://example.com/charts"

Loading…
Cancel
Save