Skip to content

Commit

Permalink
feat: decouple linux devname from object resource id in get and update
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 30, 2023
1 parent 46a842c commit 652a65a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
34 changes: 18 additions & 16 deletions pkg/evpn/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"
"log"
"net"
"path"

"github.com/vishvananda/netlink"

Expand Down Expand Up @@ -184,18 +183,21 @@ func (s *Server) UpdateLogicalBridge(_ context.Context, in *pb.UpdateLogicalBrid
log.Printf("error: %v", err)
return nil, err
}
resourceID := path.Base(bridge.Name)
iface, err := s.nLink.LinkByName(resourceID)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
log.Printf("error: %v", err)
return nil, err
}
// base := iface.Attrs()
// iface.MTU = 1500 // TODO: remove this, just an example
if err := s.nLink.LinkModify(iface); err != nil {
fmt.Printf("Failed to update link: %v", err)
return nil, err
// only if VNI is not empty
if bridge.Spec.Vni != nil {
vxlanName := fmt.Sprintf("vni%d", *bridge.Spec.Vni)
iface, err := s.nLink.LinkByName(vxlanName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", vxlanName)
log.Printf("error: %v", err)
return nil, err
}
// base := iface.Attrs()
// iface.MTU = 1500 // TODO: remove this, just an example
if err := s.nLink.LinkModify(iface); err != nil {
fmt.Printf("Failed to update link: %v", err)
return nil, err
}
}
response := proto.Clone(in.LogicalBridge).(*pb.LogicalBridge)
response.Status = &pb.LogicalBridgeStatus{OperStatus: pb.LBOperStatus_LB_OPER_STATUS_UP}
Expand Down Expand Up @@ -224,12 +226,12 @@ func (s *Server) GetLogicalBridge(_ context.Context, in *pb.GetLogicalBridgeRequ
log.Printf("error: %v", err)
return nil, err
}
resourceID := path.Base(bridge.Name)
// only if VNI is not empty
if bridge.Spec.Vni != nil {
_, err := s.nLink.LinkByName(resourceID)
vxlanName := fmt.Sprintf("vni%d", *bridge.Spec.Vni)
_, err := s.nLink.LinkByName(vxlanName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
err := status.Errorf(codes.NotFound, "unable to find key %s", vxlanName)
log.Printf("error: %v", err)
return nil, err
}
Expand Down
26 changes: 20 additions & 6 deletions pkg/evpn/svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,17 @@ func (s *Server) UpdateSvi(_ context.Context, in *pb.UpdateSviRequest) (*pb.Svi,
log.Printf("error: %v", err)
return nil, err
}
resourceID := path.Base(svi.Name)
iface, err := s.nLink.LinkByName(resourceID)
// use netlink to find VlanId from LogicalBridge object
bridgeObject, ok := s.Bridges[svi.Spec.LogicalBridge]
if !ok {
err := status.Errorf(codes.NotFound, "unable to find key %s", svi.Spec.LogicalBridge)
log.Printf("error: %v", err)
return nil, err
}
vlanName := fmt.Sprintf("vlan%d", bridgeObject.Spec.VlanId)
iface, err := s.nLink.LinkByName(vlanName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
err := status.Errorf(codes.NotFound, "unable to find key %s", vlanName)
log.Printf("error: %v", err)
return nil, err
}
Expand Down Expand Up @@ -272,10 +279,17 @@ func (s *Server) GetSvi(_ context.Context, in *pb.GetSviRequest) (*pb.Svi, error
log.Printf("error: %v", err)
return nil, err
}
resourceID := path.Base(obj.Name)
_, err := s.nLink.LinkByName(resourceID)
// use netlink to find VlanId from LogicalBridge object
bridgeObject, ok := s.Bridges[obj.Spec.LogicalBridge]
if !ok {
err := status.Errorf(codes.NotFound, "unable to find key %s", obj.Spec.LogicalBridge)
log.Printf("error: %v", err)
return nil, err
}
vlanName := fmt.Sprintf("vlan%d", bridgeObject.Spec.VlanId)
_, err := s.nLink.LinkByName(vlanName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
err := status.Errorf(codes.NotFound, "unable to find key %s", vlanName)
log.Printf("error: %v", err)
return nil, err
}
Expand Down

0 comments on commit 652a65a

Please sign in to comment.