Support --wait with helm status #10750

pull/10756/head
stan-sz 4 years ago committed by GitHub
parent 8ab18f7567
commit 3c632dc794

@ -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
}

@ -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)
}

@ -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
}

@ -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
}

Loading…
Cancel
Save