mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
helm waiter
Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
This commit is contained in:
parent
86338215b7
commit
4c97d1276c
4 changed files with 14 additions and 10 deletions
|
|
@ -126,7 +126,7 @@ func NewWaiter(strategy WaitStrategy, factory Factory, log func(string, ...inter
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &waiter{kubeClient: kc, log: log}, nil
|
||||
return &HelmWaiter{kubeClient: kc, log: log}, nil
|
||||
case StatusWaiter:
|
||||
sw, err := getStatusWatcher(factory)
|
||||
if err != nil {
|
||||
|
|
@ -333,7 +333,7 @@ func getResource(info *resource.Info) (runtime.Object, error) {
|
|||
|
||||
// WaitForDelete wait up to the given timeout for the specified resources to be deleted.
|
||||
func (c *Client) WaitForDelete(resources ResourceList, timeout time.Duration) error {
|
||||
w := waiter{
|
||||
w := HelmWaiter{
|
||||
log: c.Log,
|
||||
timeout: timeout,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ func (w *statusWaiter) WaitWithJobs(resourceList ResourceList, timeout time.Dura
|
|||
}
|
||||
|
||||
func (w *statusWaiter) waitForDelete(ctx context.Context, resourceList ResourceList) error {
|
||||
deadline, _ := ctx.Deadline()
|
||||
w.log("beginning wait for %d resources to be deleted with timeout of %v", len(resourceList), time.Until(deadline))
|
||||
cancelCtx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
runtimeObjs := []runtime.Object{}
|
||||
|
|
@ -110,6 +112,8 @@ func (w *statusWaiter) waitForDelete(ctx context.Context, resourceList ResourceL
|
|||
}
|
||||
|
||||
func (w *statusWaiter) wait(ctx context.Context, resourceList ResourceList, waitForJobs bool) error {
|
||||
deadline, _ := ctx.Deadline()
|
||||
w.log("beginning wait for %d resources with timeout of %v", len(resourceList), deadline)
|
||||
cancelCtx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
runtimeObjs := []runtime.Object{}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func TestStatusWaitForDelete(t *testing.T) {
|
|||
statusWatcher := watcher.NewDefaultStatusWatcher(fakeClient, fakeMapper)
|
||||
kwaiter := statusWaiter{
|
||||
sw: statusWatcher,
|
||||
log: log.Printf,
|
||||
log: t.Logf,
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
|
||||
defer cancel()
|
||||
|
|
|
|||
|
|
@ -39,20 +39,20 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
)
|
||||
|
||||
type waiter struct {
|
||||
type HelmWaiter struct {
|
||||
c ReadyChecker
|
||||
timeout time.Duration
|
||||
log func(string, ...interface{})
|
||||
kubeClient *kubernetes.Clientset
|
||||
}
|
||||
|
||||
func (w *waiter) Wait(resources ResourceList, timeout time.Duration) error {
|
||||
func (w *HelmWaiter) Wait(resources ResourceList, timeout time.Duration) error {
|
||||
w.c = NewReadyChecker(w.kubeClient, w.log, PausedAsReady(true))
|
||||
w.timeout = timeout
|
||||
return w.waitForResources(resources)
|
||||
}
|
||||
|
||||
func (w *waiter) WaitWithJobs(resources ResourceList, timeout time.Duration) error {
|
||||
func (w *HelmWaiter) WaitWithJobs(resources ResourceList, timeout time.Duration) error {
|
||||
w.c = NewReadyChecker(w.kubeClient, w.log, PausedAsReady(true), CheckJobs(true))
|
||||
w.timeout = timeout
|
||||
return w.waitForResources(resources)
|
||||
|
|
@ -60,7 +60,7 @@ func (w *waiter) WaitWithJobs(resources ResourceList, timeout time.Duration) err
|
|||
|
||||
// waitForResources polls to get the current status of all pods, PVCs, Services and
|
||||
// Jobs(optional) until all are ready or a timeout is reached
|
||||
func (w *waiter) waitForResources(created ResourceList) error {
|
||||
func (w *HelmWaiter) waitForResources(created ResourceList) error {
|
||||
w.log("beginning wait for %d resources with timeout of %v", len(created), w.timeout)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.timeout)
|
||||
|
|
@ -94,7 +94,7 @@ func (w *waiter) waitForResources(created ResourceList) error {
|
|||
})
|
||||
}
|
||||
|
||||
func (w *waiter) isRetryableError(err error, resource *resource.Info) bool {
|
||||
func (w *HelmWaiter) isRetryableError(err error, resource *resource.Info) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -109,12 +109,12 @@ func (w *waiter) isRetryableError(err error, resource *resource.Info) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (w *waiter) isRetryableHTTPStatusCode(httpStatusCode int32) bool {
|
||||
func (w *HelmWaiter) isRetryableHTTPStatusCode(httpStatusCode int32) bool {
|
||||
return httpStatusCode == 0 || httpStatusCode == http.StatusTooManyRequests || (httpStatusCode >= 500 && httpStatusCode != http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
// waitForDeletedResources polls to check if all the resources are deleted or a timeout is reached
|
||||
func (w *waiter) waitForDeletedResources(deleted ResourceList) error {
|
||||
func (w *HelmWaiter) waitForDeletedResources(deleted ResourceList) error {
|
||||
w.log("beginning wait for %d resources to be deleted with timeout of %v", len(deleted), w.timeout)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.timeout)
|
||||
|
|
|
|||
Loading…
Reference in a new issue