Skip to content

Commit

Permalink
fix: a smaller maxUnavaila will block the sidecarSet from updating pods
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <[email protected]>
  • Loading branch information
zmberg committed Nov 20, 2024
1 parent 54a769f commit ab68bf0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/controller/sidecarset/sidecarset_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func calculateUpgradeCount(coreControl sidecarcontrol.SidecarControl, waitUpdate
// default partition = 0, indicates all pods will been upgraded
var partition int
if strategy.Partition != nil {
partition, _ = intstrutil.GetValueFromIntOrPercent(strategy.Partition, totalReplicas, false)
totalInt32 := int32(totalReplicas)
partition, _ = util.CalculatePartitionReplicas(strategy.Partition, &totalInt32)
}
// indicates the partition pods will not be upgraded for the time
if len(waitUpdateIndexes)-partition <= 0 {
Expand All @@ -150,7 +151,7 @@ func calculateUpgradeCount(coreControl sidecarcontrol.SidecarControl, waitUpdate
// max unavailable pods number, default is 1
maxUnavailable := 1
if strategy.MaxUnavailable != nil {
maxUnavailable, _ = intstrutil.GetValueFromIntOrPercent(strategy.MaxUnavailable, totalReplicas, false)
maxUnavailable, _ = intstrutil.GetValueFromIntOrPercent(strategy.MaxUnavailable, totalReplicas, true)
}

var upgradeAndNotReadyCount int
Expand Down
17 changes: 17 additions & 0 deletions pkg/controller/sidecarset/sidecarset_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,23 @@ func testGetNextUpgradePods(t *testing.T, factoryPods FactoryPods, factorySideca
exceptNeedUpgradeCount: 0,
exceptNotUpgradableCount: 100,
},
{
name: "only maxUnavailable(5%), and pods(count=5, upgraded=0, upgradedAndReady=0)",
getPods: func() []*corev1.Pod {
pods := factoryPods(5, 0, 0)
return Random(pods)
},
getSidecarset: func() *appsv1alpha1.SidecarSet {
sidecarSet := factorySidecar()
sidecarSet.Spec.UpdateStrategy.MaxUnavailable = &intstr.IntOrString{
Type: intstr.String,
StrVal: "5%",
}
return sidecarSet
},
exceptNeedUpgradeCount: 1,
exceptNotUpgradableCount: 0,
},
}
strategy := NewStrategy()
for _, cs := range cases {
Expand Down

0 comments on commit ab68bf0

Please sign in to comment.