Skip to content

Commit

Permalink
Merge pull request #65 from telekom/fix/frr-systemd-reload
Browse files Browse the repository at this point in the history
Wait for FRR reload to complete, restart if failed
  • Loading branch information
Cellebyte authored Oct 11, 2023
2 parents 0d20295 + ca9b6d1 commit a39e717
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
26 changes: 24 additions & 2 deletions pkg/frr/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,32 @@ func (*Manager) ReloadFRR() error {
}
defer con.Close()

_, err = con.ReloadUnitContext(context.Background(), frrUnit, "fail", nil)
if err != nil {
jobChan := make(chan string)
if _, err = con.ReloadUnitContext(context.Background(), frrUnit, "fail", jobChan); err != nil {
return fmt.Errorf("error reloading %s context: %w", frrUnit, err)
}
reloadStatus := <-jobChan
if reloadStatus != "done" {
return fmt.Errorf("error reloading %s, job status is %s", frrUnit, reloadStatus)
}
return nil
}

func (*Manager) RestartFRR() error {
con, err := dbus.NewSystemConnectionContext(context.Background())
if err != nil {
return fmt.Errorf("error creating nee D-Bus connection: %w", err)
}
defer con.Close()

jobChan := make(chan string)
if _, err = con.RestartUnitContext(context.Background(), frrUnit, "fail", jobChan); err != nil {
return fmt.Errorf("error restarting %s context: %w", frrUnit, err)
}
restartStatus := <-jobChan
if restartStatus != "done" {
return fmt.Errorf("error restarting %s, job status is %s", restartStatus, restartStatus)
}
return nil
}

Expand Down
12 changes: 9 additions & 3 deletions pkg/reconciler/layer3.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ func (r *reconcile) reconcileLayer3(l3vnis []networkv1alpha1.VRFRouteConfigurati
r.Logger.Info("trying to reload FRR config because it changed")
err = r.frrManager.ReloadFRR()
if err != nil {
r.dirtyFRRConfig = true
r.Logger.Error(err, "error reloading FRR systemd unit")
return fmt.Errorf("error reloading FRR systemd unit: %w", err)
r.Logger.Error(err, "error reloading FRR systemd unit, trying restart")

err = r.frrManager.RestartFRR()
if err != nil {
r.dirtyFRRConfig = true
r.Logger.Error(err, "error restarting FRR systemd unit")
return fmt.Errorf("error reloading / restarting FRR systemd unit: %w", err)
}
}
r.dirtyFRRConfig = false
r.Logger.Info("reloaded FRR config")
}

// Make sure that all created netlink VRFs are up after FRR reload
Expand Down

0 comments on commit a39e717

Please sign in to comment.