Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/fluxcd/pkg/cache v0.12.0
github.com/fluxcd/pkg/git v0.38.0
github.com/fluxcd/pkg/masktoken v0.8.0
github.com/fluxcd/pkg/runtime v0.90.0
github.com/fluxcd/pkg/runtime v0.91.0
github.com/fluxcd/pkg/ssa v0.61.0
github.com/fluxcd/pkg/ssh v0.23.0
github.com/getsentry/sentry-go v0.35.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ github.com/fluxcd/pkg/git v0.38.0 h1:fFH2PkL+VCtQ1aJec/6l3Wq5fQG1w02HHKfVY+gz1S4
github.com/fluxcd/pkg/git v0.38.0/go.mod h1:PHilCGIM2t10CJ++yK4SFHIcBAXqMk14XcwZ/Rqw23I=
github.com/fluxcd/pkg/masktoken v0.8.0 h1:Dm5xIVNbg0s6zNttjDvimaG38bKsXwxBVo5b+D7ThVU=
github.com/fluxcd/pkg/masktoken v0.8.0/go.mod h1:Gc73ALOqIe+5Gj2V3JggMNiYcBiZ9bNNDYBE9R5XTTg=
github.com/fluxcd/pkg/runtime v0.90.0 h1:IONDsN9npJdWqbSAfsI8j10sXpgaLd6ywycKwp35Wwo=
github.com/fluxcd/pkg/runtime v0.90.0/go.mod h1:D/gUsaSpyw6Od2QEL7MELi5m+oUmwokuxUVZ+vKQxdo=
github.com/fluxcd/pkg/runtime v0.91.0 h1:Z92sOLsJXa+0RIi/vNl87zF5qnsBUdOb60d2a0b4Ulo=
github.com/fluxcd/pkg/runtime v0.91.0/go.mod h1:D/gUsaSpyw6Od2QEL7MELi5m+oUmwokuxUVZ+vKQxdo=
github.com/fluxcd/pkg/ssa v0.61.0 h1:GeueQfZVrjPLEzmEkq6gpFTBr1MDcqUihCQDf6AaIo8=
github.com/fluxcd/pkg/ssa v0.61.0/go.mod h1:PNRlgihYbmlQU5gzsB14nrsNMbtACNanBnKhLCWmeX8=
github.com/fluxcd/pkg/ssh v0.23.0 h1:PqmBpQB7Rxspdb3LZZo2yflC7m990EU/cYtjK3sO3Tg=
Expand Down
33 changes: 15 additions & 18 deletions internal/controller/receiver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,15 @@ type ReceiverReconciler struct {

type ReceiverReconcilerOptions struct {
RateLimiter workqueue.TypedRateLimiter[reconcile.Request]
WatchConfigs bool
WatchConfigsPredicate predicate.Predicate
}

func (r *ReceiverReconciler) SetupWithManager(mgr ctrl.Manager) error {
return r.SetupWithManagerAndOptions(mgr, ReceiverReconcilerOptions{
WatchConfigsPredicate: predicate.Not(predicate.Funcs{}),
})
}

const (
secretRefIndex = ".metadata.secretRef"
)

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

return ctrl.NewControllerManagedBy(mgr).
ctrlBuilder := ctrl.NewControllerManagedBy(mgr).
For(&apiv1.Receiver{}, builder.WithPredicates(
predicate.Or(predicate.GenerationChangedPredicate{}, predicates.ReconcileRequestedPredicate{}),
)).
WatchesMetadata(
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.enqueueRequestsForChangeOf),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}, opts.WatchConfigsPredicate),
).
WithOptions(controller.Options{
RateLimiter: opts.RateLimiter,
}).
Complete(r)
))

if opts.WatchConfigs {
ctrlBuilder = ctrlBuilder.
WatchesMetadata(
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.enqueueRequestsForChangeOf),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}, opts.WatchConfigsPredicate),
)
}

return ctrlBuilder.WithOptions(controller.Options{RateLimiter: opts.RateLimiter}).Complete(r)
}

// enqueueRequestsForChangeOf enqueues Receiver requests for changes in referenced Secret objects.
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestMain(m *testing.M) {
Metrics: testMetricsH,
ControllerName: controllerName,
EventRecorder: testEnv.GetEventRecorderFor(controllerName),
}).SetupWithManagerAndOptions(testEnv, ReceiverReconcilerOptions{
}).SetupWithManager(testEnv, ReceiverReconcilerOptions{
RateLimiter: controller.GetDefaultRateLimiter(),
WatchConfigsPredicate: predicate.Not(predicate.Funcs{}),
}); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package features

import (
"github.com/fluxcd/pkg/auth"
"github.com/fluxcd/pkg/runtime/controller"
feathelper "github.com/fluxcd/pkg/runtime/features"
)

Expand All @@ -36,6 +37,9 @@ var features = map[string]bool{
// CacheSecretsAndConfigMaps
// opt-in from v0.31
CacheSecretsAndConfigMaps: false,
// DisableConfigWatchers
// opt-in from v1.7.5
controller.FeatureGateDisableConfigWatchers: false,
}

func init() {
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ func main() {
os.Exit(1)
}

disableConfigWatchers, err := features.Enabled(runtimeCtrl.FeatureGateDisableConfigWatchers)
if err != nil {
setupLog.Error(err, "unable to check feature gate "+runtimeCtrl.FeatureGateDisableConfigWatchers)
os.Exit(1)
}
watchConfigs := !disableConfigWatchers

if err = (&controller.ProviderReconciler{
Client: mgr.GetClient(),
EventRecorder: mgr.GetEventRecorderFor(controllerName),
Expand All @@ -249,8 +256,9 @@ func main() {
ControllerName: controllerName,
Metrics: metricsH,
EventRecorder: mgr.GetEventRecorderFor(controllerName),
}).SetupWithManagerAndOptions(mgr, controller.ReceiverReconcilerOptions{
}).SetupWithManager(mgr, controller.ReceiverReconcilerOptions{
RateLimiter: runtimeCtrl.GetRateLimiter(rateLimiterOptions),
WatchConfigs: watchConfigs,
WatchConfigsPredicate: watchConfigsPredicate,
}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Receiver")
Expand Down