Skip to content

Commit 4661b6e

Browse files
authored
fix: a smaller maxUnavaila will block the sidecarSet from updating pods (#1834)
Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>
1 parent 54a769f commit 4661b6e

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

pkg/controller/sidecarset/sidecarset_strategy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ func calculateUpgradeCount(coreControl sidecarcontrol.SidecarControl, waitUpdate
139139
// default partition = 0, indicates all pods will been upgraded
140140
var partition int
141141
if strategy.Partition != nil {
142-
partition, _ = intstrutil.GetValueFromIntOrPercent(strategy.Partition, totalReplicas, false)
142+
totalInt32 := int32(totalReplicas)
143+
partition, _ = util.CalculatePartitionReplicas(strategy.Partition, &totalInt32)
143144
}
144145
// indicates the partition pods will not be upgraded for the time
145146
if len(waitUpdateIndexes)-partition <= 0 {
@@ -150,7 +151,7 @@ func calculateUpgradeCount(coreControl sidecarcontrol.SidecarControl, waitUpdate
150151
// max unavailable pods number, default is 1
151152
maxUnavailable := 1
152153
if strategy.MaxUnavailable != nil {
153-
maxUnavailable, _ = intstrutil.GetValueFromIntOrPercent(strategy.MaxUnavailable, totalReplicas, false)
154+
maxUnavailable, _ = intstrutil.GetValueFromIntOrPercent(strategy.MaxUnavailable, totalReplicas, true)
154155
}
155156

156157
var upgradeAndNotReadyCount int

pkg/controller/sidecarset/sidecarset_strategy_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,65 @@ func testGetNextUpgradePods(t *testing.T, factoryPods FactoryPods, factorySideca
355355
exceptNeedUpgradeCount: 0,
356356
exceptNotUpgradableCount: 100,
357357
},
358+
{
359+
name: "only maxUnavailable(5%), and pods(count=5, upgraded=0, upgradedAndReady=0)",
360+
getPods: func() []*corev1.Pod {
361+
pods := factoryPods(5, 0, 0)
362+
return Random(pods)
363+
},
364+
getSidecarset: func() *appsv1alpha1.SidecarSet {
365+
sidecarSet := factorySidecar()
366+
sidecarSet.Spec.UpdateStrategy.MaxUnavailable = &intstr.IntOrString{
367+
Type: intstr.String,
368+
StrVal: "5%",
369+
}
370+
return sidecarSet
371+
},
372+
exceptNeedUpgradeCount: 1,
373+
exceptNotUpgradableCount: 0,
374+
},
375+
{
376+
name: "maxUnavailable(5) partition(99%), and pods(count=5, upgraded=0, upgradedAndReady=0)",
377+
getPods: func() []*corev1.Pod {
378+
pods := factoryPods(5, 0, 0)
379+
return Random(pods)
380+
},
381+
getSidecarset: func() *appsv1alpha1.SidecarSet {
382+
sidecarSet := factorySidecar()
383+
sidecarSet.Spec.UpdateStrategy.MaxUnavailable = &intstr.IntOrString{
384+
Type: intstr.Int,
385+
IntVal: 5,
386+
}
387+
sidecarSet.Spec.UpdateStrategy.Partition = &intstr.IntOrString{
388+
Type: intstr.String,
389+
StrVal: "99%",
390+
}
391+
return sidecarSet
392+
},
393+
exceptNeedUpgradeCount: 1,
394+
exceptNotUpgradableCount: 0,
395+
},
396+
{
397+
name: "maxUnavailable(5) partition(1%), and pods(count=5, upgraded=0, upgradedAndReady=0)",
398+
getPods: func() []*corev1.Pod {
399+
pods := factoryPods(5, 0, 0)
400+
return Random(pods)
401+
},
402+
getSidecarset: func() *appsv1alpha1.SidecarSet {
403+
sidecarSet := factorySidecar()
404+
sidecarSet.Spec.UpdateStrategy.MaxUnavailable = &intstr.IntOrString{
405+
Type: intstr.Int,
406+
IntVal: 5,
407+
}
408+
sidecarSet.Spec.UpdateStrategy.Partition = &intstr.IntOrString{
409+
Type: intstr.String,
410+
StrVal: "1%",
411+
}
412+
return sidecarSet
413+
},
414+
exceptNeedUpgradeCount: 4,
415+
exceptNotUpgradableCount: 0,
416+
},
358417
}
359418
strategy := NewStrategy()
360419
for _, cs := range cases {

0 commit comments

Comments
 (0)