Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit fe4ec15

Browse files
⚡️ Improve scale-up/down performance by processing pod-template changes before replicas (#1310)
1 parent e0abed4 commit fe4ec15

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/nyaruka/phonenumbers v1.1.7
3333
github.com/pkg/errors v0.9.1
3434
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.70.0
35-
github.com/rigdev/rig-go-api v0.0.0-20241023135935-eac99f7a930f
35+
github.com/rigdev/rig-go-api v0.0.0-20241029083126-a6814266e716
3636
github.com/rigdev/rig-go-sdk v0.0.0-20241021090503-b515c1ca035f
3737
github.com/rivo/tview v0.0.0-20240524063012-037df494fb76
3838
github.com/robfig/cron v1.2.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJ
309309
github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
310310
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
311311
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
312-
github.com/rigdev/rig-go-api v0.0.0-20241023135935-eac99f7a930f h1:D87qhahpJla10fB/Ptd9/Ocg5ktGFJ3HosQDBrnn9vk=
313-
github.com/rigdev/rig-go-api v0.0.0-20241023135935-eac99f7a930f/go.mod h1:0yAwJnPID3gHfB3ETQAFYGM1tkNWkJKbVzauZiHmHKw=
312+
github.com/rigdev/rig-go-api v0.0.0-20241029083126-a6814266e716 h1:QpieTeTr+uVcjBcQJuGpLz7sFuHl87EKf0lST7gK9qc=
313+
github.com/rigdev/rig-go-api v0.0.0-20241029083126-a6814266e716/go.mod h1:0yAwJnPID3gHfB3ETQAFYGM1tkNWkJKbVzauZiHmHKw=
314314
github.com/rigdev/rig-go-sdk v0.0.0-20241021090503-b515c1ca035f h1:SScDJVwFt/QzURstwUdi/ejnRoqB1ZsBLlICPD6Lt0c=
315315
github.com/rigdev/rig-go-sdk v0.0.0-20241021090503-b515c1ca035f/go.mod h1:DJAwoPmFI6Jo71n/2VfFk/Nyzlyd24ARWCLC4Hsm1gg=
316316
github.com/rivo/tview v0.0.0-20240524063012-037df494fb76 h1:iqvDlgyjmqleATtFbA7c14djmPh2n4mCYUv7JlD/ruA=

pkg/pipeline/request.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func (r *RequestBase) applyChange(ctx context.Context, key ObjectKey, state Reso
505505
switch state {
506506
case ResourceStateUpdated:
507507
r.logger.Info("update object", "object", key)
508-
obj := r.newObjects[key]
508+
object := r.newObjects[key]
509509

510510
// Edge case: Deployments, when they are scaled, will apply changes in the following order:
511511
// 1) Change the number of replicas (pods) in the current ReplicaSet
@@ -518,18 +518,33 @@ func (r *RequestBase) applyChange(ctx context.Context, key ObjectKey, state Reso
518518
// 1) First, we apply the template changes (use current number of replicas)
519519
// 2) Then apply the scale changes.
520520
// That way the scale is only being applied to the new ReplicaSet.
521-
if key.GroupVersionKind == AppsDeploymentGVK && obj.Materialized != nil {
522-
currentObj := obj.Current.(*v1.Deployment)
523-
newObj := obj.New.(*v1.Deployment)
524-
materializedObj := obj.Materialized.(*v1.Deployment)
521+
if key.GroupVersionKind == AppsDeploymentGVK && object.Materialized != nil {
522+
currentObj := object.Current.(*v1.Deployment)
523+
newObj := object.New.(*v1.Deployment)
524+
materializedObj := object.Materialized.(*v1.Deployment)
525+
for _, c := range currentObj.Status.Conditions {
526+
if c.Type == v1.DeploymentProgressing && c.Reason == "ReplicaSetUpdated" {
527+
// We have an ongoing rollout, wait a little with scale-up.
528+
if newObj.Spec.Replicas != nil &&
529+
currentObj.Spec.Replicas != nil &&
530+
*newObj.Spec.Replicas > *currentObj.Spec.Replicas {
531+
newObj.Spec.Replicas = currentObj.Spec.Replicas
532+
}
533+
}
534+
}
535+
525536
if !equality.Semantic.DeepEqual(currentObj.Spec.Template, materializedObj.Spec.Template) {
526537
// We have changes to the template - don't apply potential replica changes yet.
527-
newObj.Spec.Replicas = currentObj.Spec.Replicas
538+
if newObj.Spec.Replicas != nil &&
539+
currentObj.Spec.Replicas != nil &&
540+
*newObj.Spec.Replicas > *currentObj.Spec.Replicas {
541+
newObj.Spec.Replicas = currentObj.Spec.Replicas
542+
}
528543
}
529544
}
530545

531-
obj.New.SetResourceVersion(obj.Current.GetResourceVersion())
532-
if err := r.client.Update(ctx, obj.New); err != nil {
546+
object.New.SetResourceVersion(object.Current.GetResourceVersion())
547+
if err := r.client.Update(ctx, object.New); err != nil {
533548
return fmt.Errorf("could not update %s: %w", key.GroupVersionKind, err)
534549
}
535550

0 commit comments

Comments
 (0)