From 87a2b73c2e52b114ca8299da5aa3ee5de442ba7d Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Wed, 8 Oct 2025 08:49:50 +0200 Subject: [PATCH 1/3] machineset: always use v1beta2 condition utils to ensure lastTransitionTime is set --- pkg/controllers/machinesetsync/machineset_sync_controller.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/controllers/machinesetsync/machineset_sync_controller.go b/pkg/controllers/machinesetsync/machineset_sync_controller.go index 21e025bb4..d79e9f842 100644 --- a/pkg/controllers/machinesetsync/machineset_sync_controller.go +++ b/pkg/controllers/machinesetsync/machineset_sync_controller.go @@ -1015,7 +1015,8 @@ func setChangedCAPIMachineSetStatusFields(existingCAPIMachineSet, convertedCAPIM case convertedCAPIMachineSet.Status.V1Beta2 == nil: existingCAPIMachineSet.Status.V1Beta2 = nil case existingCAPIMachineSet.Status.V1Beta2 == nil: - existingCAPIMachineSet.Status.V1Beta2 = convertedCAPIMachineSet.Status.V1Beta2 + existingCAPIMachineSet.Status.V1Beta2 = &clusterv1.MachineSetV1Beta2Status{} + fallthrough default: existingCAPIMachineSet.Status.V1Beta2.UpToDateReplicas = convertedCAPIMachineSet.Status.V1Beta2.UpToDateReplicas existingCAPIMachineSet.Status.V1Beta2.AvailableReplicas = convertedCAPIMachineSet.Status.V1Beta2.AvailableReplicas From 682e9ff0631562751dd19ae56e7a11327ea9bda7 Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Mon, 13 Oct 2025 13:54:41 +0200 Subject: [PATCH 2/3] machineset: rewrite status setting --- .../machineset_sync_controller.go | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/pkg/controllers/machinesetsync/machineset_sync_controller.go b/pkg/controllers/machinesetsync/machineset_sync_controller.go index d79e9f842..179fc624e 100644 --- a/pkg/controllers/machinesetsync/machineset_sync_controller.go +++ b/pkg/controllers/machinesetsync/machineset_sync_controller.go @@ -997,35 +997,31 @@ func (r *MachineSetSyncReconciler) ensureMAPIMachineSetStatusUpdated(ctx context // setChangedCAPIMachineSetStatusFields sets the updated fields in the CAPI machine set status. func setChangedCAPIMachineSetStatusFields(existingCAPIMachineSet, convertedCAPIMachineSet *clusterv1.MachineSet) { - // convertedCAPIMachineSet holds the computed and desired status changes, so apply them to the existing existingCAPIMachineSet. - // Set the changed v1beta1 fields. - existingCAPIMachineSet.Status.Replicas = convertedCAPIMachineSet.Status.Replicas - existingCAPIMachineSet.Status.ReadyReplicas = convertedCAPIMachineSet.Status.ReadyReplicas - existingCAPIMachineSet.Status.AvailableReplicas = convertedCAPIMachineSet.Status.AvailableReplicas - existingCAPIMachineSet.Status.FullyLabeledReplicas = convertedCAPIMachineSet.Status.FullyLabeledReplicas - existingCAPIMachineSet.Status.FailureReason = convertedCAPIMachineSet.Status.FailureReason - existingCAPIMachineSet.Status.FailureMessage = convertedCAPIMachineSet.Status.FailureMessage - - for i := range convertedCAPIMachineSet.Status.Conditions { - conditions.Set(existingCAPIMachineSet, &convertedCAPIMachineSet.Status.Conditions[i]) + // convertedCAPIMachine holds the computed and desired status changes converted from the source MAPI machine, so apply them to the existing existingCAPIMachine. + // Merge the v1beta1 conditions. + for _, condition := range convertedCAPIMachineSet.Status.Conditions { + conditions.Set(existingCAPIMachineSet, &condition) } - // Set the changed v1beta2 fields. - switch { - case convertedCAPIMachineSet.Status.V1Beta2 == nil: - existingCAPIMachineSet.Status.V1Beta2 = nil - case existingCAPIMachineSet.Status.V1Beta2 == nil: - existingCAPIMachineSet.Status.V1Beta2 = &clusterv1.MachineSetV1Beta2Status{} - fallthrough - default: - existingCAPIMachineSet.Status.V1Beta2.UpToDateReplicas = convertedCAPIMachineSet.Status.V1Beta2.UpToDateReplicas - existingCAPIMachineSet.Status.V1Beta2.AvailableReplicas = convertedCAPIMachineSet.Status.V1Beta2.AvailableReplicas - existingCAPIMachineSet.Status.V1Beta2.ReadyReplicas = convertedCAPIMachineSet.Status.V1Beta2.ReadyReplicas + // Copy them back to the convertedCAPIMachine. + convertedCAPIMachineSet.Status.Conditions = existingCAPIMachineSet.Status.Conditions - for i := range convertedCAPIMachineSet.Status.V1Beta2.Conditions { - conditionsv1beta2.Set(existingCAPIMachineSet, convertedCAPIMachineSet.Status.V1Beta2.Conditions[i]) + // Merge the v1beta2 conditions. + if convertedCAPIMachineSet.Status.V1Beta2 != nil { + if existingCAPIMachineSet.Status.V1Beta2 == nil { + existingCAPIMachineSet.Status.V1Beta2 = &clusterv1.MachineSetV1Beta2Status{} } + + for _, condition := range convertedCAPIMachineSet.Status.V1Beta2.Conditions { + conditionsv1beta2.Set(existingCAPIMachineSet, condition) + } + + // Copy them back to the convertedCAPIMachine. + convertedCAPIMachineSet.Status.V1Beta2.Conditions = existingCAPIMachineSet.Status.V1Beta2.Conditions } + + // Finally overwrite the entire existingCAPIMachine status with the convertedCAPIMachine status. + existingCAPIMachineSet.Status = convertedCAPIMachineSet.Status } // updateMAPIMachineSet updates a MAPI machine set if is out of date. From ae094eb2f8340c4f11f9f83b9faff9ae2d220079 Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Mon, 13 Oct 2025 16:57:31 +0200 Subject: [PATCH 3/3] machinesetsync: also adjust MAPItoCAPI --- .../machinesetsync/machineset_sync_controller.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/controllers/machinesetsync/machineset_sync_controller.go b/pkg/controllers/machinesetsync/machineset_sync_controller.go index 179fc624e..988fc9755 100644 --- a/pkg/controllers/machinesetsync/machineset_sync_controller.go +++ b/pkg/controllers/machinesetsync/machineset_sync_controller.go @@ -996,6 +996,7 @@ func (r *MachineSetSyncReconciler) ensureMAPIMachineSetStatusUpdated(ctx context } // setChangedCAPIMachineSetStatusFields sets the updated fields in the CAPI machine set status. +// Note: ObservedGeneration is handled after calling this function. func setChangedCAPIMachineSetStatusFields(existingCAPIMachineSet, convertedCAPIMachineSet *clusterv1.MachineSet) { // convertedCAPIMachine holds the computed and desired status changes converted from the source MAPI machine, so apply them to the existing existingCAPIMachine. // Merge the v1beta1 conditions. @@ -1059,6 +1060,7 @@ func (r *MachineSetSyncReconciler) updateMAPIMachineSet(ctx context.Context, exi } // setChangedMAPIMachineSetStatusFields sets the updated fields in the MAPI machine set status. +// Note: ObservedGeneration is handled after calling this function. func setChangedMAPIMachineSetStatusFields(existingMAPIMachineSet, convertedMAPIMachineSet *mapiv1beta1.MachineSet) { // convertedMAPIMachineSet holds the computed and desired status changes, so apply them to the existing existingMAPIMachineSet. existingMAPIMachineSet.Status.Replicas = convertedMAPIMachineSet.Status.Replicas @@ -1068,9 +1070,20 @@ func setChangedMAPIMachineSetStatusFields(existingMAPIMachineSet, convertedMAPIM existingMAPIMachineSet.Status.ErrorReason = convertedMAPIMachineSet.Status.ErrorReason existingMAPIMachineSet.Status.ErrorMessage = convertedMAPIMachineSet.Status.ErrorMessage + // Merge the v1beta1 conditions. for i := range convertedMAPIMachineSet.Status.Conditions { existingMAPIMachineSet.Status.Conditions = util.SetMAPICondition(existingMAPIMachineSet.Status.Conditions, &convertedMAPIMachineSet.Status.Conditions[i]) } + + // Copy them back to the convertedMAPIMachineSet. + convertedMAPIMachineSet.Status.Conditions = existingMAPIMachineSet.Status.Conditions + + // Keep the current SynchronizedGeneration and AuthorativeAPI. They get handled separately in `applySynchronizedConditionWithPatch` + convertedMAPIMachineSet.Status.SynchronizedGeneration = existingMAPIMachineSet.Status.SynchronizedGeneration + convertedMAPIMachineSet.Status.AuthoritativeAPI = existingMAPIMachineSet.Status.AuthoritativeAPI + + // Finally overwrite the entire existingMAPIMachineSet status with the convertedMAPIMachineSet status. + existingMAPIMachineSet.Status = convertedMAPIMachineSet.Status } // ensureSyncFinalizer ensures the sync finalizer is present across mapi and capi machine sets.