Skip to content

Commit e0d9585

Browse files
authored
Merge pull request #999 from fluxcd/test-reconciler-ratelimiter
Set rate limiter option in test reconcilers
2 parents c2e605a + e0cf840 commit e0d9585

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

controllers/gitrepository_controller_fuzz_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ import (
5959
"sigs.k8s.io/controller-runtime/pkg/manager"
6060

6161
"github.com/fluxcd/pkg/gittestserver"
62+
"github.com/fluxcd/pkg/runtime/controller"
6263
"github.com/fluxcd/pkg/runtime/testenv"
64+
6365
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
6466
)
6567

@@ -448,7 +450,9 @@ func ensureDependencies() error {
448450
utilruntime.Must((&GitRepositoryReconciler{
449451
Client: m.GetClient(),
450452
Storage: storage,
451-
}).SetupWithManager(m))
453+
}).SetupWithManagerAndOptions(m, GitRepositoryReconcilerOptions{
454+
RateLimiter: controller.GetDefaultRateLimiter(),
455+
}))
452456
})
453457

454458
return nil

controllers/suite_test.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"testing"
2929
"time"
3030

31+
"github.com/phayes/freeport"
32+
"github.com/sirupsen/logrus"
3133
"golang.org/x/crypto/bcrypt"
3234
"helm.sh/helm/v3/pkg/getter"
3335
helmreg "helm.sh/helm/v3/pkg/registry"
@@ -36,18 +38,16 @@ import (
3638
"k8s.io/client-go/tools/record"
3739
ctrl "sigs.k8s.io/controller-runtime"
3840

39-
dcontext "github.com/distribution/distribution/v3/context"
40-
"github.com/fluxcd/pkg/runtime/controller"
41-
"github.com/fluxcd/pkg/runtime/testenv"
42-
"github.com/fluxcd/pkg/testserver"
43-
"github.com/phayes/freeport"
44-
"github.com/sirupsen/logrus"
45-
4641
"github.com/distribution/distribution/v3/configuration"
42+
dcontext "github.com/distribution/distribution/v3/context"
4743
dockerRegistry "github.com/distribution/distribution/v3/registry"
4844
_ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
4945
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
5046

47+
"github.com/fluxcd/pkg/runtime/controller"
48+
"github.com/fluxcd/pkg/runtime/testenv"
49+
"github.com/fluxcd/pkg/testserver"
50+
5151
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
5252
"github.com/fluxcd/source-controller/internal/cache"
5353
"github.com/fluxcd/source-controller/internal/features"
@@ -241,7 +241,9 @@ func TestMain(m *testing.M) {
241241
features: map[string]bool{
242242
features.OptimizedGitClones: true,
243243
},
244-
}).SetupWithManager(testEnv); err != nil {
244+
}).SetupWithManagerAndOptions(testEnv, GitRepositoryReconcilerOptions{
245+
RateLimiter: controller.GetDefaultRateLimiter(),
246+
}); err != nil {
245247
panic(fmt.Sprintf("Failed to start GitRepositoryReconciler: %v", err))
246248
}
247249

@@ -250,7 +252,9 @@ func TestMain(m *testing.M) {
250252
EventRecorder: record.NewFakeRecorder(32),
251253
Metrics: testMetricsH,
252254
Storage: testStorage,
253-
}).SetupWithManager(testEnv); err != nil {
255+
}).SetupWithManagerAndOptions(testEnv, BucketReconcilerOptions{
256+
RateLimiter: controller.GetDefaultRateLimiter(),
257+
}); err != nil {
254258
panic(fmt.Sprintf("Failed to start BucketReconciler: %v", err))
255259
}
256260

@@ -262,7 +266,9 @@ func TestMain(m *testing.M) {
262266
EventRecorder: record.NewFakeRecorder(32),
263267
Metrics: testMetricsH,
264268
Storage: testStorage,
265-
}).SetupWithManager(testEnv); err != nil {
269+
}).SetupWithManagerAndOptions(testEnv, OCIRepositoryReconcilerOptions{
270+
RateLimiter: controller.GetDefaultRateLimiter(),
271+
}); err != nil {
266272
panic(fmt.Sprintf("Failed to start OCIRepositoryReconciler: %v", err))
267273
}
268274

@@ -275,7 +281,9 @@ func TestMain(m *testing.M) {
275281
Cache: testCache,
276282
TTL: 1 * time.Second,
277283
CacheRecorder: cacheRecorder,
278-
}).SetupWithManager(testEnv); err != nil {
284+
}).SetupWithManagerAndOptions(testEnv, HelmRepositoryReconcilerOptions{
285+
RateLimiter: controller.GetDefaultRateLimiter(),
286+
}); err != nil {
279287
panic(fmt.Sprintf("Failed to start HelmRepositoryReconciler: %v", err))
280288
}
281289

@@ -285,7 +293,9 @@ func TestMain(m *testing.M) {
285293
Metrics: testMetricsH,
286294
Getters: testGetters,
287295
RegistryClientGenerator: registry.ClientGenerator,
288-
}).SetupWithManager(testEnv); err != nil {
296+
}).SetupWithManagerAndOptions(testEnv, HelmRepositoryReconcilerOptions{
297+
RateLimiter: controller.GetDefaultRateLimiter(),
298+
}); err != nil {
289299
panic(fmt.Sprintf("Failed to start HelmRepositoryOCIReconciler: %v", err))
290300
}
291301

@@ -298,8 +308,10 @@ func TestMain(m *testing.M) {
298308
Cache: testCache,
299309
TTL: 1 * time.Second,
300310
CacheRecorder: cacheRecorder,
301-
}).SetupWithManager(testEnv); err != nil {
302-
panic(fmt.Sprintf("Failed to start HelmRepositoryReconciler: %v", err))
311+
}).SetupWithManagerAndOptions(testEnv, HelmChartReconcilerOptions{
312+
RateLimiter: controller.GetDefaultRateLimiter(),
313+
}); err != nil {
314+
panic(fmt.Sprintf("Failed to start HelmChartReconciler: %v", err))
303315
}
304316

305317
go func() {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/fluxcd/pkg/lockedfile v0.1.0
3232
github.com/fluxcd/pkg/masktoken v0.2.0
3333
github.com/fluxcd/pkg/oci v0.17.0
34-
github.com/fluxcd/pkg/runtime v0.25.0
34+
github.com/fluxcd/pkg/runtime v0.26.0
3535
github.com/fluxcd/pkg/sourceignore v0.3.0
3636
github.com/fluxcd/pkg/ssh v0.7.0
3737
github.com/fluxcd/pkg/testserver v0.4.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ github.com/fluxcd/pkg/masktoken v0.2.0 h1:HoSPTk4l1fz5Fevs2vVRvZGru33blfMwWSZKsH
549549
github.com/fluxcd/pkg/masktoken v0.2.0/go.mod h1:EA7GleAHL33kN6kTW06m5R3/Q26IyuGO7Ef/0CtpDI0=
550550
github.com/fluxcd/pkg/oci v0.17.0 h1:DYoT0HG3DogEmeXRif6ZzTYwAZe+iqYWP4QpsP37ZBE=
551551
github.com/fluxcd/pkg/oci v0.17.0/go.mod h1:UjxCQcdcKtog/ad9Vr2yPYjz9keNSoLdTOOiUNqCRiY=
552-
github.com/fluxcd/pkg/runtime v0.25.0 h1:Lk5WrKDJKsayymLnnSCY/Zn77/mrlIf+skYz64suoww=
553-
github.com/fluxcd/pkg/runtime v0.25.0/go.mod h1:I2T+HWVNzX0cxm9TgH+SVNHTwqlmEDiSke43JXsq9iY=
552+
github.com/fluxcd/pkg/runtime v0.26.0 h1:j78f52xzpbR8xOvvemGwbGt4BLxpn9FOzim5tngOYvo=
553+
github.com/fluxcd/pkg/runtime v0.26.0/go.mod h1:I2T+HWVNzX0cxm9TgH+SVNHTwqlmEDiSke43JXsq9iY=
554554
github.com/fluxcd/pkg/sourceignore v0.3.0 h1:pFO3hKV9ub+2SrNZPZE7xfiRhxsycRrd7JK7qB26nVw=
555555
github.com/fluxcd/pkg/sourceignore v0.3.0/go.mod h1:ak3Tve/KwVzytZ5V2yBlGGpTJ/2oQ9kcP3iuwBOAHGo=
556556
github.com/fluxcd/pkg/ssh v0.7.0 h1:FX5ky8SU9dYwbM6zEIDR3TSveLF01iyS95CtB5Ykpno=

0 commit comments

Comments
 (0)