Skip to content

Commit 201f2d9

Browse files
committed
feat: introduce ControllerPriorityQueue feature gate
Signed-off-by: zach593 <[email protected]>
1 parent 8b14046 commit 201f2d9

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

cmd/agent/app/agent.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
logsv1 "k8s.io/component-base/logs/api/v1"
3535
"k8s.io/component-base/term"
3636
"k8s.io/klog/v2"
37+
"k8s.io/utils/ptr"
3738
controllerruntime "sigs.k8s.io/controller-runtime"
3839
"sigs.k8s.io/controller-runtime/pkg/cache"
3940
"sigs.k8s.io/controller-runtime/pkg/config"
@@ -225,6 +226,7 @@ func run(ctx context.Context, opts *options.Options) error {
225226
clusterv1alpha1.SchemeGroupVersion.WithKind("Cluster").GroupKind().String(): opts.ConcurrentClusterSyncs,
226227
},
227228
CacheSyncTimeout: opts.ClusterCacheSyncTimeout.Duration,
229+
UsePriorityQueue: ptr.To(features.FeatureGate.Enabled(features.ControllerPriorityQueue)),
228230
},
229231
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
230232
opts.DefaultTransform = fedinformer.StripUnusedFields

cmd/controller-manager/app/controllermanager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
resourceclient "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1"
3939
"k8s.io/metrics/pkg/client/custom_metrics"
4040
"k8s.io/metrics/pkg/client/external_metrics"
41+
"k8s.io/utils/ptr"
4142
controllerruntime "sigs.k8s.io/controller-runtime"
4243
"sigs.k8s.io/controller-runtime/pkg/cache"
4344
"sigs.k8s.io/controller-runtime/pkg/config"
@@ -193,6 +194,7 @@ func Run(ctx context.Context, opts *options.Options) error {
193194
schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"}.GroupKind().String(): opts.ConcurrentNamespaceSyncs,
194195
},
195196
CacheSyncTimeout: opts.ClusterCacheSyncTimeout.Duration,
197+
UsePriorityQueue: ptr.To(features.FeatureGate.Enabled(features.ControllerPriorityQueue)),
196198
},
197199
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
198200
opts.DefaultTransform = fedinformer.StripUnusedFields

pkg/features/features.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ const (
113113
// owner: @mszacillo, @Dyex719, @RainbowMango, @XiShanYongYe-Chang, @zhzhuang-zju, @seanlaii
114114
// alpha: v1.15
115115
MultiplePodTemplatesScheduling featuregate.Feature = "MultiplePodTemplatesScheduling"
116+
117+
// ControllerPriorityQueue controls whether the controller-runtime Priority Queue for controllers is enabled.
118+
// When enabled, during the startup phase of karmada-controller-manager and karmada-agent,
119+
// controllers implemented with controller-runtime will prioritize processing recent cluster changes first,
120+
// while deferring items without recent updates that still need to be processed to the end of the queue.
121+
// This helps the system quickly catch up with the latest state and reduces the perceived
122+
// backlog from external users.
123+
// However, enabling this feature may increase the overall number of reconciliations. This is
124+
// because newer events spend less time in the queue, which reduces the chance of them being
125+
// deduplicated before processing.
126+
//
127+
// owner: @zach593
128+
// alpha: v1.15
129+
ControllerPriorityQueue featuregate.Feature = "ControllerPriorityQueue"
116130
)
117131

118132
var (
@@ -139,6 +153,7 @@ var (
139153
LoggingBetaOptions: {Default: true, PreRelease: featuregate.Beta},
140154
ContextualLogging: {Default: true, PreRelease: featuregate.Beta},
141155
MultiplePodTemplatesScheduling: {Default: false, PreRelease: featuregate.Alpha},
156+
ControllerPriorityQueue: {Default: false, PreRelease: featuregate.Alpha},
142157
}
143158
)
144159

0 commit comments

Comments
 (0)