From 20d28dc23ff987b21a035b30528d1feebe522925 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Tue, 30 Sep 2025 11:53:06 +0800 Subject: [PATCH] fix: hostman master nic may be nil (#23453) 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 d4bdc4fe5b..4059dc9b6d 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -1162,6 +1162,9 @@ func (h *SHostInfo) GetMasterNicIpAndMask() (string, int) { } func (h *SHostInfo) GetMasterIp() string { + if h.MasterNic == nil { + return "" + } if h.MasterNic.Addr != "" { return h.MasterNic.Addr } @@ -1567,7 +1570,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 + } } }