Compare commits

...

1 Commits

Author SHA1 Message Date
eball
1aa3def59d olaresd: add node pressure status 2025-08-21 18:59:25 +08:00
4 changed files with 45 additions and 2 deletions

View File

@@ -78,6 +78,8 @@ type state struct {
FRPEnable string `json:"frpEnable"`
ContainerMode *string `json:"containerMode,omitempty"`
Pressure []utils.NodePressure `json:"pressures,omitempty"`
}
var CurrentState state
@@ -340,6 +342,18 @@ func CheckCurrentStatus(ctx context.Context) error {
return err
}
pressure, err := utils.GetNodesPressure(ctx, kubeClient)
if err != nil {
klog.Error("get nodes pressure error, ", err)
} else {
// update node pressure of current node
if p, ok := pressure[*CurrentState.HostName]; ok && len(p) == 0 {
CurrentState.Pressure = p
} else {
CurrentState.Pressure = nil
}
}
if CurrentState.InstallFinishedTime != nil {
CurrentState.InstalledTime = pointer.Int64(CurrentState.InstallFinishedTime.Unix())
} else {

View File

@@ -5,6 +5,8 @@ package utils
import (
"fmt"
"io"
"log"
"strings"
"github.com/jaypipes/ghw"
@@ -13,7 +15,7 @@ import (
)
func GetGpuInfo() (*string, error) {
gpu, err := ghw.GPU()
gpu, err := ghw.GPU(ghw.WithAlerter(log.New(io.Discard, "", 0))) // discard warnings
if err != nil {
klog.Errorf("Error getting GPU info: %v", err)
return nil, err

View File

@@ -516,3 +516,22 @@ func GetUserspacePvcHostPath(ctx context.Context, user string, client kubernetes
return hostpath, nil
}
func GetNodesPressure(ctx context.Context, client kubernetes.Interface) (map[string][]NodePressure, error) {
nodes, err := client.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
if err != nil {
klog.Error("list nodes error, ", err)
return nil, err
}
status := make(map[string][]NodePressure)
for _, node := range nodes.Items {
for _, condition := range node.Status.Conditions {
if condition.Type != corev1.NodeReady && condition.Status == corev1.ConditionTrue {
status[node.Name] = append(status[node.Name], NodePressure{Type: condition.Type, Message: condition.Message})
}
}
}
return status, nil
}

View File

@@ -1,6 +1,9 @@
package utils
import "k8s.io/apimachinery/pkg/runtime/schema"
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
var (
UserSchemeGroupVersion = schema.GroupVersion{Group: "iam.kubesphere.io", Version: "v1alpha2"}
@@ -11,3 +14,8 @@ var (
Resource: "users",
}
)
type NodePressure struct {
Type corev1.NodeConditionType `json:"type"`
Message string `json:"message"`
}