diff --git a/controllers/featuregates/accessor.go b/controllers/featuregates/accessor.go index ce3a712c..11f76b1d 100644 --- a/controllers/featuregates/accessor.go +++ b/controllers/featuregates/accessor.go @@ -41,12 +41,15 @@ type Accessor interface { Start(context.Context) error // IsMachineAPIOperatorMHCDisabled returns if the Machine API Operator's MachineHealthCheck controller is disabled IsMachineAPIOperatorMHCDisabled() bool + // GetMHCControllerDisabledEvents returns the event channel for signalling a change + // in the MachineAPIOperatorDisableMachineHealthCheckController feature gate + GetMHCControllerDisabledEvents() <-chan event.GenericEvent } type accessor struct { config *rest.Config log logr.Logger - featureGateMHCControllerDisabledEvents chan<- event.GenericEvent + featureGateMHCControllerDisabledEvents chan event.GenericEvent featureGateAccessor featuregates.FeatureGateAccess isMaoMhcDisabled bool isMaoMhcDisabledLock *sync.Mutex @@ -54,7 +57,7 @@ type accessor struct { var _ Accessor = &accessor{} -func NewAccessor(cfg *rest.Config, featureGateMHCControllerDisabledEvents chan<- event.GenericEvent) Accessor { +func NewAccessor(cfg *rest.Config, featureGateMHCControllerDisabledEvents chan event.GenericEvent) Accessor { return &accessor{ config: cfg, log: ctrl.Log.WithName("FeatureGateAccessor"), @@ -118,6 +121,10 @@ func (fga *accessor) IsMachineAPIOperatorMHCDisabled() bool { return fga.isMaoMhcDisabled } +func (fga *accessor) GetMHCControllerDisabledEvents() <-chan event.GenericEvent { + return fga.featureGateMHCControllerDisabledEvents +} + func (fga *accessor) featureGateChanged(fc featuregates.FeatureChange) { fga.isMaoMhcDisabledLock.Lock() defer fga.isMaoMhcDisabledLock.Unlock() @@ -170,9 +177,12 @@ type FakeAccessor struct { var _ Accessor = &FakeAccessor{} -func (ds *FakeAccessor) Start(_ context.Context) error { +func (fa *FakeAccessor) Start(_ context.Context) error { return nil } -func (ds *FakeAccessor) IsMachineAPIOperatorMHCDisabled() bool { - return ds.IsMaoMhcDisabled +func (fa *FakeAccessor) IsMachineAPIOperatorMHCDisabled() bool { + return fa.IsMaoMhcDisabled +} +func (fa *FakeAccessor) GetMHCControllerDisabledEvents() <-chan event.GenericEvent { + return make(<-chan event.GenericEvent) } diff --git a/controllers/machinehealthcheck_controller.go b/controllers/machinehealthcheck_controller.go index 03e3b2cd..7007d5f0 100644 --- a/controllers/machinehealthcheck_controller.go +++ b/controllers/machinehealthcheck_controller.go @@ -49,12 +49,11 @@ var ( // MachineHealthCheckReconciler reconciles a MachineHealthCheck object type MachineHealthCheckReconciler struct { client.Client - Log logr.Logger - Recorder record.EventRecorder - ClusterUpgradeStatusChecker cluster.UpgradeChecker - MHCChecker mhc.Checker - FeatureGateMHCControllerEvents <-chan event.GenericEvent - FeatureGates featuregates.Accessor + Log logr.Logger + Recorder record.EventRecorder + ClusterUpgradeStatusChecker cluster.UpgradeChecker + MHCChecker mhc.Checker + FeatureGates featuregates.Accessor } // SetupWithManager sets up the controller with the Manager. @@ -91,7 +90,7 @@ func (r *MachineHealthCheckReconciler) SetupWithManager(mgr ctrl.Manager) error handler.EnqueueRequestsFromMapFunc(utils.MHCByMachineMapperFunc(mgr.GetClient(), mgr.GetLogger(), r.FeatureGates)), ) bldr = bldr.WatchesRawSource( - &source.Channel{Source: r.FeatureGateMHCControllerEvents}, + &source.Channel{Source: r.FeatureGates.GetMHCControllerDisabledEvents()}, handler.EnqueueRequestsFromMapFunc(utils.MHCByFeatureGateEventMapperFunc(mgr.GetClient(), mgr.GetLogger(), r.FeatureGates)), ) diff --git a/controllers/machinehealthcheck_controller_test.go b/controllers/machinehealthcheck_controller_test.go index 6cd156d1..0177617c 100644 --- a/controllers/machinehealthcheck_controller_test.go +++ b/controllers/machinehealthcheck_controller_test.go @@ -26,7 +26,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/reconcile" machinev1 "github.com/openshift/api/machine/v1beta1" @@ -2363,11 +2362,10 @@ func newFakeReconcilerWithCustomRecorder(recorder record.EventRecorder, initObje Build() mhcChecker, _ := mhc.NewMHCChecker(k8sManager, false, nil) return &MachineHealthCheckReconciler{ - Client: fakeClient, - Recorder: recorder, - ClusterUpgradeStatusChecker: upgradeChecker, - MHCChecker: mhcChecker, - FeatureGateMHCControllerEvents: make(chan event.GenericEvent), + Client: fakeClient, + Recorder: recorder, + ClusterUpgradeStatusChecker: upgradeChecker, + MHCChecker: mhcChecker, FeatureGates: &featuregates.FakeAccessor{ IsMaoMhcDisabled: true, }, diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 812663dc..424334d1 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -197,12 +197,11 @@ var _ = BeforeSuite(func() { Expect(err).NotTo(HaveOccurred()) err = (&MachineHealthCheckReconciler{ - Client: k8sManager.GetClient(), - Log: k8sManager.GetLogger().WithName("test reconciler"), - Recorder: k8sManager.GetEventRecorderFor("NodeHealthCheck"), - ClusterUpgradeStatusChecker: upgradeChecker, - MHCChecker: mhcChecker, - FeatureGateMHCControllerEvents: make(chan event.GenericEvent), + Client: k8sManager.GetClient(), + Log: k8sManager.GetLogger().WithName("test reconciler"), + Recorder: k8sManager.GetEventRecorderFor("NodeHealthCheck"), + ClusterUpgradeStatusChecker: upgradeChecker, + MHCChecker: mhcChecker, FeatureGates: &featuregates.FakeAccessor{ IsMaoMhcDisabled: false, }, diff --git a/main.go b/main.go index c1e2855e..2afccc62 100644 --- a/main.go +++ b/main.go @@ -162,13 +162,12 @@ func main() { } if err := (&controllers.MachineHealthCheckReconciler{ - Client: mgr.GetClient(), - Log: ctrl.Log.WithName("controllers").WithName("MachineHealthCheck"), - Recorder: mgr.GetEventRecorderFor("MachineHealthCheck"), - ClusterUpgradeStatusChecker: upgradeChecker, - MHCChecker: mhcChecker, - FeatureGateMHCControllerEvents: featureGateMHCControllerDisabledEvents, - FeatureGates: featureGateAccessor, + Client: mgr.GetClient(), + Log: ctrl.Log.WithName("controllers").WithName("MachineHealthCheck"), + Recorder: mgr.GetEventRecorderFor("MachineHealthCheck"), + ClusterUpgradeStatusChecker: upgradeChecker, + MHCChecker: mhcChecker, + FeatureGates: featureGateAccessor, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "MachineHealthCheck") os.Exit(1)