mirror of
https://github.com/helm/helm.git
synced 2026-08-12 22:16:30 +00:00
Update after review
Review comment: - https://github.com/helm/helm/pull/5295#pullrequestreview-203519813 Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
This commit is contained in:
@@ -35,6 +35,7 @@ import (
|
||||
"k8s.io/helm/pkg/action"
|
||||
"k8s.io/helm/pkg/chart"
|
||||
"k8s.io/helm/pkg/chart/loader"
|
||||
"k8s.io/helm/pkg/chartutil"
|
||||
"k8s.io/helm/pkg/downloader"
|
||||
"k8s.io/helm/pkg/getter"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
@@ -231,12 +232,9 @@ func (o *installOptions) run(out io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
chartType := chartRequested.Metadata.Type
|
||||
if strings.EqualFold(chartType, "library") {
|
||||
return errors.New("Library charts are not installable")
|
||||
}
|
||||
if chartType != "" && !strings.EqualFold(chartType, "application") {
|
||||
return errors.New("Invalid chart type. Valid types are: application or library")
|
||||
validInstallableChart, err := chartutil.IsChartInstallable(chartRequested)
|
||||
if !validInstallableChart {
|
||||
return err
|
||||
}
|
||||
|
||||
if req := chartRequested.Metadata.Dependencies; req != nil {
|
||||
|
||||
@@ -136,7 +136,7 @@ func TestInstall(t *testing.T) {
|
||||
name: "install chart with bad type",
|
||||
cmd: "install badtype testdata/testcharts/chart-bad-type",
|
||||
wantError: true,
|
||||
golden: "output/template-chart-bad-type.txt",
|
||||
golden: "output/install-chart-bad-type.txt",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/Masterminds/semver"
|
||||
@@ -135,10 +134,9 @@ func (o *packageOptions) run(out io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
chartType := ch.Metadata.Type
|
||||
if chartType != "" && !strings.EqualFold(chartType, "library") &&
|
||||
!strings.EqualFold(chartType, "application") {
|
||||
return errors.New("Invalid chart type. Valid types are: application or library")
|
||||
validChartType, err := chartutil.IsValidChartType(ch)
|
||||
if !validChartType {
|
||||
return err
|
||||
}
|
||||
|
||||
overrideVals, err := o.mergedValues()
|
||||
|
||||
@@ -157,12 +157,9 @@ func (o *templateOptions) run(out io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
chartType := c.Metadata.Type
|
||||
if strings.EqualFold(chartType, "library") {
|
||||
return errors.New("Library charts are not installable")
|
||||
}
|
||||
if chartType != "" && !strings.EqualFold(chartType, "application") {
|
||||
return errors.New("Invalid chart type. Valid types are: application or library")
|
||||
validInstallableChart, err := chartutil.IsChartInstallable(c)
|
||||
if !validInstallableChart {
|
||||
return err
|
||||
}
|
||||
|
||||
if req := c.Metadata.Dependencies; req != nil {
|
||||
|
||||
@@ -86,7 +86,7 @@ func TestTemplateCmd(t *testing.T) {
|
||||
name: "check chart bad type",
|
||||
cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/chart-bad-type"),
|
||||
wantError: true,
|
||||
golden: "output/template-chart-bad-type.txt",
|
||||
golden: "output/install-chart-bad-type.txt",
|
||||
},
|
||||
}
|
||||
runTestCmd(t, tests)
|
||||
|
||||
1
cmd/helm/testdata/output/install-chart-bad-type.txt
vendored
Normal file
1
cmd/helm/testdata/output/install-chart-bad-type.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Error: Invalid chart types are not installable
|
||||
@@ -1 +0,0 @@
|
||||
Error: Invalid chart type. Valid types are: application or library
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/pkg/errors"
|
||||
@@ -82,3 +83,30 @@ func IsChartDir(dirName string) (bool, error) {
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// IsChartInstallable validates if a chart can be installed
|
||||
//
|
||||
// Application chart type is only installable
|
||||
func IsChartInstallable(chart *chart.Chart) (bool, error) {
|
||||
chartType := chart.Metadata.Type
|
||||
if strings.EqualFold(chartType, "library") {
|
||||
return false, errors.New("Library charts are not installable")
|
||||
}
|
||||
validChartType, _ := IsValidChartType(chart)
|
||||
if !validChartType {
|
||||
return false, errors.New("Invalid chart types are not installable")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// IsValidChartType validates the chart type
|
||||
//
|
||||
// Valid types are: application or library
|
||||
func IsValidChartType(chart *chart.Chart) (bool, error) {
|
||||
chartType := chart.Metadata.Type
|
||||
if chartType != "" && !strings.EqualFold(chartType, "library") &&
|
||||
!strings.EqualFold(chartType, "application") {
|
||||
return false, errors.New("Invalid chart type. Valid types are: application or library")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user