From 85d8dde37de8b44f710f2f11ce8fb9b46071a3b9 Mon Sep 17 00:00:00 2001 From: wenqian Date: Tue, 22 Aug 2023 14:55:53 +0800 Subject: [PATCH] fix: uphost use mac address to match interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 郑守迪 --- pkg/iputils/addr.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/iputils/addr.go b/pkg/iputils/addr.go index 1178553..70aee74 100644 --- a/pkg/iputils/addr.go +++ b/pkg/iputils/addr.go @@ -41,19 +41,22 @@ func GetMasterInterface() string { return UHostMasterInterface } - var targetInterface string - if strings.HasPrefix(meta.InstanceId, "upm") { - targetInterface = UPHostMasterInterface + var targetMac string + // 裸金属根据mac地址匹配网卡 + if strings.HasPrefix(meta.InstanceId, "upm") && len(meta.UPHost.NetworkInterfaces) > 0 { + mac := meta.UPHost.NetworkInterfaces[0].Mac + targetMac = strings.ToLower(mac) } else { - targetInterface = UHostMasterInterface + // 云主机直接返回eth0 + return UHostMasterInterface } for _, iface := range list { - if iface.Name == targetInterface { - return targetInterface + if iface.HardwareAddr.String() == targetMac { + return iface.Name } } - return targetInterface + return UPHostMasterInterface } // Get node master network interface ip and mac address