Commit 1c3bada6 authored by Adam Reese's avatar Adam Reese

feat(helm): standardize debug output for releases

parent 934249aa
...@@ -19,14 +19,10 @@ package main ...@@ -19,14 +19,10 @@ package main
import ( import (
"errors" "errors"
"io" "io"
"text/template"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/timeconv"
) )
var getHelp = ` var getHelp = `
...@@ -83,53 +79,13 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { ...@@ -83,53 +79,13 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
return cmd 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' // getCmd is the command that implements 'helm get'
func (g *getCmd) run() error { func (g *getCmd) run() error {
res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version))
if err != nil { if err != nil {
return prettyError(err) return prettyError(err)
} }
return printRelease(g.out, res.Release)
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)
} }
func ensureHelmClient(h helm.Interface) helm.Interface { func ensureHelmClient(h helm.Interface) helm.Interface {
......
...@@ -285,9 +285,7 @@ func (i *installCmd) printRelease(rel *release.Release) { ...@@ -285,9 +285,7 @@ func (i *installCmd) printRelease(rel *release.Release) {
// TODO: Switch to text/template like everything else. // TODO: Switch to text/template like everything else.
fmt.Fprintf(i.out, "NAME: %s\n", rel.Name) fmt.Fprintf(i.out, "NAME: %s\n", rel.Name)
if flagDebug { if flagDebug {
fmt.Fprintf(i.out, "TARGET NAMESPACE: %s\n", rel.Namespace) printRelease(i.out, rel)
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)
} }
} }
......
/*
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)
}
...@@ -21,17 +21,13 @@ import ( ...@@ -21,17 +21,13 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"strings" "strings"
"time"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/helm/cmd/helm/strvals" "k8s.io/helm/cmd/helm/strvals"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/proto/hapi/release"
"k8s.io/helm/pkg/storage/driver" "k8s.io/helm/pkg/storage/driver"
"k8s.io/helm/pkg/timeconv"
) )
const upgradeDesc = ` const upgradeDesc = `
...@@ -162,7 +158,7 @@ func (u *upgradeCmd) run() error { ...@@ -162,7 +158,7 @@ func (u *upgradeCmd) run() error {
} }
if flagDebug { 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) fmt.Fprintf(u.out, "Release %q has been upgraded. Happy Helming!\n", u.release)
...@@ -201,26 +197,3 @@ func (u *upgradeCmd) vals() ([]byte, error) { ...@@ -201,26 +197,3 @@ func (u *upgradeCmd) vals() ([]byte, error) {
return yaml.Marshal(base) 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)
}
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