Skip to content

Commit 73b4954

Browse files
committed
Fix: After removing the device plugin from the gpu node, it can still be scheduled to this node
Signed-off-by: luohua13 <[email protected]>
1 parent b27a042 commit 73b4954

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

pkg/device-plugin/nvidiadevice/nvinternal/plugin/register.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (plugin *NvidiaDevicePlugin) getAPIDevices() *[]*device.DeviceInfo {
158158
return &res
159159
}
160160

161-
func (plugin *NvidiaDevicePlugin) RegistrInAnnotation() error {
161+
func (plugin *NvidiaDevicePlugin) RegisterInAnnotation() error {
162162
devices := plugin.getAPIDevices()
163163
klog.InfoS("start working on the devices", "devices", devices)
164164
annos := make(map[string]string)
@@ -222,7 +222,7 @@ func (plugin *NvidiaDevicePlugin) WatchAndRegister(disableNVML <-chan bool, ackD
222222
time.Sleep(successSleepInterval)
223223
continue
224224
}
225-
err := plugin.RegistrInAnnotation()
225+
err := plugin.RegisterInAnnotation()
226226
if err != nil {
227227
klog.Errorf("Failed to register annotation: %v", err)
228228
klog.Infof("Retrying in %v seconds...", errorSleepInterval)

pkg/device/devices.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525
"time"
2626

27+
"github.com/Project-HAMi/HAMi/pkg/util"
2728
"github.com/ccoveille/go-safecast"
2829

2930
corev1 "k8s.io/api/core/v1"
@@ -160,10 +161,6 @@ const (
160161
)
161162

162163
var (
163-
HandshakeAnnos = map[string]string{}
164-
RegisterAnnos = map[string]string{}
165-
configFile string
166-
DebugMode bool
167164
GPUSchedulerPolicy string
168165
InRequestDevices map[string]string
169166
SupportDevices map[string]string
@@ -408,7 +405,7 @@ func GetDevicesUUIDList(infos []*DeviceInfo) []string {
408405
}
409406

410407
func CheckHealth(devType string, n *corev1.Node) (bool, bool) {
411-
handshake := n.Annotations[HandshakeAnnos[devType]]
408+
handshake := n.Annotations[util.HandshakeAnnos[devType]]
412409
if strings.Contains(handshake, "Requesting") {
413410
formertime, _ := time.Parse(time.DateTime, strings.Split(handshake, "_")[1])
414411
return time.Now().Before(formertime.Add(time.Second * 60)), false

pkg/device/devices_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"testing"
2424

25+
"github.com/Project-HAMi/HAMi/pkg/util"
2526
"gotest.tools/v3/assert"
2627
corev1 "k8s.io/api/core/v1"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -530,6 +531,7 @@ func Test_EncodeNodeDevices(t *testing.T) {
530531
}
531532

532533
func Test_CheckHealth(t *testing.T) {
534+
util.HandshakeAnnos["huawei.com/Ascend910"] = "hami.io/node-handshake-ascend"
533535
tests := []struct {
534536
name string
535537
args struct {
@@ -549,7 +551,7 @@ func Test_CheckHealth(t *testing.T) {
549551
n: corev1.Node{
550552
ObjectMeta: metav1.ObjectMeta{
551553
Annotations: map[string]string{
552-
HandshakeAnnos["huawei.com/Ascend910"]: "Requesting_2128-12-02 00:00:00",
554+
util.HandshakeAnnos["huawei.com/Ascend910"]: "Requesting_2128-12-02 00:00:00",
553555
},
554556
},
555557
},
@@ -567,7 +569,7 @@ func Test_CheckHealth(t *testing.T) {
567569
n: corev1.Node{
568570
ObjectMeta: metav1.ObjectMeta{
569571
Annotations: map[string]string{
570-
HandshakeAnnos["huawei.com/Ascend910"]: "Deleted",
572+
util.HandshakeAnnos["huawei.com/Ascend910"]: "Deleted",
571573
},
572574
},
573575
},
@@ -585,7 +587,7 @@ func Test_CheckHealth(t *testing.T) {
585587
n: corev1.Node{
586588
ObjectMeta: metav1.ObjectMeta{
587589
Annotations: map[string]string{
588-
HandshakeAnnos["huawei.com/Ascend910"]: "Unknown",
590+
util.HandshakeAnnos["huawei.com/Ascend910"]: "Unknown",
589591
},
590592
},
591593
},
@@ -603,7 +605,7 @@ func Test_CheckHealth(t *testing.T) {
603605
n: corev1.Node{
604606
ObjectMeta: metav1.ObjectMeta{
605607
Annotations: map[string]string{
606-
HandshakeAnnos["huawei.com/Ascend910"]: "Requesting_2024-01-02 00:00:00",
608+
util.HandshakeAnnos["huawei.com/Ascend910"]: "Requesting_2024-01-02 00:00:00",
607609
},
608610
},
609611
},

0 commit comments

Comments
 (0)