40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package tracker
|
|
|
|
import (
|
|
"context"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/client/participantservice"
|
|
"gitlink.org.cn/jcce-pcm/utils/tool"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/kubernetes"
|
|
)
|
|
|
|
func NodesDynamicInfo(participantRpc participantservice.ParticipantService, kubeClient *kubernetes.Clientset) ([]*model.ScNodeAvailInfo, error) {
|
|
var nodes []*model.ScNodeAvailInfo
|
|
nodeList, err := kubeClient.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, node := range nodeList.Items {
|
|
nodePhy := model.ScNodeAvailInfo{
|
|
NodeName: node.ObjectMeta.Name,
|
|
}
|
|
nodes = append(nodes, &nodePhy)
|
|
}
|
|
NodeDiskAvail(nodes)
|
|
NodeDiskTotal(nodes)
|
|
NodeMemoryTotal(nodes)
|
|
NodeMemoryAvail(nodes)
|
|
NodeCpuUsage(nodes)
|
|
NodeCpuTotalCount(nodes)
|
|
|
|
nodeAvailInfo := []*participantservice.NodeAvailInfo{}
|
|
tool.Convert(nodes, &nodeAvailInfo)
|
|
req := participantservice.ParticipantAvailReq{
|
|
NodeAvailInfo: nodeAvailInfo,
|
|
}
|
|
participantRpc.ReportAvailable(context.Background(), &req)
|
|
return nodes, nil
|
|
|
|
}
|