Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep DesiredReplicas annotation up to date even if no scaling happens #821

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
},
},
}),
)
})
})