Skip to content

Commit

Permalink
Fix the issue where scheduling can still occur on the node when the d…
Browse files Browse the repository at this point in the history
…evice-plugin crashes.

Signed-off-by: chaunceyjiang <[email protected]>
  • Loading branch information
chaunceyjiang committed May 27, 2024
1 parent b398634 commit fc0ef70
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 81 deletions.
4 changes: 2 additions & 2 deletions pkg/device/ascend/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func (dev *AscendDevices) CheckUUID(annos map[string]string, d util.DeviceUsage)
return true
}

func (dev *AscendDevices) CheckHealth(devType string, n *corev1.Node) (bool, bool) {
return true, true
func (dev *AscendDevices) CheckHealth(devType string, n *corev1.Node) bool {
return true
}

func trimMemory(i int64) int64 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/device/cambricon/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ func (dev *CambriconDevices) NodeCleanUp(nn string) error {
return nil
}

func (dev *CambriconDevices) CheckHealth(devType string, n *corev1.Node) (bool, bool) {
return true, true
func (dev *CambriconDevices) CheckHealth(devType string, n *corev1.Node) bool {
return true
}

func (dev *CambriconDevices) GetNodeDevices(n corev1.Node) ([]*api.DeviceInfo, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/device/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

type Devices interface {
MutateAdmission(ctr *corev1.Container) (bool, error)
CheckHealth(devType string, n *corev1.Node) (bool, bool)
CheckHealth(devType string, n *corev1.Node) bool
NodeCleanUp(nn string) error
GetNodeDevices(n corev1.Node) ([]*api.DeviceInfo, error)
CheckType(annos map[string]string, d util.DeviceUsage, n util.ContainerDeviceRequest) (bool, bool, bool)
Expand Down
2 changes: 1 addition & 1 deletion pkg/device/hygon/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (dev *DCUDevices) NodeCleanUp(nn string) error {
return util.MarkAnnotationsToDelete(HygonDCUDevice, nn)
}

func (dev *DCUDevices) CheckHealth(devType string, n *corev1.Node) (bool, bool) {
func (dev *DCUDevices) CheckHealth(devType string, n *corev1.Node) bool {
return util.CheckHealth(devType, n)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/device/iluvatar/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func (dev *IluvatarDevices) CheckUUID(annos map[string]string, d util.DeviceUsag
return true
}

func (dev *IluvatarDevices) CheckHealth(devType string, n *corev1.Node) (bool, bool) {
return true, true
func (dev *IluvatarDevices) CheckHealth(devType string, n *corev1.Node) bool {
return true
}

func (dev *IluvatarDevices) GenerateResourceRequests(ctr *corev1.Container) util.ContainerDeviceRequest {
Expand Down
2 changes: 1 addition & 1 deletion pkg/device/nvidia/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (dev *NvidiaGPUDevices) NodeCleanUp(nn string) error {
return util.MarkAnnotationsToDelete(NvidiaGPUDevice, nn)
}

func (dev *NvidiaGPUDevices) CheckHealth(devType string, n *corev1.Node) (bool, bool) {
func (dev *NvidiaGPUDevices) CheckHealth(devType string, n *corev1.Node) bool {
return util.CheckHealth(devType, n)
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/scheduler/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (m *nodeManager) addNode(nodeID string, nodeInfo *util.NodeInfo) {
}
}

func (m *nodeManager) rmNodeDevice(nodeID string, nodeInfo *util.NodeInfo) {
func (m *nodeManager) rmNodeDevice(nodeID string, nodeInfo *util.NodeInfo, deviceVendor string) {
m.mutex.Lock()
defer m.mutex.Unlock()
_, ok := m.nodes[nodeID]
Expand All @@ -69,6 +69,9 @@ func (m *nodeManager) rmNodeDevice(nodeID string, nodeInfo *util.NodeInfo) {
klog.V(5).Infoln("before rm:", m.nodes[nodeID].Devices, "needs remove", nodeInfo.Devices)
tmp := make([]util.DeviceInfo, 0, len(m.nodes[nodeID].Devices)-len(nodeInfo.Devices))
for _, val := range m.nodes[nodeID].Devices {
if strings.Compare(val.DeviceVendor, deviceVendor) != 0 {
continue
}
found := false
for _, rmval := range nodeInfo.Devices {
if strings.Compare(val.ID, rmval.ID) == 0 {
Expand Down
43 changes: 18 additions & 25 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func (s *Scheduler) Stop() {

func (s *Scheduler) RegisterFromNodeAnnotations() {
klog.V(5).Infoln("Scheduler into RegisterFromNodeAnnotations")
nodeInfoCopy := make(map[string]*util.NodeInfo)
ticker := time.NewTicker(time.Second * 15)
for {
select {
Expand All @@ -168,26 +167,20 @@ func (s *Scheduler) RegisterFromNodeAnnotations() {
for _, val := range nodes {
nodeNames = append(nodeNames, val.Name)
for devhandsk, devInstance := range device.GetDevices() {
health, needUpdate := devInstance.CheckHealth(devhandsk, val)
health := devInstance.CheckHealth(devhandsk, val)
if !health {
_, ok := s.nodes[val.Name]
info, ok := s.nodes[val.Name]
if ok {
_, ok = nodeInfoCopy[devhandsk]
if ok && nodeInfoCopy[devhandsk] != nil {
s.rmNodeDevice(val.Name, nodeInfoCopy[devhandsk])
klog.Infof("node %v device %s:%v leave, %v remaining devices:%v", val.Name, devhandsk, nodeInfoCopy[devhandsk], err, s.nodes[val.Name].Devices)

err := devInstance.NodeCleanUp(val.Name)
if err != nil {
klog.ErrorS(err, "markAnnotationsToDeleteFailed")
}
continue
err := devInstance.NodeCleanUp(val.Name)
if err != nil {
klog.ErrorS(err, "markAnnotationsToDeleteFailed")
}
s.rmNodeDevice(val.Name, info, devhandsk)
klog.Infof("node %v device %s:%v leave, %v remaining devices:%v", val.Name, devhandsk, info, err, s.nodes[val.Name].Devices)
}
}
if !needUpdate {
continue
}

_, ok := util.HandshakeAnnos[devhandsk]
if ok {
tmppat := make(map[string]string)
Expand Down Expand Up @@ -223,21 +216,21 @@ func (s *Scheduler) RegisterFromNodeAnnotations() {
}
if !found {
nodeInfo.Devices = append(nodeInfo.Devices, util.DeviceInfo{
ID: deviceinfo.Id,
Index: uint(deviceinfo.Index),
Count: deviceinfo.Count,
Devmem: deviceinfo.Devmem,
Devcore: deviceinfo.Devcore,
Type: deviceinfo.Type,
Numa: deviceinfo.Numa,
Health: deviceinfo.Health,
ID: deviceinfo.Id,
Index: uint(deviceinfo.Index),
Count: deviceinfo.Count,
Devmem: deviceinfo.Devmem,
Devcore: deviceinfo.Devcore,
Type: deviceinfo.Type,
Numa: deviceinfo.Numa,
Health: deviceinfo.Health,
DeviceVendor: devhandsk,
})
}
}
s.addNode(val.Name, nodeInfo)
nodeInfoCopy[devhandsk] = nodeInfo
if s.nodes[val.Name] != nil && len(nodeInfo.Devices) > 0 {
klog.Infof("node %v device %s come node info=%v total=%v", val.Name, devhandsk, nodeInfoCopy[devhandsk], s.nodes[val.Name].Devices)
klog.Infof("node %v device %s come node info=%v total=%v", val.Name, devhandsk, nodeInfo, s.nodes[val.Name].Devices)
}
}
}
Expand Down
70 changes: 37 additions & 33 deletions pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func Test_Filter(t *testing.T) {
nodes, _ := s.ListNodes()
for index := range nodes {
node := nodes[index]
s.rmNodeDevice(node.ID, node)
s.rmNodeDevice(node.ID, node, nvidia.NvidiaGPUDevice)
}
pods, _ := s.ListPods()
for index := range pods {
Expand All @@ -232,49 +232,53 @@ func Test_Filter(t *testing.T) {
ID: "node1",
Devices: []util.DeviceInfo{
{
ID: "device1",
Index: 0,
Count: 10,
Devmem: 8000,
Devcore: 100,
Numa: 0,
Type: nvidia.NvidiaGPUDevice,
Health: true,
ID: "device1",
Index: 0,
Count: 10,
Devmem: 8000,
Devcore: 100,
Numa: 0,
Type: nvidia.NvidiaGPUDevice,
Health: true,
DeviceVendor: nvidia.NvidiaGPUDevice,
},
{
ID: "device2",
Index: 1,
Count: 10,
Devmem: 8000,
Devcore: 100,
Numa: 0,
Type: nvidia.NvidiaGPUDevice,
Health: true,
ID: "device2",
Index: 1,
Count: 10,
Devmem: 8000,
Devcore: 100,
Numa: 0,
Type: nvidia.NvidiaGPUDevice,
Health: true,
DeviceVendor: nvidia.NvidiaGPUDevice,
},
},
})
s.addNode("node2", &util.NodeInfo{
ID: "node2",
Devices: []util.DeviceInfo{
{
ID: "device3",
Index: 0,
Count: 10,
Devmem: 8000,
Devcore: 100,
Numa: 0,
Type: nvidia.NvidiaGPUDevice,
Health: true,
ID: "device3",
Index: 0,
Count: 10,
Devmem: 8000,
Devcore: 100,
Numa: 0,
Type: nvidia.NvidiaGPUDevice,
Health: true,
DeviceVendor: nvidia.NvidiaGPUDevice,
},
{
ID: "device4",
Index: 1,
Count: 10,
Devmem: 8000,
Devcore: 100,
Numa: 0,
Type: nvidia.NvidiaGPUDevice,
Health: true,
ID: "device4",
Index: 1,
Count: 10,
Devmem: 8000,
Devcore: 100,
Numa: 0,
Type: nvidia.NvidiaGPUDevice,
Health: true,
DeviceVendor: nvidia.NvidiaGPUDevice,
},
},
})
Expand Down
17 changes: 9 additions & 8 deletions pkg/util/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ type DeviceUsage struct {
}

type DeviceInfo struct {
ID string
Index uint
Count int32
Devmem int32
Devcore int32
Type string
Numa int
Health bool
ID string
Index uint
Count int32
Devmem int32
Devcore int32
Type string
Numa int
Health bool
DeviceVendor string
}

type NodeInfo struct {
Expand Down
11 changes: 6 additions & 5 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,17 @@ func InitKlogFlags() *flag.FlagSet {
return flagset
}

func CheckHealth(devType string, n *corev1.Node) (bool, bool) {
func CheckHealth(devType string, n *corev1.Node) bool {
handshake := n.Annotations[HandshakeAnnos[devType]]
if strings.Contains(handshake, "Requesting") {
formertime, _ := time.Parse("2006.01.02 15:04:05", strings.Split(handshake, "_")[1])
return time.Now().Before(formertime.Add(time.Second * 60)), false
return time.Now().Before(formertime.Add(time.Second * 60))
} else if strings.Contains(handshake, "Deleted") {
return true, false
} else {
return true, true
return true
} else if strings.Contains(handshake, "Reported") {
return true
}
return false
}

func MarkAnnotationsToDelete(devType string, nn string) error {
Expand Down

0 comments on commit fc0ef70

Please sign in to comment.