Skip to content

Commit d410957

Browse files
authored
Merge pull request #8415 from PiotrLewandowski323/8394
🌱 Drop the first return value from FindOldMachineSets
2 parents e9a588f + d8dae54 commit d410957

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

internal/controllers/machinedeployment/machinedeployment_sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (r *Reconciler) sync(ctx context.Context, md *clusterv1.MachineDeployment,
8282
// This may lead to stale reads of machine sets, thus incorrect deployment status.
8383
func (r *Reconciler) getAllMachineSetsAndSyncRevision(ctx context.Context, md *clusterv1.MachineDeployment, msList []*clusterv1.MachineSet, createIfNotExisted bool) (*clusterv1.MachineSet, []*clusterv1.MachineSet, error) {
8484
reconciliationTime := metav1.Now()
85-
_, allOldMSs := mdutil.FindOldMachineSets(md, msList, &reconciliationTime)
85+
allOldMSs := mdutil.FindOldMachineSets(md, msList, &reconciliationTime)
8686

8787
// Get new machine set with the updated revision number
8888
newMS, err := r.getNewMachineSet(ctx, md, msList, allOldMSs, createIfNotExisted, &reconciliationTime)

internal/controllers/machinedeployment/mdutil/util.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,8 @@ func shouldRolloutAfter(ms *clusterv1.MachineSet, reconciliationTime *metav1.Tim
439439
}
440440

441441
// FindOldMachineSets returns the old machine sets targeted by the given Deployment, within the given slice of MSes.
442-
// Returns two list of machine sets
443-
// - the first contains all old machine sets with non-zero replicas
444-
// - the second contains all old machine sets
445-
func FindOldMachineSets(deployment *clusterv1.MachineDeployment, msList []*clusterv1.MachineSet, reconciliationTime *metav1.Time) ([]*clusterv1.MachineSet, []*clusterv1.MachineSet) {
446-
var requiredMSs []*clusterv1.MachineSet
442+
// Returns a list of machine sets which contains all old machine sets.
443+
func FindOldMachineSets(deployment *clusterv1.MachineDeployment, msList []*clusterv1.MachineSet, reconciliationTime *metav1.Time) []*clusterv1.MachineSet {
447444
allMSs := make([]*clusterv1.MachineSet, 0, len(msList))
448445
newMS := FindNewMachineSet(deployment, msList, reconciliationTime)
449446
for _, ms := range msList {
@@ -452,11 +449,8 @@ func FindOldMachineSets(deployment *clusterv1.MachineDeployment, msList []*clust
452449
continue
453450
}
454451
allMSs = append(allMSs, ms)
455-
if *(ms.Spec.Replicas) != 0 {
456-
requiredMSs = append(requiredMSs, ms)
457-
}
458452
}
459-
return requiredMSs, allMSs
453+
return allMSs
460454
}
461455

462456
// GetReplicaCountForMachineSets returns the sum of Replicas of the given machine sets.

internal/controllers/machinedeployment/mdutil/util_test.go

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -431,69 +431,59 @@ func TestFindOldMachineSets(t *testing.T) {
431431
msList []*clusterv1.MachineSet
432432
reconciliationTime *metav1.Time
433433
expected []*clusterv1.MachineSet
434-
expectedRequire []*clusterv1.MachineSet
435434
}{
436435
{
437-
Name: "Get old MachineSets",
438-
deployment: deployment,
439-
msList: []*clusterv1.MachineSet{&newMS, &oldMS},
440-
expected: []*clusterv1.MachineSet{&oldMS},
441-
expectedRequire: nil,
436+
Name: "Get old MachineSets",
437+
deployment: deployment,
438+
msList: []*clusterv1.MachineSet{&newMS, &oldMS},
439+
expected: []*clusterv1.MachineSet{&oldMS},
442440
},
443441
{
444-
Name: "Get old MachineSets with no new MachineSet",
445-
deployment: deployment,
446-
msList: []*clusterv1.MachineSet{&oldMS},
447-
expected: []*clusterv1.MachineSet{&oldMS},
448-
expectedRequire: nil,
442+
Name: "Get old MachineSets with no new MachineSet",
443+
deployment: deployment,
444+
msList: []*clusterv1.MachineSet{&oldMS},
445+
expected: []*clusterv1.MachineSet{&oldMS},
449446
},
450447
{
451-
Name: "Get old MachineSets with two new MachineSets, only the MachineSet with higher replicas is seen as new MachineSet",
452-
deployment: deployment,
453-
msList: []*clusterv1.MachineSet{&oldMS, &newMS, &newMSHigherReplicas},
454-
expected: []*clusterv1.MachineSet{&oldMS, &newMS},
455-
expectedRequire: []*clusterv1.MachineSet{&newMS},
448+
Name: "Get old MachineSets with two new MachineSets, only the MachineSet with higher replicas is seen as new MachineSet",
449+
deployment: deployment,
450+
msList: []*clusterv1.MachineSet{&oldMS, &newMS, &newMSHigherReplicas},
451+
expected: []*clusterv1.MachineSet{&oldMS, &newMS},
456452
},
457453
{
458-
Name: "Get old MachineSets with two new MachineSets, when replicas are matching only the MachineSet with lower name is seen as new MachineSet",
459-
deployment: deployment,
460-
msList: []*clusterv1.MachineSet{&oldMS, &newMS, &newMSHigherName},
461-
expected: []*clusterv1.MachineSet{&oldMS, &newMSHigherName},
462-
expectedRequire: []*clusterv1.MachineSet{&newMSHigherName},
454+
Name: "Get old MachineSets with two new MachineSets, when replicas are matching only the MachineSet with lower name is seen as new MachineSet",
455+
deployment: deployment,
456+
msList: []*clusterv1.MachineSet{&oldMS, &newMS, &newMSHigherName},
457+
expected: []*clusterv1.MachineSet{&oldMS, &newMSHigherName},
463458
},
464459
{
465-
Name: "Get empty old MachineSets",
466-
deployment: deployment,
467-
msList: []*clusterv1.MachineSet{&newMS},
468-
expected: []*clusterv1.MachineSet{},
469-
expectedRequire: nil,
460+
Name: "Get empty old MachineSets",
461+
deployment: deployment,
462+
msList: []*clusterv1.MachineSet{&newMS},
463+
expected: []*clusterv1.MachineSet{},
470464
},
471465
{
472466
Name: "Get old MachineSets with new MachineSets, MachineSets created before rolloutAfter are considered new when reconciliationTime < rolloutAfter",
473467
deployment: deployment,
474468
msList: []*clusterv1.MachineSet{&msCreatedTwoBeforeRolloutAfter},
475469
reconciliationTime: &oneBeforeRolloutAfter,
476470
expected: nil,
477-
expectedRequire: nil,
478471
},
479472
{
480473
Name: "Get old MachineSets with new MachineSets, MachineSets created after rolloutAfter are considered new when reconciliationTime > rolloutAfter",
481474
deployment: deployment,
482475
msList: []*clusterv1.MachineSet{&msCreatedTwoBeforeRolloutAfter, &msCreatedAfterRolloutAfter},
483476
reconciliationTime: &twoAfterRolloutAfter,
484477
expected: []*clusterv1.MachineSet{&msCreatedTwoBeforeRolloutAfter},
485-
expectedRequire: nil,
486478
},
487479
}
488480

489481
for _, test := range tests {
490482
t.Run(test.Name, func(t *testing.T) {
491483
g := NewWithT(t)
492484

493-
requireMS, allMS := FindOldMachineSets(&test.deployment, test.msList, test.reconciliationTime)
485+
allMS := FindOldMachineSets(&test.deployment, test.msList, test.reconciliationTime)
494486
g.Expect(allMS).To(ConsistOf(test.expected))
495-
// MSs are getting filtered correctly by ms.spec.replicas
496-
g.Expect(requireMS).To(ConsistOf(test.expectedRequire))
497487
})
498488
}
499489
}

0 commit comments

Comments
 (0)