Skip to content

Commit 85d8dde

Browse files
fioncat郑守迪
and
郑守迪
authored
fix: uphost use mac address to match interface
Co-authored-by: 郑守迪 <[email protected]>
1 parent 335eb13 commit 85d8dde

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/iputils/addr.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ func GetMasterInterface() string {
4141
return UHostMasterInterface
4242
}
4343

44-
var targetInterface string
45-
if strings.HasPrefix(meta.InstanceId, "upm") {
46-
targetInterface = UPHostMasterInterface
44+
var targetMac string
45+
// 裸金属根据mac地址匹配网卡
46+
if strings.HasPrefix(meta.InstanceId, "upm") && len(meta.UPHost.NetworkInterfaces) > 0 {
47+
mac := meta.UPHost.NetworkInterfaces[0].Mac
48+
targetMac = strings.ToLower(mac)
4749
} else {
48-
targetInterface = UHostMasterInterface
50+
// 云主机直接返回eth0
51+
return UHostMasterInterface
4952
}
5053

5154
for _, iface := range list {
52-
if iface.Name == targetInterface {
53-
return targetInterface
55+
if iface.HardwareAddr.String() == targetMac {
56+
return iface.Name
5457
}
5558
}
56-
return targetInterface
59+
return UPHostMasterInterface
5760
}
5861

5962
// Get node master network interface ip and mac address

0 commit comments

Comments
 (0)