Skip to content

Commit 1d15933

Browse files
committed
fixups
1 parent 1868d54 commit 1d15933

File tree

20 files changed

+44
-33
lines changed

20 files changed

+44
-33
lines changed

cmd/clusterctl/client/client_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package client
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"testing"
2223
"time"
@@ -209,7 +210,7 @@ func newFakeCluster(kubeconfig cluster.Kubeconfig, configClient config.Client) *
209210
}
210211

211212
fake.fakeProxy = test.NewFakeProxy()
212-
pollImmediateWaiter := func(interval, timeout time.Duration, condition wait.ConditionFunc) error {
213+
pollImmediateWaiter := func(ctx context.Context, interval, timeout time.Duration, immediate bool, condition wait.ConditionWithContextFunc) error {
213214
return nil
214215
}
215216

cmd/clusterctl/client/cluster/cert_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func (cm *certManagerClient) deleteObj(obj unstructured.Unstructured) error {
526526
// cert-manager API group.
527527
// If retry is true, the createObj call will be retried if it fails. Otherwise, the
528528
// 'create' operations will only be attempted once.
529-
func (cm *certManagerClient) waitForAPIReady(_ context.Context, retry bool) error {
529+
func (cm *certManagerClient) waitForAPIReady(ctx context.Context, retry bool) error {
530530
log := logf.Log
531531
// Waits for the cert-manager to be available.
532532
if retry {
@@ -544,7 +544,7 @@ func (cm *certManagerClient) waitForAPIReady(_ context.Context, retry bool) erro
544544
// Create the Kubernetes object.
545545
// This is wrapped with a retry as the cert-manager API may not be available
546546
// yet, so we need to keep retrying until it is.
547-
if err := cm.pollImmediateWaiter(waitCertManagerInterval, cm.getWaitTimeout(), func() (bool, error) {
547+
if err := cm.pollImmediateWaiter(ctx, waitCertManagerInterval, cm.getWaitTimeout(), true, func(ctx context.Context) (bool, error) {
548548
if err := cm.createObj(o); err != nil {
549549
// If retrying is disabled, return the error here.
550550
if !retry {

cmd/clusterctl/client/cluster/cert_manager_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package cluster
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"testing"
2223
"time"
@@ -165,7 +166,7 @@ func Test_getManifestObjs(t *testing.T) {
165166
}
166167

167168
func Test_GetTimeout(t *testing.T) {
168-
pollImmediateWaiter := func(interval, timeout time.Duration, condition wait.ConditionFunc) error {
169+
pollImmediateWaiter := func(ctx context.Context, interval, timeout time.Duration, immediate bool, condition wait.ConditionWithContextFunc) error {
169170
return nil
170171
}
171172

@@ -421,7 +422,7 @@ func Test_shouldUpgrade(t *testing.T) {
421422
g := NewWithT(t)
422423
proxy := test.NewFakeProxy()
423424
fakeConfigClient := newFakeConfig().WithCertManager("", tt.configVersion, "")
424-
pollImmediateWaiter := func(interval, timeout time.Duration, condition wait.ConditionFunc) error {
425+
pollImmediateWaiter := func(ctx context.Context, interval, timeout time.Duration, immediate bool, condition wait.ConditionWithContextFunc) error {
425426
return nil
426427
}
427428
cm := newCertManagerClient(fakeConfigClient, nil, proxy, pollImmediateWaiter)
@@ -706,7 +707,7 @@ func Test_certManagerClient_PlanUpgrade(t *testing.T) {
706707

707708
proxy := test.NewFakeProxy().WithObjs(tt.objs...)
708709
fakeConfigClient := newFakeConfig()
709-
pollImmediateWaiter := func(interval, timeout time.Duration, condition wait.ConditionFunc) error {
710+
pollImmediateWaiter := func(ctx context.Context, interval, timeout time.Duration, immediate bool, condition wait.ConditionWithContextFunc) error {
710711
return nil
711712
}
712713
cm := newCertManagerClient(fakeConfigClient, nil, proxy, pollImmediateWaiter)

cmd/clusterctl/client/cluster/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type Client interface {
8989
}
9090

9191
// PollImmediateWaiter tries a condition func until it returns true, an error, or the timeout is reached.
92-
type PollImmediateWaiter func(interval, timeout time.Duration, condition wait.ConditionFunc) error
92+
type PollImmediateWaiter func(ctx context.Context, interval, timeout time.Duration, immediate bool, condition wait.ConditionWithContextFunc) error
9393

9494
// clusterClient implements Client.
9595
type clusterClient struct {
@@ -214,7 +214,7 @@ func newClusterClient(kubeconfig Kubeconfig, configClient config.Client, options
214214

215215
// if there is an injected PollImmediateWaiter, use it, otherwise use the default one
216216
if client.pollImmediateWaiter == nil {
217-
client.pollImmediateWaiter = wait.PollImmediate
217+
client.pollImmediateWaiter = wait.PollUntilContextTimeout
218218
}
219219

220220
return client

cmd/clusterctl/client/cluster/installer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func waitManagerDeploymentsReady(opts InstallOptions, installQueue []repository.
150150
}
151151

152152
func waitDeploymentReady(deployment unstructured.Unstructured, timeout time.Duration, proxy Proxy) error {
153-
return wait.Poll(100*time.Millisecond, timeout, func() (bool, error) {
153+
return wait.PollUntilContextTimeout(context.TODO(), 100*time.Millisecond, timeout, true, func(ctx context.Context) (bool, error) {
154154
c, err := proxy.NewClient()
155155
if err != nil {
156156
return false, err

cmd/clusterctl/client/cluster/inventory.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package cluster
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"time"
2223

@@ -197,7 +198,7 @@ func (p *inventoryClient) EnsureCustomResourceDefinitions() error {
197198
// If the object is a CRDs, waits for it being Established.
198199
if apiextensionsv1.SchemeGroupVersion.WithKind("CustomResourceDefinition").GroupKind() == o.GroupVersionKind().GroupKind() {
199200
crdKey := client.ObjectKeyFromObject(&o)
200-
if err := p.pollImmediateWaiter(waitInventoryCRDInterval, waitInventoryCRDTimeout, func() (bool, error) {
201+
if err := p.pollImmediateWaiter(ctx, waitInventoryCRDInterval, waitInventoryCRDTimeout, true, func(ctx context.Context) (bool, error) {
201202
c, err := p.proxy.NewClient()
202203
if err != nil {
203204
return false, err

cmd/clusterctl/client/cluster/inventory_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package cluster
1818

1919
import (
20+
"context"
2021
"testing"
2122
"time"
2223

@@ -31,7 +32,7 @@ import (
3132
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test"
3233
)
3334

34-
func fakePollImmediateWaiter(_, _ time.Duration, _ wait.ConditionFunc) error {
35+
func fakePollImmediateWaiter(_ context.Context, _, _ time.Duration, _ bool, _ wait.ConditionWithContextFunc) error {
3536
return nil
3637
}
3738

cmd/clusterctl/client/repository/repository_github.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ func (g *gitHubRepository) getVersions() ([]string, error) {
283283
// NB. currently Github API does not support result ordering, so it not possible to limit results
284284
var allReleases []*github.RepositoryRelease
285285
var retryError error
286-
_ = wait.PollImmediate(retryableOperationInterval, retryableOperationTimeout, func() (bool, error) {
286+
_ = wait.PollUntilContextTimeout(context.TODO(), retryableOperationInterval, retryableOperationTimeout, true, func(ctx context.Context) (bool, error) {
287287
var listReleasesErr error
288288
// Get the first page of GitHub releases.
289-
releases, response, listReleasesErr := client.Repositories.ListReleases(context.TODO(), g.owner, g.repository, &github.ListOptions{PerPage: githubListReleasesPerPageLimit})
289+
releases, response, listReleasesErr := client.Repositories.ListReleases(ctx, g.owner, g.repository, &github.ListOptions{PerPage: githubListReleasesPerPageLimit})
290290
if listReleasesErr != nil {
291291
retryError = g.handleGithubErr(listReleasesErr, "failed to get the list of releases")
292292
// Return immediately if we are rate limited.
@@ -301,7 +301,7 @@ func (g *gitHubRepository) getVersions() ([]string, error) {
301301
// pages in the response, which can be used to iterate through the pages.
302302
// https://github.com/google/go-github/blob/14bb610698fc2f9013cad5db79b2d5fe4d53e13c/github/github.go#L541-L551
303303
for response.NextPage != 0 {
304-
releases, response, listReleasesErr = client.Repositories.ListReleases(context.TODO(), g.owner, g.repository, &github.ListOptions{Page: response.NextPage, PerPage: githubListReleasesPerPageLimit})
304+
releases, response, listReleasesErr = client.Repositories.ListReleases(ctx, g.owner, g.repository, &github.ListOptions{Page: response.NextPage, PerPage: githubListReleasesPerPageLimit})
305305
if listReleasesErr != nil {
306306
retryError = g.handleGithubErr(listReleasesErr, "failed to get the list of releases")
307307
// Return immediately if we are rate limited.
@@ -346,9 +346,9 @@ func (g *gitHubRepository) getReleaseByTag(tag string) (*github.RepositoryReleas
346346

347347
var release *github.RepositoryRelease
348348
var retryError error
349-
_ = wait.PollImmediate(retryableOperationInterval, retryableOperationTimeout, func() (bool, error) {
349+
_ = wait.PollUntilContextTimeout(context.TODO(), retryableOperationInterval, retryableOperationTimeout, true, func(ctx context.Context) (bool, error) {
350350
var getReleasesErr error
351-
release, _, getReleasesErr = client.Repositories.GetReleaseByTag(context.TODO(), g.owner, g.repository, tag)
351+
release, _, getReleasesErr = client.Repositories.GetReleaseByTag(ctx, g.owner, g.repository, tag)
352352
if getReleasesErr != nil {
353353
retryError = g.handleGithubErr(getReleasesErr, "failed to read release %q", tag)
354354
// Return immediately if we are rate limited.
@@ -394,7 +394,7 @@ func (g *gitHubRepository) downloadFilesFromRelease(release *github.RepositoryRe
394394

395395
var reader io.ReadCloser
396396
var retryError error
397-
_ = wait.PollImmediate(retryableOperationInterval, retryableOperationTimeout, func() (bool, error) {
397+
_ = wait.PollUntilContextTimeout(ctx, retryableOperationInterval, retryableOperationTimeout, true, func(ctx context.Context) (bool, error) {
398398
var redirect string
399399
var downloadReleaseError error
400400
reader, redirect, downloadReleaseError = client.Repositories.DownloadReleaseAsset(ctx, g.owner, g.repository, *assetID, http.DefaultClient)

controllers/remote/cluster_cache_tracker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ func (t *ClusterCacheTracker) healthCheckCluster(ctx context.Context, in *health
520520
cfg.NegotiatedSerializer = serializer.NegotiatedSerializerWrapper(runtime.SerializerInfo{Serializer: codec})
521521
restClient, restClientErr := rest.UnversionedRESTClientFor(cfg)
522522

523-
runHealthCheckWithThreshold := func() (bool, error) {
523+
runHealthCheckWithThreshold := func(ctx context.Context) (bool, error) {
524524
if restClientErr != nil {
525525
return false, restClientErr
526526
}
@@ -576,12 +576,12 @@ func (t *ClusterCacheTracker) healthCheckCluster(ctx context.Context, in *health
576576
return false, nil
577577
}
578578

579-
err := wait.PollImmediateUntil(in.interval, runHealthCheckWithThreshold, ctx.Done())
579+
err := wait.PollUntilContextCancel(ctx, in.interval, true, runHealthCheckWithThreshold)
580580
// An error returned implies the health check has failed a sufficient number of
581581
// times for the cluster to be considered unhealthy
582582
// NB. we are ignoring ErrWaitTimeout because this error happens when the channel is close, that in this case
583583
// happens when the cache is explicitly stopped.
584-
if err != nil && err != wait.ErrWaitTimeout {
584+
if err != nil && !wait.Interrupted(err) {
585585
t.log.Error(err, "Error health checking cluster", "Cluster", klog.KRef(in.cluster.Namespace, in.cluster.Name))
586586
t.deleteAccessor(ctx, in.cluster)
587587
}

exp/runtime/internal/controllers/warmup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (r *warmupRunnable) Start(ctx context.Context) error {
7272
ctx, cancel := context.WithTimeout(ctx, r.warmupTimeout)
7373
defer cancel()
7474

75-
err := wait.PollImmediateWithContext(ctx, r.warmupInterval, r.warmupTimeout, func(ctx context.Context) (done bool, err error) {
75+
err := wait.PollUntilContextTimeout(ctx, r.warmupInterval, r.warmupTimeout, true, func(ctx context.Context) (done bool, err error) {
7676
if err = warmupRegistry(ctx, r.Client, r.APIReader, r.RuntimeClient); err != nil {
7777
log.Error(err, "ExtensionConfig registry warmup failed")
7878
return false, nil

0 commit comments

Comments
 (0)