Skip to content

Commit ae6a54e

Browse files
authored
Merge pull request #1213 from fluxcd/backport-1212-to-release/v1.7.x
[release/v1.7.x] Add feature gate for disabling config watchers
2 parents 6b8db98 + 52708cd commit ae6a54e

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/fluxcd/pkg/cache v0.12.0
2424
github.com/fluxcd/pkg/git v0.38.0
2525
github.com/fluxcd/pkg/masktoken v0.8.0
26-
github.com/fluxcd/pkg/runtime v0.90.0
26+
github.com/fluxcd/pkg/runtime v0.91.0
2727
github.com/fluxcd/pkg/ssa v0.61.0
2828
github.com/fluxcd/pkg/ssh v0.23.0
2929
github.com/getsentry/sentry-go v0.35.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ github.com/fluxcd/pkg/git v0.38.0 h1:fFH2PkL+VCtQ1aJec/6l3Wq5fQG1w02HHKfVY+gz1S4
155155
github.com/fluxcd/pkg/git v0.38.0/go.mod h1:PHilCGIM2t10CJ++yK4SFHIcBAXqMk14XcwZ/Rqw23I=
156156
github.com/fluxcd/pkg/masktoken v0.8.0 h1:Dm5xIVNbg0s6zNttjDvimaG38bKsXwxBVo5b+D7ThVU=
157157
github.com/fluxcd/pkg/masktoken v0.8.0/go.mod h1:Gc73ALOqIe+5Gj2V3JggMNiYcBiZ9bNNDYBE9R5XTTg=
158-
github.com/fluxcd/pkg/runtime v0.90.0 h1:IONDsN9npJdWqbSAfsI8j10sXpgaLd6ywycKwp35Wwo=
159-
github.com/fluxcd/pkg/runtime v0.90.0/go.mod h1:D/gUsaSpyw6Od2QEL7MELi5m+oUmwokuxUVZ+vKQxdo=
158+
github.com/fluxcd/pkg/runtime v0.91.0 h1:Z92sOLsJXa+0RIi/vNl87zF5qnsBUdOb60d2a0b4Ulo=
159+
github.com/fluxcd/pkg/runtime v0.91.0/go.mod h1:D/gUsaSpyw6Od2QEL7MELi5m+oUmwokuxUVZ+vKQxdo=
160160
github.com/fluxcd/pkg/ssa v0.61.0 h1:GeueQfZVrjPLEzmEkq6gpFTBr1MDcqUihCQDf6AaIo8=
161161
github.com/fluxcd/pkg/ssa v0.61.0/go.mod h1:PNRlgihYbmlQU5gzsB14nrsNMbtACNanBnKhLCWmeX8=
162162
github.com/fluxcd/pkg/ssh v0.23.0 h1:PqmBpQB7Rxspdb3LZZo2yflC7m990EU/cYtjK3sO3Tg=

internal/controller/receiver_controller.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,15 @@ type ReceiverReconciler struct {
5757

5858
type ReceiverReconcilerOptions struct {
5959
RateLimiter workqueue.TypedRateLimiter[reconcile.Request]
60+
WatchConfigs bool
6061
WatchConfigsPredicate predicate.Predicate
6162
}
6263

63-
func (r *ReceiverReconciler) SetupWithManager(mgr ctrl.Manager) error {
64-
return r.SetupWithManagerAndOptions(mgr, ReceiverReconcilerOptions{
65-
WatchConfigsPredicate: predicate.Not(predicate.Funcs{}),
66-
})
67-
}
68-
6964
const (
7065
secretRefIndex = ".metadata.secretRef"
7166
)
7267

73-
func (r *ReceiverReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts ReceiverReconcilerOptions) error {
68+
func (r *ReceiverReconciler) SetupWithManager(mgr ctrl.Manager, opts ReceiverReconcilerOptions) error {
7469
// This index is used to list Receivers by their webhook path after the receiver server
7570
// gets a request.
7671
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &apiv1.Receiver{},
@@ -87,19 +82,21 @@ func (r *ReceiverReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts R
8782
}); err != nil {
8883
}
8984

90-
return ctrl.NewControllerManagedBy(mgr).
85+
ctrlBuilder := ctrl.NewControllerManagedBy(mgr).
9186
For(&apiv1.Receiver{}, builder.WithPredicates(
9287
predicate.Or(predicate.GenerationChangedPredicate{}, predicates.ReconcileRequestedPredicate{}),
93-
)).
94-
WatchesMetadata(
95-
&corev1.Secret{},
96-
handler.EnqueueRequestsFromMapFunc(r.enqueueRequestsForChangeOf),
97-
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}, opts.WatchConfigsPredicate),
98-
).
99-
WithOptions(controller.Options{
100-
RateLimiter: opts.RateLimiter,
101-
}).
102-
Complete(r)
88+
))
89+
90+
if opts.WatchConfigs {
91+
ctrlBuilder = ctrlBuilder.
92+
WatchesMetadata(
93+
&corev1.Secret{},
94+
handler.EnqueueRequestsFromMapFunc(r.enqueueRequestsForChangeOf),
95+
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}, opts.WatchConfigsPredicate),
96+
)
97+
}
98+
99+
return ctrlBuilder.WithOptions(controller.Options{RateLimiter: opts.RateLimiter}).Complete(r)
103100
}
104101

105102
// enqueueRequestsForChangeOf enqueues Receiver requests for changes in referenced Secret objects.

internal/controller/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestMain(m *testing.M) {
9494
Metrics: testMetricsH,
9595
ControllerName: controllerName,
9696
EventRecorder: testEnv.GetEventRecorderFor(controllerName),
97-
}).SetupWithManagerAndOptions(testEnv, ReceiverReconcilerOptions{
97+
}).SetupWithManager(testEnv, ReceiverReconcilerOptions{
9898
RateLimiter: controller.GetDefaultRateLimiter(),
9999
WatchConfigsPredicate: predicate.Not(predicate.Funcs{}),
100100
}); err != nil {

internal/features/features.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package features
2020

2121
import (
2222
"github.com/fluxcd/pkg/auth"
23+
"github.com/fluxcd/pkg/runtime/controller"
2324
feathelper "github.com/fluxcd/pkg/runtime/features"
2425
)
2526

@@ -36,6 +37,9 @@ var features = map[string]bool{
3637
// CacheSecretsAndConfigMaps
3738
// opt-in from v0.31
3839
CacheSecretsAndConfigMaps: false,
40+
// DisableConfigWatchers
41+
// opt-in from v1.7.5
42+
controller.FeatureGateDisableConfigWatchers: false,
3943
}
4044

4145
func init() {

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ func main() {
226226
os.Exit(1)
227227
}
228228

229+
disableConfigWatchers, err := features.Enabled(runtimeCtrl.FeatureGateDisableConfigWatchers)
230+
if err != nil {
231+
setupLog.Error(err, "unable to check feature gate "+runtimeCtrl.FeatureGateDisableConfigWatchers)
232+
os.Exit(1)
233+
}
234+
watchConfigs := !disableConfigWatchers
235+
229236
if err = (&controller.ProviderReconciler{
230237
Client: mgr.GetClient(),
231238
EventRecorder: mgr.GetEventRecorderFor(controllerName),
@@ -249,8 +256,9 @@ func main() {
249256
ControllerName: controllerName,
250257
Metrics: metricsH,
251258
EventRecorder: mgr.GetEventRecorderFor(controllerName),
252-
}).SetupWithManagerAndOptions(mgr, controller.ReceiverReconcilerOptions{
259+
}).SetupWithManager(mgr, controller.ReceiverReconcilerOptions{
253260
RateLimiter: runtimeCtrl.GetRateLimiter(rateLimiterOptions),
261+
WatchConfigs: watchConfigs,
254262
WatchConfigsPredicate: watchConfigsPredicate,
255263
}); err != nil {
256264
setupLog.Error(err, "unable to create controller", "controller", "Receiver")

0 commit comments

Comments
 (0)