Skip to content

Commit 50861db

Browse files
Automated cherry pick of #821: keep desired replicas annotation up to date even if no (#822)
* keep desired replicas annotation up to date even if no scaling happens * Update pkg/controller/deployment_sync_test.go Co-authored-by: Himanshu Sharma <79965161+himanshu-kun@users.noreply.github.com> --------- Co-authored-by: Himanshu Sharma <79965161+himanshu-kun@users.noreply.github.com>
1 parent 79ca25e commit 50861db

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pkg/controller/deployment_sync.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ func (dc *controller) scale(ctx context.Context, deployment *v1alpha1.MachineDep
404404
// deployment. If there is no active machine set, then we should scale up the newest machine set.
405405
if activeOrLatest := FindActiveOrLatest(newIS, oldISs); activeOrLatest != nil {
406406
if (activeOrLatest.Spec.Replicas) == (deployment.Spec.Replicas) {
407-
return nil
407+
// to deal with the case where the DesiredReplicas annotation is outdated (issue - https://github.com/gardener/machine-controller-manager/issues/815)
408+
klog.V(3).Infof("DesiredReplicas annotation possibly outdated for the machineSet %s, updating if needed...", activeOrLatest.Name)
409+
_, _, err := dc.scaleMachineSet(ctx, activeOrLatest, deployment.Spec.Replicas, deployment, "no-op")
410+
return err
408411
}
409412
klog.V(3).Infof("Scaling latest/theOnlyActive machineSet %s", activeOrLatest.Name)
410413
_, _, err := dc.scaleMachineSetAndRecordEvent(ctx, activeOrLatest, deployment.Spec.Replicas, deployment)

pkg/controller/deployment_sync_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,9 @@ var _ = Describe("deployment_sync", func() {
455455
controlObjects = append(controlObjects, data.setup.oldISs[i])
456456
}
457457

458-
controlObjects = append(controlObjects, data.setup.newIS)
459-
458+
if data.setup.newIS != nil {
459+
controlObjects = append(controlObjects, data.setup.newIS)
460+
}
460461
c, trackers := createController(stop, testNamespace, controlObjects, nil, nil)
461462
defer trackers.Stop()
462463
waitForCacheSync(stop, c)
@@ -840,6 +841,21 @@ var _ = Describe("deployment_sync", func() {
840841
err: false,
841842
},
842843
}),
844+
Entry("if no scaling needed but DesiredReplicas Annotation for the only active machineSet is outdated, it should be updated with the correct value", &data{
845+
setup: setup{
846+
machineDeployment: newMachineDeployment(mDeploymentSpecTemplate, 1, 500, 2, 0, nil, nil, nil, nil),
847+
oldISs: []*machinev1.MachineSet{
848+
newMachineSet(mSetSpecTemplate, nameMachineSet1, 1, 500, nil, nil, map[string]string{DesiredReplicasAnnotation: "2", MaxReplicasAnnotation: "3"}, nil),
849+
},
850+
newIS: nil,
851+
},
852+
expect: expect{
853+
err: false,
854+
machineSets: []*machinev1.MachineSet{
855+
newMachineSet(mSetSpecTemplate, nameMachineSet1, 1, 500, nil, nil, map[string]string{DesiredReplicasAnnotation: "1", MaxReplicasAnnotation: "3"}, nil),
856+
},
857+
},
858+
}),
843859
)
844860
})
845861
})

0 commit comments

Comments
 (0)