@@ -44,6 +44,7 @@ import (
44
44
listers "knative.dev/serving-progressive-rollout/pkg/client/listers/serving/v1"
45
45
"knative.dev/serving-progressive-rollout/pkg/reconciler/common"
46
46
"knative.dev/serving-progressive-rollout/pkg/reconciler/rolloutorchestrator"
47
+ "knative.dev/serving-progressive-rollout/pkg/reconciler/rolloutorchestrator/strategies"
47
48
"knative.dev/serving-progressive-rollout/pkg/reconciler/service/resources"
48
49
"knative.dev/serving/pkg/apis/autoscaling"
49
50
"knative.dev/serving/pkg/apis/serving"
@@ -937,14 +938,38 @@ func convertIntoTrafficTarget(name string, ro *v1.RolloutOrchestrator, rc *Rollo
937
938
// The name is the same as the revision name.
938
939
spaTargetRevName := targetRevName
939
940
targetNumberReplicas , minScale := finalTargetRevs [0 ].MinScale , finalTargetRevs [0 ].MinScale
941
+ var minScalingDown * int32
942
+ targetNameScalingDown := ""
943
+ var targetReplicasPercentage * int64
940
944
941
945
// Find the target number of replicas for the current stage.
942
946
for _ , revision := range ro .Spec .StageTargetRevisions {
943
947
if revision .RevisionName == spaTargetRevName && revision .TargetReplicas != nil {
944
948
targetNumberReplicas = revision .TargetReplicas
949
+ targetReplicasPercentage = revision .Percent
945
950
}
951
+
952
+ if revision .Direction == v1 .DirectionDown {
953
+ targetNameScalingDown = revision .RevisionName
954
+ minScalingDown = revision .MinScale
955
+ }
956
+ }
957
+
958
+ // Verify if the revision scaling down is traffic driven or not.
959
+ spa , err := spaLister .Get (targetNameScalingDown )
960
+ trafficDriven := true
961
+
962
+ if err == nil && ((spa .Status .ActualScale != nil && minScalingDown != nil &&
963
+ * spa .Status .ActualScale <= * minScalingDown ) ||
964
+ (spa .Status .ActualScale != nil && * spa .Status .ActualScale == 0 && minScalingDown == nil )) {
965
+ trafficDriven = false
966
+ }
967
+
968
+ lastStage := false
969
+ if targetReplicasPercentage != nil && * targetReplicasPercentage == 100 {
970
+ lastStage = true
946
971
}
947
- spa , err : = spaLister .Get (spaTargetRevName )
972
+ spa , err = spaLister .Get (spaTargetRevName )
948
973
// Check the number of replicas has reached the target number of replicas for the revision scaling up
949
974
if err == nil && targetNumberReplicas != nil && spa .Status .ActualScale != nil && minScale != nil &&
950
975
* spa .Status .ActualScale < * minScale && * spa .Status .ActualScale < * targetNumberReplicas {
@@ -954,27 +979,31 @@ func convertIntoTrafficTarget(name string, ro *v1.RolloutOrchestrator, rc *Rollo
954
979
// However, if there is no issue getting yhe spa, and the actual number of replicas is less than
955
980
// the target number of replicas, we need to use ro.Status.StageRevisionStatus or route.Status.Traffic
956
981
// as the traffic information for the route.
957
- if len (ro .Status .StageRevisionStatus ) > 0 {
958
- // If the ro has the StageRevisionStatus in the status, use it.
959
- revisionTarget = ro .Status .StageRevisionStatus
960
- for index := range revisionTarget {
961
- if revisionTarget [index ].RevisionName == spaTargetRevName {
962
- continue
963
- }
964
- revisionTarget [index ].LatestRevision = ptr .Bool (false )
965
- }
966
- } else {
967
- // If the ro does not have the StageRevisionStatus in the status, use the existing one in route.
968
- route , errRoute := routeLister .Get (ro .Name )
969
- if errRoute == nil && len (route .Status .Traffic ) > 0 {
970
- traffics := route .Status .Traffic
971
- for index := range traffics {
972
- if traffics [index ].RevisionName == spaTargetRevName {
982
+
983
+ if rc .ProgressiveRolloutStrategy == strategies .AvailabilityStrategy ||
984
+ (rc .ProgressiveRolloutStrategy == strategies .ResourceUtilStrategy && ! trafficDriven && ! lastStage ) {
985
+ if len (ro .Status .StageRevisionStatus ) > 0 {
986
+ // If the ro has the StageRevisionStatus in the status, use it.
987
+ revisionTarget = ro .Status .StageRevisionStatus
988
+ for index := range revisionTarget {
989
+ if revisionTarget [index ].RevisionName == spaTargetRevName {
973
990
continue
974
991
}
975
- traffics [index ].LatestRevision = ptr .Bool (false )
992
+ revisionTarget [index ].LatestRevision = ptr .Bool (false )
993
+ }
994
+ } else {
995
+ // If the ro does not have the StageRevisionStatus in the status, use the existing one in route.
996
+ route , errRoute := routeLister .Get (ro .Name )
997
+ if errRoute == nil && len (route .Status .Traffic ) > 0 {
998
+ traffics := route .Status .Traffic
999
+ for index := range traffics {
1000
+ if traffics [index ].RevisionName == spaTargetRevName {
1001
+ continue
1002
+ }
1003
+ traffics [index ].LatestRevision = ptr .Bool (false )
1004
+ }
1005
+ return traffics
976
1006
}
977
- return traffics
978
1007
}
979
1008
}
980
1009
}
0 commit comments