Add unit test which checks Gated is set/unset properly

This commit is contained in:
Gabe 2024-05-02 10:41:19 +00:00
parent 72524fa574
commit 9a8197d0c3

View File

@ -44,6 +44,7 @@ import (
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/scheduler/framework"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/schedulinggates"
"k8s.io/kubernetes/pkg/scheduler/metrics"
st "k8s.io/kubernetes/pkg/scheduler/testing"
"k8s.io/kubernetes/pkg/scheduler/util"
@ -3729,3 +3730,30 @@ func Test_isPodWorthRequeuing(t *testing.T) {
})
}
}
func Test_queuedPodInfo_gatedSetUponCreationAndUnsetUponUpdate(t *testing.T) {
logger, ctx := ktesting.NewTestContext(t)
plugin, _ := schedulinggates.New(ctx, nil, nil)
m := map[string][]framework.PreEnqueuePlugin{"": {plugin.(framework.PreEnqueuePlugin)}}
q := NewTestQueue(ctx, newDefaultQueueSort(), WithPreEnqueuePluginMap(m))
gatedPod := st.MakePod().SchedulingGates([]string{"hello world"}).Obj()
if err := q.Add(logger, gatedPod); err != nil {
t.Error("Error calling Add")
}
if !q.unschedulablePods.get(gatedPod).Gated {
t.Error("expected pod to be gated")
}
ungatedPod := gatedPod.DeepCopy()
ungatedPod.Spec.SchedulingGates = nil
if err := q.Update(logger, gatedPod, ungatedPod); err != nil {
t.Error("Error calling Update")
}
ungatedPodInfo, _ := q.Pop(logger)
if ungatedPodInfo.Gated {
t.Error("expected pod to be ungated")
}
}