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

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2025-09-30 11:17:25 +08:00
committed by GitHub
parent 01c6e646f8
commit bdf4199859

View File

@@ -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
}
}
}