Skip to content

Commit

Permalink
cloneset ignore maxSurge when UpdateStrategyPaused=true (#1324)
Browse files Browse the repository at this point in the history
* cloneset ignore maxSurge when UpdateStrategyPaused=true

Signed-off-by: pingjaing <xiangpingjiang1998@gmail.com>

* add scale down  UT case for cloneSet UpdateStrategyPaused=true

Signed-off-by: pingjaing <xiangpingjiang1998@gmail.com>

* add UTs for cloneSet when UpdateStrategyPaused=true

Signed-off-by: pingjiang <xiangpingjiang1998@gmail.com>

---------

Signed-off-by: pingjaing <xiangpingjiang1998@gmail.com>
Signed-off-by: pingjiang <xiangpingjiang1998@gmail.com>
  • Loading branch information
xiangpingjiang committed Jul 5, 2023
1 parent 5e8a991 commit 33c9ce1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/cloneset/sync/cloneset_sync_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func calculateDiffsWithExpectation(cs *appsv1alpha1.CloneSet, pods []*v1.Pod, cu
}
if cs.Spec.UpdateStrategy.MaxSurge != nil {
maxSurge, _ = intstrutil.GetValueFromIntOrPercent(cs.Spec.UpdateStrategy.MaxSurge, replicas, true)
if cs.Spec.UpdateStrategy.Paused {
maxSurge = 0
klog.V(3).Infof("Because CloneSet(%s/%s) updateStrategy.paused=true, and Set maxSurge=0", cs.Namespace, cs.Name)
}
}
maxUnavailable, _ = intstrutil.GetValueFromIntOrPercent(
intstrutil.ValueOrDefault(cs.Spec.UpdateStrategy.MaxUnavailable, intstrutil.FromString(appsv1alpha1.DefaultCloneSetMaxUnavailable)), replicas, maxSurge == 0)
Expand Down
62 changes: 62 additions & 0 deletions pkg/controller/cloneset/sync/cloneset_sync_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,58 @@ func TestCalculateDiffsWithExpectation(t *testing.T) {
isPodUpdate: revision.IsPodUpdate,
expectResult: expectationDiffs{scaleUpNum: 1, scaleUpLimit: 1},
},
{
name: "[UpdateStrategyPaused=true] scale up pods with maxSurge=3,maxUnavailable=0",
set: setUpdateStrategyPaused(createTestCloneSet(5, intstr.FromInt(0), intstr.FromInt(0), intstr.FromInt(3)), true),
pods: []*v1.Pod{
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
},
expectResult: expectationDiffs{scaleUpNum: 2, scaleUpLimit: 2, updateNum: 3, updateMaxUnavailable: -2},
},
{
name: "[UpdateStrategyPaused=true] scale down pods with maxSurge=3,maxUnavailable=0",
set: setUpdateStrategyPaused(createTestCloneSet(3, intstr.FromInt(0), intstr.FromInt(0), intstr.FromInt(3)), true),
pods: []*v1.Pod{
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
},
expectResult: expectationDiffs{scaleDownNum: 2, scaleDownNumOldRevision: 5, deleteReadyLimit: 2, updateNum: 3, updateMaxUnavailable: 2},
},
{
name: "[UpdateStrategyPaused=true] create 0 newRevision pods with maxSurge=3,maxUnavailable=0",
set: setUpdateStrategyPaused(createTestCloneSet(5, intstr.FromInt(0), intstr.FromInt(0), intstr.FromInt(3)), true),
pods: []*v1.Pod{
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(newRevision, appspub.LifecycleStateNormal, false, false),
createTestPod(newRevision, appspub.LifecycleStateNormal, false, false),
createTestPod(newRevision, appspub.LifecycleStateNormal, false, false),
},
expectResult: expectationDiffs{scaleDownNum: 3, scaleDownNumOldRevision: 5, updateNum: 2, updateMaxUnavailable: 3},
},
{
name: "[UpdateStrategyPaused=true] create 0 newRevision pods with maxSurge=3,maxUnavailable=0",
set: setUpdateStrategyPaused(createTestCloneSet(5, intstr.FromInt(2), intstr.FromInt(0), intstr.FromInt(3)), true),
pods: []*v1.Pod{
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(oldRevision, appspub.LifecycleStateNormal, true, false),
createTestPod(newRevision, appspub.LifecycleStateNormal, false, false),
createTestPod(newRevision, appspub.LifecycleStateNormal, false, false),
createTestPod(newRevision, appspub.LifecycleStateNormal, false, false),
},
expectResult: expectationDiffs{scaleDownNum: 3, scaleDownNumOldRevision: 3},
},
}

defer utilfeature.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PreparingUpdateAsUpdate, true)()
Expand Down Expand Up @@ -992,3 +1044,13 @@ func createTestPod(revisionHash string, lifecycleState appspub.LifecycleStateTyp
}
return pod
}

func setUpdateStrategyPaused(cs *appsv1alpha1.CloneSet, paused bool) *appsv1alpha1.CloneSet {
cs.Spec.UpdateStrategy = appsv1alpha1.CloneSetUpdateStrategy{
Partition: cs.Spec.UpdateStrategy.Partition,
MaxSurge: cs.Spec.UpdateStrategy.MaxSurge,
MaxUnavailable: cs.Spec.UpdateStrategy.MaxUnavailable,
Paused: paused,
}
return cs
}

0 comments on commit 33c9ce1

Please sign in to comment.