Skip to content

Commit

Permalink
bump controller-runtime to 0.19
Browse files Browse the repository at this point in the history
1. replace controller-runtime/pkg/ratelimiter to k8s.io/client-go/util/workqueue
2. regenerate mock code
3. remove Controller Manager ConfigFile logic according by kubernetes-sigs/controller-runtime#895 and https://github.com/guacamole-operator/guacamole-operator/pull/35/files#diff-2873f79a86c0d8b3335cd7731b0ecf7dd4301eb19a82ef7a1cba7589b5252261
4. remove unused replacement in go.mod
5. remove admission.DecoderInjector, we should set decoder explicitly

in controller-runtime 1.19, controller-runtime/pkg/ratelimiter has been removed
replace controller-runtime/pkg/ratelimiter to k8s.io/client-go/util/workqueue
  • Loading branch information
jtcheng committed Oct 23, 2024
1 parent 2fe9867 commit 32e2d63
Show file tree
Hide file tree
Showing 17 changed files with 482 additions and 468 deletions.
15 changes: 0 additions & 15 deletions config/feature_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"knative.dev/pkg/logging"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// ListByFeatureFlagChanged when the function switch is changed, get the object function that triggers reconile.
Expand All @@ -44,17 +40,6 @@ func defaultFeatureChanged(new *FeatureFlags, old *FeatureFlags) bool {
return equality.Semantic.DeepEqual(new, old)
}

// WatchFeatureFlagChanged trigger reconcile when the function switch is changed.
func (manager *Manager) WatchFeatureFlagChanged(ctx context.Context, listFunc ListByFeatureFlagChanged, featureChanged HasFeatureChangedFunc) (source.Source, handler.EventHandler, builder.WatchesOption) {

return &source.Kind{Type: &corev1.ConfigMap{}},
handler.EnqueueRequestsFromMapFunc(enqueueRequestsConfigMapFunc(ctx, listFunc)),
// determine whether the function switch has changed, and return true when it changes.
builder.WithPredicates(predicate.Funcs{
UpdateFunc: predicatesUpdateFunc(manager, featureChanged),
})
}

func enqueueRequestsConfigMapFunc(ctx context.Context, listFunc ListByFeatureFlagChanged) func(client.Object) []reconcile.Request {
return func(obj client.Object) (reqs []reconcile.Request) {
reqs = []reconcile.Request{}
Expand Down
7 changes: 4 additions & 3 deletions controllers/builderoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
package controllers

import (
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/ratelimiter"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

// DefaultMaxConcurrentReconciles is the default number of max concurrent reconciles
Expand All @@ -41,7 +42,7 @@ func BuilderOptions(opts ...BuilderOptionFunc) controller.Options {
func DefaultOptions() controller.Options {
return controller.Options{
MaxConcurrentReconciles: DefaultMaxConcurrentReconciles,
RateLimiter: DefaultRateLimiter(),
RateLimiter: DefaultTypedRateLimiter[reconcile.Request](),
}
}

Expand All @@ -54,7 +55,7 @@ func MaxConCurrentReconciles(num int) BuilderOptionFunc {
}

// RateLimiter sets the rate limiter
func RateLimiter(rl ratelimiter.RateLimiter) BuilderOptionFunc {
func RateLimiter(rl workqueue.TypedRateLimiter[reconcile.Request]) BuilderOptionFunc {
return func(options controller.Options) controller.Options {
options.RateLimiter = rl
return options
Expand Down
3 changes: 2 additions & 1 deletion controllers/builderoptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
. "github.com/onsi/gomega"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

var _ = Describe("Test.BuilderOptions", func() {
Expand All @@ -43,7 +44,7 @@ var _ = Describe("Test.BuilderOptions", func() {
})

Context("builderoptions with custom rate limiter", func() {
customRateLimiter := workqueue.NewMaxOfRateLimiter()
customRateLimiter := workqueue.NewTypedMaxOfRateLimiter[reconcile.Request]()

BeforeEach(func() {
buildOptFuns = append(buildOptFuns, RateLimiter(customRateLimiter))
Expand Down
3 changes: 2 additions & 1 deletion controllers/controllerbuilderoptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -34,7 +35,7 @@ var _ = Describe("Test.ApplyControllerBuilderOptions", func() {

BeforeEach(func() {
builderFuncs = append(builderFuncs, WithBuilderOptions(controller.Options{
RateLimiter: DefaultRateLimiter(),
RateLimiter: DefaultTypedRateLimiter[reconcile.Request](),
}))
})

Expand Down
11 changes: 11 additions & 0 deletions controllers/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,21 @@ import (

// DefaultRateLimiter returns a workqueue rate limiter with a starting value of 2 seconds
// opposed to controller-runtime's default one of 1 millisecond
// Deprecated: DefaultRateLimiter is deprecated, use DefaultTypedRateLimiter instead.
func DefaultRateLimiter() workqueue.RateLimiter {
return workqueue.NewMaxOfRateLimiter(
workqueue.NewItemExponentialFailureRateLimiter(2*time.Second, 1000*time.Second),
// 10 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item)
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
)
}

// DefaultTypedRateLimiter returns a workqueue rate limiter with a starting value of 2 seconds
// opposed to controller-runtime's default one of 1 millisecond
func DefaultTypedRateLimiter[T comparable]() workqueue.TypedRateLimiter[T] {
return workqueue.NewTypedMaxOfRateLimiter(
workqueue.NewTypedItemExponentialFailureRateLimiter[T](2*time.Second, 1000*time.Second),
// 10 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item)
&workqueue.TypedBucketRateLimiter[T]{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
)
}
140 changes: 68 additions & 72 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
module github.com/katanomi/pkg

go 1.18
go 1.22.0

toolchain go1.22.7

require (
github.com/blendle/zapdriver v1.3.1
github.com/cloudevents/sdk-go/v2 v2.15.2
github.com/davecgh/go-spew v1.1.1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/emicklei/go-restful-openapi/v2 v2.3.0
github.com/emicklei/go-restful/v3 v3.10.2
github.com/go-logr/logr v1.4.1
github.com/emicklei/go-restful/v3 v3.12.1
github.com/go-logr/logr v1.4.2
github.com/go-logr/zapr v1.3.0
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-resty/resty/v2 v2.6.0
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0
github.com/jarcoal/httpmock v1.0.8
github.com/onsi/ginkgo/v2 v2.17.0
github.com/onsi/gomega v1.30.0
github.com/prometheus/client_golang v1.16.0
github.com/onsi/ginkgo/v2 v2.20.0
github.com/onsi/gomega v1.34.1
github.com/prometheus/client_golang v1.19.1
go.uber.org/zap v1.27.0
golang.org/x/sync v0.6.0
golang.org/x/time v0.5.0
k8s.io/api v0.27.1
k8s.io/apimachinery v0.29.0
k8s.io/apiserver v0.26.10
k8s.io/client-go v0.27.1
golang.org/x/sync v0.8.0
golang.org/x/time v0.6.0
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/apiserver v0.31.0
k8s.io/client-go v0.31.0
knative.dev/pkg v0.0.0-20231023150739-56bfe0dd9626
sigs.k8s.io/controller-runtime v0.14.7
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/yaml v1.4.0
yunion.io/x/log v0.0.0-20201210064738-43181789dc74 // indirect
yunion.io/x/pkg v0.0.0-20210218105412-13a69f60034c
)

require (
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
go.opentelemetry.io/otel/exporters/zipkin v1.2.0
go.opentelemetry.io/otel/sdk v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
)

require (
Expand All @@ -50,45 +52,48 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/pkg/errors v0.9.1
github.com/robfig/cron/v3 v3.0.1
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
golang.org/x/net v0.24.0
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
golang.org/x/net v0.30.0
k8s.io/cli-runtime v0.25.2
k8s.io/klog/v2 v2.100.1
k8s.io/klog/v2 v2.130.1
)

require (
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20240320155624-b11c3daa6f07 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -99,74 +104,65 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/spdystream v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/statsd_exporter v0.21.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/prometheus/statsd_exporter v0.22.7 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/tools v0.26.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/api v0.156.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/api v0.183.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.26.10 // indirect
k8s.io/component-base v0.26.10 // indirect
k8s.io/kube-openapi v0.0.0-20230525220651-2546d827e515 // indirect
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/component-base v0.31.0 // indirect
k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.12.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/openzipkin/zipkin-go v0.4.0 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106
github.com/openzipkin/zipkin-go v0.4.3 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
)

replace (
go.uber.org/zap => github.com/katanomi/zap v1.27.0-katanomi // indirect
knative.dev/pkg => github.com/katanomi/knative-pkg v0.0.0-20240409030957-1aad1aa6fd94
)

// TODO: Remove this once https://github.com/knative/pkg/issues/2759 is fixed
replace (
k8s.io/api => k8s.io/api v0.26.7
k8s.io/apimachinery => k8s.io/apimachinery v0.26.7
k8s.io/client-go => k8s.io/client-go v0.26.7
k8s.io/code-generator => k8s.io/code-generator v0.26.7
knative.dev/pkg => github.com/katanomi/knative-pkg v0.0.0-20241021183759-9b9d535af5ad
)
Loading

0 comments on commit 32e2d63

Please sign in to comment.