fix: hostman master nic may be nil (#23453)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2025-09-30 11:53:06 +08:00
committed by GitHub
co-authored by Qiu Jian
parent 2f3359c83f
commit 20d28dc23f
+8 -1
View File
@@ -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
}
}
}