Skip to content

Commit

Permalink
use wait.PollUntilContextTimeout instead of wait.Poll
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Lavery <laverya@umich.edu>
  • Loading branch information
laverya committed May 2, 2023
1 parent c942829 commit f5aa6ba
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.3.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *SonobuoyClient) Delete(cfg *DeleteConfig) error {

if cfg.Wait > time.Duration(0) {
lastProgress := ""
allConditions := func() (bool, error) {
allConditions := func(ctx context.Context) (bool, error) {
for _, condition := range conditions {
progress, done, err := condition()
if cfg.WaitOutput == progressMode {
Expand All @@ -111,7 +111,7 @@ func (c *SonobuoyClient) Delete(cfg *DeleteConfig) error {
s.Start()
defer s.Stop()
}
if err := wait.Poll(pollFreq, cfg.Wait, allConditions); err != nil {
if err := wait.PollUntilContextTimeout(context.TODO(), pollFreq, cfg.Wait, false, allConditions); err != nil {
return errors.Wrap(err, "waiting for delete conditions to be met")
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"bytes"
"context"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -138,7 +139,7 @@ func (c *SonobuoyClient) WaitForRun(cfg *RunConfig) error {
lastMsg = s
}
}
runCondition := func() (bool, error) {
runCondition := func(ctx context.Context) (bool, error) {

// Get the Aggregator pod and check if its status is completed or terminated.
status, pod, err := c.GetStatusPod(&StatusConfig{Namespace: ns})
Expand Down Expand Up @@ -186,7 +187,7 @@ func (c *SonobuoyClient) WaitForRun(cfg *RunConfig) error {
// handled by conditionFunc since it has to be part of the polling.
// Could use channels but that will lead to future issues.
}
err := wait.Poll(pollInterval, cfg.Wait, runCondition)
err := wait.PollUntilContextTimeout(context.TODO(), pollInterval, cfg.Wait, false, runCondition)
if err != nil {
return errors.Wrap(err, "waiting for run to finish")
}
Expand Down

0 comments on commit f5aa6ba

Please sign in to comment.