Skip to content

Commit 854a55a

Browse files
Address comments
1 parent b062d83 commit 854a55a

17 files changed

+86
-80
lines changed

internal/controllers/machinedeployment/machinedeployment_controller.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -355,28 +355,16 @@ func (r *Reconciler) createOrUpdateMachineSetsAndSyncMachineDeploymentRevision(c
355355

356356
// Apply changes to MachineSets.
357357
for _, ms := range allMSs {
358-
log = log.WithValues("MachineSet", klog.KObj(ms))
359-
ctx = ctrl.LoggerInto(ctx, log)
358+
log := log.WithValues("MachineSet", klog.KObj(ms))
359+
ctx := ctrl.LoggerInto(ctx, log)
360360

361361
// Retrieve the diff for the MachineSet.
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_ondelete_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ func TestReconcileOldMachineSetsOnDelete(t *testing.T) {
153153
"ms2": 0, // scale down by one, one machines has been deleted
154154
},
155155
expectedNotes: map[string][]string{
156-
"ms1": {"scale down unavailable or not existing Machines"},
157-
"ms2": {"scale down unavailable or not existing Machines"},
156+
"ms1": {"scale down to align to existing Machines"},
157+
"ms2": {"scale down to align to existing Machines"},
158158
},
159159
},
160160
{
@@ -330,7 +330,7 @@ func TestReconcileOldMachineSetsOnDelete(t *testing.T) {
330330
"ms2": 1, // scale down by one, 1 exceeding machine removed from ms1
331331
},
332332
expectedNotes: map[string][]string{
333-
"ms1": {"scale down unavailable or not existing Machines"},
333+
"ms1": {"scale down to align to existing Machines"},
334334
"ms2": {"scale down to align MachineSet spec.replicas to MachineDeployment spec.replicas"},
335335
},
336336
},

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
}

internal/controllers/machinedeployment/machinedeployment_rollout_rollingupdate_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ func Test_reconcileOldMachineSetsRollingUpdate(t *testing.T) {
559559
// no need to further scale down.
560560
},
561561
expectedNotes: map[string][]string{
562-
"ms2": {"scale down unavailable or not existing Machines"},
563-
"ms3": {"scale down unavailable or not existing Machines"},
562+
"ms2": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
563+
"ms3": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
564564
},
565565
},
566566
{
@@ -582,8 +582,8 @@ func Test_reconcileOldMachineSetsRollingUpdate(t *testing.T) {
582582
},
583583
expectedNotes: map[string][]string{
584584
"ms1": {"4 available replicas > 3 minimum available replicas"},
585-
"ms2": {"scale down unavailable or not existing Machines"},
586-
"ms3": {"scale down unavailable or not existing Machines"},
585+
"ms2": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
586+
"ms3": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
587587
},
588588
},
589589
{
@@ -604,9 +604,9 @@ func Test_reconcileOldMachineSetsRollingUpdate(t *testing.T) {
604604
"ms1": 2, // 3 available replicas from ms1 + 1 available replica from ms4 = 4 available replicas > minAvailability, scale down to 2 replicas, also drop the replica without machine (-2)
605605
},
606606
expectedNotes: map[string][]string{
607-
"ms1": {"scale down unavailable or not existing Machines", "4 available replicas > 3 minimum available replicas"},
608-
"ms2": {"scale down unavailable or not existing Machines"},
609-
"ms3": {"scale down unavailable or not existing Machines"},
607+
"ms1": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)", "4 available replicas > 3 minimum available replicas"},
608+
"ms2": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
609+
"ms3": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
610610
},
611611
},
612612
{
@@ -626,7 +626,7 @@ func Test_reconcileOldMachineSetsRollingUpdate(t *testing.T) {
626626
// does not make sense to continue scale down as there is no guarantee that MS3 would remove the unavailable replica
627627
},
628628
expectedNotes: map[string][]string{
629-
"ms2": {"scale down unavailable or not existing Machines"},
629+
"ms2": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
630630
},
631631
},
632632
{
@@ -647,9 +647,9 @@ func Test_reconcileOldMachineSetsRollingUpdate(t *testing.T) {
647647
// does not make sense to continue scale down.
648648
},
649649
expectedNotes: map[string][]string{
650-
"ms1": {"scale down unavailable or not existing Machines"},
651-
"ms2": {"scale down unavailable or not existing Machines"},
652-
"ms3": {"scale down unavailable or not existing Machines"},
650+
"ms1": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
651+
"ms2": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
652+
"ms3": {"scale down to align to existing Machines or scale down by removing unavailable replicas (and no available replicas exist on the MachineSet)"},
653653
},
654654
},
655655
{

internal/controllers/machinedeployment/testdata/ondelete/12 replicas, maxuserunavailable 1, scale down to 6, random(0).test.log.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
md: md: 5/6 replicas, 5 available, 0 upToDate
9393
ms1: from 2/3 to 2/2 replicas, 2 available, 0 upToDate (m10,m11)
9494
- Scaled down old MachineSet ms1 from 3 to 2 replicas (-1)
95-
- Reason: scale down unavailable or not existing Machines
95+
- Reason: scale down to align to existing Machines
9696
- Diff: replicas 2
9797
ms2: 3/3 replicas, 3 available, 3 upToDate (m13,m14,m15)
9898
[M controller] Iteration 8, Reconcile m10
@@ -162,7 +162,7 @@
162162
md: md: 5/6 replicas, 5 available, 0 upToDate
163163
ms1: from 1/2 to 1/1 replicas, 1 available, 0 upToDate (m10)
164164
- Scaled down old MachineSet ms1 from 2 to 1 replicas (-1)
165-
- Reason: scale down unavailable or not existing Machines
165+
- Reason: scale down to align to existing Machines
166166
- Diff: replicas 1
167167
ms2: 4/4 replicas, 4 available, 4 upToDate (m13,m14,m15,m16)
168168
[M controller] Iteration 14, Reconcile m10
@@ -209,7 +209,7 @@
209209
md: md: 5/6 replicas, 5 available, 0 upToDate
210210
ms1: from 0/1 to 0/0 replicas, 0 available, 0 upToDate ()
211211
- Scaled down old MachineSet ms1 from 1 to 0 replicas (-1)
212-
- Reason: scale down unavailable or not existing Machines
212+
- Reason: scale down to align to existing Machines
213213
- Diff: replicas 0
214214
ms2: 5/5 replicas, 5 available, 5 upToDate (m13,m14,m15,m16,m17)
215215
[M controller] Iteration 17, Reconcile m17

internal/controllers/machinedeployment/testdata/ondelete/12 replicas, maxuserunavailable 1, scale down to 6.test.log.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
md: md: 5/6 replicas, 5 available, 0 upToDate
4444
ms1: from 2/3 to 2/2 replicas, 2 available, 0 upToDate (m11,m12)
4545
- Scaled down old MachineSet ms1 from 3 to 2 replicas (-1)
46-
- Reason: scale down unavailable or not existing Machines
46+
- Reason: scale down to align to existing Machines
4747
- Diff: replicas 2
4848
ms2: 3/3 replicas, 3 available, 3 upToDate (m13,m14,m15)
4949
[MS controller] Iteration 3, Reconcile ms1: 2/2 replicas, 2 available, 0 upToDate (m11,m12)
@@ -88,7 +88,7 @@
8888
md: md: 5/6 replicas, 5 available, 0 upToDate
8989
ms1: from 1/2 to 1/1 replicas, 1 available, 0 upToDate (m12)
9090
- Scaled down old MachineSet ms1 from 2 to 1 replicas (-1)
91-
- Reason: scale down unavailable or not existing Machines
91+
- Reason: scale down to align to existing Machines
9292
- Diff: replicas 1
9393
ms2: 4/4 replicas, 4 available, 4 upToDate (m13,m14,m15,m16)
9494
[MS controller] Iteration 6, Reconcile ms1: 1/1 replicas, 1 available, 0 upToDate (m12)
@@ -133,7 +133,7 @@
133133
md: md: 5/6 replicas, 5 available, 0 upToDate
134134
ms1: from 0/1 to 0/0 replicas, 0 available, 0 upToDate ()
135135
- Scaled down old MachineSet ms1 from 1 to 0 replicas (-1)
136-
- Reason: scale down unavailable or not existing Machines
136+
- Reason: scale down to align to existing Machines
137137
- Diff: replicas 0
138138
ms2: 5/5 replicas, 5 available, 5 upToDate (m13,m14,m15,m16,m17)
139139
[MS controller] Iteration 9, Reconcile ms1: 0/0 replicas, 0 available, 0 upToDate ()

internal/controllers/machinedeployment/testdata/ondelete/3 replicas, maxuserunavailable 1, random(0).test.log.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
md: md: 2/3 replicas, 2 available, 0 upToDate
4141
ms1: from 2/3 to 2/2 replicas, 2 available, 0 upToDate (m1,m3)
4242
- Scaled down old MachineSet ms1 from 3 to 2 replicas (-1)
43-
- Reason: scale down unavailable or not existing Machines
43+
- Reason: scale down to align to existing Machines
4444
- Diff: replicas 2
4545
ms2: 0/0 replicas, 0 available, 0 upToDate ()
4646
[MS controller] Iteration 5, Reconcile ms1: 2/2 replicas, 2 available, 0 upToDate (m1,m3)
@@ -109,7 +109,7 @@
109109
md: md: 2/3 replicas, 2 available, 0 upToDate
110110
ms1: from 1/2 to 1/1 replicas, 1 available, 0 upToDate (m1)
111111
- Scaled down old MachineSet ms1 from 2 to 1 replicas (-1)
112-
- Reason: scale down unavailable or not existing Machines
112+
- Reason: scale down to align to existing Machines
113113
- Diff: replicas 1
114114
ms2: 1/1 replicas, 1 available, 1 upToDate (m4)
115115
[MD controller] Iteration 10, Reconcile md
@@ -154,7 +154,7 @@
154154
md: md: 2/3 replicas, 2 available, 0 upToDate
155155
ms1: from 0/1 to 0/0 replicas, 0 available, 0 upToDate ()
156156
- Scaled down old MachineSet ms1 from 1 to 0 replicas (-1)
157-
- Reason: scale down unavailable or not existing Machines
157+
- Reason: scale down to align to existing Machines
158158
- Diff: replicas 0
159159
ms2: 2/2 replicas, 2 available, 2 upToDate (m4,m5)
160160
[MS controller] Iteration 14, Reconcile ms2: 2/2 replicas, 2 available, 2 upToDate (m4,m5)

0 commit comments

Comments
 (0)