Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/vGPUmonitor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package main

import (
"fmt"
"github.com/Project-HAMi/HAMi/pkg/util"
"log"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -229,8 +231,8 @@ func (cc ClusterManagerCollector) Collect(ch chan<- prometheus.Metric) {

}
}

pods, err := cc.ClusterManager.PodLister.List(labels.Everything())
nodeName := os.Getenv(util.NodeNameEnvName)
pods, err := cc.ClusterManager.PodLister.List(labels.SelectorFromSet(labels.Set{util.AssignedNodeAnnotations: nodeName}))
if err != nil {
klog.Error("failed to list pods with err=", err.Error())
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/monitor/nvidia/cudevshr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"github.com/Project-HAMi/HAMi/pkg/util"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -122,7 +123,13 @@ func (l *ContainerLister) Clientset() *kubernetes.Clientset {
}

func (l *ContainerLister) Update() error {
pods, err := l.clientset.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{})
nodename := os.Getenv(util.NodeNameEnvName)
if nodename == "" {
return fmt.Errorf("env %s not set", util.NodeNameEnvName)
}
pods, err := l.clientset.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{
FieldSelector: fmt.Sprintf("spec.nodeName=%s", nodename),
})
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func PatchNodeAnnotations(node *corev1.Node, annotations map[string]string) erro
func PatchPodAnnotations(pod *corev1.Pod, annotations map[string]string) error {
type patchMetadata struct {
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
type patchPod struct {
Metadata patchMetadata `json:"metadata"`
Expand All @@ -371,6 +372,11 @@ func PatchPodAnnotations(pod *corev1.Pod, annotations map[string]string) error {

p := patchPod{}
p.Metadata.Annotations = annotations
label := make(map[string]string)
if v, ok := annotations[AssignedNodeAnnotations]; ok && v != "" {
label[AssignedNodeAnnotations] = v
p.Metadata.Labels = label
}

bytes, err := json.Marshal(p)
if err != nil {
Expand Down