From c3fa80d518fd59685eaa2eed59ab2cb4dc35e9c2 Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Fri, 12 Apr 2024 14:49:34 +0800 Subject: [PATCH] :bug: fix net interface sort (#4672) Signed-off-by: cuisongliu --- pkg/utils/iputils/iputils_v2.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/utils/iputils/iputils_v2.go b/pkg/utils/iputils/iputils_v2.go index fa0f8be0de8..74499bfdfb4 100644 --- a/pkg/utils/iputils/iputils_v2.go +++ b/pkg/utils/iputils/iputils_v2.go @@ -19,6 +19,7 @@ import ( "fmt" "math/big" "net" + "sort" "strings" "k8s.io/apimachinery/pkg/util/sets" @@ -105,6 +106,9 @@ func ListLocalHostAddrs() (*[]net.Addr, error) { logger.Warn("net.Interfaces failed, err:", err.Error()) return nil, err } + sort.Slice(netInterfaces, func(i, j int) bool { + return netInterfaces[i].Index < netInterfaces[j].Index + }) var allAddrs []net.Addr for i := 0; i < len(netInterfaces); i++ { if (netInterfaces[i].Flags & net.FlagUp) == 0 {