Skip to content

Commit 035f78b

Browse files
authored
Merge pull request #77 from Project-HAMi/fix
fix incompatible with hami 2.8.0
2 parents 25772c4 + b33fbc7 commit 035f78b

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

server/internal/provider/nvidia/provider.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package nvidia
22

33
import (
4-
"github.com/go-kratos/kratos/v2/log"
5-
corev1 "k8s.io/api/core/v1"
6-
"k8s.io/apimachinery/pkg/labels"
4+
"encoding/json"
75
"vgpu/internal/biz"
86
"vgpu/internal/data/prom"
97
"vgpu/internal/provider/util"
8+
9+
"github.com/go-kratos/kratos/v2/log"
10+
corev1 "k8s.io/api/core/v1"
11+
"k8s.io/apimachinery/pkg/labels"
1012
)
1113

1214
type Nvidia struct {
@@ -42,5 +44,15 @@ func (n *Nvidia) FetchDevices(node *corev1.Node) ([]*util.DeviceInfo, error) {
4244
return deviceInfos, nil
4345
}
4446
deviceInfos, err = util.DecodeNodeDevices(deviceEncode, n.log)
47+
if err != nil {
48+
var newDeviceInfos []*util.NewDeviceInfo
49+
err = json.Unmarshal([]byte(deviceEncode), &newDeviceInfos)
50+
if err != nil {
51+
return deviceInfos, err
52+
}
53+
for _, newDeviceInfo := range newDeviceInfos {
54+
deviceInfos = append(deviceInfos, util.MapNewDeviceInfoToDeviceInfo(newDeviceInfo))
55+
}
56+
}
4557
return deviceInfos, err
4658
}

server/internal/provider/util/types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ type DeviceInfo struct {
102102
Driver string
103103
}
104104

105+
type NewDeviceInfo struct {
106+
ID string `json:"id,omitempty"`
107+
Index uint `json:"index,omitempty"`
108+
Count int32 `json:"count,omitempty"`
109+
Devmem int32 `json:"devmem,omitempty"`
110+
Devcore int32 `json:"devcore,omitempty"`
111+
Type string `json:"type,omitempty"`
112+
Numa int `json:"numa,omitempty"`
113+
Mode string `json:"mode,omitempty"`
114+
Health bool `json:"health,omitempty"`
115+
DeviceVendor string `json:"devicevendor,omitempty"`
116+
CustomInfo map[string]any `json:"custominfo,omitempty"`
117+
}
118+
105119
type NodeInfo struct {
106120
ID string
107121
Devices []DeviceInfo

server/internal/provider/util/util.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,18 @@ func UnMarshalNodeDevices(str string) ([]*DeviceInfo, error) {
402402
err := json.Unmarshal([]byte(str), &dlist)
403403
return dlist, err
404404
}
405+
406+
func MapNewDeviceInfoToDeviceInfo(newDeviceInfo *NewDeviceInfo) *DeviceInfo {
407+
return &DeviceInfo{
408+
ID: newDeviceInfo.ID,
409+
AliasId: newDeviceInfo.ID,
410+
Index: newDeviceInfo.Index,
411+
Count: newDeviceInfo.Count,
412+
Devmem: newDeviceInfo.Devmem,
413+
Devcore: newDeviceInfo.Devcore,
414+
Type: newDeviceInfo.Type,
415+
Numa: newDeviceInfo.Numa,
416+
Mode: newDeviceInfo.Mode,
417+
Health: newDeviceInfo.Health,
418+
}
419+
}

0 commit comments

Comments
 (0)