Skip to content

Commit d360bd1

Browse files
Updates InfraMachine watch_filters
1 parent 2a0af92 commit d360bd1

File tree

4 files changed

+229
-95
lines changed

4 files changed

+229
-95
lines changed

pkg/controllers/machinesync/machine_sync_controller.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ const (
8181
mapiNamespace string = "openshift-machine-api"
8282
capiInfraCommonFinalizerSuffix string = ".cluster.x-k8s.io"
8383

84+
requeueInfraProgress = 1 * time.Second
85+
8486
messageSuccessfullySynchronizedCAPItoMAPI = "Successfully synchronized CAPI Machine to MAPI"
8587
messageSuccessfullySynchronizedMAPItoCAPI = "Successfully synchronized MAPI Machine to CAPI"
8688
progressingToSynchronizeMAPItoCAPI = "Progressing to synchronize MAPI Machine to CAPI"
@@ -134,7 +136,7 @@ type MachineSyncReconciler struct {
134136
MAPINamespace string
135137
}
136138

137-
// SetupWithManager sets the CoreClusterReconciler controller up with the given manager.
139+
// SetupWithManager sets the MachineSyncReconciler controller up with the given manager.
138140
func (r *MachineSyncReconciler) SetupWithManager(mgr ctrl.Manager) error {
139141
infraMachine, _, err := controllers.InitInfraMachineAndInfraClusterFromProvider(r.Platform)
140142
if err != nil {
@@ -161,7 +163,7 @@ func (r *MachineSyncReconciler) SetupWithManager(mgr ctrl.Manager) error {
161163
).
162164
Watches(
163165
infraMachine,
164-
handler.EnqueueRequestsFromMapFunc(util.RewriteNamespace(r.MAPINamespace)),
166+
handler.EnqueueRequestsFromMapFunc(util.ResolveCAPIMachineFromInfraMachine(r.MAPINamespace)),
165167
builder.WithPredicates(util.FilterNamespace(r.CAPINamespace)),
166168
).
167169
Complete(r); err != nil {
@@ -182,8 +184,8 @@ func (r *MachineSyncReconciler) SetupWithManager(mgr ctrl.Manager) error {
182184
func (r *MachineSyncReconciler) Reconcile(ctx context.Context, req reconcile.Request) (ctrl.Result, error) {
183185
logger := log.FromContext(ctx, "namespace", req.Namespace, "name", req.Name)
184186

185-
logger.V(1).Info("Reconciling machine")
186-
defer logger.V(1).Info("Finished reconciling machine")
187+
logger.Info("Reconciling machine")
188+
defer logger.Info("Finished reconciling machine")
187189

188190
var mapiMachineNotFound, capiMachineNotFound bool
189191

@@ -279,6 +281,8 @@ func (r *MachineSyncReconciler) reconcileCAPIMachinetoMAPIMachine(ctx context.Co
279281
return ctrl.Result{}, errCAPIMachineNotFound
280282
}
281283

284+
// TODO (In review cc @dam): Currently, if we dont have an infra ref this fails: unexpected InfraMachine type, expected AWSMachine, got <nil>
285+
// should we make this error more human friendly? Is this a scenario we're likely to have users hit?
282286
infraCluster, infraMachine, err := r.fetchCAPIInfraResources(ctx, capiMachine)
283287
if err != nil {
284288
fetchErr := fmt.Errorf("failed to fetch Cluster API infra resources: %w", err)
@@ -540,13 +544,13 @@ func (r *MachineSyncReconciler) reconcileMAPIMachinetoCAPIMachine(ctx context.Co
540544
BlockOwnerDeletion: ptr.To(true),
541545
}})
542546

543-
result, syncronizationIsProgressing, err := r.createOrUpdateCAPIInfraMachine(ctx, mapiMachine, infraMachine, newCAPIInfraMachine)
547+
result, synchronizationIsProgressing, err := r.createOrUpdateCAPIInfraMachine(ctx, mapiMachine, infraMachine, newCAPIInfraMachine)
544548
if err != nil {
545549
return result, fmt.Errorf("unable to ensure Cluster API infra machine: %w", err)
546550
}
547551

548-
if syncronizationIsProgressing {
549-
return ctrl.Result{RequeueAfter: time.Second * 1}, r.applySynchronizedConditionWithPatch(ctx, mapiMachine, corev1.ConditionUnknown,
552+
if synchronizationIsProgressing {
553+
return ctrl.Result{RequeueAfter: requeueInfraProgress}, r.applySynchronizedConditionWithPatch(ctx, mapiMachine, corev1.ConditionUnknown,
550554
reasonProgressingToCreateCAPIInfraMachine, progressingToSynchronizeMAPItoCAPI, nil)
551555
}
552556

@@ -1011,7 +1015,9 @@ func (r *MachineSyncReconciler) fetchCAPIInfraResources(ctx context.Context, cap
10111015
}
10121016

10131017
//nolint:funlen,gocognit,cyclop
1014-
func (r *MachineSyncReconciler) reconcileMAPItoCAPIMachineDeletion(ctx context.Context, mapiMachine *machinev1beta1.Machine, capiMachine *clusterv1.Machine, infraMachine client.Object) (bool, error) {
1018+
func (r *MachineSyncReconciler) reconcileMAPItoCAPIMachineDeletion(ctx context.Context, mapiMachine *machinev1beta1.Machine, capiMachine *clusterv1.Machine, infraMachine client.Object) (shouldReqeue bool, err error) {
1019+
logger := log.FromContext(ctx)
1020+
10151021
if mapiMachine.DeletionTimestamp.IsZero() {
10161022
if capiMachine == nil || capiMachine.DeletionTimestamp.IsZero() {
10171023
// Neither MAPI authoritative machine nor its CAPI non-authoritative machine mirror
@@ -1029,8 +1035,6 @@ func (r *MachineSyncReconciler) reconcileMAPItoCAPIMachineDeletion(ctx context.C
10291035
return true, nil
10301036
}
10311037

1032-
logger := log.FromContext(ctx)
1033-
10341038
if capiMachine == nil && util.IsNilObject(infraMachine) {
10351039
logger.Info("Cluster API machine and infra machine do not exist, removing corresponding Machine API machine sync finalizer")
10361040
// We don't have a capi machine or infra resouorces to clean up we can
@@ -1228,9 +1232,7 @@ func (r *MachineSyncReconciler) reconcileCAPItoMAPIMachineDeletion(ctx context.C
12281232

12291233
// ensureSyncFinalizer ensures the sync finalizer is present across the mapi
12301234
// machine, capi machine and capi infra machine.
1231-
func (r *MachineSyncReconciler) ensureSyncFinalizer(ctx context.Context, mapiMachine *machinev1beta1.Machine, capiMachine *clusterv1.Machine, infraMachine client.Object) (bool, error) {
1232-
var shouldRequeue bool
1233-
1235+
func (r *MachineSyncReconciler) ensureSyncFinalizer(ctx context.Context, mapiMachine *machinev1beta1.Machine, capiMachine *clusterv1.Machine, infraMachine client.Object) (shouldRequeue bool, err error) {
12341236
var errors []error
12351237

12361238
if mapiMachine != nil {

0 commit comments

Comments
 (0)