Skip to content

Commit

Permalink
fix QuotaNonPreempt test unit
Browse files Browse the repository at this point in the history
Signed-off-by: wangyang55 <[email protected]>
  • Loading branch information
tan90github committed Oct 10, 2023
1 parent 58989c2 commit 6750752
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,10 @@ func (gqm *GroupQuotaManager) updatePodUsedNoLock(quotaName string, oldPod, newP
deltaUsed := quotav1.Subtract(newPodUsed, oldPodUsed)
deltaNonPreemptibleUsed := quotav1.Subtract(newNonPreemptibleUsed, oldNonPreemptibleUsed)
if quotav1.IsZero(deltaUsed) && quotav1.IsZero(deltaNonPreemptibleUsed) {
klog.V(5).Infof("updatePodUsed, deltaUsed and deltaNonPreemptibleUsed IsZero, quotaName:%v, podName:%v, podUsed:%v, podNonPreemptibleUsed:%v",
quotaName, getPodName(oldPod, newPod), newPodUsed, newNonPreemptibleUsed)
return
if klog.V(5).Enabled() {
klog.Infof("updatePodUsed, deltaUsedIsZero and deltaNonPreemptibleUsedIsZero, quotaName: %v, podName: %v, podUsed: %v, podNonPreemptibleUsed: %v",
quotaName, getPodName(oldPod, newPod), util.DumpJSON(newPodUsed), util.DumpJSON(newNonPreemptibleUsed))
}
}
gqm.updateGroupDeltaUsedNoLock(quotaName, deltaUsed, deltaNonPreemptibleUsed)
}
Expand Down
36 changes: 14 additions & 22 deletions pkg/scheduler/plugins/elasticquota/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,31 +756,29 @@ func TestPlugin_Prefilter_QuotaNonPreempt(t *testing.T) {
pod *corev1.Pod
initPods []*corev1.Pod
quotaInfos []*v1alpha1.ElasticQuota
runtime corev1.ResourceList
totalResource corev1.ResourceList
expectedStatus *framework.Status
}{
{
name: "default",
pod: defaultCreatePodWithQuotaAndNonPreemptible("4", "test1", 1, 20, 20, true),
pod: defaultCreatePodWithQuotaAndNonPreemptible("4", "test1", 1, 2, 2, true),
initPods: []*corev1.Pod{
defaultCreatePodWithQuotaName("1", "test1", 10, 50, 10),
defaultCreatePodWithQuotaName("2", "test1", 9, 10, 10),
defaultCreatePodWithQuotaName("3", "test1", 8, 10, 10),
defaultCreatePodWithQuotaAndNonPreemptible("1", "test1", 10, 2, 1, false),
defaultCreatePodWithQuotaAndNonPreemptible("2", "test1", 9, 1, 1, false),
defaultCreatePodWithQuotaAndNonPreemptible("3", "test1", 8, 1, 1, false),
},
quotaInfos: []*v1alpha1.ElasticQuota{
{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
Labels: map[string]string{
extension.LabelQuotaParent: extension.DefaultQuotaName,
},
},
Spec: v1alpha1.ElasticQuotaSpec{
Max: MakeResourceList().CPU(90).Mem(80).Obj(),
Min: MakeResourceList().CPU(50).Mem(50).Obj(),
Max: MakeResourceList().CPU(10).Mem(10).Obj(),
Min: MakeResourceList().CPU(5).Mem(5).Obj(),
},
},
},
totalResource: createResourceList(10, 10),
expectedStatus: framework.NewStatus(framework.Success, ""),
},
{
Expand All @@ -795,17 +793,14 @@ func TestPlugin_Prefilter_QuotaNonPreempt(t *testing.T) {
{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
Labels: map[string]string{
extension.LabelQuotaParent: extension.DefaultQuotaName,
},
},
Spec: v1alpha1.ElasticQuotaSpec{
Max: MakeResourceList().CPU(10).Mem(8).Obj(),
Min: MakeResourceList().CPU(5).Mem(5).Obj(),
},
},
},
runtime: MakeResourceList().CPU(8).Mem(5).Obj(),
totalResource: createResourceList(8, 5),
expectedStatus: framework.NewStatus(framework.Unschedulable,
fmt.Sprintf("Insufficient non-preemptible quotas, "+
"quotaName: %v, min: %v, nonPreemptibleUsed: %v, pod's request: %v, exceedDimensions: [cpu]",
Expand All @@ -824,17 +819,14 @@ func TestPlugin_Prefilter_QuotaNonPreempt(t *testing.T) {
{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
Labels: map[string]string{
extension.LabelQuotaParent: extension.DefaultQuotaName,
},
},
Spec: v1alpha1.ElasticQuotaSpec{
Max: MakeResourceList().CPU(10).Mem(8).Obj(),
Min: MakeResourceList().CPU(5).Mem(5).Obj(),
},
},
},
runtime: MakeResourceList().CPU(7).Mem(5).Obj(),
totalResource: createResourceList(7, 5),
expectedStatus: framework.NewStatus(framework.Unschedulable,
fmt.Sprintf("Insufficient quotas, "+
"quotaName: %v, runtime: %v, used: %v, pod's request: %v, exceedDimensions: [cpu]",
Expand All @@ -847,17 +839,17 @@ func TestPlugin_Prefilter_QuotaNonPreempt(t *testing.T) {
suit := newPluginTestSuit(t, nil)
p, _ := suit.proxyNew(suit.elasticQuotaArgs, suit.Handle)
gp := p.(*Plugin)
gp.groupQuotaManager.UpdateClusterTotalResource(tt.totalResource)
for _, qis := range tt.quotaInfos {
gp.OnQuotaAdd(qis)
}

for _, pod := range tt.initPods {
gp.OnPodAdd(pod)
}
tt.pod.Spec.NodeName = ""
gp.OnPodAdd(tt.pod)

qi := gp.groupQuotaManager.GetQuotaInfoByName("test1")
qi.Lock()
qi.CalculateInfo.Runtime = tt.runtime.DeepCopy()
qi.UnLock()
state := framework.NewCycleState()
ctx := context.TODO()
_, status := gp.PreFilter(ctx, state, tt.pod)
Expand Down

0 comments on commit 6750752

Please sign in to comment.