From 18f900e443ec1f2a0fac068e8a732ff9dccb1897 Mon Sep 17 00:00:00 2001 From: Sushil Kumar Date: Mon, 22 May 2017 15:28:58 -0700 Subject: [PATCH 1/2] Errors out if install/upgrade fails to load-requirements Fixes https://github.com/kubernetes/helm/issues/2480 --- cmd/helm/install.go | 2 ++ cmd/helm/upgrade.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index b9eb3b28a..c51786f90 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -232,6 +232,8 @@ func (i *installCmd) run() error { if err := checkDependencies(chartRequested, req, i.out); err != nil { return prettyError(err) } + } else if err != chartutil.ErrRequirementsNotFound { + return fmt.Errorf("cannot load requirements: %v", err) } res, err := i.client.InstallReleaseFromChart( diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index c27581c57..3aeb0eace 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -185,7 +185,11 @@ func (u *upgradeCmd) run() error { if err := checkDependencies(ch, req, u.out); err != nil { return err } + } else if err != chartutil.ErrRequirementsNotFound { + return fmt.Errorf("cannot load requirements: %v", err) } + } else { + return prettyError(err) } resp, err := u.client.UpdateRelease( From f80a7aa384a7ebf2e2c00824cb39b02ea24956d2 Mon Sep 17 00:00:00 2001 From: Sushil Kumar Date: Thu, 25 May 2017 11:24:03 -0700 Subject: [PATCH 2/2] Added tests for install/upgrade to test bad requirements.yaml --- cmd/helm/install_test.go | 6 ++++++ .../chart-bad-requirements/.helmignore | 21 +++++++++++++++++++ .../chart-bad-requirements/Chart.yaml | 3 +++ .../charts/reqsubchart/.helmignore | 21 +++++++++++++++++++ .../charts/reqsubchart/Chart.yaml | 3 +++ .../charts/reqsubchart/values.yaml | 4 ++++ .../chart-bad-requirements/requirements.yaml | 4 ++++ .../chart-bad-requirements/values.yaml | 4 ++++ cmd/helm/upgrade_test.go | 7 +++++++ 9 files changed, 73 insertions(+) create mode 100644 cmd/helm/testdata/testcharts/chart-bad-requirements/.helmignore create mode 100644 cmd/helm/testdata/testcharts/chart-bad-requirements/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/.helmignore create mode 100644 cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/values.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-bad-requirements/requirements.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-bad-requirements/values.yaml diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 7e749afc7..b2e47a1dd 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -138,6 +138,12 @@ func TestInstall(t *testing.T) { args: []string{"testdata/testcharts/chart-missing-deps"}, err: true, }, + // Install, chart with bad requirements.yaml in /charts + { + name: "install chart with bad requirements.yaml", + args: []string{"testdata/testcharts/chart-bad-requirements"}, + err: true, + }, } runReleaseCases(t, tests, func(c *fakeReleaseClient, out io.Writer) *cobra.Command { diff --git a/cmd/helm/testdata/testcharts/chart-bad-requirements/.helmignore b/cmd/helm/testdata/testcharts/chart-bad-requirements/.helmignore new file mode 100644 index 000000000..f0c131944 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-bad-requirements/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/cmd/helm/testdata/testcharts/chart-bad-requirements/Chart.yaml b/cmd/helm/testdata/testcharts/chart-bad-requirements/Chart.yaml new file mode 100644 index 000000000..02be4c013 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-bad-requirements/Chart.yaml @@ -0,0 +1,3 @@ +description: A Helm chart for Kubernetes +name: chart-missing-deps +version: 0.1.0 diff --git a/cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/.helmignore b/cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/.helmignore new file mode 100644 index 000000000..f0c131944 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/Chart.yaml b/cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/Chart.yaml new file mode 100644 index 000000000..c3813bc8c --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/Chart.yaml @@ -0,0 +1,3 @@ +description: A Helm chart for Kubernetes +name: reqsubchart +version: 0.1.0 diff --git a/cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/values.yaml b/cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/values.yaml new file mode 100644 index 000000000..0f0b63f2a --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-bad-requirements/charts/reqsubchart/values.yaml @@ -0,0 +1,4 @@ +# Default values for reqsubchart. +# This is a YAML-formatted file. +# Declare name/value pairs to be passed into your templates. +# name: value diff --git a/cmd/helm/testdata/testcharts/chart-bad-requirements/requirements.yaml b/cmd/helm/testdata/testcharts/chart-bad-requirements/requirements.yaml new file mode 100644 index 000000000..10c4d6dcb --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-bad-requirements/requirements.yaml @@ -0,0 +1,4 @@ +dependencies: + - name: reqsubchart + version: 0.1.0 + repository: "https://example.com/charts" diff --git a/cmd/helm/testdata/testcharts/chart-bad-requirements/values.yaml b/cmd/helm/testdata/testcharts/chart-bad-requirements/values.yaml new file mode 100644 index 000000000..d57f76b07 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-bad-requirements/values.yaml @@ -0,0 +1,4 @@ +# Default values for reqtest. +# This is a YAML-formatted file. +# Declare name/value pairs to be passed into your templates. +# name: value diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index 9ee1ae585..d9bff45bb 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -82,6 +82,7 @@ func TestUpgradeCmd(t *testing.T) { originalDepsPath := filepath.Join("testdata/testcharts/reqtest") missingDepsPath := filepath.Join("testdata/testcharts/chart-missing-deps") + badDepsPath := filepath.Join("testdata/testcharts/chart-bad-requirements") var ch3 *chart.Chart ch3, err = chartutil.Load(originalDepsPath) if err != nil { @@ -143,6 +144,12 @@ func TestUpgradeCmd(t *testing.T) { resp: releaseMock(&releaseOptions{name: "bonkers-bunny", version: 1, chart: ch3}), err: true, }, + { + name: "upgrade a release with bad dependencies", + args: []string{"bonkers-bunny", badDepsPath}, + resp: releaseMock(&releaseOptions{name: "bonkers-bunny", version: 1, chart: ch3}), + err: true, + }, } cmd := func(c *fakeReleaseClient, out io.Writer) *cobra.Command {