This change adds support for timeout of each resource

Update pkg\kube\wait.go, pkg\kube\client.go

    Signed-off-by: Anhj An <anhongyang125@163.com>
pull/11536/head
Anhj An anhongyang125@163.com 3 years ago
parent 9a5eb70320
commit 85851c3dd9

@ -147,6 +147,22 @@ func (c *Client) Wait(resources ResourceList, timeout time.Duration) error {
return w.waitForResources(resources) return w.waitForResources(resources)
} }
// Wait waits up to the given timeout for the specified resources to be ready. perResourceTimeout means the timeout of each resource
func (c *Client) WaitWithPerResource(resources ResourceList, timeout, perResourceTimeout time.Duration) error {
cs, err := c.getKubeClient()
if err != nil {
return err
}
checker := NewReadyChecker(cs, c.Log, PausedAsReady(true))
w := waiter{
c: checker,
log: c.Log,
timeout: timeout,
perResourceTimeout: perResourceTimeout,
}
return w.waitForResources(resources)
}
// WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs. // 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 { func (c *Client) WaitWithJobs(resources ResourceList, timeout time.Duration) error {
cs, err := c.getKubeClient() cs, err := c.getKubeClient()

@ -41,6 +41,7 @@ import (
type waiter struct { type waiter struct {
c ReadyChecker c ReadyChecker
timeout time.Duration timeout time.Duration
perResourceTimeout time.Duration
log func(string, ...interface{}) log func(string, ...interface{})
} }
@ -68,7 +69,12 @@ func (w *waiter) waitForResources(created ResourceList) error {
ctx, cancel := context.WithTimeout(context.Background(), w.timeout) ctx, cancel := context.WithTimeout(context.Background(), w.timeout)
defer cancel() defer cancel()
return wait.PollImmediateUntil(2*time.Second, func() (bool, error) { timeout := 2 * time.Second
if w.perResourceTimeout > timeout {
timeout = w.perResourceTimeout
}
return wait.PollImmediateUntil(timeout, func() (bool, error) {
for _, v := range created { for _, v := range created {
ready, err := w.c.IsReady(ctx, v) ready, err := w.c.IsReady(ctx, v)
if !ready || err != nil { if !ready || err != nil {

Loading…
Cancel
Save