diff --git a/cmd/helm/status.go b/cmd/helm/status.go index 6085251d5..1ae4a7488 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -91,6 +91,9 @@ 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") + f.DurationVar(&client.Timeout, "timeout", 300*time.Second, "time to wait for any individual Kubernetes operation (like Jobs for hooks)") + f.BoolVar(&client.Wait, "wait", false, "if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state before marking the release as successful. It will wait for as long as --timeout") + f.BoolVar(&client.WaitForJobs, "wait-for-jobs", false, "if set and --wait enabled, will wait until all Jobs have been completed before marking the release as successful. It will wait for as long as --timeout") return cmd } diff --git a/cmd/helm/status_test.go b/cmd/helm/status_test.go index 7f305d56b..f5e317b43 100644 --- a/cmd/helm/status_test.go +++ b/cmd/helm/status_test.go @@ -108,6 +108,14 @@ func TestStatusCmd(t *testing.T) { }, }, ), + }, { + name: "get status of a deployed release with wait", + cmd: "status --wait flummoxed-chickadee", + golden: "output/status.txt", + rels: releasesMockWithStatus(&release.Info{ + Status: release.StatusDeployed, + Description: "Mock description", + }), }} runTestCmd(t, tests) } diff --git a/internal/test/test.go b/internal/test/test.go index 646037606..e4f7f639a 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -88,7 +88,7 @@ func compare(actual []byte, filename string) error { } expected = normalize(expected) if !bytes.Equal(expected, actual) { - return errors.Errorf("does not match golden file %s\n\nWANT:\n'%s'\n\nGOT:\n'%s'\n", filename, expected, actual) + return errors.Errorf("does not match golden file %s\n\nWANT:\n'%s'\n\nGOT:\n'%s'", filename, expected, actual) } return nil } diff --git a/pkg/action/status.go b/pkg/action/status.go index 1c556e28d..0330f1abe 100644 --- a/pkg/action/status.go +++ b/pkg/action/status.go @@ -17,6 +17,11 @@ limitations under the License. package action import ( + "bytes" + "time" + + "github.com/pkg/errors" + "helm.sh/helm/v3/pkg/release" ) @@ -32,6 +37,10 @@ type Status struct { // only affect print type table. // TODO Helm 4: Remove this flag and output the description by default. ShowDescription bool + + Timeout time.Duration + Wait bool + WaitForJobs bool } // NewStatus creates a new Status object with the given configuration. @@ -47,5 +56,23 @@ func (s *Status) Run(name string) (*release.Release, error) { return nil, err } - return s.cfg.releaseContent(name, s.Version) + release, err := s.cfg.releaseContent(name, s.Version) + if s.Wait && err == nil { + resources, err := s.cfg.KubeClient.Build(bytes.NewBufferString(release.Manifest), false) + if err != nil { + return release, errors.Wrap(err, "unable to build kubernetes objects from existing release manifest") + } + + if s.WaitForJobs { + if err := s.cfg.KubeClient.WaitWithJobs(resources, s.Timeout); err != nil { + return nil, err + } + } else { + if err := s.cfg.KubeClient.Wait(resources, s.Timeout); err != nil { + return nil, err + } + } + } + + return release, err }