Skip to content

Commit

Permalink
[release-1.14] Added the target revisions scaling down into the Spec.…
Browse files Browse the repository at this point in the history
…StageTargetRevisions (#218)

Added the target revisions scaling down into the Spec.StageTargetRevisions

Co-authored-by: Vincent Hou <[email protected]>
  • Loading branch information
knative-prow-robot and houshengbo authored Jul 24, 2024
1 parent 191438e commit 8097c7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
13 changes: 12 additions & 1 deletion pkg/reconciler/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,23 @@ func updateStageTargetRevisions(ro *v1.RolloutOrchestrator, config *RolloutConfi
var stageRevisionTarget []v1.TargetRevision
if !targetsEqual(ro.Spec.InitialRevisions, ro.Spec.TargetRevisions) {
startRevisions := getStartRevisions(ro)
if len(startRevisions) == 0 || config.OverConsumptionRatio >= common.HundredPercent {
if len(startRevisions) == 0 {
// If the index is out of bound, assign the StageTargetRevisions to the final TargetRevisions.
ro.Spec.StageTargetRevisions = append([]v1.TargetRevision{}, ro.Spec.TargetRevisions...)
return nil
}

if config.OverConsumptionRatio >= common.HundredPercent {
ro.Spec.StageTargetRevisions = make([]v1.TargetRevision, 0, len(startRevisions)+len(ro.Spec.TargetRevisions))
for _, rev := range startRevisions {
rev.Percent = nil
rev.Direction = v1.DirectionDown
rev.LatestRevision = ptr.Bool(false)
ro.Spec.StageTargetRevisions = append(ro.Spec.StageTargetRevisions, rev)
}
ro.Spec.StageTargetRevisions = append(ro.Spec.StageTargetRevisions, ro.Spec.TargetRevisions...)
}

// The currentReplicas and currentTraffic will be used as the standard values to calculate
// the further target number of replicas for each revision.
currentReplicas, currentTraffic, repMap, err := getGauge(startRevisions, podAutoscalerLister,
Expand Down
17 changes: 15 additions & 2 deletions pkg/reconciler/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,27 @@ func TestUpdateStageTargetRevisions(t *testing.T) {
},
StageTarget: v1.StageTarget{
StageTargetRevisions: []v1.TargetRevision{
{
TrafficTarget: servingv1.TrafficTarget{
RevisionName: "rev-001",
LatestRevision: ptr.Bool(false),
Percent: nil,
},
Direction: "down",
TargetReplicas: ptr.Int32(0),
MinScale: ptr.Int32(8),
MaxScale: ptr.Int32(8),
},
{
TrafficTarget: servingv1.TrafficTarget{
RevisionName: "rev-002",
LatestRevision: ptr.Bool(true),
Percent: ptr.Int64(100),
},
MinScale: ptr.Int32(10),
MaxScale: ptr.Int32(10),
Direction: "up",
TargetReplicas: ptr.Int32(10),
MinScale: ptr.Int32(10),
MaxScale: ptr.Int32(10),
},
},
TargetFinishTime: apis.VolatileTime{
Expand Down

0 comments on commit 8097c7d

Please sign in to comment.