Skip to content

Commit

Permalink
fix(evpn): fix graceful shutdown, tracer option
Browse files Browse the repository at this point in the history
Signed-off-by: Saikumar, Banoth <[email protected]>
  • Loading branch information
Inbanoth committed Jun 21, 2024
1 parent 09d82b5 commit f1a3e0e
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 324 deletions.
37 changes: 13 additions & 24 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
intel_e2000_linux "github.com/opiproject/opi-evpn-bridge/pkg/LinuxVendorModule/intele2000"
frr "github.com/opiproject/opi-evpn-bridge/pkg/frr"
netlink "github.com/opiproject/opi-evpn-bridge/pkg/netlink"
"github.com/opiproject/opi-evpn-bridge/pkg/vendor_plugins/intel-e2000/p4runtime/p4driverapi"
ipu_vendor "github.com/opiproject/opi-evpn-bridge/pkg/vendor_plugins/intel-e2000/p4runtime/p4translation"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
)
Expand Down Expand Up @@ -73,7 +74,7 @@ var rootCmd = &cobra.Command{
intel_e2000_linux.Initialize()
frr.Initialize()
ipu_vendor.Initialize()
netlink.DeInitialize()

case "ci":
gen_linux.Initialize()
ci_linux.Initialize()
Expand All @@ -91,7 +92,6 @@ var rootCmd = &cobra.Command{
netlink.Initialize()
default:
}

runGrpcServer(config.GlobalConfig.GRPCPort, config.GlobalConfig.TLSFiles)

},
Expand Down Expand Up @@ -135,9 +135,6 @@ func setupLogger(filename string) {

func cleanUp() {
log.Println("Defer function called")
if err := deleteGrdVrf(); err != nil {
log.Println("Failed to delete GRD vrf")
}
if err := infradb.DeleteAllResources(); err != nil {
log.Println("Failed to delete all the resources: ", err)
}
Expand All @@ -146,7 +143,10 @@ func cleanUp() {
gen_linux.DeInitialize()
intel_e2000_linux.DeInitialize()
frr.DeInitialize()
netlink.DeInitialize()
ipu_vendor.DeInitialize()
close(p4driverapi.StopCh)

case "ci":
gen_linux.DeInitialize()
ci_linux.DeInitialize()
Expand Down Expand Up @@ -205,12 +205,14 @@ func main() {

// runGrpcServer start the grpc server for all the components
func runGrpcServer(grpcPort uint16, tlsFiles string) {
tp := utils.InitTracerProvider("opi-evpn-bridge")
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
log.Panicf("Tracer Provider Shutdown: %v", err)
}
}()
if config.GlobalConfig.Tracer {
tp := utils.InitTracerProvider("opi-evpn-bridge")
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
log.Panicf("Tracer Provider Shutdown: %v", err)
}
}()
}

lis, err := net.Listen("tcp", fmt.Sprintf(":%d", grpcPort))
if err != nil {
Expand Down Expand Up @@ -313,16 +315,3 @@ func createGrdVrf() error {

return nil
}

// deleteGrdVrf creates the grd vrf with vni 0
func deleteGrdVrf() error {
log.Printf("DeleteGrdVrf(): deleted GRD VRF object\n")

err := infradb.DeleteVrf("//network.opiproject.org/vrfs/GRD")
if err != nil {
log.Printf("CreateGrdVrf(): Error in deleting GRD VRF object %+v\n", err)
return err
}

return nil
}
1 change: 1 addition & 0 deletions config-intel-e2000.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ tlsfiles:
database: redis
dbaddress: 127.0.0.1:6379
buildenv: intel_e2000
tracer: false
subscribers:
- name: "lvm"
priority: 2
Expand Down
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ tlsfiles:
database: redis
dbaddress: 127.0.0.1:6379
buildenv: ci
tracer: false
subscribers:
- name: "lgm"
priority: 1
Expand Down
2 changes: 1 addition & 1 deletion pkg/LinuxCIModule/lci.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func Initialize() {
}
}
ctx = context.Background()
nlink = utils.NewNetlinkWrapperWithArgs(false)
nlink = utils.NewNetlinkWrapperWithArgs(config.GlobalConfig.Tracer)
}

// DeInitialize function handles stops functionality
Expand Down
2 changes: 1 addition & 1 deletion pkg/LinuxGeneralModule/lgm.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func Initialize() {
brTenant = "br-tenant"
ipMtu = config.GlobalConfig.LinuxFrr.IPMtu
ctx = context.Background()
nlink = utils.NewNetlinkWrapperWithArgs(false)
nlink = utils.NewNetlinkWrapperWithArgs(config.GlobalConfig.Tracer)
// Set up the static configuration parts
_, err := nlink.LinkByName(ctx, brTenant)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/LinuxVendorModule/intele2000/intelE2000.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func tearDownVrf(vrf *infradb.Vrf) bool {
Intf, err := nlink.LinkByName(ctx, vlanIntf)
if err != nil {
log.Printf("Failed to get link %v: %s\n", vlanIntf, err)
return true
return false
}
if err = nlink.LinkDel(ctx, Intf); err != nil {
log.Printf("Failed to delete link %v: %s\n", vlanIntf, err)
Expand Down Expand Up @@ -421,7 +421,7 @@ func Initialize() {
ipMtu = config.GlobalConfig.LinuxFrr.IPMtu
brTenant = "br-tenant"
ctx = context.Background()
nlink = utils.NewNetlinkWrapperWithArgs(false)
nlink = utils.NewNetlinkWrapperWithArgs(config.GlobalConfig.Tracer)
}

// DeInitialize function handles stops functionality
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type Config struct {
Database string `yaml:"database"`
DBAddress string `yaml:"dbaddress"`
Buildenv string `yaml:"buildenv"`
Tracer bool `yaml:"tracer"`
Subscribers []SubscriberConfig `yaml:"subscribers"`
LinuxFrr LinuxFrrConfig `yaml:"linuxfrr"`
Netlink NetlinkConfig `yaml:"netlink"`
Expand Down
26 changes: 25 additions & 1 deletion pkg/frr/frr.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,24 @@ func (h *ModulefrrHandler) HandleEvent(eventType string, objectData *eventbus.Ob
}

// handlesvi handles the svi functionality
//
//nolint:funlen,gocognit
func handlesvi(objectData *eventbus.ObjectData) {
var comp common.Component
svi, err := infradb.GetSvi(objectData.Name)
if err != nil {
log.Printf("GetSvi error: %s %s\n", err, objectData.Name)
comp.Name = frrComp
comp.CompStatus = common.ComponentStatusError
if comp.Timer == 0 {
comp.Timer = 2 * time.Second
} else {
comp.Timer *= 2
}
err := infradb.UpdateSviStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp)
if err != nil {
log.Printf("error in updating svi status: %s\n", err)
}
return
}

Expand Down Expand Up @@ -127,6 +140,17 @@ func handlevrf(objectData *eventbus.ObjectData) {
vrf, err := infradb.GetVrf(objectData.Name)
if err != nil {
log.Printf("GetVRF error: %s %s\n", err, objectData.Name)
comp.Name = frrComp
comp.CompStatus = common.ComponentStatusError
if comp.Timer == 0 { // wait timer is 2 powerof natural numbers ex : 1,2,3...
comp.Timer = 2 * time.Second
} else {
comp.Timer *= 2
}
err := infradb.UpdateVrfStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp)
if err != nil {
log.Printf("error in updating vrf status: %s\n", err)
}
return
}

Expand Down Expand Up @@ -256,7 +280,7 @@ func Initialize() {
subscribeInfradb(&config.GlobalConfig)

ctx = context.Background()
Frr = utils.NewFrrWrapperWithArgs("localhost", false)
Frr = utils.NewFrrWrapperWithArgs("localhost", config.GlobalConfig.Tracer)

// Make sure IPv4 forwarding is enabled.
detail, flag := run([]string{"sysctl", "-w", " net.ipv4.ip_forward=1"}, false)
Expand Down
54 changes: 47 additions & 7 deletions pkg/infradb/infradb.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"log"
"sync"
"time"

"github.com/opiproject/opi-evpn-bridge/pkg/infradb/common"
"github.com/opiproject/opi-evpn-bridge/pkg/infradb/subscriberframework/eventbus"
Expand Down Expand Up @@ -1217,27 +1218,56 @@ func GetAllSvis() ([]*Svi, error) {

// DeleteAllResources deletes all components from infradb
func DeleteAllResources() error {
duration := 10 * time.Second
bps, _ := GetAllBPs()
for _, bp := range bps {
err := DeleteBP(bp.Name)
if err != nil {
return err
}
}
startTime := time.Now()
for {
b, _ := GetAllBPs()
if len(b) == 0 {
break
}
if time.Since(startTime) > duration {
return errors.New("failed to delete BridgePorts")
}
}
svis, _ := GetAllSvis()
for _, svi := range svis {
err := DeleteSvi(svi.Name)
if err != nil {
return err
}
}

startTime = time.Now()
for {
s, _ := GetAllSvis()
if len(s) == 0 {
break
}
if time.Since(startTime) > duration {
return errors.New("failed to delete svis")
}
}
vrfs, _ := GetAllVrfs()
for _, vrf := range vrfs {
err := DeleteVrf(vrf.Name)
if err != nil {
return err
}
}

bps, _ := GetAllBPs()
for _, bp := range bps {
err := DeleteBP(bp.Name)
if err != nil {
return err
startTime = time.Now()
for {
v, _ := GetAllVrfs()
if len(v) == 0 {
break
}
if time.Since(startTime) > duration {
return errors.New("failed to delete vrfs")
}
}
lbs, _ := GetAllLBs()
Expand All @@ -1247,6 +1277,16 @@ func DeleteAllResources() error {
return err
}
}
startTime = time.Now()
for {
l, _ := GetAllLBs()
if len(l) == 0 {
break
}
if time.Since(startTime) > duration {
return errors.New("failed to delete LogicalBridges")
}
}
return nil
}

Expand Down
Loading

0 comments on commit f1a3e0e

Please sign in to comment.