Unverified Commit 04665a54 authored by Matthew Fisher's avatar Matthew Fisher Committed by GitHub

Merge pull request #3196 from adshmh/add-app-version-option-to-helm-package

add --app-version flag to 'helm package'
parents b7c2a95f 9e869700
......@@ -56,6 +56,7 @@ type packageCmd struct {
key string
keyring string
version string
appVersion string
destination string
dependencyUpdate bool
......@@ -99,6 +100,7 @@ func newPackageCmd(out io.Writer) *cobra.Command {
f.StringVar(&pkg.key, "key", "", "name of the key to use when signing. Used if --sign is true")
f.StringVar(&pkg.keyring, "keyring", defaultKeyring(), "location of a public keyring")
f.StringVar(&pkg.version, "version", "", "set the version on the chart to this semver version")
f.StringVar(&pkg.appVersion, "app-version", "", "set the appVersion on the chart to this version")
f.StringVarP(&pkg.destination, "destination", "d", ".", "location to write the chart.")
f.BoolVarP(&pkg.dependencyUpdate, "dependency-update", "u", false, `update dependencies from "requirements.yaml" to dir "charts/" before packaging`)
......@@ -139,6 +141,11 @@ func (p *packageCmd) run() error {
debug("Setting version to %s", p.version)
}
if p.appVersion != "" {
ch.Metadata.AppVersion = p.appVersion
debug("Setting appVersion to %s", p.appVersion)
}
if filepath.Base(path) != ch.Metadata.Name {
return fmt.Errorf("directory name (%s) and Chart.yaml name (%s) must match", filepath.Base(path), ch.Metadata.Name)
}
......
......@@ -25,6 +25,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/helm/helmpath"
"k8s.io/helm/pkg/proto/hapi/chart"
)
......@@ -200,6 +201,38 @@ func TestPackage(t *testing.T) {
}
}
func TestSetAppVersion(t *testing.T) {
var ch *chart.Chart
expectedAppVersion := "app-version-foo"
tmp, _ := ioutil.TempDir("", "helm-package-app-version-")
defer os.RemoveAll(tmp)
c := newPackageCmd(&bytes.Buffer{})
flags := map[string]string{
"destination": tmp,
"app-version": expectedAppVersion,
}
setFlags(c, flags)
err := c.RunE(c, []string{"testdata/testcharts/alpine"})
if err != nil {
t.Errorf("unexpected error %q", err)
}
chartPath := filepath.Join(tmp, "alpine-0.1.0.tgz")
if fi, err := os.Stat(chartPath); err != nil {
t.Errorf("expected file %q, got err %q", chartPath, err)
} else if fi.Size() == 0 {
t.Errorf("file %q has zero bytes.", chartPath)
}
ch, err = chartutil.Load(chartPath)
if err != nil {
t.Errorf("unexpected error loading packaged chart: %v", err)
}
if ch.Metadata.AppVersion != expectedAppVersion {
t.Errorf("expected app-version %q, found %q", expectedAppVersion, ch.Metadata.AppVersion)
}
}
func setFlags(cmd *cobra.Command, flags map[string]string) {
dest := cmd.Flags()
for f, v := range flags {
......
......@@ -23,6 +23,7 @@ helm package [flags] [CHART_PATH] [...]
### Options
```
--app-version string set the appVersion on the chart to this version
-u, --dependency-update update dependencies from "requirements.yaml" to dir "charts/" before packaging
-d, --destination string location to write the chart. (default ".")
--key string name of the key to use when signing. Used if --sign is true
......@@ -46,4 +47,4 @@ helm package [flags] [CHART_PATH] [...]
### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 7-Nov-2017
###### Auto generated by spf13/cobra on 24-Nov-2017
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment