From ee5dab9cb3eced74f5709cda6726794df4e152ae Mon Sep 17 00:00:00 2001 From: Qin Wang Date: Fri, 3 Mar 2017 22:09:54 -0800 Subject: [PATCH] Fix helm dep list reporting wrong status Version matching is used for checking status of subcharts. closes: #2056 --- cmd/helm/dependency.go | 60 ++++++++++++++---- cmd/helm/dependency_test.go | 9 ++- .../reqtest/charts/reqsubchart3-0.2.0.tgz | Bin 0 -> 593 bytes .../testcharts/reqtest/requirements.yaml | 3 + 4 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 cmd/helm/testdata/testcharts/reqtest/charts/reqsubchart3-0.2.0.tgz diff --git a/cmd/helm/dependency.go b/cmd/helm/dependency.go index fe1cde114..b5b22f6ce 100644 --- a/cmd/helm/dependency.go +++ b/cmd/helm/dependency.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" + "github.com/Masterminds/semver" "github.com/gosuri/uitable" "github.com/spf13/cobra" @@ -140,21 +141,41 @@ func (l *dependencyListCmd) run() error { } func (l *dependencyListCmd) dependencyStatus(dep *chartutil.Dependency) string { - filename := fmt.Sprintf("%s-%s.tgz", dep.Name, dep.Version) - archive := filepath.Join(l.chartpath, "charts", filename) - if _, err := os.Stat(archive); err == nil { - c, err := chartutil.Load(archive) - if err != nil { - return "corrupt" - } - if c.Metadata.Name != dep.Name { - return "misnamed" - } + filename := fmt.Sprintf("%s-%s.tgz", dep.Name, "*") + 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 { + c, err := chartutil.Load(archive) + if err != nil { + return "corrupt" + } + if c.Metadata.Name != dep.Name { + return "misnamed" + } - if c.Metadata.Version != dep.Version { - return "wrong 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 "ok" } - return "ok" } folder := filepath.Join(l.chartpath, "charts", dep.Name) @@ -174,6 +195,19 @@ func (l *dependencyListCmd) dependencyStatus(dep *chartutil.Dependency) string { } 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" } diff --git a/cmd/helm/dependency_test.go b/cmd/helm/dependency_test.go index 749d490cb..887764742 100644 --- a/cmd/helm/dependency_test.go +++ b/cmd/helm/dependency_test.go @@ -40,9 +40,12 @@ func TestDependencyListCmd(t *testing.T) { expect: "WARNING: no requirements at ", }, { - name: "Requirements in chart dir", - 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", + name: "Requirements in chart dir", + args: []string{"testdata/testcharts/reqtest"}, + 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", diff --git a/cmd/helm/testdata/testcharts/reqtest/charts/reqsubchart3-0.2.0.tgz b/cmd/helm/testdata/testcharts/reqtest/charts/reqsubchart3-0.2.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..84b0fb65e6b05967ef186f30248384033a7d0a5f GIT binary patch literal 593 zcmV-X0Ch>%v#7WE? zC$pWF@vy(0OR{yXP?-eX(8PUI*^YCzFFk*K*8IZsSza@3BX4#;_`d%tNnotgbgca_ zp6Y8Li2NjtVm}T-@Pjx?;u$3O^+fqzUV4)LGIe-59RwOlI$wuLG7u&KF% ztQWEns)CN?=d9w!b>{H776we;b*;A8!2Kejl5GYJvw4lyFFIsZDCf54vp7enP<^K1`_~`y8+5p!@E919de7pP^{r6u)AHHHP>bw=ewcnKgQip z?CF2aWRK_ku@8W|^dAQ4FZn8IB%Q%XT5P~2G ff*=TjAP9mW2!bF8f*=Tj_$z(_p3(*m04M+eV_7RC literal 0 HcmV?d00001 diff --git a/cmd/helm/testdata/testcharts/reqtest/requirements.yaml b/cmd/helm/testdata/testcharts/reqtest/requirements.yaml index 4b0b8c2db..1ddedc742 100644 --- a/cmd/helm/testdata/testcharts/reqtest/requirements.yaml +++ b/cmd/helm/testdata/testcharts/reqtest/requirements.yaml @@ -5,3 +5,6 @@ dependencies: - name: reqsubchart2 version: 0.2.0 repository: "https://example.com/charts" + - name: reqsubchart3 + version: ">=0.1.0" + repository: "https://example.com/charts"