Addressing review comments:

Extend Interface with new InterfaceResources to avoid breaking changes
Move change to staus command behind --show-resources flag

Signed-off-by: Soujanya Mangipudi <somangip@microsoft.com>
pull/11660/head
Soujanya Mangipudi 2 years ago
parent 9d5be803bc
commit 20e3577543

@ -59,7 +59,7 @@ func newGetAllCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return tpl(template, data, out) return tpl(template, data, out)
} }
return output.Table.Write(out, &statusPrinter{res, true, false}) return output.Table.Write(out, &statusPrinter{res, true, false, false})
}, },
} }

@ -141,7 +141,7 @@ func newInstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return errors.Wrap(err, "INSTALLATION FAILED") return errors.Wrap(err, "INSTALLATION FAILED")
} }
return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false}) return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false, false})
}, },
} }

@ -72,7 +72,7 @@ func newReleaseTestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command
return runErr return runErr
} }
if err := outfmt.Write(out, &statusPrinter{rel, settings.Debug, false}); err != nil { if err := outfmt.Write(out, &statusPrinter{rel, settings.Debug, false, false}); err != nil {
return err return err
} }

@ -41,7 +41,7 @@ The status consists of:
- state of the release (can be: unknown, deployed, uninstalled, superseded, failed, uninstalling, pending-install, pending-upgrade or pending-rollback) - state of the release (can be: unknown, deployed, uninstalled, superseded, failed, uninstalling, pending-install, pending-upgrade or pending-rollback)
- revision of the release - revision of the release
- description of the release (can be completion message or error message, need to enable --show-desc) - 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 - list of resources that this release consists of (need to enable --show-resources)
- details on last test suite run, if applicable - details on last test suite run, if applicable
- additional notes provided by the chart - additional notes provided by the chart
` `
@ -70,7 +70,7 @@ func newStatusCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
// strip chart metadata from the output // strip chart metadata from the output
rel.Chart = nil rel.Chart = nil
return outfmt.Write(out, &statusPrinter{rel, false, client.ShowDescription}) return outfmt.Write(out, &statusPrinter{rel, false, client.ShowDescription, client.ShowResources})
}, },
} }
@ -92,6 +92,8 @@ func newStatusCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
bindOutputFlag(cmd, &outfmt) bindOutputFlag(cmd, &outfmt)
f.BoolVar(&client.ShowDescription, "show-desc", false, "if set, display the description message of the named release") f.BoolVar(&client.ShowDescription, "show-desc", false, "if set, display the description message of the named release")
f.BoolVar(&client.ShowResources, "show-resources", false, "if set, display the resources of the named release")
return cmd return cmd
} }
@ -99,6 +101,7 @@ type statusPrinter struct {
release *release.Release release *release.Release
debug bool debug bool
showDescription bool showDescription bool
showResources bool
} }
func (s statusPrinter) WriteJSON(out io.Writer) error { func (s statusPrinter) WriteJSON(out io.Writer) error {
@ -124,7 +127,7 @@ func (s statusPrinter) WriteTable(out io.Writer) error {
fmt.Fprintf(out, "DESCRIPTION: %s\n", s.release.Info.Description) fmt.Fprintf(out, "DESCRIPTION: %s\n", s.release.Info.Description)
} }
if len(s.release.Info.Resources) > 0 { if s.showResources && len(s.release.Info.Resources) > 0 {
fmt.Fprintf(out, "RESOURCES:\n%s\n", s.release.Info.Resources) fmt.Fprintf(out, "RESOURCES:\n%s\n", s.release.Info.Resources)
} }

@ -70,7 +70,7 @@ func TestStatusCmd(t *testing.T) {
}), }),
}, { }, {
name: "get status of a deployed release with resources", name: "get status of a deployed release with resources",
cmd: "status flummoxed-chickadee", cmd: "status --show-resources flummoxed-chickadee",
golden: "output/status-with-resources.txt", golden: "output/status-with-resources.txt",
rels: releasesMockWithStatus( rels: releasesMockWithStatus(
&release.Info{ &release.Info{
@ -80,7 +80,7 @@ func TestStatusCmd(t *testing.T) {
), ),
}, { }, {
name: "get status of a deployed release with resources in json", name: "get status of a deployed release with resources in json",
cmd: "status flummoxed-chickadee -o json", cmd: "status --show-resources flummoxed-chickadee -o json",
golden: "output/status-with-resources.json", golden: "output/status-with-resources.json",
rels: releasesMockWithStatus( rels: releasesMockWithStatus(
&release.Info{ &release.Info{

@ -123,7 +123,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
if err != nil { if err != nil {
return err return err
} }
return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false}) return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false, false})
} else if err != nil { } else if err != nil {
return err return err
} }
@ -205,7 +205,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", args[0]) fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", args[0])
} }
return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false}) return outfmt.Write(out, &statusPrinter{rel, settings.Debug, false, false})
}, },
} }

@ -19,6 +19,7 @@ package action
import ( import (
"bytes" "bytes"
"helm.sh/helm/v3/pkg/kube"
"helm.sh/helm/v3/pkg/release" "helm.sh/helm/v3/pkg/release"
) )
@ -34,6 +35,10 @@ type Status struct {
// only affect print type table. // only affect print type table.
// TODO Helm 4: Remove this flag and output the description by default. // TODO Helm 4: Remove this flag and output the description by default.
ShowDescription bool ShowDescription bool
// If true, display resources of release to output format
// TODO Helm 4: Remove this flag and output the resources by default.
ShowResources bool
} }
// NewStatus creates a new Status object with the given configuration. // NewStatus creates a new Status object with the given configuration.
@ -49,17 +54,26 @@ func (s *Status) Run(name string) (*release.Release, error) {
return nil, err return nil, err
} }
if !s.ShowResources {
return s.cfg.releaseContent(name, s.Version)
}
rel, err := s.cfg.releaseContent(name, s.Version) rel, err := s.cfg.releaseContent(name, s.Version)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resources, _ := s.cfg.KubeClient.Build(bytes.NewBufferString(rel.Manifest), false) resources, _ := s.cfg.KubeClient.Build(bytes.NewBufferString(rel.Manifest), false)
resp, err := s.cfg.KubeClient.Get(resources, bytes.NewBufferString(rel.Manifest))
if err != nil { if kubeClient, ok := s.cfg.KubeClient.(kube.InterfaceResources); ok {
return nil, err resp, err := kubeClient.Get(resources, bytes.NewBufferString(rel.Manifest))
} if err != nil {
if resp != "" { return nil, err
rel.Info.Resources = resp }
if resp != "" {
rel.Info.Resources = resp
}
return rel, nil
} }
return rel, nil return nil, err
} }

@ -68,8 +68,6 @@ type Interface interface {
// IsReachable checks whether the client is able to connect to the cluster. // IsReachable checks whether the client is able to connect to the cluster.
IsReachable() error IsReachable() error
Get(resources ResourceList, reader io.Reader) (string, error)
} }
// InterfaceExt is introduced to avoid breaking backwards compatibility for Interface implementers. // InterfaceExt is introduced to avoid breaking backwards compatibility for Interface implementers.
@ -80,5 +78,14 @@ type InterfaceExt interface {
WaitForDelete(resources ResourceList, timeout time.Duration) error WaitForDelete(resources ResourceList, timeout time.Duration) error
} }
// InterfaceResources is introduced to avoid breaking backwards compatibility for Interface implementers.
//
// TODO Helm 4: Remove InterfaceResources and integrate its method(s) into the Interface.
type InterfaceResources interface {
// Get details of deployed resources in ResourceList to be printed.
Get(resources ResourceList, reader io.Reader) (string, error)
}
var _ Interface = (*Client)(nil) var _ Interface = (*Client)(nil)
var _ InterfaceExt = (*Client)(nil) var _ InterfaceExt = (*Client)(nil)
var _ InterfaceResources = (*Client)(nil)

Loading…
Cancel
Save