Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make connecting to OVN more reliable #1089

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
incusd: Switch OVN to a getter function
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
Sponsored-by: Buddy (https://buddy.works)
  • Loading branch information
stgraber committed Aug 7, 2024
commit 79bb269219ddc9589b170dd9e89c391e81a4fbb4
3 changes: 3 additions & 0 deletions cmd/incusd/api_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ func clusterPutJoin(d *Daemon, r *http.Request, req api.ClusterPut) response.Res
// Refresh the state.
s = d.State()

// Re-connect OVN if needed.
_ = d.setupOVN()

// Start up networks so any post-join changes can be applied now that we have a Node ID.
logger.Debug("Starting networks after cluster join")
err = networkStartup(s)
Expand Down
21 changes: 16 additions & 5 deletions cmd/incusd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type Daemon struct {
// OVN clients.
ovnnb *ovn.NB
ovnsb *ovn.SB
ovnMu sync.Mutex

// API info.
apiExtensions int
Expand Down Expand Up @@ -559,8 +560,7 @@ func (d *Daemon) State() *state.State {
InstanceTypes: instanceTypes,
LocalConfig: localConfig,
OS: d.os,
OVNNB: d.ovnnb,
OVNSB: d.ovnsb,
OVN: d.getOVN,
Proxy: d.proxy,
ServerCert: d.serverCert,
ServerClustered: d.serverClustered,
Expand Down Expand Up @@ -1467,9 +1467,6 @@ func (d *Daemon) init() error {
logger.Info("Started BGP server")
}

// Attempt to setup OVN clients.
_ = d.setupOVN()

// Setup DNS listener.
d.dns = dns.NewServer(d.db.Cluster, func(name string, full bool) (*dns.Zone, error) {
// Fetch the zone.
Expand Down Expand Up @@ -2535,6 +2532,9 @@ func (d *Daemon) nodeRefreshTask(heartbeatData *cluster.APIHeartbeat, isLeader b
}

func (d *Daemon) setupOVN() error {
d.ovnMu.Lock()
defer d.ovnMu.Unlock()

// Clear any existing clients.
d.ovnnb = nil
d.ovnsb = nil
Expand Down Expand Up @@ -2597,3 +2597,14 @@ func (d *Daemon) setupOVN() error {

return nil
}

func (d *Daemon) getOVN() (*ovn.NB, *ovn.SB, error) {
if d.ovnnb == nil || d.ovnsb == nil {
err := d.setupOVN()
if err != nil {
return nil, nil, fmt.Errorf("Failed to connect to OVN: %w", err)
}
}

return d.ovnnb, d.ovnsb, nil
}
3 changes: 1 addition & 2 deletions internal/server/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,5 @@ type State struct {
Authorizer auth.Authorizer

// OVN.
OVNNB *ovn.NB
OVNSB *ovn.SB
OVN func() (*ovn.NB, *ovn.SB, error)
}