From 934249aadf69d9b43d1613627b83b323f2ec91b8 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Mon, 19 Dec 2016 22:07:09 -0800 Subject: [PATCH 1/2] feat(helm): add release debugging for upgrade --- cmd/helm/install.go | 6 ++---- cmd/helm/upgrade.go | 38 ++++++++++++++++++++++++++++++++++---- cmd/helm/upgrade_test.go | 4 ++-- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 17043bee5..00313f6b6 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -56,7 +56,7 @@ or $ helm install --set name=prod ./redis You can specify the '--values'/'-f' flag multiple times. The priority will be given to the -last (right-most) file specified. For example, if both myvalues.yaml and override.yaml +last (right-most) file specified. For example, if both myvalues.yaml and override.yaml contained a key called 'Test', the value set in override.yaml would take precedence: $ helm install -f myvalues.yaml -f override.yaml ./redis @@ -283,13 +283,11 @@ func (i *installCmd) printRelease(rel *release.Release) { return } // TODO: Switch to text/template like everything else. + fmt.Fprintf(i.out, "NAME: %s\n", rel.Name) if flagDebug { - fmt.Fprintf(i.out, "NAME: %s\n", rel.Name) fmt.Fprintf(i.out, "TARGET NAMESPACE: %s\n", rel.Namespace) fmt.Fprintf(i.out, "CHART: %s %s\n", rel.Chart.Metadata.Name, rel.Chart.Metadata.Version) fmt.Fprintf(i.out, "MANIFEST: %s\n", rel.Manifest) - } else { - fmt.Fprintf(i.out, "NAME: %s\n", rel.Name) } } diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 70ce9ea22..58b746490 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -21,13 +21,17 @@ import ( "io" "io/ioutil" "strings" + "time" "github.com/ghodss/yaml" "github.com/spf13/cobra" "k8s.io/helm/cmd/helm/strvals" + "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/helm" + "k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/storage/driver" + "k8s.io/helm/pkg/timeconv" ) const upgradeDesc = ` @@ -42,7 +46,7 @@ To override values in a chart, use either the '--values' flag and pass in a file or use the '--set' flag and pass configuration from the command line. You can specify the '--values'/'-f' flag multiple times. The priority will be given to the -last (right-most) file specified. For example, if both myvalues.yaml and override.yaml +last (right-most) file specified. For example, if both myvalues.yaml and override.yaml contained a key called 'Test', the value set in override.yaml would take precedence: $ helm install -f myvalues.yaml -f override.yaml ./redis @@ -146,7 +150,7 @@ func (u *upgradeCmd) run() error { return err } - _, err = u.client.UpdateRelease( + resp, err := u.client.UpdateRelease( u.release, chartPath, helm.UpdateValueOverrides(rawVals), @@ -157,8 +161,11 @@ func (u *upgradeCmd) run() error { return fmt.Errorf("UPGRADE FAILED: %v", prettyError(err)) } - success := u.release + " has been upgraded. Happy Helming!\n" - fmt.Fprintf(u.out, success) + if flagDebug { + u.printRelease(resp.Release) + } + + fmt.Fprintf(u.out, "Release %q has been upgraded. Happy Helming!\n", u.release) // Print the status like status command does status, err := u.client.ReleaseStatus(u.release) @@ -194,3 +201,26 @@ func (u *upgradeCmd) vals() ([]byte, error) { return yaml.Marshal(base) } + +// printRelease prints info about a release. +func (u *upgradeCmd) printRelease(rel *release.Release) error { + if rel == nil { + return nil + } + + cfg, err := chartutil.CoalesceValues(rel.Chart, rel.Config) + if err != nil { + return err + } + cfgStr, err := cfg.YAML() + if err != nil { + return err + } + + data := map[string]interface{}{ + "Release": rel, + "ComputedValues": cfgStr, + "ReleaseDate": timeconv.Format(rel.Info.LastDeployed, time.ANSIC), + } + return tpl(getTemplate, data, u.out) +} diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index 7eab8acde..bd6f324cc 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -67,14 +67,14 @@ func TestUpgradeCmd(t *testing.T) { name: "upgrade a release", args: []string{"funny-bunny", chartPath}, resp: releaseMock(&releaseOptions{name: "funny-bunny", version: 2, chart: ch}), - expected: "funny-bunny has been upgraded. Happy Helming!\n", + expected: "Release \"funny-bunny\" has been upgraded. Happy Helming!\n", }, { name: "install a release with 'upgrade --install'", args: []string{"zany-bunny", chartPath}, flags: []string{"-i"}, resp: releaseMock(&releaseOptions{name: "zany-bunny", version: 1, chart: ch}), - expected: "zany-bunny has been upgraded. Happy Helming!\n", + expected: "Release \"zany-bunny\" has been upgraded. Happy Helming!\n", }, } From 1c3bada618042e00e5e1880be34b36faf05f201b Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 20 Dec 2016 10:20:40 -0800 Subject: [PATCH 2/2] feat(helm): standardize debug output for releases --- cmd/helm/get.go | 46 +--------------------------- cmd/helm/install.go | 4 +-- cmd/helm/printer.go | 74 +++++++++++++++++++++++++++++++++++++++++++++ cmd/helm/upgrade.go | 29 +----------------- 4 files changed, 77 insertions(+), 76 deletions(-) create mode 100644 cmd/helm/printer.go diff --git a/cmd/helm/get.go b/cmd/helm/get.go index 5eeb095a5..97d00ace1 100644 --- a/cmd/helm/get.go +++ b/cmd/helm/get.go @@ -19,14 +19,10 @@ package main import ( "errors" "io" - "text/template" - "time" "github.com/spf13/cobra" - "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/helm" - "k8s.io/helm/pkg/timeconv" ) var getHelp = ` @@ -83,53 +79,13 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { return cmd } -var getTemplate = `REVISION: {{.Release.Version}} -RELEASED: {{.ReleaseDate}} -CHART: {{.Release.Chart.Metadata.Name}}-{{.Release.Chart.Metadata.Version}} -USER-SUPPLIED VALUES: -{{.Release.Config.Raw}} -COMPUTED VALUES: -{{.ComputedValues}} -HOOKS: -{{- range .Release.Hooks }} ---- -# {{.Name}} -{{.Manifest}} -{{- end }} -MANIFEST: -{{.Release.Manifest}} -` - // getCmd is the command that implements 'helm get' func (g *getCmd) run() error { res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) if err != nil { return prettyError(err) } - - cfg, err := chartutil.CoalesceValues(res.Release.Chart, res.Release.Config) - if err != nil { - return err - } - cfgStr, err := cfg.YAML() - if err != nil { - return err - } - - data := map[string]interface{}{ - "Release": res.Release, - "ComputedValues": cfgStr, - "ReleaseDate": timeconv.Format(res.Release.Info.LastDeployed, time.ANSIC), - } - return tpl(getTemplate, data, g.out) -} - -func tpl(t string, vals map[string]interface{}, out io.Writer) error { - tt, err := template.New("_").Parse(t) - if err != nil { - return err - } - return tt.Execute(out, vals) + return printRelease(g.out, res.Release) } func ensureHelmClient(h helm.Interface) helm.Interface { diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 00313f6b6..dd5757c65 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -285,9 +285,7 @@ func (i *installCmd) printRelease(rel *release.Release) { // TODO: Switch to text/template like everything else. fmt.Fprintf(i.out, "NAME: %s\n", rel.Name) if flagDebug { - fmt.Fprintf(i.out, "TARGET NAMESPACE: %s\n", rel.Namespace) - fmt.Fprintf(i.out, "CHART: %s %s\n", rel.Chart.Metadata.Name, rel.Chart.Metadata.Version) - fmt.Fprintf(i.out, "MANIFEST: %s\n", rel.Manifest) + printRelease(i.out, rel) } } diff --git a/cmd/helm/printer.go b/cmd/helm/printer.go new file mode 100644 index 000000000..34b1122be --- /dev/null +++ b/cmd/helm/printer.go @@ -0,0 +1,74 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "io" + "text/template" + "time" + + "k8s.io/helm/pkg/chartutil" + "k8s.io/helm/pkg/proto/hapi/release" + "k8s.io/helm/pkg/timeconv" +) + +var printReleaseTemplate = `REVISION: {{.Release.Version}} +RELEASED: {{.ReleaseDate}} +CHART: {{.Release.Chart.Metadata.Name}}-{{.Release.Chart.Metadata.Version}} +USER-SUPPLIED VALUES: +{{.Release.Config.Raw}} +COMPUTED VALUES: +{{.ComputedValues}} +HOOKS: +{{- range .Release.Hooks }} +--- +# {{.Name}} +{{.Manifest}} +{{- end }} +MANIFEST: +{{.Release.Manifest}} +` + +func printRelease(out io.Writer, rel *release.Release) error { + if rel == nil { + return nil + } + + cfg, err := chartutil.CoalesceValues(rel.Chart, rel.Config) + if err != nil { + return err + } + cfgStr, err := cfg.YAML() + if err != nil { + return err + } + + data := map[string]interface{}{ + "Release": rel, + "ComputedValues": cfgStr, + "ReleaseDate": timeconv.Format(rel.Info.LastDeployed, time.ANSIC), + } + return tpl(printReleaseTemplate, data, out) +} + +func tpl(t string, vals map[string]interface{}, out io.Writer) error { + tt, err := template.New("_").Parse(t) + if err != nil { + return err + } + return tt.Execute(out, vals) +} diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 58b746490..db55f3b38 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -21,17 +21,13 @@ import ( "io" "io/ioutil" "strings" - "time" "github.com/ghodss/yaml" "github.com/spf13/cobra" "k8s.io/helm/cmd/helm/strvals" - "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/helm" - "k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/storage/driver" - "k8s.io/helm/pkg/timeconv" ) const upgradeDesc = ` @@ -162,7 +158,7 @@ func (u *upgradeCmd) run() error { } if flagDebug { - u.printRelease(resp.Release) + printRelease(u.out, resp.Release) } fmt.Fprintf(u.out, "Release %q has been upgraded. Happy Helming!\n", u.release) @@ -201,26 +197,3 @@ func (u *upgradeCmd) vals() ([]byte, error) { return yaml.Marshal(base) } - -// printRelease prints info about a release. -func (u *upgradeCmd) printRelease(rel *release.Release) error { - if rel == nil { - return nil - } - - cfg, err := chartutil.CoalesceValues(rel.Chart, rel.Config) - if err != nil { - return err - } - cfgStr, err := cfg.YAML() - if err != nil { - return err - } - - data := map[string]interface{}{ - "Release": rel, - "ComputedValues": cfgStr, - "ReleaseDate": timeconv.Format(rel.Info.LastDeployed, time.ANSIC), - } - return tpl(getTemplate, data, u.out) -}