Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: a smaller maxUnavaila will block the sidecarSet from updating pods #1834

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
59 changes: 59 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,65 @@ 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,
},
{
name: "maxUnavailable(5) partition(99%), 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.Int,
IntVal: 5,
}
sidecarSet.Spec.UpdateStrategy.Partition = &intstr.IntOrString{
Type: intstr.String,
StrVal: "99%",
}
return sidecarSet
},
exceptNeedUpgradeCount: 1,
exceptNotUpgradableCount: 0,
},
{
name: "maxUnavailable(5) partition(1%), 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.Int,
IntVal: 5,
}
sidecarSet.Spec.UpdateStrategy.Partition = &intstr.IntOrString{
Type: intstr.String,
StrVal: "1%",
}
return sidecarSet
},
exceptNeedUpgradeCount: 4,
exceptNotUpgradableCount: 0,
},
}
strategy := NewStrategy()
for _, cs := range cases {
Expand Down
Loading