Skip to content

Commit 89f5479

Browse files
committed
Rename NeedWarmup to EnableWarmup.
1 parent a49f3a4 commit 89f5479

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

pkg/config/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ type Controller struct {
6060
// Defaults to true, which means the controller will use leader election.
6161
NeedLeaderElection *bool
6262

63-
// NeedWarmup specifies whether the controller should start its sources when the manager is not
63+
// EnableWarmup specifies whether the controller should start its sources when the manager is not
6464
// the leader. This is useful for cases where sources take a long time to start, as it allows
6565
// for the controller to warm up its caches even before it is elected as the leader. This
6666
// improves leadership failover time, as the caches will be prepopulated before the controller
6767
// transitions to be leader.
6868
//
69-
// Setting NeedWarmup to true and NeedLeaderElection to true means the controller will start its
69+
// Setting EnableWarmup to true and NeedLeaderElection to true means the controller will start its
7070
// sources without waiting to become leader.
71-
// Setting NeedWarmup to true and NeedLeaderElection is false is a no-op as controllers without
71+
// Setting EnableWarmup to true and NeedLeaderElection is false is a no-op as controllers without
7272
// leader election do not wait on leader election to start their sources.
7373
// Defaults to false.
74-
NeedWarmup *bool
74+
EnableWarmup *bool
7575

7676
// UsePriorityQueue configures the controllers queue to use the controller-runtime provided
7777
// priority queue.

pkg/controller/controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ type TypedOptions[request comparable] struct {
9494
// Note: This flag is disabled by default until a future version. It's currently in beta.
9595
UsePriorityQueue *bool
9696

97-
// NeedWarmup specifies whether the controller should start its sources when the manager is not
97+
// EnableWarmup specifies whether the controller should start its sources when the manager is not
9898
// the leader. This is useful for cases where sources take a long time to start, as it allows
9999
// for the controller to warm up its caches even before it is elected as the leader. This
100100
// improves leadership failover time, as the caches will be prepopulated before the controller
101101
// transitions to be leader.
102102
//
103103
// When set to true, the controller will start its sources without transitioning to be leader.
104104
// Defaults to false.
105-
NeedWarmup *bool
105+
EnableWarmup *bool
106106
}
107107

108108
// DefaultFromConfig defaults the config from a config.Controller
@@ -135,8 +135,8 @@ func (options *TypedOptions[request]) DefaultFromConfig(config config.Controller
135135
options.NeedLeaderElection = config.NeedLeaderElection
136136
}
137137

138-
if options.NeedWarmup == nil {
139-
options.NeedWarmup = config.NeedWarmup
138+
if options.EnableWarmup == nil {
139+
options.EnableWarmup = config.EnableWarmup
140140
}
141141
}
142142

@@ -267,7 +267,7 @@ func NewTypedUnmanaged[request comparable](name string, options TypedOptions[req
267267
LogConstructor: options.LogConstructor,
268268
RecoverPanic: options.RecoverPanic,
269269
LeaderElected: options.NeedLeaderElection,
270-
NeedWarmup: options.NeedWarmup,
270+
EnableWarmup: options.EnableWarmup,
271271
}, nil
272272
}
273273

pkg/controller/controller_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -475,48 +475,48 @@ var _ = Describe("controller.Controller", func() {
475475
Expect(ok).To(BeFalse())
476476
})
477477

478-
It("should set NeedWarmup correctly", func() {
478+
It("should set EnableWarmup correctly", func() {
479479
m, err := manager.New(cfg, manager.Options{})
480480
Expect(err).NotTo(HaveOccurred())
481481

482-
// Test with NeedWarmup set to true
482+
// Test with EnableWarmup set to true
483483
ctrlWithWarmup, err := controller.New("warmup-enabled-ctrl", m, controller.Options{
484-
Reconciler: reconcile.Func(nil),
485-
NeedWarmup: ptr.To(true),
484+
Reconciler: reconcile.Func(nil),
485+
EnableWarmup: ptr.To(true),
486486
})
487487
Expect(err).NotTo(HaveOccurred())
488488

489489
internalCtrlWithWarmup, ok := ctrlWithWarmup.(*internalcontroller.Controller[reconcile.Request])
490490
Expect(ok).To(BeTrue())
491-
Expect(internalCtrlWithWarmup.NeedWarmup).To(HaveValue(BeTrue()))
491+
Expect(internalCtrlWithWarmup.EnableWarmup).To(HaveValue(BeTrue()))
492492

493-
// Test with NeedWarmup set to false
493+
// Test with EnableWarmup set to false
494494
ctrlWithoutWarmup, err := controller.New("warmup-disabled-ctrl", m, controller.Options{
495-
Reconciler: reconcile.Func(nil),
496-
NeedWarmup: ptr.To(false),
495+
Reconciler: reconcile.Func(nil),
496+
EnableWarmup: ptr.To(false),
497497
})
498498
Expect(err).NotTo(HaveOccurred())
499499

500500
internalCtrlWithoutWarmup, ok := ctrlWithoutWarmup.(*internalcontroller.Controller[reconcile.Request])
501501
Expect(ok).To(BeTrue())
502-
Expect(internalCtrlWithoutWarmup.NeedWarmup).To(HaveValue(BeFalse()))
502+
Expect(internalCtrlWithoutWarmup.EnableWarmup).To(HaveValue(BeFalse()))
503503

504-
// Test with NeedWarmup not set (should default to nil)
504+
// Test with EnableWarmup not set (should default to nil)
505505
ctrlWithDefaultWarmup, err := controller.New("warmup-default-ctrl", m, controller.Options{
506506
Reconciler: reconcile.Func(nil),
507507
})
508508
Expect(err).NotTo(HaveOccurred())
509509

510510
internalCtrlWithDefaultWarmup, ok := ctrlWithDefaultWarmup.(*internalcontroller.Controller[reconcile.Request])
511511
Expect(ok).To(BeTrue())
512-
Expect(internalCtrlWithDefaultWarmup.NeedWarmup).To(BeNil())
512+
Expect(internalCtrlWithDefaultWarmup.EnableWarmup).To(BeNil())
513513
})
514514

515-
It("should inherit NeedWarmup from manager config", func() {
516-
// Test with manager default setting NeedWarmup to true
515+
It("should inherit EnableWarmup from manager config", func() {
516+
// Test with manager default setting EnableWarmup to true
517517
managerWithWarmup, err := manager.New(cfg, manager.Options{
518518
Controller: config.Controller{
519-
NeedWarmup: ptr.To(true),
519+
EnableWarmup: ptr.To(true),
520520
},
521521
})
522522
Expect(err).NotTo(HaveOccurred())
@@ -527,18 +527,18 @@ var _ = Describe("controller.Controller", func() {
527527

528528
internalCtrlInheritingWarmup, ok := ctrlInheritingWarmup.(*internalcontroller.Controller[reconcile.Request])
529529
Expect(ok).To(BeTrue())
530-
Expect(internalCtrlInheritingWarmup.NeedWarmup).To(HaveValue(BeTrue()))
530+
Expect(internalCtrlInheritingWarmup.EnableWarmup).To(HaveValue(BeTrue()))
531531

532532
// Test that explicit controller setting overrides manager setting
533533
ctrlOverridingWarmup, err := controller.New("override-warmup-disabled", managerWithWarmup, controller.Options{
534-
Reconciler: reconcile.Func(nil),
535-
NeedWarmup: ptr.To(false),
534+
Reconciler: reconcile.Func(nil),
535+
EnableWarmup: ptr.To(false),
536536
})
537537
Expect(err).NotTo(HaveOccurred())
538538

539539
internalCtrlOverridingWarmup, ok := ctrlOverridingWarmup.(*internalcontroller.Controller[reconcile.Request])
540540
Expect(ok).To(BeTrue())
541-
Expect(internalCtrlOverridingWarmup.NeedWarmup).To(HaveValue(BeFalse()))
541+
Expect(internalCtrlOverridingWarmup.EnableWarmup).To(HaveValue(BeFalse()))
542542
})
543543
})
544544
})

pkg/internal/controller/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ type Controller[request comparable] struct {
112112
// LeaderElected indicates whether the controller is leader elected or always running.
113113
LeaderElected *bool
114114

115-
// NeedWarmup specifies whether the controller should start its sources
115+
// EnableWarmup specifies whether the controller should start its sources
116116
// when the manager is not the leader.
117117
// Defaults to false, which means that the controller will wait for leader election to start
118118
// before starting sources.
119-
NeedWarmup *bool
119+
EnableWarmup *bool
120120
}
121121

122122
// Reconcile implements reconcile.Reconciler.
@@ -168,7 +168,7 @@ func (c *Controller[request]) NeedLeaderElection() bool {
168168

169169
// Warmup implements the manager.WarmupRunnable interface.
170170
func (c *Controller[request]) Warmup(ctx context.Context) error {
171-
if c.NeedWarmup == nil || !*c.NeedWarmup {
171+
if c.EnableWarmup == nil || !*c.EnableWarmup {
172172
return nil
173173
}
174174

@@ -183,7 +183,7 @@ func (c *Controller[request]) Warmup(ctx context.Context) error {
183183
// WaitForWarmupComplete returns true if warmup has completed without error, and false if there was
184184
// an error during warmup. If context is cancelled, it returns true.
185185
func (c *Controller[request]) WaitForWarmupComplete(ctx context.Context) bool {
186-
if c.NeedWarmup == nil || !*c.NeedWarmup {
186+
if c.EnableWarmup == nil || !*c.EnableWarmup {
187187
return true
188188
}
189189

pkg/internal/controller/controller_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ var _ = Describe("controller", func() {
10511051

10521052
Describe("Warmup", func() {
10531053
JustBeforeEach(func() {
1054-
ctrl.NeedWarmup = ptr.To(true)
1054+
ctrl.EnableWarmup = ptr.To(true)
10551055
})
10561056

10571057
It("should track warmup status correctly with successful sync", func() {
@@ -1165,7 +1165,7 @@ var _ = Describe("controller", func() {
11651165
return log.RuntimeLog.WithName("controller").WithName("test")
11661166
},
11671167
CacheSyncTimeout: time.Second,
1168-
NeedWarmup: ptr.To(false),
1168+
EnableWarmup: ptr.To(false),
11691169
LeaderElected: ptr.To(true),
11701170
startWatches: []source.TypedSource[reconcile.Request]{
11711171
source.Func(func(ctx context.Context, _ workqueue.TypedRateLimitingInterface[reconcile.Request]) error {
@@ -1206,7 +1206,7 @@ var _ = Describe("controller", func() {
12061206

12071207
Describe("Warmup with warmup disabled", func() {
12081208
JustBeforeEach(func() {
1209-
ctrl.NeedWarmup = ptr.To(false)
1209+
ctrl.EnableWarmup = ptr.To(false)
12101210
})
12111211

12121212
It("should not start sources when Warmup is called if warmup is disabled but start it when Start is called.", func() {
@@ -1224,12 +1224,12 @@ var _ = Describe("controller", func() {
12241224
}),
12251225
}
12261226

1227-
By("Calling Warmup when NeedWarmup is false")
1227+
By("Calling Warmup when EnableWarmup is false")
12281228
err := ctrl.Warmup(ctx)
12291229
Expect(err).NotTo(HaveOccurred())
12301230
Expect(isSourceStarted.Load()).To(BeFalse())
12311231

1232-
By("Calling Start when NeedWarmup is false")
1232+
By("Calling Start when EnableWarmup is false")
12331233
// Now call Start
12341234
go func() {
12351235
defer GinkgoRecover()
@@ -1241,7 +1241,7 @@ var _ = Describe("controller", func() {
12411241

12421242
Describe("WaitForWarmupComplete", func() {
12431243
It("should short circuit without blocking if warmup is disabled", func() {
1244-
ctrl.NeedWarmup = ptr.To(false)
1244+
ctrl.EnableWarmup = ptr.To(false)
12451245

12461246
ctx, cancel := context.WithCancel(context.Background())
12471247
defer cancel()
@@ -1252,7 +1252,7 @@ var _ = Describe("controller", func() {
12521252
})
12531253

12541254
It("should block until warmup is complete if warmup is enabled", func() {
1255-
ctrl.NeedWarmup = ptr.To(true)
1255+
ctrl.EnableWarmup = ptr.To(true)
12561256
// Setup controller with sources that complete successfully
12571257
ctx, cancel := context.WithCancel(context.Background())
12581258
defer cancel()

0 commit comments

Comments
 (0)