Skip to content

Commit

Permalink
Automated cherry pick of #821: keep desired replicas annotation up to…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>

---------

Co-authored-by: Himanshu Sharma <[email protected]>
  • Loading branch information
rishabh-11 and himanshu-kun authored Jun 5, 2023
1 parent 79ca25e commit 50861db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pkg/controller/deployment_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,10 @@ func (dc *controller) scale(ctx context.Context, deployment *v1alpha1.MachineDep
// deployment. If there is no active machine set, then we should scale up the newest machine set.
if activeOrLatest := FindActiveOrLatest(newIS, oldISs); activeOrLatest != nil {
if (activeOrLatest.Spec.Replicas) == (deployment.Spec.Replicas) {
return nil
// to deal with the case where the DesiredReplicas annotation is outdated (issue - https://github.com/gardener/machine-controller-manager/issues/815)
klog.V(3).Infof("DesiredReplicas annotation possibly outdated for the machineSet %s, updating if needed...", activeOrLatest.Name)
_, _, err := dc.scaleMachineSet(ctx, activeOrLatest, deployment.Spec.Replicas, deployment, "no-op")
return err
}
klog.V(3).Infof("Scaling latest/theOnlyActive machineSet %s", activeOrLatest.Name)
_, _, err := dc.scaleMachineSetAndRecordEvent(ctx, activeOrLatest, deployment.Spec.Replicas, deployment)
Expand Down
20 changes: 18 additions & 2 deletions pkg/controller/deployment_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,9 @@ var _ = Describe("deployment_sync", func() {
controlObjects = append(controlObjects, data.setup.oldISs[i])
}

controlObjects = append(controlObjects, data.setup.newIS)

if data.setup.newIS != nil {
controlObjects = append(controlObjects, data.setup.newIS)
}
c, trackers := createController(stop, testNamespace, controlObjects, nil, nil)
defer trackers.Stop()
waitForCacheSync(stop, c)
Expand Down Expand Up @@ -840,6 +841,21 @@ var _ = Describe("deployment_sync", func() {
err: false,
},
}),
Entry("if no scaling needed but DesiredReplicas Annotation for the only active machineSet is outdated, it should be updated with the correct value", &data{
setup: setup{
machineDeployment: newMachineDeployment(mDeploymentSpecTemplate, 1, 500, 2, 0, nil, nil, nil, nil),
oldISs: []*machinev1.MachineSet{
newMachineSet(mSetSpecTemplate, nameMachineSet1, 1, 500, nil, nil, map[string]string{DesiredReplicasAnnotation: "2", MaxReplicasAnnotation: "3"}, nil),
},
newIS: nil,
},
expect: expect{
err: false,
machineSets: []*machinev1.MachineSet{
newMachineSet(mSetSpecTemplate, nameMachineSet1, 1, 500, nil, nil, map[string]string{DesiredReplicasAnnotation: "1", MaxReplicasAnnotation: "3"}, nil),
},
},
}),
)
})
})

0 comments on commit 50861db

Please sign in to comment.