From e884b530dcdadda121faaafaf7e7651c712f5fe8 Mon Sep 17 00:00:00 2001 From: ricky Date: Sat, 1 Jul 2023 16:52:58 +0800 Subject: [PATCH] add ut for sidecarset priority strategy Signed-off-by: ricky --- .../sidecarset/sidecarset_strategy_test.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/pkg/controller/sidecarset/sidecarset_strategy_test.go b/pkg/controller/sidecarset/sidecarset_strategy_test.go index 48a0c9ee42..00b44a671e 100644 --- a/pkg/controller/sidecarset/sidecarset_strategy_test.go +++ b/pkg/controller/sidecarset/sidecarset_strategy_test.go @@ -23,6 +23,7 @@ import ( "reflect" "testing" + appspub "github.com/openkruise/kruise/apis/apps/pub" appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1" "github.com/openkruise/kruise/pkg/control/sidecarcontrol" @@ -517,6 +518,72 @@ func testSortNextUpgradePods(t *testing.T, factoryPods FactoryPods, factorySidec }, exceptNextUpgradePods: []string{"pod-13", "pod-10", "pod-19", "pod-18", "pod-17", "pod-16", "pod-15"}, }, + { + name: "with weight priority strategy, maxUnavailable(int=10) and pods(count=20, upgraded=10, upgradedAndReady=2)", + getPods: func() []*corev1.Pod { + pods := factoryPods(20, 10, 2) + pods[15].Labels["test-key"] = "bar" + pods[16].Labels["test-key"] = "foo" + return Random(pods) + }, + getSidecarset: func() *appsv1alpha1.SidecarSet { + sidecarSet := factorySidecar() + sidecarSet.Spec.UpdateStrategy.MaxUnavailable = &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 10, + } + sidecarSet.Spec.UpdateStrategy.PriorityStrategy = &appspub.UpdatePriorityStrategy{ + WeightPriority: []appspub.UpdatePriorityWeightTerm{ + { + Weight: 50, + MatchSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{ + "test-key": "foo", + }, + }, + }, + { + Weight: 30, + MatchSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{ + "test-key": "bar", + }, + }, + }, + }, + } + return sidecarSet + }, + exceptNextUpgradePods: []string{"pod-16", "pod-15"}, + }, + { + name: "with order priority strategy, maxUnavailable(int=10) and pods(count=20, upgraded=10, upgradedAndReady=2)", + getPods: func() []*corev1.Pod { + pods := factoryPods(20, 10, 2) + for i := 0; i < 20; i++ { + pods[i].Labels["key1"] = "5" + } + pods[17].Labels["key1"] = "10" + pods[18].Labels["key1"] = "20" + return Random(pods) + }, + getSidecarset: func() *appsv1alpha1.SidecarSet { + sidecarSet := factorySidecar() + sidecarSet.Spec.UpdateStrategy.MaxUnavailable = &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 10, + } + sidecarSet.Spec.UpdateStrategy.PriorityStrategy = &appspub.UpdatePriorityStrategy{ + OrderPriority: []appspub.UpdatePriorityOrderTerm{ + { + OrderedKey: "key1", + }, + }, + } + return sidecarSet + }, + exceptNextUpgradePods: []string{"pod-18", "pod-17"}, + }, } strategy := NewStrategy()