From 02f49a5db92f1a44fb5192b537cf575029513304 Mon Sep 17 00:00:00 2001 From: wawa0210 Date: Mon, 3 Jun 2024 14:07:37 +0800 Subject: [PATCH] enhance get current node pendding pods Signed-off-by: wawa0210 --- .../nvidiadevice/nvinternal/plugin/server.go | 2 +- pkg/util/util.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go b/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go index 554d01b45..16ae8643d 100644 --- a/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go +++ b/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go @@ -287,7 +287,7 @@ func (plugin *NvidiaDevicePlugin) GetPreferredAllocation(ctx context.Context, r // Allocate which return list of devices. func (plugin *NvidiaDevicePlugin) Allocate(ctx context.Context, reqs *kubeletdevicepluginv1beta1.AllocateRequest) (*kubeletdevicepluginv1beta1.AllocateResponse, error) { - klog.Infoln("Allocate", reqs.ContainerRequests) + klog.InfoS("Allocate", "request", reqs) responses := kubeletdevicepluginv1beta1.AllocateResponse{} nodename := os.Getenv(util.NodeNameEnvName) current, err := util.GetPendingPod(nodename) diff --git a/pkg/util/util.go b/pkg/util/util.go index 2d71742f2..06ecdb5b6 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -61,7 +61,13 @@ func GetNode(nodename string) (*corev1.Node, error) { } func GetPendingPod(node string) (*corev1.Pod, error) { - podlist, err := client.GetClient().CoreV1().Pods("").List(context.Background(), metav1.ListOptions{}) + + // filter pods for this node. + selector := fmt.Sprintf("spec.nodeName=%s", node) + podListOptions := metav1.ListOptions{ + FieldSelector: selector, + } + podlist, err := client.GetClient().CoreV1().Pods("").List(context.Background(), podListOptions) if err != nil { return nil, err }