Skip to content

Commit b858653

Browse files
[release-1.18] Assigned 0% traffic to the new revision before reaching the minimum replicas (#345)
Assigned 0% traffic to the new revision before reaching the minimum replicas Fixed: #335 Co-authored-by: Vincent Hou <shou73@bloomberg.net>
1 parent b0f6b05 commit b858653

File tree

2 files changed

+110
-10
lines changed

2 files changed

+110
-10
lines changed

pkg/reconciler/service/service.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,23 +989,53 @@ func convertIntoTrafficTarget(name string, ro *v1.RolloutOrchestrator, rc *Rollo
989989
if len(ro.Status.StageRevisionStatus) > 0 {
990990
// If the ro has the StageRevisionStatus in the status, use it.
991991
revisionTarget = ro.Status.StageRevisionStatus
992+
found := false
992993
for index := range revisionTarget {
993994
if revisionTarget[index].RevisionName == spaTargetRevName {
995+
found = true
994996
continue
995997
}
996998
revisionTarget[index].LatestRevision = ptr.Bool(false)
997999
}
1000+
if !found {
1001+
// We must assign the traffic to the new revision, even of it is 0%. Otherwise, the PA will
1002+
// sometimes report the error of "No traffic. The target is not receiving traffic", which
1003+
// will kill the pods of the new revision during the progressive rollout.
1004+
// The last one of ro.Spec.StageTargetRevisions is certainly the RevisionTarget for the
1005+
// new revision,
1006+
newRevisionTarget := ro.Spec.StageTargetRevisions[len(ro.Spec.StageTargetRevisions)-1]
1007+
newRevisionTarget.Percent = ptr.Int64(int64(0))
1008+
revisionTarget = append(revisionTarget, newRevisionTarget)
1009+
}
9981010
} else {
9991011
// If the ro does not have the StageRevisionStatus in the status, use the existing one in route.
10001012
route, errRoute := routeLister.Get(ro.Name)
10011013
if errRoute == nil && len(route.Status.Traffic) > 0 {
10021014
traffics := route.Status.Traffic
1015+
found := false
10031016
for index := range traffics {
10041017
if traffics[index].RevisionName == spaTargetRevName {
1018+
found = true
10051019
continue
10061020
}
10071021
traffics[index].LatestRevision = ptr.Bool(false)
10081022
}
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+
}
10091039
return traffics
10101040
}
10111041
}

pkg/reconciler/service/service_test.go

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,9 @@ func TestTransformService(t *testing.T) {
911911
spaLister: MockSPALister{
912912
ActualScale: ptr.Int32(2),
913913
},
914-
routeLister: MockRouteLister{},
914+
routeLister: MockRouteLister{
915+
WithNewRev: true,
916+
},
915917
rc: &RolloutConfig{
916918
ProgressiveRolloutEnabled: true,
917919
ProgressiveRolloutStrategy: strategies.AvailabilityStrategy,
@@ -950,7 +952,9 @@ func TestTransformService(t *testing.T) {
950952
spaLister: MockSPALister{
951953
ActualScale: ptr.Int32(1),
952954
},
953-
routeLister: MockRouteLister{},
955+
routeLister: MockRouteLister{
956+
WithNewRev: true,
957+
},
954958
rc: &RolloutConfig{
955959
ProgressiveRolloutEnabled: true,
956960
ProgressiveRolloutStrategy: strategies.AvailabilityStrategy,
@@ -975,6 +979,52 @@ func TestTransformService(t *testing.T) {
975979
LatestRevision: ptr.Bool(false),
976980
Percent: ptr.Int64(100),
977981
},
982+
{
983+
ConfigurationName: "test-name",
984+
LatestRevision: ptr.Bool(true),
985+
Percent: ptr.Int64(0),
986+
},
987+
},
988+
},
989+
},
990+
},
991+
}, {
992+
name: "Test with StageTargetRevisions with revision name for the latest revision, with no ro status, but route status",
993+
spaLister: MockSPALister{
994+
ActualScale: ptr.Int32(1),
995+
},
996+
routeLister: MockRouteLister{
997+
WithNewRev: false,
998+
},
999+
rc: &RolloutConfig{
1000+
ProgressiveRolloutEnabled: true,
1001+
ProgressiveRolloutStrategy: strategies.AvailabilityStrategy,
1002+
},
1003+
service: &servingv1.Service{
1004+
ObjectMeta: metav1.ObjectMeta{
1005+
Name: "test-name",
1006+
Namespace: "test-ns",
1007+
},
1008+
},
1009+
ro: MockRolloutOrchestratorNoStatus,
1010+
ExpectedService: &servingv1.Service{
1011+
ObjectMeta: metav1.ObjectMeta{
1012+
Name: "test-name",
1013+
Namespace: "test-ns",
1014+
},
1015+
Spec: servingv1.ServiceSpec{
1016+
RouteSpec: servingv1.RouteSpec{
1017+
Traffic: []servingv1.TrafficTarget{
1018+
{
1019+
RevisionName: "rev-001",
1020+
LatestRevision: ptr.Bool(false),
1021+
Percent: ptr.Int64(100),
1022+
},
1023+
{
1024+
ConfigurationName: "test-name",
1025+
LatestRevision: ptr.Bool(true),
1026+
Percent: ptr.Int64(0),
1027+
},
9781028
},
9791029
},
9801030
},
@@ -984,7 +1034,9 @@ func TestTransformService(t *testing.T) {
9841034
spaLister: MockSPALister{
9851035
ActualScale: ptr.Int32(1),
9861036
},
987-
routeLister: MockRouteLister{},
1037+
routeLister: MockRouteLister{
1038+
WithNewRev: true,
1039+
},
9881040
rc: &RolloutConfig{
9891041
ProgressiveRolloutEnabled: true,
9901042
ProgressiveRolloutStrategy: strategies.AvailabilityStrategy,
@@ -1024,7 +1076,9 @@ func TestTransformService(t *testing.T) {
10241076
ActualScale: ptr.Int32(1),
10251077
Err: fmt.Errorf("Unable to find the resource"),
10261078
},
1027-
routeLister: MockRouteLister{},
1079+
routeLister: MockRouteLister{
1080+
WithNewRev: true,
1081+
},
10281082
rc: &RolloutConfig{
10291083
ProgressiveRolloutEnabled: true,
10301084
ProgressiveRolloutStrategy: strategies.AvailabilityStrategy,
@@ -1088,25 +1142,41 @@ func (spaLister MockSPALister) Get(_ string) (*v1.StagePodAutoscaler, error) {
10881142
}
10891143

10901144
type MockRouteLister struct {
1145+
WithNewRev bool
10911146
}
10921147

10931148
func (routeLister MockRouteLister) List(_ labels.Selector) (ret []*servingv1.Route, err error) {
10941149
return nil, nil
10951150
}
10961151

10971152
func (routeLister MockRouteLister) Get(_ string) (*servingv1.Route, error) {
1153+
if routeLister.WithNewRev {
1154+
return &servingv1.Route{
1155+
Status: servingv1.RouteStatus{
1156+
RouteStatusFields: servingv1.RouteStatusFields{
1157+
Traffic: []servingv1.TrafficTarget{
1158+
{
1159+
RevisionName: "rev-001",
1160+
Percent: ptr.Int64(90),
1161+
LatestRevision: ptr.Bool(false),
1162+
},
1163+
{
1164+
RevisionName: "rev-002",
1165+
Percent: ptr.Int64(10),
1166+
LatestRevision: ptr.Bool(true),
1167+
},
1168+
},
1169+
},
1170+
},
1171+
}, nil
1172+
}
10981173
return &servingv1.Route{
10991174
Status: servingv1.RouteStatus{
11001175
RouteStatusFields: servingv1.RouteStatusFields{
11011176
Traffic: []servingv1.TrafficTarget{
11021177
{
11031178
RevisionName: "rev-001",
1104-
Percent: ptr.Int64(90),
1105-
LatestRevision: ptr.Bool(false),
1106-
},
1107-
{
1108-
RevisionName: "rev-002",
1109-
Percent: ptr.Int64(10),
1179+
Percent: ptr.Int64(100),
11101180
LatestRevision: ptr.Bool(true),
11111181
},
11121182
},

0 commit comments

Comments
 (0)