From bdf4199859951e86cf9f01cd1626f2e187fd1e31 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Tue, 30 Sep 2025 11:17:25 +0800 Subject: [PATCH] fix: hostman master nic may be nil (#23447) Co-authored-by: Qiu Jian --- pkg/hostman/hostinfo/hostinfo.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/hostman/hostinfo/hostinfo.go b/pkg/hostman/hostinfo/hostinfo.go index f5a280cd48..fb0fa3d33d 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -1145,6 +1145,9 @@ func (h *SHostInfo) GetMasterNicIpAndMask() (string, int) { } func (h *SHostInfo) GetMasterIp() string { + if h.MasterNic == nil { + return "" + } return h.MasterNic.Addr } @@ -1547,7 +1550,11 @@ func (h *SHostInfo) fetchHostname() string { hn = "host" } masterIp := h.GetMasterIp() - return hn + "-" + strings.Replace(masterIp, ".", "-", -1) + if len(masterIp) > 0 { + return hn + "-" + strings.Replace(masterIp, ".", "-", -1) + } else { + return hn + } } }