@@ -474,5 +474,78 @@ var _ = Describe("controller.Controller", func() {
474474 _ , ok = q .(priorityqueue.PriorityQueue [reconcile.Request ])
475475 Expect (ok ).To (BeFalse ())
476476 })
477+
478+ It ("should set ShouldWarmupWithoutLeadership correctly" , func () {
479+ m , err := manager .New (cfg , manager.Options {})
480+ Expect (err ).NotTo (HaveOccurred ())
481+
482+ // Test with ShouldWarmupWithoutLeadership set to true
483+ ctrlWithWarmup , err := controller .New ("warmup-enabled-ctrl" , m , controller.Options {
484+ Reconciler : reconcile .Func (nil ),
485+ ShouldWarmupWithoutLeadership : ptr .To (true ),
486+ })
487+ Expect (err ).NotTo (HaveOccurred ())
488+
489+ internalCtrlWithWarmup , ok := ctrlWithWarmup .(* internalcontroller.Controller [reconcile.Request ])
490+ Expect (ok ).To (BeTrue ())
491+ Expect (internalCtrlWithWarmup .ShouldWarmupWithoutLeadership ).NotTo (BeNil ())
492+ Expect (* internalCtrlWithWarmup .ShouldWarmupWithoutLeadership ).To (BeTrue ())
493+
494+ // Test with ShouldWarmupWithoutLeadership set to false
495+ ctrlWithoutWarmup , err := controller .New ("warmup-disabled-ctrl" , m , controller.Options {
496+ Reconciler : reconcile .Func (nil ),
497+ ShouldWarmupWithoutLeadership : ptr .To (false ),
498+ })
499+ Expect (err ).NotTo (HaveOccurred ())
500+
501+ internalCtrlWithoutWarmup , ok := ctrlWithoutWarmup .(* internalcontroller.Controller [reconcile.Request ])
502+ Expect (ok ).To (BeTrue ())
503+ Expect (internalCtrlWithoutWarmup .ShouldWarmupWithoutLeadership ).NotTo (BeNil ())
504+ Expect (* internalCtrlWithoutWarmup .ShouldWarmupWithoutLeadership ).To (BeFalse ())
505+
506+ // Test with ShouldWarmupWithoutLeadership not set (should default to nil)
507+ ctrlWithDefaultWarmup , err := controller .New ("warmup-default-ctrl" , m , controller.Options {
508+ Reconciler : reconcile .Func (nil ),
509+ })
510+ Expect (err ).NotTo (HaveOccurred ())
511+
512+ internalCtrlWithDefaultWarmup , ok := ctrlWithDefaultWarmup .(* internalcontroller.Controller [reconcile.Request ])
513+ Expect (ok ).To (BeTrue ())
514+ Expect (internalCtrlWithDefaultWarmup .ShouldWarmupWithoutLeadership ).To (BeNil ())
515+ })
516+
517+ It ("should inherit ShouldWarmupWithoutLeadership from manager config" , func () {
518+ // Test with manager default setting ShouldWarmupWithoutLeadership to true
519+ managerWithWarmup , err := manager .New (cfg , manager.Options {
520+ Controller : config.Controller {
521+ NeedWarmUp : ptr .To (true ),
522+ },
523+ })
524+ Expect (err ).NotTo (HaveOccurred ())
525+ ctrlInheritingWarmup , err := controller .New ("inherit-warmup-enabled" , managerWithWarmup , controller.Options {
526+ Reconciler : reconcile .Func (nil ),
527+ })
528+ Expect (err ).NotTo (HaveOccurred ())
529+
530+ internalCtrlInheritingWarmup , ok := ctrlInheritingWarmup .(* internalcontroller.Controller [reconcile.Request ])
531+ Expect (ok ).To (BeTrue ())
532+ // Note: This test will fail until the DefaultFromConfig method is updated to set
533+ // ShouldWarmupWithoutLeadership from config.Controller.NeedWarmUp
534+ // This test demonstrates that the feature needs to be completed
535+ Expect (internalCtrlInheritingWarmup .ShouldWarmupWithoutLeadership ).NotTo (BeNil ())
536+ Expect (* internalCtrlInheritingWarmup .ShouldWarmupWithoutLeadership ).To (BeTrue ())
537+
538+ // Test that explicit controller setting overrides manager setting
539+ ctrlOverridingWarmup , err := controller .New ("override-warmup-disabled" , managerWithWarmup , controller.Options {
540+ Reconciler : reconcile .Func (nil ),
541+ ShouldWarmupWithoutLeadership : ptr .To (false ),
542+ })
543+ Expect (err ).NotTo (HaveOccurred ())
544+
545+ internalCtrlOverridingWarmup , ok := ctrlOverridingWarmup .(* internalcontroller.Controller [reconcile.Request ])
546+ Expect (ok ).To (BeTrue ())
547+ Expect (internalCtrlOverridingWarmup .ShouldWarmupWithoutLeadership ).NotTo (BeNil ())
548+ Expect (* internalCtrlOverridingWarmup .ShouldWarmupWithoutLeadership ).To (BeFalse ())
549+ })
477550 })
478551})
0 commit comments