feat(history): add --show-rollback flag for opt-in rollback column

Replace the always-visible ROLLBACK column with an opt-in --show-rollback
flag to avoid breaking the default table output (HIP-0004). JSON and YAML
formats continue to include rollback_revision when present via omitempty.

Signed-off-by: MrJack <36191829+biagiopietro@users.noreply.github.com>
pull/31859/head
MrJack 4 months ago
parent 9ea6b5ab99
commit e889cff089

@ -43,6 +43,15 @@ configures the maximum length of the revision list returned.
The historical release set is printed as a formatted table, e.g:
$ helm history angry-bird
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Mon Oct 3 10:15:13 2016 superseded alpine-0.1.0 1.0 Initial install
2 Mon Oct 3 10:15:13 2016 superseded alpine-0.1.0 1.0 Upgraded successfully
3 Mon Oct 3 10:15:13 2016 superseded alpine-0.1.0 1.0 Rolled back to 2
4 Mon Oct 3 10:15:13 2016 deployed alpine-0.1.0 1.0 Upgraded successfully
Use '--show-rollback' to include a column showing the revision that was rolled back to:
$ helm history angry-bird --show-rollback
REVISION UPDATED STATUS CHART APP VERSION ROLLBACK DESCRIPTION
1 Mon Oct 3 10:15:13 2016 superseded alpine-0.1.0 1.0 Initial install
2 Mon Oct 3 10:15:13 2016 superseded alpine-0.1.0 1.0 Upgraded successfully
@ -53,6 +62,7 @@ The historical release set is printed as a formatted table, e.g:
func newHistoryCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
client := action.NewHistory(cfg)
var outfmt output.Format
var showRollback bool
cmd := &cobra.Command{
Use: "history RELEASE_NAME",
@ -72,12 +82,16 @@ func newHistoryCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return err
}
if showRollback {
return outfmt.Write(out, releaseHistoryWithRollback(history))
}
return outfmt.Write(out, history)
},
}
f := cmd.Flags()
f.IntVar(&client.Max, "max", 256, "maximum number of revision to include in history")
f.BoolVar(&showRollback, "show-rollback", false, "show the rollback revision column in the output")
bindOutputFlag(cmd, &outfmt)
return cmd
@ -176,6 +190,26 @@ func (r releaseHistory) WriteYAML(out io.Writer) error {
}
func (r releaseHistory) WriteTable(out io.Writer) error {
tbl := uitable.New()
tbl.AddRow("REVISION", "UPDATED", "STATUS", "CHART", "APP VERSION", "DESCRIPTION")
for _, item := range r {
tbl.AddRow(item.Revision, item.Updated.Format(time.ANSIC), item.Status, item.Chart, item.AppVersion, item.Description)
}
return output.EncodeTable(out, tbl)
}
// releaseHistoryWithRollback wraps releaseHistory to include the rollback column in table output.
type releaseHistoryWithRollback releaseHistory
func (r releaseHistoryWithRollback) WriteJSON(out io.Writer) error {
return output.EncodeJSON(out, releaseHistory(r))
}
func (r releaseHistoryWithRollback) WriteYAML(out io.Writer) error {
return output.EncodeYAML(out, releaseHistory(r))
}
func (r releaseHistoryWithRollback) WriteTable(out io.Writer) error {
tbl := uitable.New()
tbl.AddRow("REVISION", "UPDATED", "STATUS", "CHART", "APP VERSION", "ROLLBACK", "DESCRIPTION")
for _, item := range r {

@ -25,9 +25,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
chart "helm.sh/helm/v4/pkg/chart/v2"
"helm.sh/helm/v4/pkg/release/common"
release "helm.sh/helm/v4/pkg/release/v1"
chart "helm.sh/helm/v4/pkg/chart/v2"
)
func TestHistoryCmd(t *testing.T) {
@ -125,9 +125,14 @@ func TestHistoryWithRollback(t *testing.T) {
}
tests := []cmdTestCase{{
name: "history with rollback revision",
name: "history with rollback revision (default, no rollback column)",
cmd: "history angry-bird",
rels: rels,
golden: "output/history-with-rollback-no-flag.txt",
}, {
name: "history with rollback revision and --show-rollback flag",
cmd: "history angry-bird --show-rollback",
rels: rels,
golden: "output/history-with-rollback.txt",
}, {
name: "history with rollback revision json",

@ -1,3 +1,3 @@
REVISION UPDATED STATUS CHART APP VERSION ROLLBACK DESCRIPTION
3 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Release mock
4 Fri Sep 2 22:04:05 1977 deployed foo-0.1.0-beta.1 1.0 Release mock
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
3 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Release mock
4 Fri Sep 2 22:04:05 1977 deployed foo-0.1.0-beta.1 1.0 Release mock

@ -0,0 +1,4 @@
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Install complete
2 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Upgrade complete
3 Fri Sep 2 22:04:05 1977 deployed foo-0.1.0-beta.1 1.0 Rollback to 1

@ -1,4 +1,4 @@
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION ROLLBACK
1 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Install complete 0
2 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Upgrade complete 0
3 Fri Sep 2 22:04:05 1977 deployed foo-0.1.0-beta.1 1.0 Rollback to 1 1
REVISION UPDATED STATUS CHART APP VERSION ROLLBACK DESCRIPTION
1 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Install complete
2 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Upgrade complete
3 Fri Sep 2 22:04:05 1977 deployed foo-0.1.0-beta.1 1.0 1 Rollback to 1

@ -1,5 +1,5 @@
REVISION UPDATED STATUS CHART APP VERSION ROLLBACK DESCRIPTION
1 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Release mock
2 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Release mock
3 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Release mock
4 Fri Sep 2 22:04:05 1977 deployed foo-0.1.0-beta.1 1.0 Release mock
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Release mock
2 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Release mock
3 Fri Sep 2 22:04:05 1977 superseded foo-0.1.0-beta.1 1.0 Release mock
4 Fri Sep 2 22:04:05 1977 deployed foo-0.1.0-beta.1 1.0 Release mock

Loading…
Cancel
Save