Skip to content

Commit dd73b50

Browse files
committed
refactor: refactor away from deprecated wait.Poll calls
With the update, some other calls had to be updated: - `NewDiscoveryRESTMapper` expects an extra `HTTPClient` argument - `client` does not have `NewDelegatingClient` anymore, instead we can create the same resource with `client.New(...)` Resolves #3812 References: - #3812 - kubernetes-sigs/controller-runtime#2150 - https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.15.0 Signed-off-by: Balazs Nadasdi <balazs@weave.works>
1 parent bd4bb27 commit dd73b50

File tree

10 files changed

+47
-59
lines changed

10 files changed

+47
-59
lines changed

core/clustersmngr/cluster/delegating_cache.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ func (c *delegatingCacheCluster) GetHost() string {
4141
}
4242

4343
func (c *delegatingCacheCluster) makeCachingClient(leafClient client.Client) (client.Client, error) {
44-
mapper, err := apiutil.NewDiscoveryRESTMapper(c.restConfig)
44+
httpClient, err := rest.HTTPClientFor(c.restConfig)
45+
if err != nil {
46+
return nil, fmt.Errorf("could not create HTTP client from config: %w", err)
47+
}
48+
49+
mapper, err := apiutil.NewDiscoveryRESTMapper(c.restConfig, httpClient)
4550
if err != nil {
4651
return nil, fmt.Errorf("could not create RESTMapper from config: %w", err)
4752
}
@@ -58,16 +63,16 @@ func (c *delegatingCacheCluster) makeCachingClient(leafClient client.Client) (cl
5863
// https://github.com/kubernetes-sigs/controller-runtime/pull/2150
5964
delegatingCache := newDelegatingCache(leafClient, cache, c.scheme)
6065

61-
delegatingClient, err := client.NewDelegatingClient(client.NewDelegatingClientInput{
62-
CacheReader: delegatingCache,
63-
Client: leafClient,
64-
// Non-exact field matches are not supported by the cache.
65-
// https://github.com/kubernetes-sigs/controller-runtime/issues/612
66-
// TODO: Research if we can change the way we query those events so we can enable the cache for it.
67-
UncachedObjects: []client.Object{&v1.Event{}},
68-
CacheUnstructured: true,
66+
delegatingClient, err := client.New(c.restConfig, client.Options{
67+
Cache: &client.CacheOptions{
68+
Reader: delegatingCache,
69+
// Non-exact field matches are not supported by the cache.
70+
// https://github.com/kubernetes-sigs/controller-runtime/issues/612
71+
// TODO: Research if we can change the way we query those events so we can enable the cache for it.
72+
DisableFor: []client.Object{&v1.Event{}},
73+
Unstructured: true,
74+
},
6975
})
70-
7176
if err != nil {
7277
return nil, fmt.Errorf("failed creating DelegatingClient: %w", err)
7378
}

core/clustersmngr/cluster/single.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ func (c *singleCluster) GetHost() string {
5555
}
5656

5757
func getClientFromConfig(config *rest.Config, scheme *apiruntime.Scheme) (client.Client, error) {
58-
mapper, err := apiutil.NewDiscoveryRESTMapper(config)
58+
httpClient, err := rest.HTTPClientFor(config)
59+
if err != nil {
60+
return nil, fmt.Errorf("could not create HTTP client from config: %w", err)
61+
}
62+
63+
mapper, err := apiutil.NewDiscoveryRESTMapper(config, httpClient)
5964
if err != nil {
6065
return nil, fmt.Errorf("could not create RESTMapper from config: %w", err)
6166
}

go.mod

-11
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,3 @@ require (
231231

232232
// Use patched version that fixed recursive gets, and force delete for buckets
233233
replace github.com/johannesboyne/gofakes3 => github.com/chanwit/gofakes3 v0.0.0-20220715114300-3f51f1961f7b
234-
235-
// Replace k8s.io packages v0.26 to downgrade controller-runtime to v0.14.6
236-
replace (
237-
k8s.io/api => k8s.io/api v0.26.8
238-
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.26.8
239-
k8s.io/apimachinery => k8s.io/apimachinery v0.26.8
240-
k8s.io/cli-runtime => k8s.io/cli-runtime v0.26.8
241-
k8s.io/client-go => k8s.io/client-go v0.26.8
242-
243-
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.14.6
244-
)

go.sum

+10-11
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55k
143143
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
144144
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
145145
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
146-
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc=
147146
github.com/emicklei/go-restful/v3 v3.10.0 h1:X4gma4HM7hFm6WMeAsTfqA0GOfdNoCzBIkHGoRLGXuM=
148147
github.com/emicklei/go-restful/v3 v3.10.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
149148
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
@@ -1061,16 +1060,16 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
10611060
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
10621061
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
10631062
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
1064-
k8s.io/api v0.26.8 h1:k2OtFmQPWfDUyAuYAwQPftVygF/vz4BMGSKnd15iddM=
1065-
k8s.io/api v0.26.8/go.mod h1:QaflR7cmG3V9lIz0VLBM+ylndNN897OAUAoJDcgwiQw=
1066-
k8s.io/apiextensions-apiserver v0.26.8 h1:ESVQ22MH6YfcpflpZMIvkgnHs/EwOgKKSCkS9AfxJOY=
1067-
k8s.io/apiextensions-apiserver v0.26.8/go.mod h1:ySo6rPc9ulNtKoZczw7ljCAdZN3DbyxLNat8wuYk4r8=
1068-
k8s.io/apimachinery v0.26.8 h1:SzpGtRX3/j/Ylg8Eg65Iobpxi9Jz4vOvI0qcBZyPVrM=
1069-
k8s.io/apimachinery v0.26.8/go.mod h1:qYzLkrQ9lhrZRh0jNKo2cfvf/R1/kQONnSiyB7NUJU0=
1063+
k8s.io/api v0.27.3 h1:yR6oQXXnUEBWEWcvPWS0jQL575KoAboQPfJAuKNrw5Y=
1064+
k8s.io/api v0.27.3/go.mod h1:C4BNvZnQOF7JA/0Xed2S+aUyJSfTGkGFxLXz9MnpIpg=
1065+
k8s.io/apiextensions-apiserver v0.27.3 h1:xAwC1iYabi+TDfpRhxh4Eapl14Hs2OftM2DN5MpgKX4=
1066+
k8s.io/apiextensions-apiserver v0.27.3/go.mod h1:BH3wJ5NsB9XE1w+R6SSVpKmYNyIiyIz9xAmBl8Mb+84=
1067+
k8s.io/apimachinery v0.27.3 h1:Ubye8oBufD04l9QnNtW05idcOe9Z3GQN8+7PqmuVcUM=
1068+
k8s.io/apimachinery v0.27.3/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E=
10701069
k8s.io/cli-runtime v0.26.8 h1:LFiS+z20j8gt9Iyo4EsbivzrDYPRbFFj8wmpwdhy7cQ=
10711070
k8s.io/cli-runtime v0.26.8/go.mod h1:j3YQ0OtQnqsQRsMWbmZrKqbOvN2OUu0K+dPffeKPVj0=
1072-
k8s.io/client-go v0.26.8 h1:pPuTYaVtLlg/7n6rqs3MsKLi4XgNaJ3rTMyS37Y5CKU=
1073-
k8s.io/client-go v0.26.8/go.mod h1:1sBQqKmdy9rWZYQnoedpc0gnRXG7kU3HrKZvBe2QbGM=
1071+
k8s.io/client-go v0.27.3 h1:7dnEGHZEJld3lYwxvLl7WoehK6lAq7GvgjxpA3nv1E8=
1072+
k8s.io/client-go v0.27.3/go.mod h1:2MBEKuTo6V1lbKy3z1euEGnhPfGZLKTS9tiJ2xodM48=
10741073
k8s.io/component-base v0.27.3 h1:g078YmdcdTfrCE4fFobt7qmVXwS8J/3cI1XxRi/2+6k=
10751074
k8s.io/component-base v0.27.3/go.mod h1:JNiKYcGImpQ44iwSYs6dysxzR9SxIIgQalk4HaCNVUY=
10761075
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
@@ -1087,8 +1086,8 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
10871086
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
10881087
sigs.k8s.io/cli-utils v0.34.0 h1:zCUitt54f0/MYj/ajVFnG6XSXMhpZ72O/3RewIchW8w=
10891088
sigs.k8s.io/cli-utils v0.34.0/go.mod h1:EXyMwPMu9OL+LRnj0JEMsGG/fRvbgFadcVlSnE8RhFs=
1090-
sigs.k8s.io/controller-runtime v0.14.6 h1:oxstGVvXGNnMvY7TAESYk+lzr6S3V5VFxQ6d92KcwQA=
1091-
sigs.k8s.io/controller-runtime v0.14.6/go.mod h1:WqIdsAY6JBsjfc/CqO0CORmNtoCtE4S6qbPc9s68h+0=
1089+
sigs.k8s.io/controller-runtime v0.15.0 h1:ML+5Adt3qZnMSYxZ7gAverBLNPSMQEibtzAgp0UPojU=
1090+
sigs.k8s.io/controller-runtime v0.15.0/go.mod h1:7ngYvp1MLT+9GeZ+6lH3LOlcHkp/+tzA/fmHa4iq9kk=
10921091
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
10931092
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
10941093
sigs.k8s.io/kustomize/api v0.12.1 h1:7YM7gW3kYBwtKvoY216ZzY+8hM+lV53LUayghNRJ0vM=

pkg/run/install/install_dashboard.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ func ReconcileDashboard(ctx context.Context, kubeClient client.Client, dashboard
228228

229229
var sourceRequestedAt string
230230

231-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
232-
if err := wait.Poll(interval, timeout, func() (bool, error) {
231+
if err := wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(_ context.Context) (bool, error) {
233232
var err error
234233
sourceRequestedAt, err = run.RequestReconciliation(ctx, kubeClient,
235234
namespacedName, gvk)
@@ -240,8 +239,7 @@ func ReconcileDashboard(ctx context.Context, kubeClient client.Client, dashboard
240239
}
241240

242241
// wait for the reconciliation of dashboard to be done
243-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
244-
if err := wait.Poll(interval, timeout, func() (bool, error) {
242+
if err := wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(_ context.Context) (bool, error) {
245243
dashboard := &sourcev1b2.HelmChart{}
246244
if err := kubeClient.Get(ctx, types.NamespacedName{
247245
Namespace: namespace,
@@ -256,8 +254,7 @@ func ReconcileDashboard(ctx context.Context, kubeClient client.Client, dashboard
256254
}
257255

258256
// wait for dashboard to be ready
259-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
260-
if err := wait.Poll(interval, timeout, func() (bool, error) {
257+
if err := wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(_ context.Context) (bool, error) {
261258
namespacedName := types.NamespacedName{Namespace: namespace, Name: podName}
262259

263260
var labels map[string]string = nil

pkg/run/install/install_fluent_bit.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"
87
"html/template"
98
"strings"
109
"time"
1110

11+
sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"
12+
1213
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
1314
"github.com/weaveworks/weave-gitops/pkg/logger"
1415
"github.com/weaveworks/weave-gitops/pkg/run/constants"
@@ -270,8 +271,7 @@ func InstallFluentBit(ctx context.Context, log logger.Logger, kubeClient client.
270271

271272
log.Actionf("waiting for HelmRelease %s/%s to be ready", helmRelease.Namespace, helmRelease.Name)
272273

273-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
274-
if err := wait.Poll(2*time.Second, 5*time.Minute, func() (bool, error) {
274+
if err := wait.PollUntilContextTimeout(context.Background(), time.Second*2, time.Minute*5, true, func(_ context.Context) (bool, error) {
275275
instance := appsv1.DaemonSet{}
276276
if err := kubeClient.Get(
277277
ctx,

pkg/run/install/install_vcluster.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package install
33
import (
44
"context"
55
"fmt"
6-
sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"
76
"os"
87
"path/filepath"
98
"strings"
109
"time"
1110

11+
sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"
12+
1213
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
1314
"github.com/weaveworks/weave-gitops/cmd/gitops/version"
1415
coretypes "github.com/weaveworks/weave-gitops/core/server/types"
@@ -133,8 +134,7 @@ func installVCluster(kubeClient client.Client, name, namespace, fluxNamespace st
133134
}
134135
}
135136

136-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
137-
if err := wait.Poll(2*time.Second, 5*time.Minute, func() (bool, error) {
137+
if err := wait.PollUntilContextTimeout(context.Background(), time.Second*2, time.Minute*5, true, func(_ context.Context) (bool, error) {
138138
instance := appsv1.StatefulSet{}
139139
if err := kubeClient.Get(
140140
context.Background(),

pkg/run/session/connect/connect.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,7 @@ func (conn *Connection) createServiceAccountToken(vKubeConfig api.Config) (strin
607607
token := ""
608608
conn.Log.Actionf("Create service account token for %s/%s", serviceAccountNamespace, serviceAccount)
609609

610-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
611-
err = wait.Poll(time.Second, time.Minute*3, func() (bool, error) {
610+
err = wait.PollUntilContextTimeout(context.Background(), time.Second*2, time.Minute*5, true, func(_ context.Context) (bool, error) {
612611
// check if namespace exists
613612
_, err := vKubeClient.CoreV1().Namespaces().Get(context.TODO(), serviceAccountNamespace, metav1.GetOptions{})
614613
if err != nil {

pkg/run/session/remove.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ func Remove(kubeClient client.Client, session *InternalSession) error {
4242
result = multierror.Append(result, err)
4343
}
4444

45-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
46-
if err := wait.Poll(2*time.Second, 5*time.Minute, func() (bool, error) {
45+
if err := wait.PollUntilContextTimeout(context.Background(), time.Second*2, time.Minute*5, true, func(_ context.Context) (bool, error) {
4746
instance := appsv1.StatefulSet{}
4847
if err := kubeClient.Get(
4948
context.Background(),
@@ -62,8 +61,7 @@ func Remove(kubeClient client.Client, session *InternalSession) error {
6261
result = multierror.Append(result, err)
6362
}
6463

65-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
66-
if err := wait.Poll(2*time.Second, 5*time.Minute, func() (bool, error) {
64+
if err := wait.PollUntilContextTimeout(context.Background(), time.Second*2, time.Minute*5, true, func(_ context.Context) (bool, error) {
6765
pvc := corev1.PersistentVolumeClaim{}
6866
if err := kubeClient.Get(
6967
context.Background(),

pkg/run/watch/setup_dev_ks.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ func ReconcileDevBucketSourceAndKS(ctx context.Context, log logger.Logger, kubeC
429429
}
430430

431431
// wait for the reconciliation of dev-bucket to be done
432-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
433-
if err := wait.Poll(interval, timeout, func() (bool, error) {
432+
if err := wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(_ context.Context) (bool, error) {
434433
devBucket := &sourcev1b2.Bucket{}
435434
if err := kubeClient.Get(ctx, types.NamespacedName{
436435
Name: constants.RunDevBucketName,
@@ -445,8 +444,7 @@ func ReconcileDevBucketSourceAndKS(ctx context.Context, log logger.Logger, kubeC
445444
}
446445

447446
// wait for devBucket to be ready
448-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
449-
if err := wait.Poll(interval, timeout, func() (bool, error) {
447+
if err := wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(_ context.Context) (bool, error) {
450448
devBucket := &sourcev1b2.Bucket{}
451449
if err := kubeClient.Get(ctx, types.NamespacedName{
452450
Name: constants.RunDevBucketName,
@@ -473,8 +471,7 @@ func ReconcileDevBucketSourceAndKS(ctx context.Context, log logger.Logger, kubeC
473471
return err
474472
}
475473

476-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
477-
if err := wait.Poll(interval, timeout, func() (bool, error) {
474+
if err := wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(_ context.Context) (bool, error) {
478475
devKs := &kustomizev1.Kustomization{}
479476
if err := kubeClient.Get(ctx, types.NamespacedName{
480477
Name: constants.RunDevKsName,
@@ -489,8 +486,7 @@ func ReconcileDevBucketSourceAndKS(ctx context.Context, log logger.Logger, kubeC
489486
}
490487

491488
devKs := &kustomizev1.Kustomization{}
492-
//nolint:staticcheck // deprecated, tracking issue: https://github.com/weaveworks/weave-gitops/issues/3812
493-
devKsErr := wait.Poll(interval, timeout, func() (bool, error) {
489+
devKsErr := wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(_ context.Context) (bool, error) {
494490
if err := kubeClient.Get(ctx, types.NamespacedName{
495491
Name: constants.RunDevKsName,
496492
Namespace: namespace,

0 commit comments

Comments
 (0)