Skip to content

Commit

Permalink
review finding: replace deepequal
Browse files Browse the repository at this point in the history
  • Loading branch information
mwennrich committed Nov 26, 2024
1 parent 55f2d19 commit da1e14c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cmd/metal-api/internal/service/switch-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log/slog"
"net/http"
"net/netip"
"reflect"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -327,21 +326,29 @@ func (r *switchResource) notifySwitch(request *restful.Request, response *restfu
}

if requestPayload.BGPPortStates != nil {
r.log.Debug("bgp port states", "id", id, "states", requestPayload.BGPPortStates)
r.log.Debug("bgp port states received", "id", id, "states", requestPayload.BGPPortStates)
for i, nic := range newSwitch.Nics {
bpsnew, ok := requestPayload.BGPPortStates[nic.Name]
if !ok && nic.BGPPortState == nil {
bpsnew, has := requestPayload.BGPPortStates[nic.Name]
if !has && nic.BGPPortState == nil {
continue
}
if nic.BGPPortState == nil {
if !has {
newSwitch.Nics[i].BGPPortState = nil
switchUpdated = true
continue
}
if reflect.DeepEqual(nic.BGPPortState, &bpsnew) {
if nic.BGPPortState != nil &&
nic.BGPPortState.Neighbor == bpsnew.Neighbor &&
nic.BGPPortState.PeerGroup == bpsnew.PeerGroup &&
nic.BGPPortState.VrfName == bpsnew.VrfName &&
nic.BGPPortState.BgpState == bpsnew.BgpState &&
nic.BGPPortState.BgpTimerUpEstablished == bpsnew.BgpTimerUpEstablished &&
nic.BGPPortState.SentPrefixCounter == bpsnew.SentPrefixCounter &&
nic.BGPPortState.AcceptedPrefixCounter == bpsnew.AcceptedPrefixCounter {
continue
}

r.log.Debug("bgp port state", "id", id, "nic", nic.Name, "state", bpsnew)
r.log.Debug("bgp port state updated", "id", id, "nic", nic.Name, "state", bpsnew)
newSwitch.Nics[i].BGPPortState = &metal.SwitchBGPPortState{
Neighbor: bpsnew.Neighbor,
PeerGroup: bpsnew.PeerGroup,
Expand Down

0 comments on commit da1e14c

Please sign in to comment.