From 9a8197d0c36b7ca51d775a34c43eb6dde02c9960 Mon Sep 17 00:00:00 2001 From: Gabe <15304068+gabesaba@users.noreply.github.com> Date: Thu, 2 May 2024 10:41:19 +0000 Subject: [PATCH] Add unit test which checks Gated is set/unset properly --- .../internal/queue/scheduling_queue_test.go | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/scheduler/internal/queue/scheduling_queue_test.go b/pkg/scheduler/internal/queue/scheduling_queue_test.go index e160b89a4e9..60202b37950 100644 --- a/pkg/scheduler/internal/queue/scheduling_queue_test.go +++ b/pkg/scheduler/internal/queue/scheduling_queue_test.go @@ -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") + } +}