helm: add --annotations option for install and upgrade commands

pull/2631/head
Igor Bazhitov 8 years ago
parent 18a2a907f6
commit 275353e7d3

@ -118,6 +118,7 @@ type installCmd struct {
wait bool
repoURL string
devel bool
annotations []string
certFile string
keyFile string
@ -193,6 +194,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
f.StringVar(&inst.keyFile, "key-file", "", "identify HTTPS client using this SSL key file")
f.StringVar(&inst.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
f.BoolVar(&inst.devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-a'. If --version is set, this is ignored.")
f.StringArrayVar(&inst.annotations, "annotations", []string{}, "set release annotations (can specify multiple or separate values with commas: key1=val1,key2=val2)")
return cmd
}
@ -209,6 +211,11 @@ func (i *installCmd) run() error {
return err
}
annotations, err := parseAnnotations(i.annotations)
if err != nil {
return err
}
// If template is specified, try to run the template.
if i.nameTemplate != "" {
i.name, err = generateName(i.nameTemplate)
@ -245,7 +252,8 @@ func (i *installCmd) run() error {
helm.InstallReuseName(i.replace),
helm.InstallDisableHooks(i.disableHooks),
helm.InstallTimeout(i.timeout),
helm.InstallWait(i.wait))
helm.InstallWait(i.wait),
helm.InstallAnnotations(annotations))
if err != nil {
return prettyError(err)
}
@ -462,3 +470,17 @@ func checkDependencies(ch *chart.Chart, reqs *chartutil.Requirements) error {
}
return nil
}
func parseAnnotations(input []string) (map[string]string, error) {
annotations := map[string]string{}
for _, a := range input {
for _, s := range strings.Split(a, ",") {
v := strings.Split(s, "=")
if len(v) < 2 || len(v[0]) == 0 {
return nil, fmt.Errorf("invalid annotations format: '%s', should be <key>=[value]", s)
}
annotations[v[0]] = v[1]
}
}
return annotations, nil
}

@ -42,6 +42,10 @@ HOOKS:
{{- end }}
MANIFEST:
{{.Release.Manifest}}
ANNOTATIONS:
{{- range $k, $v := .Release.Annotations }}
{{$k}}={{$v}}
{{- end }}
`
func printRelease(out io.Writer, rel *release.Release) error {

@ -74,6 +74,7 @@ type upgradeCmd struct {
wait bool
repoURL string
devel bool
annotations []string
certFile string
keyFile string
@ -132,6 +133,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
f.StringVar(&upgrade.keyFile, "key-file", "", "identify HTTPS client using this SSL key file")
f.StringVar(&upgrade.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
f.BoolVar(&upgrade.devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-a'. If --version is set, this is ignored.")
f.StringArrayVar(&upgrade.annotations, "annotations", []string{}, "set release annotations (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.MarkDeprecated("disable-hooks", "use --no-hooks instead")
@ -168,6 +170,7 @@ func (u *upgradeCmd) run() error {
namespace: u.namespace,
timeout: u.timeout,
wait: u.wait,
annotations: u.annotations,
}
return ic.run()
}
@ -178,6 +181,11 @@ func (u *upgradeCmd) run() error {
return err
}
annotations, err := parseAnnotations(u.annotations)
if err != nil {
return err
}
// 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 {
@ -202,7 +210,8 @@ func (u *upgradeCmd) run() error {
helm.UpgradeTimeout(u.timeout),
helm.ResetValues(u.resetValues),
helm.ReuseValues(u.reuseValues),
helm.UpgradeWait(u.wait))
helm.UpgradeWait(u.wait),
helm.UpgradeAnnotations(annotations))
if err != nil {
return fmt.Errorf("UPGRADE FAILED: %v", prettyError(err))
}

Loading…
Cancel
Save