Skip to content

Commit

Permalink
Fix linting errors caused by workqueue rate limiter (#2852)
Browse files Browse the repository at this point in the history
This updates rate limiters where possible to make use of newer, generic,
rate limiters.
Eliminating remaining errors would require updating `rancher/lasso`'s
`SharedControllerFactoryOptions`, therefore this commit simply ignores
them through `golangci-lint` configuration.
  • Loading branch information
weyfonk authored Sep 16, 2024
1 parent 2ce68bd commit 8c173a1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .golangci.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
"path": "internal/cmd/agent/register/register.go",
"text": "G107: Potential HTTP request made with variable url"
},
{
"path": "internal/cmd",
"text": "SA1019: workqueue.RateLimiter is deprecated"
},
{
"path": "internal/cmd/agent/deployer/internal/",
"linters": [
Expand Down
5 changes: 4 additions & 1 deletion internal/cmd/agent/clusterstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ func newSharedControllerFactory(config *rest.Config, mapper meta.RESTMapper, nam
DefaultNamespace: namespace,
DefaultResync: durations.DefaultResyncAgent,
})
slowRateLimiter := workqueue.NewItemExponentialFailureRateLimiter(durations.SlowFailureRateLimiterBase, durations.SlowFailureRateLimiterMax)
slowRateLimiter := workqueue.NewTypedItemExponentialFailureRateLimiter[any](
durations.SlowFailureRateLimiterBase,
durations.SlowFailureRateLimiterMax,
)

return controller.NewSharedControllerFactory(cacheFactory, &controller.SharedControllerFactoryOptions{
KindRateLimiter: map[schema.GroupVersionKind]workqueue.RateLimiter{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,14 @@ func NewAppContext(cfg clientcmd.ClientConfig) (*AppContext, error) {
}

func controllerFactory(rest *rest.Config) (controller.SharedControllerFactory, error) {
rateLimit := workqueue.NewItemExponentialFailureRateLimiter(durations.FailureRateLimiterBase, durations.FailureRateLimiterMax)
clusterRateLimiter := workqueue.NewItemExponentialFailureRateLimiter(durations.SlowFailureRateLimiterBase, durations.SlowFailureRateLimiterMax)
rateLimit := workqueue.NewTypedItemExponentialFailureRateLimiter[any](
durations.FailureRateLimiterBase,
durations.FailureRateLimiterMax,
)
clusterRateLimiter := workqueue.NewTypedItemExponentialFailureRateLimiter[any](
durations.SlowFailureRateLimiterBase,
durations.SlowFailureRateLimiterMax,
)
clientFactory, err := client.NewSharedClientFactory(rest, nil)
if err != nil {
return nil, err
Expand Down
10 changes: 8 additions & 2 deletions internal/cmd/controller/cleanup/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,14 @@ func NewAppContext(cfg clientcmd.ClientConfig) (*AppContext, error) {
}

func controllerFactory(rest *rest.Config) (controller.SharedControllerFactory, error) {
rateLimit := workqueue.NewItemExponentialFailureRateLimiter(durations.FailureRateLimiterBase, durations.FailureRateLimiterMax)
clusterRateLimiter := workqueue.NewItemExponentialFailureRateLimiter(durations.SlowFailureRateLimiterBase, durations.SlowFailureRateLimiterMax)
rateLimit := workqueue.NewTypedItemExponentialFailureRateLimiter[any](
durations.FailureRateLimiterBase,
durations.FailureRateLimiterMax,
)
clusterRateLimiter := workqueue.NewTypedItemExponentialFailureRateLimiter[any](
durations.SlowFailureRateLimiterBase,
durations.SlowFailureRateLimiterMax,
)
clientFactory, err := client.NewSharedClientFactory(rest, nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit 8c173a1

Please sign in to comment.