Skip to content

Commit

Permalink
koord-scheduler: fix leaky operating pod in reservation (#1341)
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph <joseph.t.lee@outlook.com>
  • Loading branch information
eahydra committed Jun 2, 2023
1 parent 3c84030 commit b79c951
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/scheduler/plugins/reservation/pod_eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ func (h *podEventHandler) updatePod(oldPod, newPod *corev1.Pod) {

func (h *podEventHandler) deletePod(pod *corev1.Pod) {
reservationAllocated, err := apiext.GetReservationAllocated(pod)
if err != nil || reservationAllocated == nil || reservationAllocated.UID == "" {
return
if err == nil && reservationAllocated != nil && reservationAllocated.UID != "" {
h.cache.deletePod(reservationAllocated.UID, pod)
}
h.cache.deletePod(reservationAllocated.UID, pod)

if apiext.IsReservationOperatingMode(pod) {
h.cache.deleteReservationOperatingPod(pod)
Expand Down
67 changes: 67 additions & 0 deletions pkg/scheduler/plugins/reservation/pod_eventhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,70 @@ func TestPodEventHandler(t *testing.T) {
rInfo = handler.cache.getReservationInfoByUID(reservationUID)
assert.Empty(t, rInfo.AssignedPods)
}

func TestPodEventHandlerWithOperatingPod(t *testing.T) {
handler := &podEventHandler{
cache: newReservationCache(nil),
}
reservationUID := uuid.NewUUID()
reservationName := "test-reservation"
operatingReservationPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: reservationName,
UID: reservationUID,
Labels: map[string]string{
apiext.LabelPodOperatingMode: string(apiext.ReservationPodOperatingMode),
},
Annotations: map[string]string{},
},
Spec: corev1.PodSpec{
NodeName: "test-node-1",
},
}
handler.OnAdd(operatingReservationPod)

pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod",
Namespace: "default",
UID: uuid.NewUUID(),
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "main",
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("4"),
},
},
},
},
},
}
handler.OnAdd(pod)
rInfo := handler.cache.getReservationInfoByUID(operatingReservationPod.UID)
assert.NotNil(t, rInfo)

p := operatingReservationPod.DeepCopy()
err := apiext.SetReservationCurrentOwner(p.Annotations, &corev1.ObjectReference{
Name: pod.Name,
Namespace: pod.Namespace,
UID: pod.UID,
})
assert.NoError(t, err)
handler.OnUpdate(operatingReservationPod, p)
rInfo = handler.cache.getReservationInfoByUID(reservationUID)
assert.Len(t, rInfo.AssignedPods, 1)
expectPodRequirement := &frameworkext.PodRequirement{
Name: pod.Name,
Namespace: pod.Namespace,
UID: pod.UID,
Requests: corev1.ResourceList{},
}
assert.Equal(t, expectPodRequirement, rInfo.AssignedPods[pod.UID])

handler.OnDelete(operatingReservationPod)
rInfo = handler.cache.getReservationInfoByUID(reservationUID)
assert.Nil(t, rInfo)
}

0 comments on commit b79c951

Please sign in to comment.