|
|
@ -23,12 +23,24 @@ import (
|
|
|
|
"github.com/gosuri/uitable"
|
|
|
|
"github.com/gosuri/uitable"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/ghodss/yaml"
|
|
|
|
"k8s.io/helm/pkg/helm"
|
|
|
|
"k8s.io/helm/pkg/helm"
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/chart"
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/chart"
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/release"
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/release"
|
|
|
|
"k8s.io/helm/pkg/timeconv"
|
|
|
|
"k8s.io/helm/pkg/timeconv"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type releaseInfo struct {
|
|
|
|
|
|
|
|
Revision int32 `json:"revision" yaml:"revision"`
|
|
|
|
|
|
|
|
Updated string `json:"updated" yaml:"updated"`
|
|
|
|
|
|
|
|
Status string `json:"status" yaml:"status"`
|
|
|
|
|
|
|
|
Chart string `json:"chart" yaml:"chart"`
|
|
|
|
|
|
|
|
Description string `json:"description" yaml:"description"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type releaseHistory []releaseInfo
|
|
|
|
|
|
|
|
|
|
|
|
var historyHelp = `
|
|
|
|
var historyHelp = `
|
|
|
|
History prints historical revisions for a given release.
|
|
|
|
History prints historical revisions for a given release.
|
|
|
|
|
|
|
|
|
|
|
@ -51,6 +63,7 @@ type historyCmd struct {
|
|
|
|
out io.Writer
|
|
|
|
out io.Writer
|
|
|
|
helmc helm.Interface
|
|
|
|
helmc helm.Interface
|
|
|
|
colWidth uint
|
|
|
|
colWidth uint
|
|
|
|
|
|
|
|
outputFormat string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command {
|
|
|
|
func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command {
|
|
|
@ -77,6 +90,7 @@ func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command {
|
|
|
|
f := cmd.Flags()
|
|
|
|
f := cmd.Flags()
|
|
|
|
f.Int32Var(&his.max, "max", 256, "maximum number of revision to include in history")
|
|
|
|
f.Int32Var(&his.max, "max", 256, "maximum number of revision to include in history")
|
|
|
|
f.UintVar(&his.colWidth, "col-width", 60, "specifies the max column width of output")
|
|
|
|
f.UintVar(&his.colWidth, "col-width", 60, "specifies the max column width of output")
|
|
|
|
|
|
|
|
f.StringVarP(&his.outputFormat, "output", "o", "table", "prints the output in the specified format (json|table|yaml)")
|
|
|
|
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -90,15 +104,31 @@ func (cmd *historyCmd) run() error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Fprintln(cmd.out, formatHistory(r.Releases, cmd.colWidth))
|
|
|
|
releaseHistory := getReleaseHistory(r.Releases)
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
|
|
var history []byte
|
|
|
|
|
|
|
|
var formattingError error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch cmd.outputFormat {
|
|
|
|
|
|
|
|
case "yaml":
|
|
|
|
|
|
|
|
history, formattingError = yaml.Marshal(releaseHistory)
|
|
|
|
|
|
|
|
case "json":
|
|
|
|
|
|
|
|
history, formattingError = json.Marshal(releaseHistory)
|
|
|
|
|
|
|
|
case "table":
|
|
|
|
|
|
|
|
history = formatAsTable(releaseHistory, cmd.colWidth)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return fmt.Errorf("unknown output format %q", cmd.outputFormat)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func formatHistory(rls []*release.Release, colWidth uint) string {
|
|
|
|
if formattingError != nil {
|
|
|
|
tbl := uitable.New()
|
|
|
|
return prettyError(formattingError)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tbl.MaxColWidth = colWidth
|
|
|
|
fmt.Fprintln(cmd.out, string(history))
|
|
|
|
tbl.AddRow("REVISION", "UPDATED", "STATUS", "CHART", "DESCRIPTION")
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getReleaseHistory(rls []*release.Release) (history releaseHistory) {
|
|
|
|
for i := len(rls) - 1; i >= 0; i-- {
|
|
|
|
for i := len(rls) - 1; i >= 0; i-- {
|
|
|
|
r := rls[i]
|
|
|
|
r := rls[i]
|
|
|
|
c := formatChartname(r.Chart)
|
|
|
|
c := formatChartname(r.Chart)
|
|
|
@ -106,9 +136,30 @@ func formatHistory(rls []*release.Release, colWidth uint) string {
|
|
|
|
s := r.Info.Status.Code.String()
|
|
|
|
s := r.Info.Status.Code.String()
|
|
|
|
v := r.Version
|
|
|
|
v := r.Version
|
|
|
|
d := r.Info.Description
|
|
|
|
d := r.Info.Description
|
|
|
|
tbl.AddRow(v, t, s, c, d)
|
|
|
|
|
|
|
|
|
|
|
|
rInfo := releaseInfo{
|
|
|
|
|
|
|
|
Revision: v,
|
|
|
|
|
|
|
|
Updated: t,
|
|
|
|
|
|
|
|
Status: s,
|
|
|
|
|
|
|
|
Chart: c,
|
|
|
|
|
|
|
|
Description: d,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
history = append(history, rInfo)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return history
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func formatAsTable(releases releaseHistory, colWidth uint) []byte {
|
|
|
|
|
|
|
|
tbl := uitable.New()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tbl.MaxColWidth = colWidth
|
|
|
|
|
|
|
|
tbl.AddRow("REVISION", "UPDATED", "STATUS", "CHART", "DESCRIPTION")
|
|
|
|
|
|
|
|
for i := 0; i <= len(releases)-1; i++ {
|
|
|
|
|
|
|
|
r := releases[i]
|
|
|
|
|
|
|
|
tbl.AddRow(r.Revision, r.Updated, r.Status, r.Chart, r.Description)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tbl.String()
|
|
|
|
return tbl.Bytes()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func formatChartname(c *chart.Chart) string {
|
|
|
|
func formatChartname(c *chart.Chart) string {
|
|
|
|