@@ -71,7 +71,7 @@ func TestLabelPatcher(t *testing.T) {
7171 },
7272 Batches : []v1beta1.ReleaseBatch {
7373 {
74- CanaryReplicas : intstr .FromInt (5 ),
74+ CanaryReplicas : intstr .FromInt32 (5 ),
7575 },
7676 },
7777 expectedPatched : []int {5 },
@@ -91,7 +91,7 @@ func TestLabelPatcher(t *testing.T) {
9191 },
9292 Batches : []v1beta1.ReleaseBatch {
9393 {
94- CanaryReplicas : intstr .FromInt (5 ),
94+ CanaryReplicas : intstr .FromInt32 (5 ),
9595 },
9696 },
9797 expectedPatched : []int {5 },
@@ -111,7 +111,7 @@ func TestLabelPatcher(t *testing.T) {
111111 },
112112 Batches : []v1beta1.ReleaseBatch {
113113 {
114- CanaryReplicas : intstr .FromInt (5 ),
114+ CanaryReplicas : intstr .FromInt32 (5 ),
115115 },
116116 },
117117 expectedPatched : []int {5 },
@@ -131,7 +131,7 @@ func TestLabelPatcher(t *testing.T) {
131131 },
132132 Batches : []v1beta1.ReleaseBatch {
133133 {
134- CanaryReplicas : intstr .FromInt (5 ),
134+ CanaryReplicas : intstr .FromInt32 (5 ),
135135 },
136136 },
137137 expectedPatched : []int {7 },
@@ -151,7 +151,7 @@ func TestLabelPatcher(t *testing.T) {
151151 },
152152 Batches : []v1beta1.ReleaseBatch {
153153 {
154- CanaryReplicas : intstr .FromInt (5 ),
154+ CanaryReplicas : intstr .FromInt32 (5 ),
155155 },
156156 },
157157 expectedPatched : []int {2 },
@@ -171,7 +171,7 @@ func TestLabelPatcher(t *testing.T) {
171171 },
172172 Batches : []v1beta1.ReleaseBatch {
173173 {
174- CanaryReplicas : intstr .FromInt (5 ),
174+ CanaryReplicas : intstr .FromInt32 (5 ),
175175 },
176176 },
177177 expectedPatched : []int {5 },
@@ -191,8 +191,8 @@ func TestLabelPatcher(t *testing.T) {
191191 return ctx
192192 },
193193 Batches : []v1beta1.ReleaseBatch {
194- {CanaryReplicas : intstr .FromInt (2 )},
195- {CanaryReplicas : intstr .FromInt (5 )},
194+ {CanaryReplicas : intstr .FromInt32 (2 )},
195+ {CanaryReplicas : intstr .FromInt32 (5 )},
196196 },
197197 expectedPatched : []int {2 , 3 },
198198 },
@@ -211,8 +211,8 @@ func TestLabelPatcher(t *testing.T) {
211211 return ctx
212212 },
213213 Batches : []v1beta1.ReleaseBatch {
214- {CanaryReplicas : intstr .FromInt (2 )},
215- {CanaryReplicas : intstr .FromInt (5 )},
214+ {CanaryReplicas : intstr .FromInt32 (2 )},
215+ {CanaryReplicas : intstr .FromInt32 (5 )},
216216 },
217217 expectedPatched : []int {2 , 3 },
218218 },
@@ -231,11 +231,31 @@ func TestLabelPatcher(t *testing.T) {
231231 return ctx
232232 },
233233 Batches : []v1beta1.ReleaseBatch {
234- {CanaryReplicas : intstr .FromInt (2 )},
235- {CanaryReplicas : intstr .FromInt (5 )},
234+ {CanaryReplicas : intstr .FromInt32 (2 )},
235+ {CanaryReplicas : intstr .FromInt32 (5 )},
236236 },
237237 expectedPatched : []int {3 , 2 },
238238 },
239+ "batch-id out of range, equal to no pods are labelled" : {
240+ batchContext : func () * batchcontext.BatchContext {
241+ ctx := & batchcontext.BatchContext {
242+ RolloutID : "rollout-1" ,
243+ UpdateRevision : "version-1" ,
244+ PlannedUpdatedReplicas : 5 ,
245+ CurrentBatch : 1 ,
246+ Replicas : 10 ,
247+ }
248+ pods := generatePods (1 , 5 , 3 ,
249+ "rollout-1" , strconv .Itoa (3 ), ctx .UpdateRevision )
250+ ctx .Pods = pods
251+ return ctx
252+ },
253+ Batches : []v1beta1.ReleaseBatch {
254+ {CanaryReplicas : intstr .FromInt32 (2 )},
255+ {CanaryReplicas : intstr .FromInt32 (5 )},
256+ },
257+ expectedPatched : []int {2 , 3 },
258+ },
239259 }
240260
241261 for name , cs := range cases {
@@ -255,7 +275,7 @@ func TestLabelPatcher(t *testing.T) {
255275 patched := make ([]int , ctx .CurrentBatch + 1 )
256276 for _ , pod := range podList .Items {
257277 if pod .Labels [v1beta1 .RolloutIDLabel ] == ctx .RolloutID {
258- if batchID , err := strconv .Atoi (pod .Labels [v1beta1 .RolloutBatchIDLabel ]); err == nil {
278+ if batchID , err := strconv .Atoi (pod .Labels [v1beta1 .RolloutBatchIDLabel ]); err == nil && batchID <= len ( patched ) {
259279 patched [batchID - 1 ]++
260280 }
261281 }
@@ -311,7 +331,7 @@ func TestDeploymentPatch(t *testing.T) {
311331 },
312332 Batches : []v1beta1.ReleaseBatch {
313333 {
314- CanaryReplicas : intstr .FromInt (5 ),
334+ CanaryReplicas : intstr .FromInt32 (5 ),
315335 },
316336 },
317337 expectedPatched : []int {5 },
@@ -331,7 +351,7 @@ func TestDeploymentPatch(t *testing.T) {
331351 },
332352 Batches : []v1beta1.ReleaseBatch {
333353 {
334- CanaryReplicas : intstr .FromInt (5 ),
354+ CanaryReplicas : intstr .FromInt32 (5 ),
335355 },
336356 },
337357 expectedPatched : []int {5 },
@@ -351,7 +371,7 @@ func TestDeploymentPatch(t *testing.T) {
351371 },
352372 Batches : []v1beta1.ReleaseBatch {
353373 {
354- CanaryReplicas : intstr .FromInt (5 ),
374+ CanaryReplicas : intstr .FromInt32 (5 ),
355375 },
356376 },
357377 expectedPatched : []int {5 },
@@ -371,7 +391,7 @@ func TestDeploymentPatch(t *testing.T) {
371391 },
372392 Batches : []v1beta1.ReleaseBatch {
373393 {
374- CanaryReplicas : intstr .FromInt (5 ),
394+ CanaryReplicas : intstr .FromInt32 (5 ),
375395 },
376396 },
377397 expectedPatched : []int {7 },
@@ -391,7 +411,7 @@ func TestDeploymentPatch(t *testing.T) {
391411 },
392412 Batches : []v1beta1.ReleaseBatch {
393413 {
394- CanaryReplicas : intstr .FromInt (5 ),
414+ CanaryReplicas : intstr .FromInt32 (5 ),
395415 },
396416 },
397417 expectedPatched : []int {2 },
@@ -411,7 +431,7 @@ func TestDeploymentPatch(t *testing.T) {
411431 },
412432 Batches : []v1beta1.ReleaseBatch {
413433 {
414- CanaryReplicas : intstr .FromInt (5 ),
434+ CanaryReplicas : intstr .FromInt32 (5 ),
415435 },
416436 },
417437 expectedPatched : []int {5 },
@@ -431,8 +451,8 @@ func TestDeploymentPatch(t *testing.T) {
431451 return ctx
432452 },
433453 Batches : []v1beta1.ReleaseBatch {
434- {CanaryReplicas : intstr .FromInt (2 )},
435- {CanaryReplicas : intstr .FromInt (5 )},
454+ {CanaryReplicas : intstr .FromInt32 (2 )},
455+ {CanaryReplicas : intstr .FromInt32 (5 )},
436456 },
437457 expectedPatched : []int {2 , 3 },
438458 },
@@ -451,8 +471,8 @@ func TestDeploymentPatch(t *testing.T) {
451471 return ctx
452472 },
453473 Batches : []v1beta1.ReleaseBatch {
454- {CanaryReplicas : intstr .FromInt (2 )},
455- {CanaryReplicas : intstr .FromInt (5 )},
474+ {CanaryReplicas : intstr .FromInt32 (2 )},
475+ {CanaryReplicas : intstr .FromInt32 (5 )},
456476 },
457477 expectedPatched : []int {2 , 3 },
458478 },
@@ -471,8 +491,8 @@ func TestDeploymentPatch(t *testing.T) {
471491 return ctx
472492 },
473493 Batches : []v1beta1.ReleaseBatch {
474- {CanaryReplicas : intstr .FromInt (2 )},
475- {CanaryReplicas : intstr .FromInt (5 )},
494+ {CanaryReplicas : intstr .FromInt32 (2 )},
495+ {CanaryReplicas : intstr .FromInt32 (5 )},
476496 },
477497 expectedPatched : []int {3 , 2 },
478498 },
0 commit comments