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
18 changes: 15 additions & 3 deletions server/internal/provider/nvidia/provider.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package nvidia

import (
"github.com/go-kratos/kratos/v2/log"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"encoding/json"
"vgpu/internal/biz"
"vgpu/internal/data/prom"
"vgpu/internal/provider/util"

"github.com/go-kratos/kratos/v2/log"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
)

type Nvidia struct {
Expand Down Expand Up @@ -42,5 +44,15 @@ func (n *Nvidia) FetchDevices(node *corev1.Node) ([]*util.DeviceInfo, error) {
return deviceInfos, nil
}
deviceInfos, err = util.DecodeNodeDevices(deviceEncode, n.log)
if err != nil {
var newDeviceInfos []*util.NewDeviceInfo
err = json.Unmarshal([]byte(deviceEncode), &newDeviceInfos)
if err != nil {
return deviceInfos, err
}
for _, newDeviceInfo := range newDeviceInfos {
deviceInfos = append(deviceInfos, util.MapNewDeviceInfoToDeviceInfo(newDeviceInfo))
}
}
return deviceInfos, err
}
14 changes: 14 additions & 0 deletions server/internal/provider/util/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ type DeviceInfo struct {
Driver string
}

type NewDeviceInfo struct {
ID string `json:"id,omitempty"`
Index uint `json:"index,omitempty"`
Count int32 `json:"count,omitempty"`
Devmem int32 `json:"devmem,omitempty"`
Devcore int32 `json:"devcore,omitempty"`
Type string `json:"type,omitempty"`
Numa int `json:"numa,omitempty"`
Mode string `json:"mode,omitempty"`
Health bool `json:"health,omitempty"`
DeviceVendor string `json:"devicevendor,omitempty"`
CustomInfo map[string]any `json:"custominfo,omitempty"`
}

type NodeInfo struct {
ID string
Devices []DeviceInfo
Expand Down
15 changes: 15 additions & 0 deletions server/internal/provider/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,18 @@ func UnMarshalNodeDevices(str string) ([]*DeviceInfo, error) {
err := json.Unmarshal([]byte(str), &dlist)
return dlist, err
}

func MapNewDeviceInfoToDeviceInfo(newDeviceInfo *NewDeviceInfo) *DeviceInfo {
return &DeviceInfo{
ID: newDeviceInfo.ID,
AliasId: newDeviceInfo.ID,
Index: newDeviceInfo.Index,
Count: newDeviceInfo.Count,
Devmem: newDeviceInfo.Devmem,
Devcore: newDeviceInfo.Devcore,
Type: newDeviceInfo.Type,
Numa: newDeviceInfo.Numa,
Mode: newDeviceInfo.Mode,
Health: newDeviceInfo.Health,
}
}
Loading