Skip to content

Commit

Permalink
hoststatus: add lasted warning log (#35)
Browse files Browse the repository at this point in the history
* hoststatus: add lasted warning log

Signed-off-by: weizhoublue <[email protected]>

* d

Signed-off-by: weizhoublue <[email protected]>

---------

Signed-off-by: weizhoublue <[email protected]>
  • Loading branch information
weizhoublue authored Jan 20, 2025
1 parent be83a70 commit 1cee628
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.0
v0.5.0
4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: bmc-operator
description: A Helm chart for BMC Operator

# This is the chart version, which will be taken from VERSION file
version: 0.4.0
version: 0.5.0

# This is the version number of the application being deployed, which will be taken from VERSION file
appVersion: "0.4.0"
appVersion: "0.5.0"

type: application

Expand Down
10 changes: 10 additions & 0 deletions chart/crds/bmc.spidernet.io_hoststatuses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ spec:
- message
- time
type: object
lastestWarningLog:
properties:
message:
type: string
time:
type: string
required:
- message
- time
type: object
totalLogAccount:
format: int32
type: integer
Expand Down
4 changes: 4 additions & 0 deletions doc/usage/dhcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

Agent 中的 DHCP server,支持把 DHCP client 的 IP 固定到 DHCP server 的配置中, 从而实现 DHCP client 的 IP 固定。

### DHCP server 的配置

DHCP server 的配置文件,位于 confimap bmc-dhcp-config 中,若有修改需求,设置后,再重启 agent pod

### DHCP client 的 IP 固定

`EnableDhcpDiscovery`功能开启时:
Expand Down
16 changes: 12 additions & 4 deletions doc/usage/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ test-hostendpoint bmc-clusteragent true 192.168.0.50 ho
```bash
# 获取所有 BMC 主机的日志
kubectl get events -n bmc --field-selector reason=BMCLogEntry
LAST SEEN TYPE REASON OBJECT MESSAGE
30s Warning BMCLogEntry hoststatus/bmc-clusteragent-192-168-0-100 [2012-03-07T14:45:00Z][Critical]: Temperature threshold exceeded
2m13s Warning BMCLogEntry hoststatus/bmc-clusteragent-192-168-0-101 [2012-03-07T14:45:00Z][Critical]: Temperature threshold exceeded
105s Normal BMCLogEntry hoststatus/device-safe [2018-08-31T13:33:54+00:00][]: [ PS1 Status ] Power Supply Failure

# 获取指定 BMC 主机的日志
kubectl get events -n bmc --field-selector reason=BMCLogEntry,involvedObject.name=${HoststatusName}
Expand All @@ -322,11 +326,15 @@ kubectl get events -n bmc --field-selector reason=BMCLogEntry,involvedObject.nam
kubectl get hoststatus ${HoststatusName} -n bmc -o jsonpath='{.status.log}' | jq .
{
"lastestLog": {
"message": "[][2018-08-31T13:33:54+00:00][]: [ PS1 Status ] Power Supply Failure",
"time": "2018-08-31T13:33:54+00:00"
"message": "[2024-10-16T22:47:28Z][Critical]: [GS-0002] GPU Temp, 6 is not present",
"time": "2024-10-16T22:47:28Z"
},
"totalLogAccount": 67,
"warningLogAccount": 67
"lastestWarningLog": {
"message": "[2024-10-16T22:47:28Z][Critical]: [GS-0002] GPU Temp, 6 is not present",
"time": "2024-10-16T22:47:28Z"
},
"totalLogAccount": 52,
"warningLogAccount": 35
}

```
1 change: 1 addition & 0 deletions pkg/agent/hostendpoint/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func (r *HostEndpointReconciler) handleHostEndpoint(ctx context.Context, hostEnd
TotalLogAccount: 0,
WarningLogAccount: 0,
LastestLog: nil,
LastestWarningLog: nil,
},
}

Expand Down
14 changes: 12 additions & 2 deletions pkg/agent/hoststatus/HostStatusReconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ var hostStatusLock = &sync.Mutex{}
// ------------------------------ update the spec.info of the hoststatus

// GenerateEvents creates Kubernetes events from Redfish log entries and returns the latest message and count
func (c *hostStatusController) GenerateEvents(logEntrys []*gofishredfish.LogEntry, hostStatusName string, lastLogTime string) (newLastestTime, newLastestMsg string, totalMsgCount, warningMsgCount, newLogAccount int) {
func (c *hostStatusController) GenerateEvents(logEntrys []*gofishredfish.LogEntry, hostStatusName string, lastLogTime string) (newLastestTime, newLastestMsg, newLastestWarningTime, newLastestWarningMsg string, totalMsgCount, warningMsgCount, newLogAccount int) {
totalMsgCount = 0
warningMsgCount = 0
newLogAccount = 0
newLastestTime = ""
newLastestMsg = ""
newLastestWarningTime = ""
newLastestWarningMsg = ""

if len(logEntrys) == 0 {
return
Expand All @@ -52,6 +54,10 @@ func (c *hostStatusController) GenerateEvents(logEntrys []*gofishredfish.LogEntr
ty := corev1.EventTypeNormal
if entry.Severity != gofishredfish.OKEventSeverity && entry.Severity != "" {
ty = corev1.EventTypeWarning
if newLastestWarningMsg == "" {
newLastestWarningTime = entry.Created
newLastestWarningMsg = msg
}
warningMsgCount++
}

Expand Down Expand Up @@ -145,14 +151,18 @@ func (c *hostStatusController) UpdateHostStatusInfo(name string, d *hoststatusda
if updated.Status.Log.LastestLog != nil {
lastLogTime = updated.Status.Log.LastestLog.Time
}
newLastestTime, newLastestMsg, totalMsgCount, warningMsgCount, newLogAccount := c.GenerateEvents(logEntrys, name, lastLogTime)
newLastestTime, newLastestMsg, newLastestWarningTime, newLastestWarningMsg, totalMsgCount, warningMsgCount, newLogAccount := c.GenerateEvents(logEntrys, name, lastLogTime)
if newLastestTime != "" {
updated.Status.Log.TotalLogAccount = int32(totalMsgCount)
updated.Status.Log.WarningLogAccount = int32(warningMsgCount)
updated.Status.Log.LastestLog = &bmcv1beta1.LogEntry{
Time: newLastestTime,
Message: newLastestMsg,
}
updated.Status.Log.LastestWarningLog = &bmcv1beta1.LogEntry{
Time: newLastestWarningTime,
Message: newLastestWarningMsg,
}
log.Logger.Infof("find %d new logs for hostStatus %s", newLogAccount, name)
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/hoststatus/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (c *hostStatusController) handleDHCPAdd(client dhcptypes.ClientInfo) error
TotalLogAccount: 0,
WarningLogAccount: 0,
LastestLog: nil,
LastestWarningLog: nil,
},
}
if c.config.AgentObjSpec.Endpoint.SecretName != "" {
Expand Down
2 changes: 2 additions & 0 deletions pkg/k8s/apis/bmc.spidernet.io/v1beta1/hoststatus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type LogStruct struct {
WarningLogAccount int32 `json:"warningLogAccount"`
// +optional
LastestLog *LogEntry `json:"lastestLog,omitempty"`
// +optional
LastestWarningLog *LogEntry `json:"lastestWarningLog,omitempty"`
}

type LogEntry struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1cee628

Please sign in to comment.