Skip to content

Commit

Permalink
add ut for sidecarset priority strategy
Browse files Browse the repository at this point in the history
Signed-off-by: ricky <yricky509@gmail.com>
  • Loading branch information
y-ykcir committed Jul 1, 2023
1 parent 4be2873 commit e884b53
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions pkg/controller/sidecarset/sidecarset_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e884b53

Please sign in to comment.