Update after review

Review comment:
- https://github.com/helm/helm/pull/5295#pullrequestreview-203519813

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
pull/5295/head
Martin Hickey 6 years ago
parent b5f04eec04
commit ef4d2a6e65

@ -35,6 +35,7 @@ import (
"k8s.io/helm/pkg/action" "k8s.io/helm/pkg/action"
"k8s.io/helm/pkg/chart" "k8s.io/helm/pkg/chart"
"k8s.io/helm/pkg/chart/loader" "k8s.io/helm/pkg/chart/loader"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/downloader" "k8s.io/helm/pkg/downloader"
"k8s.io/helm/pkg/getter" "k8s.io/helm/pkg/getter"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
@ -231,12 +232,9 @@ func (o *installOptions) run(out io.Writer) error {
return err return err
} }
chartType := chartRequested.Metadata.Type validInstallableChart, err := chartutil.IsChartInstallable(chartRequested)
if strings.EqualFold(chartType, "library") { if !validInstallableChart {
return errors.New("Library charts are not installable") return err
}
if chartType != "" && !strings.EqualFold(chartType, "application") {
return errors.New("Invalid chart type. Valid types are: application or library")
} }
if req := chartRequested.Metadata.Dependencies; req != nil { if req := chartRequested.Metadata.Dependencies; req != nil {

@ -136,7 +136,7 @@ func TestInstall(t *testing.T) {
name: "install chart with bad type", name: "install chart with bad type",
cmd: "install badtype testdata/testcharts/chart-bad-type", cmd: "install badtype testdata/testcharts/chart-bad-type",
wantError: true, wantError: true,
golden: "output/template-chart-bad-type.txt", golden: "output/install-chart-bad-type.txt",
}, },
} }

@ -22,7 +22,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"syscall" "syscall"
"github.com/Masterminds/semver" "github.com/Masterminds/semver"
@ -135,10 +134,9 @@ func (o *packageOptions) run(out io.Writer) error {
return err return err
} }
chartType := ch.Metadata.Type validChartType, err := chartutil.IsValidChartType(ch)
if chartType != "" && !strings.EqualFold(chartType, "library") && if !validChartType {
!strings.EqualFold(chartType, "application") { return err
return errors.New("Invalid chart type. Valid types are: application or library")
} }
overrideVals, err := o.mergedValues() overrideVals, err := o.mergedValues()

@ -157,12 +157,9 @@ func (o *templateOptions) run(out io.Writer) error {
return err return err
} }
chartType := c.Metadata.Type validInstallableChart, err := chartutil.IsChartInstallable(c)
if strings.EqualFold(chartType, "library") { if !validInstallableChart {
return errors.New("Library charts are not installable") return err
}
if chartType != "" && !strings.EqualFold(chartType, "application") {
return errors.New("Invalid chart type. Valid types are: application or library")
} }
if req := c.Metadata.Dependencies; req != nil { if req := c.Metadata.Dependencies; req != nil {

@ -86,7 +86,7 @@ func TestTemplateCmd(t *testing.T) {
name: "check chart bad type", name: "check chart bad type",
cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/chart-bad-type"), cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/chart-bad-type"),
wantError: true, wantError: true,
golden: "output/template-chart-bad-type.txt", golden: "output/install-chart-bad-type.txt",
}, },
} }
runTestCmd(t, tests) runTestCmd(t, tests)

@ -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" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -82,3 +83,30 @@ func IsChartDir(dirName string) (bool, error) {
return true, nil 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
}

Loading…
Cancel
Save