Skip to content

Commit

Permalink
Merge pull request #999 from fluxcd/test-reconciler-ratelimiter
Browse files Browse the repository at this point in the history
Set rate limiter option in test reconcilers
  • Loading branch information
darkowlzz authored Jan 18, 2023
2 parents c2e605a + e0cf840 commit e0d9585
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
6 changes: 5 additions & 1 deletion controllers/gitrepository_controller_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/fluxcd/pkg/gittestserver"
"github.com/fluxcd/pkg/runtime/controller"
"github.com/fluxcd/pkg/runtime/testenv"

sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
)

Expand Down Expand Up @@ -448,7 +450,9 @@ func ensureDependencies() error {
utilruntime.Must((&GitRepositoryReconciler{
Client: m.GetClient(),
Storage: storage,
}).SetupWithManager(m))
}).SetupWithManagerAndOptions(m, GitRepositoryReconcilerOptions{
RateLimiter: controller.GetDefaultRateLimiter(),
}))
})

return nil
Expand Down
40 changes: 26 additions & 14 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"testing"
"time"

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

dcontext "github.com/distribution/distribution/v3/context"
"github.com/fluxcd/pkg/runtime/controller"
"github.com/fluxcd/pkg/runtime/testenv"
"github.com/fluxcd/pkg/testserver"
"github.com/phayes/freeport"
"github.com/sirupsen/logrus"

"github.com/distribution/distribution/v3/configuration"
dcontext "github.com/distribution/distribution/v3/context"
dockerRegistry "github.com/distribution/distribution/v3/registry"
_ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"

"github.com/fluxcd/pkg/runtime/controller"
"github.com/fluxcd/pkg/runtime/testenv"
"github.com/fluxcd/pkg/testserver"

sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
"github.com/fluxcd/source-controller/internal/cache"
"github.com/fluxcd/source-controller/internal/features"
Expand Down Expand Up @@ -241,7 +241,9 @@ func TestMain(m *testing.M) {
features: map[string]bool{
features.OptimizedGitClones: true,
},
}).SetupWithManager(testEnv); err != nil {
}).SetupWithManagerAndOptions(testEnv, GitRepositoryReconcilerOptions{
RateLimiter: controller.GetDefaultRateLimiter(),
}); err != nil {
panic(fmt.Sprintf("Failed to start GitRepositoryReconciler: %v", err))
}

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

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

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

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

Expand All @@ -298,8 +308,10 @@ func TestMain(m *testing.M) {
Cache: testCache,
TTL: 1 * time.Second,
CacheRecorder: cacheRecorder,
}).SetupWithManager(testEnv); err != nil {
panic(fmt.Sprintf("Failed to start HelmRepositoryReconciler: %v", err))
}).SetupWithManagerAndOptions(testEnv, HelmChartReconcilerOptions{
RateLimiter: controller.GetDefaultRateLimiter(),
}); err != nil {
panic(fmt.Sprintf("Failed to start HelmChartReconciler: %v", err))
}

go func() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/fluxcd/pkg/lockedfile v0.1.0
github.com/fluxcd/pkg/masktoken v0.2.0
github.com/fluxcd/pkg/oci v0.17.0
github.com/fluxcd/pkg/runtime v0.25.0
github.com/fluxcd/pkg/runtime v0.26.0
github.com/fluxcd/pkg/sourceignore v0.3.0
github.com/fluxcd/pkg/ssh v0.7.0
github.com/fluxcd/pkg/testserver v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ github.com/fluxcd/pkg/masktoken v0.2.0 h1:HoSPTk4l1fz5Fevs2vVRvZGru33blfMwWSZKsH
github.com/fluxcd/pkg/masktoken v0.2.0/go.mod h1:EA7GleAHL33kN6kTW06m5R3/Q26IyuGO7Ef/0CtpDI0=
github.com/fluxcd/pkg/oci v0.17.0 h1:DYoT0HG3DogEmeXRif6ZzTYwAZe+iqYWP4QpsP37ZBE=
github.com/fluxcd/pkg/oci v0.17.0/go.mod h1:UjxCQcdcKtog/ad9Vr2yPYjz9keNSoLdTOOiUNqCRiY=
github.com/fluxcd/pkg/runtime v0.25.0 h1:Lk5WrKDJKsayymLnnSCY/Zn77/mrlIf+skYz64suoww=
github.com/fluxcd/pkg/runtime v0.25.0/go.mod h1:I2T+HWVNzX0cxm9TgH+SVNHTwqlmEDiSke43JXsq9iY=
github.com/fluxcd/pkg/runtime v0.26.0 h1:j78f52xzpbR8xOvvemGwbGt4BLxpn9FOzim5tngOYvo=
github.com/fluxcd/pkg/runtime v0.26.0/go.mod h1:I2T+HWVNzX0cxm9TgH+SVNHTwqlmEDiSke43JXsq9iY=
github.com/fluxcd/pkg/sourceignore v0.3.0 h1:pFO3hKV9ub+2SrNZPZE7xfiRhxsycRrd7JK7qB26nVw=
github.com/fluxcd/pkg/sourceignore v0.3.0/go.mod h1:ak3Tve/KwVzytZ5V2yBlGGpTJ/2oQ9kcP3iuwBOAHGo=
github.com/fluxcd/pkg/ssh v0.7.0 h1:FX5ky8SU9dYwbM6zEIDR3TSveLF01iyS95CtB5Ykpno=
Expand Down

0 comments on commit e0d9585

Please sign in to comment.