Skip to content

Commit ed764c1

Browse files
Merge pull request #1286 from theobarberbany/featuregated-paused-condition
OCPCLOUD-2565: Adds paused condition to Machine
2 parents 2befcec + e139bc5 commit ed764c1

File tree

910 files changed

+68357
-33926
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

910 files changed

+68357
-33926
lines changed

go.mod

Lines changed: 85 additions & 78 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 184 additions & 558 deletions
Large diffs are not rendered by default.

pkg/controller/machine/controller.go

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"reflect"
2424
"time"
2525

26+
openshiftfeatures "github.com/openshift/api/features"
2627
machinev1 "github.com/openshift/api/machine/v1beta1"
2728
"github.com/openshift/machine-api-operator/pkg/metrics"
2829
"github.com/openshift/machine-api-operator/pkg/util"
@@ -74,6 +75,16 @@ const (
7475
skipWaitForDeleteTimeoutSeconds = 1
7576
)
7677

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+
7788
var DefaultActuator Actuator
7889

7990
func AddWithActuator(mgr manager.Manager, actuator Actuator, gate featuregate.MutableFeatureGate) error {
@@ -97,6 +108,7 @@ func AddWithActuatorOpts(mgr manager.Manager, actuator Actuator, opts controller
97108
return nil
98109
}
99110

111+
// newReconciler returns a new reconcile.Reconciler
100112
func newReconciler(mgr manager.Manager, actuator Actuator, gate featuregate.MutableFeatureGate) reconcile.Reconciler {
101113
r := &ReconcileMachine{
102114
Client: mgr.GetClient(),
@@ -163,12 +175,45 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
163175

164176
// Implement controller logic here
165177
machineName := m.GetName()
166-
klog.Infof("%q: reconciling Machine", machineName)
178+
klog.Infof("%v: reconciling Machine", machineName)
167179

168180
// Get the original state of conditions now so that they can be used to calculate the patch later.
169181
// This must be a copy otherwise the referenced slice will be modified by later machine conditions changes.
170182
originalConditions := conditions.DeepCopyConditions(m.Status.Conditions)
171183

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+
172217
if errList := validateMachine(m); len(errList) > 0 {
173218
err := fmt.Errorf("%v: machine validation failed: %v", machineName, errList.ToAggregate().Error())
174219
klog.Error(err)
@@ -231,14 +276,14 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
231276
// we can loose instances, e.g. right after request to create one
232277
// was sent and before a list of node addresses was set.
233278
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)
235280
return delayIfRequeueAfterError(err)
236281
}
237282
}
238283

239284
instanceExists, err := r.actuator.Exists(ctx, m)
240285
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)
242287
return reconcile.Result{}, err
243288
}
244289

@@ -273,7 +318,7 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
273318

274319
instanceExists, err := r.actuator.Exists(ctx, m)
275320
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)
277322

278323
conditions.Set(m, conditions.UnknownCondition(
279324
machinev1.InstanceExistsCondition,
@@ -291,7 +336,7 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
291336
if instanceExists {
292337
klog.Infof("%v: reconciling machine triggers idempotent update", machineName)
293338
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)
295340

296341
if patchErr := r.updateStatus(ctx, m, ptr.Deref(m.Status.Phase, ""), nil, originalConditions); patchErr != nil {
297342
klog.Errorf("%v: error patching status: %v", machineName, patchErr)
@@ -358,7 +403,7 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ
358403

359404
klog.Infof("%v: reconciling machine triggers idempotent create", machineName)
360405
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)
362407
if isInvalidMachineConfigurationError(err) {
363408
if err := r.updateStatus(ctx, m, machinev1.PhaseFailed, err, originalConditions); err != nil {
364409
return reconcile.Result{}, err

0 commit comments

Comments
 (0)