Skip to content

Commit

Permalink
feat(vrf): delete bridge and vxlan netdevs
Browse files Browse the repository at this point in the history
Fixes #120

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Aug 14, 2023
1 parent e8c2c86 commit 14319a1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/evpn/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,47 @@ func (s *Server) DeleteVrf(_ context.Context, in *pb.DeleteVrfRequest) (*emptypb
fmt.Printf("Failed to delete link: %v", err)
return nil, err
}
// delete bridge and vxlan only if VNI value is not empty
if obj.Spec.Vni != nil {
// use netlink to find BRIDGE device
bridgeName := fmt.Sprintf("br%d", *obj.Spec.Vni)
bridgedev, err := netlink.LinkByName(bridgeName)
log.Printf("Deleting BRIDGE %v", bridgedev)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
log.Printf("error: %v", err)
return nil, err
}

Check warning on line 198 in pkg/evpn/vrf.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/vrf.go#L189-L198

Added lines #L189 - L198 were not covered by tests
// bring link down
if err := netlink.LinkSetDown(bridgedev); err != nil {
fmt.Printf("Failed to up link: %v", err)
return nil, err
}

Check warning on line 203 in pkg/evpn/vrf.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/vrf.go#L200-L203

Added lines #L200 - L203 were not covered by tests
// use netlink to delete BRIDGE device
if err := netlink.LinkDel(bridgedev); err != nil {
fmt.Printf("Failed to delete link: %v", err)
return nil, err
}

Check warning on line 208 in pkg/evpn/vrf.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/vrf.go#L205-L208

Added lines #L205 - L208 were not covered by tests
// use netlink to find VXLAN device
vxlanName := fmt.Sprintf("vni%d", *obj.Spec.Vni)
vxlandev, err := netlink.LinkByName(vxlanName)
log.Printf("Deleting VXLAN %v", vxlandev)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
log.Printf("error: %v", err)
return nil, err
}

Check warning on line 217 in pkg/evpn/vrf.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/vrf.go#L210-L217

Added lines #L210 - L217 were not covered by tests
// bring link down
if err := netlink.LinkSetDown(vxlandev); err != nil {
fmt.Printf("Failed to up link: %v", err)
return nil, err
}

Check warning on line 222 in pkg/evpn/vrf.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/vrf.go#L219-L222

Added lines #L219 - L222 were not covered by tests
// use netlink to delete VXLAN device
if err := netlink.LinkDel(vxlandev); err != nil {
fmt.Printf("Failed to delete link: %v", err)
return nil, err
}

Check warning on line 227 in pkg/evpn/vrf.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/vrf.go#L224-L227

Added lines #L224 - L227 were not covered by tests
}
// remove from the Database
delete(s.Vrfs, obj.Name)
return &emptypb.Empty{}, nil
Expand Down

0 comments on commit 14319a1

Please sign in to comment.