Merge pull request #2338 from technosophos/fix/2209-warning-to-error

fix(helm): return error when dependencies are missing
pull/2358/head
Matt Butcher 8 years ago committed by GitHub
commit 9a33628e4e

@ -206,7 +206,12 @@ func (i *installCmd) run() error {
}
if req, err := chartutil.LoadRequirements(chartRequested); err == nil {
checkDependencies(chartRequested, req, i.out)
// If checkDependencies returns an error, we have unfullfilled dependencies.
// As of Helm 2.4.0, this is treated as a stopping condition:
// https://github.com/kubernetes/helm/issues/2209
if err := checkDependencies(chartRequested, req, i.out); err != nil {
return prettyError(err)
}
}
res, err := i.client.InstallReleaseFromChart(
@ -398,7 +403,9 @@ func defaultNamespace() string {
return "default"
}
func checkDependencies(ch *chart.Chart, reqs *chartutil.Requirements, out io.Writer) {
func checkDependencies(ch *chart.Chart, reqs *chartutil.Requirements, out io.Writer) error {
missing := []string{}
deps := ch.GetDependencies()
for _, r := range reqs.Dependencies {
found := false
@ -409,7 +416,12 @@ func checkDependencies(ch *chart.Chart, reqs *chartutil.Requirements, out io.Wri
}
}
if !found {
fmt.Fprintf(out, "Warning: %s is in requirements.yaml but not in the charts/ directory!\n", r.Name)
missing = append(missing, r.Name)
}
}
if len(missing) > 0 {
return fmt.Errorf("found in requirements.yaml, but missing in charts/ directory: %s", strings.Join(missing, ", "))
}
return nil
}

@ -134,9 +134,9 @@ func TestInstall(t *testing.T) {
},
// Install, chart with missing dependencies in /charts
{
name: "install chart with missing dependencies",
args: []string{"testdata/testcharts/chart-missing-deps"},
expected: "Warning: reqsubchart2 is in requirements.yaml but not in the charts/ directory!",
name: "install chart with missing dependencies",
args: []string{"testdata/testcharts/chart-missing-deps"},
err: true,
},
}

@ -127,7 +127,9 @@ func (p *packageCmd) run(cmd *cobra.Command, args []string) error {
}
if reqs, err := chartutil.LoadRequirements(ch); err == nil {
checkDependencies(ch, reqs, p.out)
if err := checkDependencies(ch, reqs, p.out); err != nil {
return err
}
}
var dest string

@ -118,8 +118,8 @@ func TestPackage(t *testing.T) {
{
name: "package testdata/testcharts/chart-missing-deps",
args: []string{"testdata/testcharts/chart-missing-deps"},
expect: "Warning: reqsubchart2 is in requirements.yaml but not in the charts/ directory!\n",
hasfile: "chart-missing-deps-0.1.0.tgz",
err: true,
},
}

@ -166,7 +166,9 @@ func (u *upgradeCmd) run() error {
// Check chart requirements to make sure all dependencies are present in /charts
if ch, err := chartutil.Load(chartPath); err == nil {
if req, err := chartutil.LoadRequirements(ch); err == nil {
checkDependencies(ch, req, u.out)
if err := checkDependencies(ch, req, u.out); err != nil {
return err
}
}
}

@ -138,10 +138,10 @@ func TestUpgradeCmd(t *testing.T) {
expected: "Release \"crazy-bunny\" has been upgraded. Happy Helming!\n",
},
{
name: "upgrade a release with missing dependencies",
args: []string{"bonkers-bunny", missingDepsPath},
resp: releaseMock(&releaseOptions{name: "bonkers-bunny", version: 1, chart: ch3}),
expected: "Warning: reqsubchart2 is in requirements.yaml but not in the charts/ directory!",
name: "upgrade a release with missing dependencies",
args: []string{"bonkers-bunny", missingDepsPath},
resp: releaseMock(&releaseOptions{name: "bonkers-bunny", version: 1, chart: ch3}),
err: true,
},
}

Loading…
Cancel
Save