From c0c8045ec69b74e002997973c9cd5dcba90a4a4f Mon Sep 17 00:00:00 2001 From: Nathan Skrzypczak Date: Thu, 7 Nov 2024 11:57:54 +0100 Subject: [PATCH] Silence casting warnings Signed-off-by: Nathan Skrzypczak --- .../connectivity/connectivity_server.go | 42 ++++++++++--------- .../watchers/uplink_route_watcher.go | 36 ++++++++-------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/calico-vpp-agent/connectivity/connectivity_server.go b/calico-vpp-agent/connectivity/connectivity_server.go index d2d13d6e..c05c2372 100644 --- a/calico-vpp-agent/connectivity/connectivity_server.go +++ b/calico-vpp-agent/connectivity/connectivity_server.go @@ -198,28 +198,30 @@ func (s *ConnectivityServer) ServeConnectivity(t *tomb.Tomb) error { s.updateAllIPConnectivity() } case common.PeerNodeStateChanged: - old, ok := evt.Old.(*common.LocalNodeSpec) - if !ok { - s.log.Errorf("evt.Old is not a *common.LocalNodeSpec %v", evt.Old) - } - new, ok := evt.New.(*common.LocalNodeSpec) - if !ok { - s.log.Errorf("evt.New is not a *common.LocalNodeSpec %v", evt.New) - } - if old != nil { - if old.IPv4Address != nil { - delete(s.nodeByAddr, old.IPv4Address.IP.String()) - } - if old.IPv6Address != nil { - delete(s.nodeByAddr, old.IPv6Address.IP.String()) + if evt.Old != nil { + old, ok := evt.Old.(*common.LocalNodeSpec) + if !ok { + s.log.Errorf("evt.Old is not a *common.LocalNodeSpec %v", evt.Old) + } else { + if old.IPv4Address != nil { + delete(s.nodeByAddr, old.IPv4Address.IP.String()) + } + if old.IPv6Address != nil { + delete(s.nodeByAddr, old.IPv6Address.IP.String()) + } } } - if new != nil { - if new.IPv4Address != nil { - s.nodeByAddr[new.IPv4Address.IP.String()] = *new - } - if new.IPv6Address != nil { - s.nodeByAddr[new.IPv6Address.IP.String()] = *new + if evt.New != nil { + new, ok := evt.New.(*common.LocalNodeSpec) + if !ok { + s.log.Errorf("evt.New is not a *common.LocalNodeSpec %v", evt.New) + } else { + if new.IPv4Address != nil { + s.nodeByAddr[new.IPv4Address.IP.String()] = *new + } + if new.IPv6Address != nil { + s.nodeByAddr[new.IPv6Address.IP.String()] = *new + } } } case common.FelixConfChanged: diff --git a/calico-vpp-agent/watchers/uplink_route_watcher.go b/calico-vpp-agent/watchers/uplink_route_watcher.go index 0b497fd4..23ddbed9 100644 --- a/calico-vpp-agent/watchers/uplink_route_watcher.go +++ b/calico-vpp-agent/watchers/uplink_route_watcher.go @@ -278,20 +278,14 @@ func (r *RouteWatcher) WatchRoutes(t *tomb.Tomb) error { } } case common.IpamConfChanged: - old, ok := event.Old.(*proto.IPAMPool) - if !ok { - r.log.Errorf("event.Old is not a (*proto.IPAMPool) %v", event.Old) - goto restart - } - new, ok := event.New.(*proto.IPAMPool) - if !ok { - r.log.Errorf("event.New is not a (*proto.IPAMPool) %v", event.New) - goto restart - } - r.log.Debugf("Received IPAM config update in route watcher old:%+v new:%+v", old, new) - if new == nil { - key := old.Cidr - routes, err := r.getNetworkRoute(key, "") + r.log.Debugf("Received IPAM config update in route watcher old:%+v new:%+v", event.Old, event.New) + if event.New == nil && event.Old != nil { + old, ok := event.Old.(*proto.IPAMPool) + if !ok { + r.log.Errorf("event.Old is not a (*proto.IPAMPool) %v", event.Old) + goto restart + } + routes, err := r.getNetworkRoute(old.Cidr, "") if err != nil { r.log.Error("Error getting route from ipam update:", err) goto restart @@ -299,13 +293,17 @@ func (r *RouteWatcher) WatchRoutes(t *tomb.Tomb) error { for _, route := range routes { err = r.DelRoute(route) if err != nil { - r.log.Errorf("Cannot delete pool route %s through vpp tap: %v", key, err) + r.log.Errorf("Cannot delete pool route %s through vpp tap: %v", old.Cidr, err) goto restart } } - } else { - key := new.Cidr - routes, err := r.getNetworkRoute(key, "") + } else if event.New != nil { + new, ok := event.New.(*proto.IPAMPool) + if !ok { + r.log.Errorf("event.New is not a (*proto.IPAMPool) %v", event.New) + goto restart + } + routes, err := r.getNetworkRoute(new.Cidr, "") if err != nil { r.log.Error("Error getting route from ipam update:", err) goto restart @@ -313,7 +311,7 @@ func (r *RouteWatcher) WatchRoutes(t *tomb.Tomb) error { for _, route := range routes { err = r.AddRoute(route) if err != nil { - r.log.Errorf("Cannot add pool route %s through vpp tap: %v", key, err) + r.log.Errorf("Cannot add pool route %s through vpp tap: %v", new.Cidr, err) goto restart } }