Skip to content

Commit ee70a95

Browse files
Address comments
1 parent b062d83 commit ee70a95

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

internal/controllers/machinedeployment/machinedeployment_controller.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,21 +362,9 @@ func (r *Reconciler) createOrUpdateMachineSetsAndSyncMachineDeploymentRevision(c
362362
// Note: no need to check for diff doesn't exist, all the diff have been computed right above.
363363
diff := machineSetsDiff[ms.Name]
364364

365-
// Add to the log kv pairs providing context and details about changes in this MachineSet (reason, diff),
366-
// and also add the overview of all the MachineSets computed above.
367-
// Note: Those values should not be added to the context to prevent propagation to other func.
368-
statusToLogKeyAndValues := []any{
369-
"reason", diff.Reason,
370-
"diff", diff.OtherChanges,
371-
"machinesets", machineSetsSummary,
372-
}
373-
if len(p.acknowledgedMachineNames) > 0 {
374-
statusToLogKeyAndValues = append(statusToLogKeyAndValues, "acknowledgedMachines", sortAndJoin(p.acknowledgedMachineNames))
375-
}
376-
if len(p.updatingMachineNames) > 0 {
377-
statusToLogKeyAndValues = append(statusToLogKeyAndValues, "updatingMachines", sortAndJoin(p.updatingMachineNames))
378-
}
379-
log := log.WithValues(statusToLogKeyAndValues...)
365+
// Add to the log kv pairs providing the overview of all the MachineSets computed above.
366+
// Note: This value should not be added to the context to prevent propagation to other func.
367+
log := log.WithValues("machineSets", machineSetsSummary)
380368

381369
if diff.OriginalMS == nil {
382370
// Create the MachineSet.
@@ -388,7 +376,7 @@ func (r *Reconciler) createOrUpdateMachineSetsAndSyncMachineDeploymentRevision(c
388376
log.Info(fmt.Sprintf("MachineSets need rollout: %s", strings.Join(machineSetNames(p.oldMSs), ", ")), "reason", p.createReason)
389377
}
390378
log.Info(fmt.Sprintf("MachineSet %s created, it is now the current MachineSet", ms.Name))
391-
if ptr.Deref(ms.Spec.Replicas, 0) > 0 {
379+
if diff.DesiredReplicas > 0 {
392380
log.Info(fmt.Sprintf("Scaled up current MachineSet %s from 0 to %d replicas (+%[2]d)", ms.Name, diff.DesiredReplicas))
393381
}
394382
r.recorder.Eventf(p.md, corev1.EventTypeNormal, "SuccessfulCreate", "Created MachineSet %s with %d replicas", klog.KObj(ms), diff.DesiredReplicas)
@@ -403,6 +391,20 @@ func (r *Reconciler) createOrUpdateMachineSetsAndSyncMachineDeploymentRevision(c
403391
continue
404392
}
405393

394+
// Add to the log kv pairs providing context and details about changes in this MachineSet (reason, diff)
395+
// Note: Those values should not be added to the context to prevent propagation to other func.
396+
statusToLogKeyAndValues := []any{
397+
"reason", diff.Reason,
398+
"diff", diff.OtherChanges,
399+
}
400+
if len(p.acknowledgedMachineNames) > 0 {
401+
statusToLogKeyAndValues = append(statusToLogKeyAndValues, "acknowledgedMachines", sortAndJoin(p.acknowledgedMachineNames))
402+
}
403+
if len(p.updatingMachineNames) > 0 {
404+
statusToLogKeyAndValues = append(statusToLogKeyAndValues, "updatingMachines", sortAndJoin(p.updatingMachineNames))
405+
}
406+
log = log.WithValues(statusToLogKeyAndValues...)
407+
406408
err := ssa.Patch(ctx, r.Client, machineDeploymentManagerName, ms, ssa.WithCachingProxy{Cache: r.ssaCache, Original: diff.OriginalMS})
407409
if err != nil {
408410
// Note: If we are Applying a MachineSet with UID set and the MachineSet does not exist anymore, the

internal/controllers/machinedeployment/machinedeployment_rollout_ondelete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (p *rolloutPlanner) reconcileOldMachineSetsOnDelete(ctx context.Context) {
111111
scaleDownCount := max(ptr.Deref(oldMS.Spec.Replicas, 0)-ptr.Deref(oldMS.Status.Replicas, 0), 0)
112112
if scaleDownCount > 0 {
113113
newScaleIntent := max(ptr.Deref(oldMS.Spec.Replicas, 0)-scaleDownCount, 0)
114-
p.addNote(oldMS, "scale down unavailable or not existing Machines")
114+
p.addNote(oldMS, "scale down to align to existing Machines")
115115
log.V(5).Info(fmt.Sprintf("Setting scale down intent for MachineSet %s to %d replicas (-%d)", oldMS.Name, newScaleIntent, scaleDownCount), "MachineSet", klog.KObj(oldMS))
116116
p.scaleIntents[oldMS.Name] = newScaleIntent
117117

internal/controllers/machinedeployment/machinedeployment_rollout_planner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ func (p *rolloutPlanner) init(ctx context.Context, md *clusterv1.MachineDeployme
126126
return err
127127
}
128128
p.newMS = desiredNewMS
129+
// Note: when an oldMS becomes again the current one, computeDesiredNewMS changes its revision number;
130+
// the new revision number is also surfaced in p.revision, and thus we are using this information
131+
// to determine when to add this note.
129132
if oldRevision != p.revision {
130133
p.addNote(p.newMS, "this is now the current MachineSet")
131134
}
@@ -379,9 +382,6 @@ func (p *rolloutPlanner) getMachineSetDiff(ms *clusterv1.MachineSet) machineSetD
379382
// Compute the desired spec.replicas
380383
// Note: Used to determine if this is a scale up or a scale down operation.
381384
diff.DesiredReplicas = ptr.Deref(ms.Spec.Replicas, 0)
382-
if v, ok := p.scaleIntents[ms.Name]; ok {
383-
diff.DesiredReplicas = v
384-
}
385385

386386
// Compute a message that summarize changes to Machine set spec replicas.
387387
// Note. Also other replicas counters not changed by the rollout planner are included, because they are used in the computation.

internal/controllers/machinedeployment/machinedeployment_rollout_planner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ func (r rolloutScope) rolloutPlannerResultSummary(p *rolloutPlanner) string {
10021002
if d.OriginalMS == nil {
10031003
o += fmt.Sprintf(" - MachineSet %s created, it is now the current MachineSet\n", ms.Name)
10041004
if d.DesiredReplicas > 0 {
1005-
o += fmt.Sprintf(" - Scaled up current MachineSet %s from 0 to %d replicas (+%[2]d)\n", ms.Name, ptr.Deref(ms.Spec.Replicas, 0))
1005+
o += fmt.Sprintf(" - Scaled up current MachineSet %s from 0 to %d replicas (+%[2]d)\n", ms.Name, d.DesiredReplicas)
10061006
o += fmt.Sprintf(" - Reason: %s\n", d.Reason)
10071007
}
10081008
continue

internal/controllers/machinedeployment/machinedeployment_rollout_rollingupdate.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,12 @@ func (p *rolloutPlanner) scaleDownOldMSs(ctx context.Context, totalScaleDownCoun
372372

373373
if scaleDown > 0 {
374374
newScaleIntent := max(replicas-scaleDown, 0)
375+
// Check if totalAvailableReplicas has been changed above and use it as a signal to determine if scale down
376+
// was to align to existing Machines (replicas count > number of machines) or if scale down was performed
377+
// removing unavailable replicas when no available replicas exist on the MachineSet.
378+
// Note. In both cases overall availability is not impacted.
375379
if oldTotalAvailableReplicas == totalAvailableReplicas {
376-
p.addNote(oldMS, "scale down unavailable or not existing Machines")
380+
p.addNote(oldMS, "scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)")
377381
} else {
378382
p.addNote(oldMS, "%d available replicas > %d minimum available replicas", oldTotalAvailableReplicas, minAvailable)
379383
}

0 commit comments

Comments
 (0)