Commit e53f8333 authored by Adam Reese's avatar Adam Reese Committed by GitHub

Merge pull request #1738 from adamreese/feat/1537-upgrade-debug

feat(helm): add release debugging for upgrade
parents 5aa40517 1c3bada6
......@@ -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 {
......
......@@ -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,9 @@ 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)
printRelease(i.out, rel)
}
}
......
/*
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)
}
......@@ -42,7 +42,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 +146,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 +157,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 {
printRelease(u.out, 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)
......
......@@ -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",
},
}
......
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