Skip to content

Commit

Permalink
fix(bridge): delete and get only if VNI is not empty
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Aug 11, 2023
1 parent 12ce81a commit b9b3688
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions pkg/evpn/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,31 @@ func (s *Server) DeleteLogicalBridge(_ context.Context, in *pb.DeleteLogicalBrid
return nil, err
}
resourceID := path.Base(obj.Name)
// use netlink to find vxlan device
vxlan, err := netlink.LinkByName(resourceID)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
log.Printf("error: %v", err)
return nil, err
}
log.Printf("Deleting Vxlan %v", vxlan)
// bring link down
if err := netlink.LinkSetDown(vxlan); err != nil {
fmt.Printf("Failed to up link: %v", err)
return nil, err
}
// delete bridge vlan
if err := netlink.BridgeVlanDel(vxlan, uint16(obj.Spec.VlanId), true, true, false, false); err != nil {
fmt.Printf("Failed to delete vlan to bridge: %v", err)
return nil, err
}
// use netlink to delete vxlan device
if err := netlink.LinkDel(vxlan); err != nil {
fmt.Printf("Failed to delete link: %v", err)
return nil, err
// only if VNI is not empty
if obj.Spec.Vni > 0 {
// use netlink to find vxlan device
vxlan, err := netlink.LinkByName(resourceID)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
log.Printf("error: %v", err)
return nil, err
}
log.Printf("Deleting Vxlan %v", vxlan)
// bring link down
if err := netlink.LinkSetDown(vxlan); err != nil {
fmt.Printf("Failed to up link: %v", err)
return nil, err
}
// delete bridge vlan
if err := netlink.BridgeVlanDel(vxlan, uint16(obj.Spec.VlanId), true, true, false, false); err != nil {
fmt.Printf("Failed to delete vlan to bridge: %v", err)
return nil, err
}
// use netlink to delete vxlan device
if err := netlink.LinkDel(vxlan); err != nil {
fmt.Printf("Failed to delete link: %v", err)
return nil, err
}
}
// remove from the Database
delete(s.Bridges, obj.Name)
Expand Down Expand Up @@ -221,11 +224,14 @@ func (s *Server) GetLogicalBridge(_ context.Context, in *pb.GetLogicalBridgeRequ
return nil, err
}
resourceID := path.Base(bridge.Name)
_, err := netlink.LinkByName(resourceID)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
log.Printf("error: %v", err)
return nil, err
// only if VNI is not empty
if bridge.Spec.Vni > 0 {
_, err := netlink.LinkByName(resourceID)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
log.Printf("error: %v", err)
return nil, err
}
}
// TODO
return &pb.LogicalBridge{Name: in.Name, Spec: &pb.LogicalBridgeSpec{Vni: bridge.Spec.Vni, VlanId: bridge.Spec.VlanId}, Status: &pb.LogicalBridgeStatus{OperStatus: pb.LBOperStatus_LB_OPER_STATUS_UP}}, nil
Expand Down

0 comments on commit b9b3688

Please sign in to comment.