File tree Expand file tree Collapse file tree 8 files changed +278
-32
lines changed
Expand file tree Collapse file tree 8 files changed +278
-32
lines changed Original file line number Diff line number Diff line change 7676 weight : 80
7777 - stackName : mystack-v2
7878 weight : 20
79+ # optional percentage of required Replicas ready to allow traffic switch
80+ # if none specified, defaults to 100
81+ minReadyPercent : 90
7982 stackLifecycle :
8083 scaledownTTLSeconds : 300
8184 limit : 5 # maximum number of scaled down stacks to keep.
Original file line number Diff line number Diff line change 1313 weight : 40
1414 - stackName : my-app-v2
1515 weight : 60
16+ minReadyPercent : 90
1617 stackLifecycle :
1718 scaledownTTLSeconds : 300
1819 limit : 5
Original file line number Diff line number Diff line change @@ -103,6 +103,10 @@ spec:
103103 - backendPort
104104 - hosts
105105 type: object
106+ minReadyPercent:
107+ description: minReadyPercent sets the minimum percentage of Pods expected
108+ to be Ready to consider a Stack for traffic switch
109+ type: integer
106110 routegroup:
107111 description: RouteGroup is an alternative to ingress allowing more
108112 advanced routing configuration while still maintaining the ability
Original file line number Diff line number Diff line change @@ -61,6 +61,9 @@ type StackSetSpec struct {
6161 // weights. It defines the desired traffic. Clients that
6262 // orchestrate traffic switching should write this part.
6363 Traffic []* DesiredTraffic `json:"traffic,omitempty"`
64+ // minReadyPercent sets the minimum percentage of Pods expected
65+ // to be Ready to consider a Stack for traffic switch
66+ MinReadyPercent int `json:"minReadyPercent,omitempty"`
6467}
6568
6669// EmbeddedObjectMetaWithAnnotations defines the metadata which can be attached
Original file line number Diff line number Diff line change @@ -45,10 +45,14 @@ func testStack(name string) *testStackFactory {
4545}
4646
4747func (f * testStackFactory ) ready (replicas int32 ) * testStackFactory {
48+ return f .partiallyReady (replicas , replicas )
49+ }
50+
51+ func (f * testStackFactory ) partiallyReady (readyReplicas , replicas int32 ) * testStackFactory {
4852 f .container .resourcesUpdated = true
4953 f .container .deploymentReplicas = replicas
50- f .container .updatedReplicas = replicas
51- f .container .readyReplicas = replicas
54+ f .container .updatedReplicas = readyReplicas
55+ f .container .readyReplicas = readyReplicas
5256 return f
5357}
5458
Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ func allZero(weights map[string]float64) bool {
2121 return true
2222}
2323
24+ // normalizeMinReadyPercent normalizes minimum percentage of Ready pods.
25+ // If value is under or equal to 0, or over or equal to 100, set it to 1.0
26+ // If value is between 0-100, it's then set as decimal
27+ func normalizeMinReadyPercent (minReadyPercent int ) float64 {
28+ if minReadyPercent >= 100 || minReadyPercent <= 0 {
29+ return 1.0
30+ }
31+ return float64 (minReadyPercent ) / 100
32+ }
33+
2434// normalizeWeights normalizes a map of backend weights.
2535// If all weights are zero the total weight of 100 is distributed equally
2636// between all backends.
@@ -155,9 +165,11 @@ func (ssc *StackSetContainer) ManageTraffic(currentTimestamp time.Time) error {
155165 }
156166 }
157167
168+ minReadyPercent := normalizeMinReadyPercent (ssc .StackSet .Spec .MinReadyPercent )
158169 for stackName , stack := range stacks {
159170 stack .desiredTrafficWeight = desiredWeights [stackName ]
160171 stack .actualTrafficWeight = actualWeights [stackName ]
172+ stack .minReadyPercent = minReadyPercent
161173 }
162174
163175 // Run the traffic reconciler which will update the actual weights according to the desired weights. The resulting
You can’t perform that action at this time.
0 commit comments