From da6878dc0f5c99d1062c2c220b0ab5a8d548a773 Mon Sep 17 00:00:00 2001 From: Ling Samuel Date: Wed, 29 Jul 2020 09:36:21 +0800 Subject: [PATCH] feat: status command display description Signed-off-by: Ling Samuel --- cmd/helm/get_all.go | 2 +- cmd/helm/install.go | 2 +- cmd/helm/release_testing.go | 2 +- cmd/helm/status.go | 13 ++++++++++--- cmd/helm/status_test.go | 8 ++++++++ cmd/helm/testdata/output/status-with-desc.txt | 7 +++++++ cmd/helm/upgrade.go | 4 ++-- pkg/action/status.go | 5 +++++ 8 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 cmd/helm/testdata/output/status-with-desc.txt diff --git a/cmd/helm/get_all.go b/cmd/helm/get_all.go index a5037e4df..53f8d5905 100644 --- a/cmd/helm/get_all.go +++ b/cmd/helm/get_all.go @@ -59,7 +59,7 @@ func newGetAllCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return tpl(template, data, out) } - return output.Table.Write(out, &statusPrinter{res, true}) + return output.Table.Write(out, &statusPrinter{res, true, false}) }, } diff --git a/cmd/helm/install.go b/cmd/helm/install.go index f7d0239fb..7edd98091 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -122,7 +122,7 @@ func newInstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return err } - return outfmt.Write(out, &statusPrinter{rel, settings.Debug}) + return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false}) }, } diff --git a/cmd/helm/release_testing.go b/cmd/helm/release_testing.go index 37cac6186..e4e09ef3b 100644 --- a/cmd/helm/release_testing.go +++ b/cmd/helm/release_testing.go @@ -61,7 +61,7 @@ func newReleaseTestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command return runErr } - if err := outfmt.Write(out, &statusPrinter{rel, settings.Debug}); err != nil { + if err := outfmt.Write(out, &statusPrinter{rel, settings.Debug, false}); err != nil { return err } diff --git a/cmd/helm/status.go b/cmd/helm/status.go index abd32a9c2..7a3204cb9 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -39,6 +39,8 @@ The status consists of: - last deployment time - k8s namespace in which the release lives - state of the release (can be: unknown, deployed, uninstalled, superseded, failed, uninstalling, pending-install, pending-upgrade or pending-rollback) +- revision of the release +- description of the release (can be completion message or error message, need to enable --show-desc) - list of resources that this release consists of, sorted by kind - details on last test suite run, if applicable - additional notes provided by the chart @@ -68,7 +70,7 @@ func newStatusCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { // strip chart metadata from the output rel.Chart = nil - return outfmt.Write(out, &statusPrinter{rel, false}) + return outfmt.Write(out, &statusPrinter{rel, false, client.ShowDescription}) }, } @@ -88,13 +90,15 @@ func newStatusCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } bindOutputFlag(cmd, &outfmt) + f.BoolVar(&client.ShowDescription, "show-desc", false, "if set, display the description message of the named release") return cmd } type statusPrinter struct { - release *release.Release - debug bool + release *release.Release + debug bool + showDescription bool } func (s statusPrinter) WriteJSON(out io.Writer) error { @@ -116,6 +120,9 @@ func (s statusPrinter) WriteTable(out io.Writer) error { fmt.Fprintf(out, "NAMESPACE: %s\n", s.release.Namespace) fmt.Fprintf(out, "STATUS: %s\n", s.release.Info.Status.String()) fmt.Fprintf(out, "REVISION: %d\n", s.release.Version) + if s.showDescription { + fmt.Fprintf(out, "DESCRIPTION: %s\n", s.release.Info.Description) + } executions := executionsByHookEvent(s.release) if tests, ok := executions[release.HookTest]; !ok || len(tests) == 0 { diff --git a/cmd/helm/status_test.go b/cmd/helm/status_test.go index 0d2500e65..2d0ce4b03 100644 --- a/cmd/helm/status_test.go +++ b/cmd/helm/status_test.go @@ -44,6 +44,14 @@ func TestStatusCmd(t *testing.T) { rels: releasesMockWithStatus(&release.Info{ Status: release.StatusDeployed, }), + }, { + name: "get status of a deployed release, with desc", + cmd: "status --show-desc flummoxed-chickadee", + golden: "output/status-with-desc.txt", + rels: releasesMockWithStatus(&release.Info{ + Status: release.StatusDeployed, + Description: "Mock description", + }), }, { name: "get status of a deployed release with notes", cmd: "status flummoxed-chickadee", diff --git a/cmd/helm/testdata/output/status-with-desc.txt b/cmd/helm/testdata/output/status-with-desc.txt new file mode 100644 index 000000000..c681fe3ec --- /dev/null +++ b/cmd/helm/testdata/output/status-with-desc.txt @@ -0,0 +1,7 @@ +NAME: flummoxed-chickadee +LAST DEPLOYED: Sat Jan 16 00:00:00 2016 +NAMESPACE: default +STATUS: deployed +REVISION: 0 +DESCRIPTION: Mock description +TEST SUITE: None diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index dbddaa368..12d797545 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -115,7 +115,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - return outfmt.Write(out, &statusPrinter{rel, settings.Debug}) + return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false}) } else if err != nil { return err } @@ -160,7 +160,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", args[0]) } - return outfmt.Write(out, &statusPrinter{rel, settings.Debug}) + return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false}) }, } diff --git a/pkg/action/status.go b/pkg/action/status.go index a0c7f6e21..1c556e28d 100644 --- a/pkg/action/status.go +++ b/pkg/action/status.go @@ -27,6 +27,11 @@ type Status struct { cfg *Configuration Version int + + // If true, display description to output format, + // only affect print type table. + // TODO Helm 4: Remove this flag and output the description by default. + ShowDescription bool } // NewStatus creates a new Status object with the given configuration.