add waitwithjobs instead of changing wait api

Signed-off-by: zh168654 <zhangye.168@163.com>
pull/8363/head
zh168654 4 years ago
parent 957d2a2bf9
commit bfc575dec2

@ -157,7 +157,7 @@ func (i *Install) installCRDs(crds []chart.CRD) error {
discoveryClient.Invalidate()
// Give time for the CRD to be recognized.
if err := i.cfg.KubeClient.Wait(totalItems, 60*time.Second, false); err != nil {
if err := i.cfg.KubeClient.Wait(totalItems, 60*time.Second); err != nil {
return err
}
@ -346,9 +346,15 @@ func (i *Install) Run(chrt *chart.Chart, vals map[string]interface{}) (*release.
}
if i.Wait {
if err := i.cfg.KubeClient.Wait(resources, i.Timeout, i.WaitForJobs); err != nil {
if i.WaitForJobs {
if err := i.cfg.KubeClient.WaitWithJobs(resources, i.Timeout); err != nil {
return i.failRelease(rel, err)
}
} else {
if err := i.cfg.KubeClient.Wait(resources, i.Timeout); err != nil {
return i.failRelease(rel, err)
}
}
}
if !i.DisableHooks {

@ -200,12 +200,21 @@ func (r *Rollback) performRollback(currentRelease, targetRelease *release.Releas
}
if r.Wait {
if err := r.cfg.KubeClient.Wait(target, r.Timeout, r.WaitForJobs); err != nil {
if r.WaitForJobs {
if err := r.cfg.KubeClient.WaitWithJobs(target, r.Timeout); err != nil {
targetRelease.SetStatus(release.StatusFailed, fmt.Sprintf("Release %q failed: %s", targetRelease.Name, err.Error()))
r.cfg.recordRelease(currentRelease)
r.cfg.recordRelease(targetRelease)
return targetRelease, errors.Wrapf(err, "release %s failed", targetRelease.Name)
}
} else {
if err := r.cfg.KubeClient.Wait(target, r.Timeout); err != nil {
targetRelease.SetStatus(release.StatusFailed, fmt.Sprintf("Release %q failed: %s", targetRelease.Name, err.Error()))
r.cfg.recordRelease(currentRelease)
r.cfg.recordRelease(targetRelease)
return targetRelease, errors.Wrapf(err, "release %s failed", targetRelease.Name)
}
}
}
// post-rollback hooks

@ -331,10 +331,17 @@ func (u *Upgrade) performUpgrade(originalRelease, upgradedRelease *release.Relea
}
if u.Wait {
if err := u.cfg.KubeClient.Wait(target, u.Timeout, u.WaitForJobs); err != nil {
if u.WaitForJobs {
if err := u.cfg.KubeClient.WaitWithJobs(target, u.Timeout); err != nil {
u.cfg.recordRelease(originalRelease)
return u.failRelease(upgradedRelease, results.Created, err)
}
} else {
if err := u.cfg.KubeClient.Wait(target, u.Timeout); err != nil {
u.cfg.recordRelease(originalRelease)
return u.failRelease(upgradedRelease, results.Created, err)
}
}
}
// post-upgrade hooks

@ -127,7 +127,7 @@ func (c *Client) Create(resources ResourceList) (*Result, error) {
}
// Wait up to the given timeout for the specified resources to be ready
func (c *Client) Wait(resources ResourceList, timeout time.Duration, waitForJobsEnabled bool) error {
func (c *Client) Wait(resources ResourceList, timeout time.Duration) error {
cs, err := c.getKubeClient()
if err != nil {
return err
@ -137,7 +137,21 @@ func (c *Client) Wait(resources ResourceList, timeout time.Duration, waitForJobs
log: c.Log,
timeout: timeout,
}
return w.waitForResources(resources, waitForJobsEnabled)
return w.waitForResources(resources, false)
}
// WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs.
func (c *Client) WaitWithJobs(resources ResourceList, timeout time.Duration) error {
cs, err := c.getKubeClient()
if err != nil {
return err
}
w := waiter{
c: cs,
log: c.Log,
timeout: timeout,
}
return w.waitForResources(resources, true)
}
func (c *Client) namespace() string {

@ -51,11 +51,19 @@ func (f *FailingKubeClient) Create(resources kube.ResourceList) (*kube.Result, e
}
// Wait returns the configured error if set or prints
func (f *FailingKubeClient) Wait(resources kube.ResourceList, d time.Duration, waitForJobsEnabled bool) error {
func (f *FailingKubeClient) Wait(resources kube.ResourceList, d time.Duration) error {
if f.WaitError != nil {
return f.WaitError
}
return f.PrintingKubeClient.Wait(resources, d, waitForJobsEnabled)
return f.PrintingKubeClient.Wait(resources, d)
}
// WaitWithJobs returns the configured error if set or prints
func (f *FailingKubeClient) WaitWithJobs(resources kube.ResourceList, d time.Duration) error {
if f.WaitError != nil {
return f.WaitError
}
return f.PrintingKubeClient.Wait(resources, d)
}
// Delete returns the configured error if set or prints

@ -47,7 +47,12 @@ func (p *PrintingKubeClient) Create(resources kube.ResourceList) (*kube.Result,
return &kube.Result{Created: resources}, nil
}
func (p *PrintingKubeClient) Wait(resources kube.ResourceList, _ time.Duration, _ bool) error {
func (p *PrintingKubeClient) Wait(resources kube.ResourceList, _ time.Duration) error {
_, err := io.Copy(p.Out, bufferize(resources))
return err
}
func (p *PrintingKubeClient) WaitWithJobs(resources kube.ResourceList, _ time.Duration) error {
_, err := io.Copy(p.Out, bufferize(resources))
return err
}

@ -30,7 +30,9 @@ type Interface interface {
// Create creates one or more resources.
Create(resources ResourceList) (*Result, error)
Wait(resources ResourceList, timeout time.Duration, waitForJobsEnabled bool) error
Wait(resources ResourceList, timeout time.Duration) error
WaitWithJobs(resources ResourceList, timeout time.Duration) error
// Delete destroys one or more resources.
Delete(resources ResourceList) (*Result, []error)

Loading…
Cancel
Save