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 e27c84e
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
}

Check warning on line 194 in pkg/evpn/bridge.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/bridge.go#L187-L194

Added lines #L187 - L194 were not covered by tests
// 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
}

Check warning on line 200 in pkg/evpn/bridge.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/bridge.go#L197-L200

Added lines #L197 - L200 were not covered by tests
}
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)

Check warning on line 232 in pkg/evpn/bridge.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/bridge.go#L231-L232

Added lines #L231 - L232 were not covered by tests
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)

Check warning on line 234 in pkg/evpn/bridge.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/bridge.go#L234

Added line #L234 was not covered by tests
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)

Check warning on line 243 in pkg/evpn/svi.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/svi.go#L236-L243

Added lines #L236 - L243 were not covered by tests
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)

Check warning on line 245 in pkg/evpn/svi.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/svi.go#L245

Added line #L245 was not covered by tests
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)

Check warning on line 290 in pkg/evpn/svi.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/svi.go#L283-L290

Added lines #L283 - L290 were not covered by tests
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)

Check warning on line 292 in pkg/evpn/svi.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/svi.go#L292

Added line #L292 was not covered by tests
log.Printf("error: %v", err)
return nil, err
}
Expand Down

0 comments on commit e27c84e

Please sign in to comment.