Skip to content

Commit 5af2743

Browse files
Merge pull request #1274 from theobarberbany/machine-feature-gating
OCPCLOUD-2565: Machine controller feature gating
2 parents 8fda37a + d170650 commit 5af2743

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

cmd/vsphere/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func main() {
193193
klog.Fatalf("unable to add ipamv1beta1 to scheme: %v", err)
194194
}
195195

196-
if err := capimachine.AddWithActuator(mgr, machineActuator); err != nil {
196+
if err := capimachine.AddWithActuator(mgr, machineActuator, defaultMutableGate); err != nil {
197197
klog.Fatal(err)
198198
}
199199

pkg/controller/machine/controller.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"k8s.io/apimachinery/pkg/util/validation/field"
3636
"k8s.io/client-go/rest"
3737
"k8s.io/client-go/tools/record"
38+
"k8s.io/component-base/featuregate"
3839
"k8s.io/klog/v2"
3940
"k8s.io/utils/ptr"
4041
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -75,13 +76,13 @@ const (
7576

7677
var DefaultActuator Actuator
7778

78-
func AddWithActuator(mgr manager.Manager, actuator Actuator) error {
79-
return AddWithActuatorOpts(mgr, actuator, controller.Options{})
79+
func AddWithActuator(mgr manager.Manager, actuator Actuator, gate featuregate.MutableFeatureGate) error {
80+
return AddWithActuatorOpts(mgr, actuator, controller.Options{}, gate)
8081
}
8182

82-
func AddWithActuatorOpts(mgr manager.Manager, actuator Actuator, opts controller.Options) error {
83+
func AddWithActuatorOpts(mgr manager.Manager, actuator Actuator, opts controller.Options, gate featuregate.MutableFeatureGate) error {
8384
machineControllerOpts := opts
84-
machineControllerOpts.Reconciler = newReconciler(mgr, actuator)
85+
machineControllerOpts.Reconciler = newReconciler(mgr, actuator, gate)
8586

8687
if err := addWithOpts(mgr, machineControllerOpts, "machine-controller"); err != nil {
8788
return err
@@ -96,14 +97,14 @@ func AddWithActuatorOpts(mgr manager.Manager, actuator Actuator, opts controller
9697
return nil
9798
}
9899

99-
// newReconciler returns a new reconcile.Reconciler
100-
func newReconciler(mgr manager.Manager, actuator Actuator) reconcile.Reconciler {
100+
func newReconciler(mgr manager.Manager, actuator Actuator, gate featuregate.MutableFeatureGate) reconcile.Reconciler {
101101
r := &ReconcileMachine{
102102
Client: mgr.GetClient(),
103103
eventRecorder: mgr.GetEventRecorderFor("machine-controller"),
104104
config: mgr.GetConfig(),
105105
scheme: mgr.GetScheme(),
106106
actuator: actuator,
107+
gate: gate,
107108
}
108109
return r
109110
}
@@ -137,6 +138,7 @@ type ReconcileMachine struct {
137138
eventRecorder record.EventRecorder
138139

139140
actuator Actuator
141+
gate featuregate.MutableFeatureGate
140142

141143
// nowFunc is used to mock time in testing. It should be nil in production.
142144
nowFunc func() time.Time

pkg/controller/machine/machine_controller_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"sigs.k8s.io/controller-runtime/pkg/client"
3030
"sigs.k8s.io/controller-runtime/pkg/manager"
3131
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
32+
33+
testutils "github.com/openshift/machine-api-operator/pkg/util/testing"
3234
)
3335

3436
var c client.Client
@@ -66,7 +68,12 @@ func TestReconcile(t *testing.T) {
6668
c = mgr.GetClient()
6769

6870
a := newTestActuator()
69-
recFn := newReconciler(mgr, a)
71+
gate, err := testutils.NewDefaultMutableFeatureGate()
72+
if err != nil {
73+
t.Errorf("Unexpected error setting up feature gates: %v", err)
74+
}
75+
76+
recFn := newReconciler(mgr, a, gate)
7077
if err := add(mgr, recFn, "dummy"); err != nil {
7178
t.Fatalf("error adding controller to manager: %v", err)
7279
}

0 commit comments

Comments
 (0)