-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy pathpod_controller_test.go
More file actions
56 lines (48 loc) · 1.82 KB
/
Copy pathpod_controller_test.go
File metadata and controls
56 lines (48 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2026 NVIDIA CORPORATION
// SPDX-License-Identifier: Apache-2.0
package controllers
import (
"context"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/event"
resourcereservationmock "github.com/kai-scheduler/KAI-scheduler/pkg/binder/binding/resourcereservation/mock"
"github.com/kai-scheduler/KAI-scheduler/pkg/common/constants"
)
var _ = Describe("Pod Controller", func() {
It("syncs reservations for completed and deleted Pods without enqueueing reconciles", func() {
resourceReservation := resourcereservationmock.NewMockInterface(gomock.NewController(GinkgoT()))
reconciler := &PodReconciler{
ResourceReservation: resourceReservation,
SchedulerName: "kai-scheduler",
}
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[ctrl.Request]())
DeferCleanup(queue.ShutDown)
completedPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod",
Namespace: "default",
Labels: map[string]string{
constants.GPUGroup: "group",
},
},
Spec: corev1.PodSpec{SchedulerName: "kai-scheduler"},
Status: corev1.PodStatus{Phase: corev1.PodSucceeded},
}
pendingPod := completedPod.DeepCopy()
pendingPod.Status.Phase = corev1.PodPending
resourceReservation.EXPECT().SyncForGpuGroup(gomock.Any(), "group").Return(nil).Times(2)
handlers := reconciler.eventHandlers()
handlers.UpdateFunc(context.TODO(), event.UpdateEvent{
ObjectOld: pendingPod,
ObjectNew: completedPod,
}, queue)
handlers.DeleteFunc(context.TODO(), event.DeleteEvent{Object: completedPod}, queue)
Expect(queue.Len()).To(Equal(0))
})
})