Skip to content

Commit 938a0a9

Browse files
authored
[release-1.18] Avoid the cases when RolloutDuration is set for traffic shift (#362)
1 parent b858653 commit 938a0a9

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

pkg/reconciler/service/service.go

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -975,15 +975,16 @@ func convertIntoTrafficTarget(name string, ro *v1.RolloutOrchestrator, rc *Rollo
975975

976976
spa, err := spaLister.Get(spaTargetRevName)
977977
// Check the number of replicas has reached the target number of replicas for the revision scaling up
978-
if apierrs.IsNotFound(err) || (err == nil && targetNumberReplicas != nil && spa.Status.ActualScale != nil &&
979-
minScale != nil && *targetNumberReplicas <= *minScale && *spa.Status.ActualScale < *targetNumberReplicas) {
978+
if err != nil || spa.Status.ActualScale == nil || (err == nil && targetNumberReplicas != nil &&
979+
spa.Status.ActualScale != nil && minScale != nil && *targetNumberReplicas <= *minScale &&
980+
*spa.Status.ActualScale < *targetNumberReplicas) {
980981
// If we have issues getting the spa, or the number of the replicas has reached the target number of
981982
// the revision to scale up, we set the revisionTarget to ro.Spec.StageTargetRevisions.
982983

983984
// However, if there is no issue getting yhe spa, and the actual number of replicas is less than
984985
// the target number of replicas, we need to use ro.Status.StageRevisionStatus or route.Status.Traffic
985986
// as the traffic information for the route.
986-
if strings.EqualFold(rc.ProgressiveRolloutStrategy, strategies.AvailabilityStrategy) {
987+
if strings.EqualFold(rc.ProgressiveRolloutStrategy, strategies.AvailabilityStrategy) && rc.RolloutDuration == "0" {
987988
// Comment out the following lines for further consideration with resourceUtil mode
988989
// || (strings.EqualFold(rc.ProgressiveRolloutStrategy, strategies.ResourceUtilStrategy) && !trafficDriven && !lastStage) {
989990
if len(ro.Status.StageRevisionStatus) > 0 {
@@ -997,7 +998,7 @@ func convertIntoTrafficTarget(name string, ro *v1.RolloutOrchestrator, rc *Rollo
997998
}
998999
revisionTarget[index].LatestRevision = ptr.Bool(false)
9991000
}
1000-
if !found {
1001+
if !found && spa != nil && spa.Status.ActualScale != nil && *spa.Status.ActualScale > 0 {
10011002
// We must assign the traffic to the new revision, even of it is 0%. Otherwise, the PA will
10021003
// sometimes report the error of "No traffic. The target is not receiving traffic", which
10031004
// will kill the pods of the new revision during the progressive rollout.
@@ -1007,37 +1008,6 @@ func convertIntoTrafficTarget(name string, ro *v1.RolloutOrchestrator, rc *Rollo
10071008
newRevisionTarget.Percent = ptr.Int64(int64(0))
10081009
revisionTarget = append(revisionTarget, newRevisionTarget)
10091010
}
1010-
} else {
1011-
// If the ro does not have the StageRevisionStatus in the status, use the existing one in route.
1012-
route, errRoute := routeLister.Get(ro.Name)
1013-
if errRoute == nil && len(route.Status.Traffic) > 0 {
1014-
traffics := route.Status.Traffic
1015-
found := false
1016-
for index := range traffics {
1017-
if traffics[index].RevisionName == spaTargetRevName {
1018-
found = true
1019-
continue
1020-
}
1021-
traffics[index].LatestRevision = ptr.Bool(false)
1022-
}
1023-
if !found {
1024-
// We must assign the traffic to the new revision, even of it is 0%. Otherwise, the PA will
1025-
// sometimes report the error of "No traffic. The target is not receiving traffic", which
1026-
// will kill the pods of the new revision during the progressive rollout.
1027-
newRevisionTarget := ro.Spec.StageTargetRevisions[len(ro.Spec.StageTargetRevisions)-1]
1028-
newRevisionTarget.Percent = ptr.Int64(int64(0))
1029-
1030-
newRevisionTraffic := servingv1.TrafficTarget{
1031-
ConfigurationName: name,
1032-
LatestRevision: newRevisionTarget.LatestRevision,
1033-
Percent: newRevisionTarget.Percent,
1034-
Tag: newRevisionTarget.Tag,
1035-
URL: newRevisionTarget.URL,
1036-
}
1037-
traffics = append(traffics, newRevisionTraffic)
1038-
}
1039-
return traffics
1040-
}
10411011
}
10421012
}
10431013
}

pkg/reconciler/service/service_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ func TestTransformService(t *testing.T) {
958958
rc: &RolloutConfig{
959959
ProgressiveRolloutEnabled: true,
960960
ProgressiveRolloutStrategy: strategies.AvailabilityStrategy,
961+
RolloutDuration: "0",
961962
},
962963
service: &servingv1.Service{
963964
ObjectMeta: metav1.ObjectMeta{
@@ -1018,12 +1019,12 @@ func TestTransformService(t *testing.T) {
10181019
{
10191020
RevisionName: "rev-001",
10201021
LatestRevision: ptr.Bool(false),
1021-
Percent: ptr.Int64(100),
1022+
Percent: ptr.Int64(80),
10221023
},
10231024
{
10241025
ConfigurationName: "test-name",
10251026
LatestRevision: ptr.Bool(true),
1026-
Percent: ptr.Int64(0),
1027+
Percent: ptr.Int64(20),
10271028
},
10281029
},
10291030
},
@@ -1058,13 +1059,13 @@ func TestTransformService(t *testing.T) {
10581059
Traffic: []servingv1.TrafficTarget{
10591060
{
10601061
RevisionName: "rev-001",
1061-
Percent: ptr.Int64(90),
1062+
Percent: ptr.Int64(80),
10621063
LatestRevision: ptr.Bool(false),
10631064
},
10641065
{
1065-
RevisionName: "rev-002",
1066-
Percent: ptr.Int64(10),
1067-
LatestRevision: ptr.Bool(true),
1066+
ConfigurationName: "test-name",
1067+
Percent: ptr.Int64(20),
1068+
LatestRevision: ptr.Bool(true),
10681069
},
10691070
},
10701071
},

0 commit comments

Comments
 (0)