Skip to content

Commit 1119540

Browse files
committed
Merge remote-tracking branch 'origin/eks_overhead_friendly_benchmarks' into eks_overhead_friendly_benchmarks
2 parents 1205ed6 + cd02d78 commit 1119540

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

pkg/operator/operator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
"sigs.k8s.io/controller-runtime/pkg/cache"
4949
"sigs.k8s.io/controller-runtime/pkg/client"
5050
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
51+
ctrlconfig "sigs.k8s.io/controller-runtime/pkg/config"
5152
"sigs.k8s.io/controller-runtime/pkg/healthz"
5253
"sigs.k8s.io/controller-runtime/pkg/log"
5354
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -179,6 +180,12 @@ func NewOperator(o ...option.Function[Options]) (context.Context, *Operator) {
179180
},
180181
},
181182
},
183+
Controller: ctrlconfig.Controller{
184+
// EnableWarmup allows controllers to start their sources (watches/informers) before leader election
185+
// is won. This pre-populates caches and improves leader failover time. Only effective when leader
186+
// election is enabled, so we only set it when both conditions are true.
187+
EnableWarmup: lo.ToPtr(!options.FromContext(ctx).DisableLeaderElection && !options.FromContext(ctx).DisableControllerWarmup),
188+
},
182189
}
183190
if options.FromContext(ctx).EnableProfiling {
184191
// TODO @joinnis: Investigate the mgrOpts.PprofBindAddress that would allow native support for pprof

pkg/operator/options/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Options struct {
7171
KubeClientQPS int
7272
KubeClientBurst int
7373
EnableProfiling bool
74+
DisableControllerWarmup bool
7475
DisableLeaderElection bool
7576
DisableClusterStateObservability bool
7677
LeaderElectionName string
@@ -114,6 +115,7 @@ func (o *Options) AddFlags(fs *FlagSet) {
114115
fs.IntVar(&o.KubeClientQPS, "kube-client-qps", env.WithDefaultInt("KUBE_CLIENT_QPS", 200), "The smoothed rate of qps to kube-apiserver")
115116
fs.IntVar(&o.KubeClientBurst, "kube-client-burst", env.WithDefaultInt("KUBE_CLIENT_BURST", 300), "The maximum allowed burst of queries to the kube-apiserver")
116117
fs.BoolVarWithEnv(&o.EnableProfiling, "enable-profiling", "ENABLE_PROFILING", false, "Enable the profiling on the metric endpoint")
118+
fs.BoolVarWithEnv(&o.DisableControllerWarmup, "disable-controller-warmup", "DISABLE_CONTROLLER_WARMUP", true, "Disable controller warmup which starts controller sources before leader election is won. Controller warmup pre-populates caches and improves leader failover time.")
117119
fs.BoolVarWithEnv(&o.DisableLeaderElection, "disable-leader-election", "DISABLE_LEADER_ELECTION", false, "Disable the leader election client before executing the main loop. Disable when running replicated components for high availability is not desired.")
118120
fs.BoolVarWithEnv(&o.DisableClusterStateObservability, "disable-cluster-state-observability", "DISABLE_CLUSTER_STATE_OBSERVABILITY", false, "Disable cluster state metrics and events")
119121
fs.StringVar(&o.LeaderElectionName, "leader-election-name", env.WithDefaultString("LEADER_ELECTION_NAME", "karpenter-leader-election"), "Leader election name to create and monitor the lease if running outside the cluster")

pkg/operator/options/suite_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var _ = Describe("Options", func() {
5252
"KUBE_CLIENT_QPS",
5353
"KUBE_CLIENT_BURST",
5454
"ENABLE_PROFILING",
55+
"DISABLE_CONTROLLER_WARMUP",
5556
"DISABLE_LEADER_ELECTION",
5657
"DISABLE_CLUSTER_STATE_OBSERVABILITY",
5758
"LEADER_ELECTION_NAMESPACE",
@@ -106,6 +107,7 @@ var _ = Describe("Options", func() {
106107
KubeClientQPS: lo.ToPtr(200),
107108
KubeClientBurst: lo.ToPtr(300),
108109
EnableProfiling: lo.ToPtr(false),
110+
DisableControllerWarmup: lo.ToPtr(true),
109111
DisableLeaderElection: lo.ToPtr(false),
110112
DisableClusterStateObservability: lo.ToPtr(false),
111113
LeaderElectionName: lo.ToPtr("karpenter-leader-election"),
@@ -140,6 +142,7 @@ var _ = Describe("Options", func() {
140142
"--kube-client-qps", "0",
141143
"--kube-client-burst", "0",
142144
"--enable-profiling",
145+
"--disable-controller-warmup=false",
143146
"--disable-leader-election=true",
144147
"--disable-cluster-state-observability=true",
145148
"--leader-election-name=karpenter-controller",
@@ -162,6 +165,7 @@ var _ = Describe("Options", func() {
162165
KubeClientQPS: lo.ToPtr(0),
163166
KubeClientBurst: lo.ToPtr(0),
164167
EnableProfiling: lo.ToPtr(true),
168+
DisableControllerWarmup: lo.ToPtr(false),
165169
DisableLeaderElection: lo.ToPtr(true),
166170
DisableClusterStateObservability: lo.ToPtr(true),
167171
LeaderElectionName: lo.ToPtr("karpenter-controller"),
@@ -192,6 +196,7 @@ var _ = Describe("Options", func() {
192196
os.Setenv("KUBE_CLIENT_QPS", "0")
193197
os.Setenv("KUBE_CLIENT_BURST", "0")
194198
os.Setenv("ENABLE_PROFILING", "true")
199+
os.Setenv("DISABLE_CONTROLLER_WARMUP", "false")
195200
os.Setenv("DISABLE_LEADER_ELECTION", "true")
196201
os.Setenv("DISABLE_CLUSTER_STATE_OBSERVABILITY", "true")
197202
os.Setenv("LEADER_ELECTION_NAME", "karpenter-controller")
@@ -218,6 +223,7 @@ var _ = Describe("Options", func() {
218223
KubeClientQPS: lo.ToPtr(0),
219224
KubeClientBurst: lo.ToPtr(0),
220225
EnableProfiling: lo.ToPtr(true),
226+
DisableControllerWarmup: lo.ToPtr(false),
221227
DisableLeaderElection: lo.ToPtr(true),
222228
DisableClusterStateObservability: lo.ToPtr(true),
223229
LeaderElectionName: lo.ToPtr("karpenter-controller"),
@@ -247,6 +253,7 @@ var _ = Describe("Options", func() {
247253
os.Setenv("KUBE_CLIENT_QPS", "0")
248254
os.Setenv("KUBE_CLIENT_BURST", "0")
249255
os.Setenv("ENABLE_PROFILING", "true")
256+
os.Setenv("DISABLE_CONTROLLER_WARMUP", "false")
250257
os.Setenv("DISABLE_LEADER_ELECTION", "true")
251258
os.Setenv("DISABLE_CLUSTER_STATE_OBSERVABILITY", "true")
252259
os.Setenv("MEMORY_LIMIT", "0")
@@ -276,6 +283,7 @@ var _ = Describe("Options", func() {
276283
KubeClientQPS: lo.ToPtr(0),
277284
KubeClientBurst: lo.ToPtr(0),
278285
EnableProfiling: lo.ToPtr(true),
286+
DisableControllerWarmup: lo.ToPtr(false),
279287
DisableLeaderElection: lo.ToPtr(true),
280288
DisableClusterStateObservability: lo.ToPtr(true),
281289
LeaderElectionName: lo.ToPtr("karpenter-leader-election"),
@@ -381,6 +389,7 @@ func expectOptionsMatch(optsA, optsB *options.Options) {
381389
Expect(optsA.KubeClientQPS).To(Equal(optsB.KubeClientQPS))
382390
Expect(optsA.KubeClientBurst).To(Equal(optsB.KubeClientBurst))
383391
Expect(optsA.EnableProfiling).To(Equal(optsB.EnableProfiling))
392+
Expect(optsA.DisableControllerWarmup).To(Equal(optsB.DisableControllerWarmup))
384393
Expect(optsA.DisableLeaderElection).To(Equal(optsB.DisableLeaderElection))
385394
Expect(optsA.DisableClusterStateObservability).To(Equal(optsB.DisableClusterStateObservability))
386395
Expect(optsA.MemoryLimit).To(Equal(optsB.MemoryLimit))

pkg/test/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type OptionsFields struct {
3434
KubeClientQPS *int
3535
KubeClientBurst *int
3636
EnableProfiling *bool
37+
DisableControllerWarmup *bool
3738
DisableLeaderElection *bool
3839
DisableClusterStateObservability *bool
3940
LeaderElectionName *string
@@ -74,6 +75,7 @@ func Options(overrides ...OptionsFields) *options.Options {
7475
KubeClientQPS: lo.FromPtrOr(opts.KubeClientQPS, 200),
7576
KubeClientBurst: lo.FromPtrOr(opts.KubeClientBurst, 300),
7677
EnableProfiling: lo.FromPtrOr(opts.EnableProfiling, false),
78+
DisableControllerWarmup: lo.FromPtrOr(opts.DisableControllerWarmup, true),
7779
DisableLeaderElection: lo.FromPtrOr(opts.DisableLeaderElection, false),
7880
DisableClusterStateObservability: lo.FromPtrOr(opts.DisableClusterStateObservability, false),
7981
MemoryLimit: lo.FromPtrOr(opts.MemoryLimit, -1),

0 commit comments

Comments
 (0)