@@ -23,6 +23,7 @@ import (
23
23
"reflect"
24
24
"time"
25
25
26
+ openshiftfeatures "github.com/openshift/api/features"
26
27
machinev1 "github.com/openshift/api/machine/v1beta1"
27
28
"github.com/openshift/machine-api-operator/pkg/metrics"
28
29
"github.com/openshift/machine-api-operator/pkg/util"
@@ -74,6 +75,16 @@ const (
74
75
skipWaitForDeleteTimeoutSeconds = 1
75
76
)
76
77
78
+ // We export the PausedCondition and reasons as they're shared
79
+ // across the Machine and MachineSet controllers.
80
+ const (
81
+ PausedCondition machinev1.ConditionType = "Paused"
82
+
83
+ PausedConditionReason = "AuthoritativeAPINotMachineAPI"
84
+
85
+ NotPausedConditionReason = "AuthoritativeAPIMachineAPI"
86
+ )
87
+
77
88
var DefaultActuator Actuator
78
89
79
90
func AddWithActuator (mgr manager.Manager , actuator Actuator , gate featuregate.MutableFeatureGate ) error {
@@ -97,6 +108,7 @@ func AddWithActuatorOpts(mgr manager.Manager, actuator Actuator, opts controller
97
108
return nil
98
109
}
99
110
111
+ // newReconciler returns a new reconcile.Reconciler
100
112
func newReconciler (mgr manager.Manager , actuator Actuator , gate featuregate.MutableFeatureGate ) reconcile.Reconciler {
101
113
r := & ReconcileMachine {
102
114
Client : mgr .GetClient (),
@@ -163,12 +175,45 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
163
175
164
176
// Implement controller logic here
165
177
machineName := m .GetName ()
166
- klog .Infof ("%q : reconciling Machine" , machineName )
178
+ klog .Infof ("%v : reconciling Machine" , machineName )
167
179
168
180
// Get the original state of conditions now so that they can be used to calculate the patch later.
169
181
// This must be a copy otherwise the referenced slice will be modified by later machine conditions changes.
170
182
originalConditions := conditions .DeepCopyConditions (m .Status .Conditions )
171
183
184
+ if r .gate .Enabled (featuregate .Feature (openshiftfeatures .FeatureGateMachineAPIMigration )) {
185
+ // Check Status.AuthoritativeAPI
186
+ // If not MachineAPI. Set the paused condition true and return early.
187
+ //
188
+ // Once we have a webhook, we want to remove the check that the AuthoritativeAPI
189
+ // field is populated.
190
+ if m .Status .AuthoritativeAPI != "" &&
191
+ m .Status .AuthoritativeAPI != machinev1 .MachineAuthorityMachineAPI {
192
+ conditions .Set (m , conditions .TrueConditionWithReason (
193
+ PausedCondition ,
194
+ PausedConditionReason ,
195
+ "The AuthoritativeAPI is set to %s" , m .Status .AuthoritativeAPI ,
196
+ ))
197
+ if patchErr := r .updateStatus (ctx , m , ptr .Deref (m .Status .Phase , "" ), nil , originalConditions ); patchErr != nil {
198
+ klog .Errorf ("%v: error patching status: %v" , machineName , patchErr )
199
+ }
200
+
201
+ klog .Infof ("%v: machine is paused, taking no further action" , machineName )
202
+ return reconcile.Result {}, nil
203
+ }
204
+
205
+ // Set the paused condition to false, continue reconciliation
206
+ conditions .Set (m , conditions .FalseCondition (
207
+ PausedCondition ,
208
+ NotPausedConditionReason ,
209
+ machinev1 .ConditionSeverityInfo ,
210
+ "The AuthoritativeAPI is set to %s" , m .Status .AuthoritativeAPI ,
211
+ ))
212
+ if patchErr := r .updateStatus (ctx , m , ptr .Deref (m .Status .Phase , "" ), nil , originalConditions ); patchErr != nil {
213
+ klog .Errorf ("%v: error patching status: %v" , machineName , patchErr )
214
+ }
215
+ }
216
+
172
217
if errList := validateMachine (m ); len (errList ) > 0 {
173
218
err := fmt .Errorf ("%v: machine validation failed: %v" , machineName , errList .ToAggregate ().Error ())
174
219
klog .Error (err )
@@ -231,14 +276,14 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
231
276
// we can loose instances, e.g. right after request to create one
232
277
// was sent and before a list of node addresses was set.
233
278
if len (m .Status .Addresses ) > 0 || ! isInvalidMachineConfigurationError (err ) {
234
- klog .Errorf ("%q : failed to delete machine: %v" , machineName , err )
279
+ klog .Errorf ("%v : failed to delete machine: %v" , machineName , err )
235
280
return delayIfRequeueAfterError (err )
236
281
}
237
282
}
238
283
239
284
instanceExists , err := r .actuator .Exists (ctx , m )
240
285
if err != nil {
241
- klog .Errorf ("%q : failed to check if machine exists: %v" , machineName , err )
286
+ klog .Errorf ("%v : failed to check if machine exists: %v" , machineName , err )
242
287
return reconcile.Result {}, err
243
288
}
244
289
@@ -273,7 +318,7 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
273
318
274
319
instanceExists , err := r .actuator .Exists (ctx , m )
275
320
if err != nil {
276
- klog .Errorf ("%q : failed to check if machine exists: %v" , machineName , err )
321
+ klog .Errorf ("%v : failed to check if machine exists: %v" , machineName , err )
277
322
278
323
conditions .Set (m , conditions .UnknownCondition (
279
324
machinev1 .InstanceExistsCondition ,
@@ -291,7 +336,7 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
291
336
if instanceExists {
292
337
klog .Infof ("%v: reconciling machine triggers idempotent update" , machineName )
293
338
if err := r .actuator .Update (ctx , m ); err != nil {
294
- klog .Errorf ("%q : error updating machine: %v, retrying in %s seconds" , machineName , err , requeueAfter . String () )
339
+ klog .Errorf ("%v : error updating machine: %v, retrying in %v seconds" , machineName , err , requeueAfter )
295
340
296
341
if patchErr := r .updateStatus (ctx , m , ptr .Deref (m .Status .Phase , "" ), nil , originalConditions ); patchErr != nil {
297
342
klog .Errorf ("%v: error patching status: %v" , machineName , patchErr )
@@ -358,7 +403,7 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
358
403
359
404
klog .Infof ("%v: reconciling machine triggers idempotent create" , machineName )
360
405
if err := r .actuator .Create (ctx , m ); err != nil {
361
- klog .Warningf ("%q : failed to create machine: %v" , machineName , err )
406
+ klog .Warningf ("%v : failed to create machine: %v" , machineName , err )
362
407
if isInvalidMachineConfigurationError (err ) {
363
408
if err := r .updateStatus (ctx , m , machinev1 .PhaseFailed , err , originalConditions ); err != nil {
364
409
return reconcile.Result {}, err
0 commit comments