From 1cee62835a6db621e933f2b07d362e60de3e6a26 Mon Sep 17 00:00:00 2001 From: weizhoublue <45163302+weizhoublue@users.noreply.github.com> Date: Mon, 20 Jan 2025 11:18:19 +0800 Subject: [PATCH] hoststatus: add lasted warning log (#35) * hoststatus: add lasted warning log Signed-off-by: weizhoublue * d Signed-off-by: weizhoublue --------- Signed-off-by: weizhoublue --- VERSION | 2 +- chart/Chart.yaml | 4 ++-- chart/crds/bmc.spidernet.io_hoststatuses.yaml | 10 ++++++++++ doc/usage/dhcp.md | 4 ++++ doc/usage/quickstart.md | 16 ++++++++++++---- pkg/agent/hostendpoint/controller.go | 1 + pkg/agent/hoststatus/HostStatusReconcile.go | 14 ++++++++++++-- pkg/agent/hoststatus/dhcp.go | 1 + .../bmc.spidernet.io/v1beta1/hoststatus_types.go | 2 ++ .../v1beta1/zz_generated.deepcopy.go | 5 +++++ 10 files changed, 50 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 01e994d..48080b4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.4.0 \ No newline at end of file +v0.5.0 \ No newline at end of file diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 1e1a62c..ad96adb 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -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 diff --git a/chart/crds/bmc.spidernet.io_hoststatuses.yaml b/chart/crds/bmc.spidernet.io_hoststatuses.yaml index d43560a..7ee2ed9 100644 --- a/chart/crds/bmc.spidernet.io_hoststatuses.yaml +++ b/chart/crds/bmc.spidernet.io_hoststatuses.yaml @@ -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 diff --git a/doc/usage/dhcp.md b/doc/usage/dhcp.md index ca0f740..eadb135 100644 --- a/doc/usage/dhcp.md +++ b/doc/usage/dhcp.md @@ -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`功能开启时: diff --git a/doc/usage/quickstart.md b/doc/usage/quickstart.md index 92344a4..001b34a 100644 --- a/doc/usage/quickstart.md +++ b/doc/usage/quickstart.md @@ -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} @@ -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 } ``` diff --git a/pkg/agent/hostendpoint/controller.go b/pkg/agent/hostendpoint/controller.go index f9d2516..ac3cd8d 100644 --- a/pkg/agent/hostendpoint/controller.go +++ b/pkg/agent/hostendpoint/controller.go @@ -180,6 +180,7 @@ func (r *HostEndpointReconciler) handleHostEndpoint(ctx context.Context, hostEnd TotalLogAccount: 0, WarningLogAccount: 0, LastestLog: nil, + LastestWarningLog: nil, }, } diff --git a/pkg/agent/hoststatus/HostStatusReconcile.go b/pkg/agent/hoststatus/HostStatusReconcile.go index 66f3aed..23273c3 100644 --- a/pkg/agent/hoststatus/HostStatusReconcile.go +++ b/pkg/agent/hoststatus/HostStatusReconcile.go @@ -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 @@ -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++ } @@ -145,7 +151,7 @@ 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) @@ -153,6 +159,10 @@ func (c *hostStatusController) UpdateHostStatusInfo(name string, d *hoststatusda 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) } } diff --git a/pkg/agent/hoststatus/dhcp.go b/pkg/agent/hoststatus/dhcp.go index eafb611..0b5b2fd 100644 --- a/pkg/agent/hoststatus/dhcp.go +++ b/pkg/agent/hoststatus/dhcp.go @@ -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 != "" { diff --git a/pkg/k8s/apis/bmc.spidernet.io/v1beta1/hoststatus_types.go b/pkg/k8s/apis/bmc.spidernet.io/v1beta1/hoststatus_types.go index 02ee4ef..ec38089 100644 --- a/pkg/k8s/apis/bmc.spidernet.io/v1beta1/hoststatus_types.go +++ b/pkg/k8s/apis/bmc.spidernet.io/v1beta1/hoststatus_types.go @@ -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 { diff --git a/pkg/k8s/apis/bmc.spidernet.io/v1beta1/zz_generated.deepcopy.go b/pkg/k8s/apis/bmc.spidernet.io/v1beta1/zz_generated.deepcopy.go index cc677a1..b7304f8 100644 --- a/pkg/k8s/apis/bmc.spidernet.io/v1beta1/zz_generated.deepcopy.go +++ b/pkg/k8s/apis/bmc.spidernet.io/v1beta1/zz_generated.deepcopy.go @@ -393,6 +393,11 @@ func (in *LogStruct) DeepCopyInto(out *LogStruct) { *out = new(LogEntry) **out = **in } + if in.LastestWarningLog != nil { + in, out := &in.LastestWarningLog, &out.LastestWarningLog + *out = new(LogEntry) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogStruct.