fix(bgp policy): sort the slice items before deep equal(#1188)

This commit is contained in:
Xiang Liu 2021-11-10 17:35:49 +08:00 committed by Aaron U'Ren
parent 8e7d585217
commit 73b7c22ae4

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"reflect" "reflect"
"sort"
"strconv" "strconv"
"strings" "strings"
@ -125,7 +126,14 @@ func (nrc *NetworkRoutingController) addServiceVIPsDefinedSet() error {
&gobgpapi.AddDefinedSetRequest{DefinedSet: clusterIPPrefixSet}) &gobgpapi.AddDefinedSetRequest{DefinedSet: clusterIPPrefixSet})
} }
if reflect.DeepEqual(advIPPrefixList, currentDefinedSet.Prefixes) { currentPrefixes := currentDefinedSet.Prefixes
sort.SliceStable(advIPPrefixList, func(i, j int) bool {
return advIPPrefixList[i].IpPrefix < advIPPrefixList[j].IpPrefix
})
sort.SliceStable(currentPrefixes, func(i, j int) bool {
return currentPrefixes[i].IpPrefix < currentPrefixes[j].IpPrefix
})
if reflect.DeepEqual(advIPPrefixList, currentPrefixes) {
return nil return nil
} }
toAdd := make([]*gobgpapi.Prefix, 0) toAdd := make([]*gobgpapi.Prefix, 0)
@ -243,7 +251,10 @@ func (nrc *NetworkRoutingController) addiBGPPeersDefinedSet() ([]string, error)
return iBGPPeerCIDRs, err return iBGPPeerCIDRs, err
} }
if reflect.DeepEqual(iBGPPeerCIDRs, currentDefinedSet.List) { currentCIDRs := currentDefinedSet.List
sort.Strings(iBGPPeerCIDRs)
sort.Strings(currentCIDRs)
if reflect.DeepEqual(iBGPPeerCIDRs, currentCIDRs) {
return iBGPPeerCIDRs, nil return iBGPPeerCIDRs, nil
} }
toAdd := make([]string, 0) toAdd := make([]string, 0)