From ab68bf0cb871d6fefadab439b73cdda629df2c24 Mon Sep 17 00:00:00 2001 From: "liheng.zms" Date: Wed, 20 Nov 2024 13:14:03 +0800 Subject: [PATCH] fix: a smaller maxUnavaila will block the sidecarSet from updating pods Signed-off-by: liheng.zms --- .../sidecarset/sidecarset_strategy.go | 5 +++-- .../sidecarset/sidecarset_strategy_test.go | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/controller/sidecarset/sidecarset_strategy.go b/pkg/controller/sidecarset/sidecarset_strategy.go index e3884a0df2..9e9c59eef6 100644 --- a/pkg/controller/sidecarset/sidecarset_strategy.go +++ b/pkg/controller/sidecarset/sidecarset_strategy.go @@ -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 { @@ -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 diff --git a/pkg/controller/sidecarset/sidecarset_strategy_test.go b/pkg/controller/sidecarset/sidecarset_strategy_test.go index b13d8ebfd6..fb57d3ab89 100644 --- a/pkg/controller/sidecarset/sidecarset_strategy_test.go +++ b/pkg/controller/sidecarset/sidecarset_strategy_test.go @@ -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 {