Skip to content

Commit

Permalink
lxd/daemon: Initialise server name and global config before patches
Browse files Browse the repository at this point in the history
And then reload them after patches have run in case its been modified.

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
  • Loading branch information
tomponline committed Oct 19, 2023
1 parent 9a916ab commit 56fa98f
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions lxd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,30 @@ func (d *Daemon) init() error {
version.UserAgentFeatures([]string{"cluster"})
}

// Load server name and config before patches run (so they can access them from d.State()).
err = d.db.Cluster.Transaction(d.shutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
config, err := clusterConfig.Load(ctx, tx)
if err != nil {
return err
}

// Get the local node (will be used if clustered).
serverName, err := tx.GetLocalNodeName(ctx)
if err != nil {
return err
}

d.globalConfigMu.Lock()
d.serverName = serverName
d.globalConfig = config
d.globalConfigMu.Unlock()

return nil
})
if err != nil {
return err
}

// Mount the storage pools.
logger.Infof("Initializing storage pools")
err = storageStartup(d.State(), false)
Expand Down Expand Up @@ -1262,6 +1286,30 @@ func (d *Daemon) init() error {
return err
}

// Load server name and config after patches run (in case its been changed).
err = d.db.Cluster.Transaction(d.shutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
config, err := clusterConfig.Load(ctx, tx)
if err != nil {
return err
}

// Get the local node (will be used if clustered).
serverName, err := tx.GetLocalNodeName(ctx)
if err != nil {
return err
}

d.globalConfigMu.Lock()
d.serverName = serverName
d.globalConfig = config
d.globalConfigMu.Unlock()

return nil
})
if err != nil {
return err
}

// Get daemon configuration.
bgpAddress := d.localConfig.BGPAddress()
bgpRouterID := d.localConfig.BGPRouterID()
Expand All @@ -1286,29 +1334,6 @@ func (d *Daemon) init() error {
maasAPIKey := ""
maasMachine := d.localConfig.MAASMachine()

err = d.db.Cluster.Transaction(d.shutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
config, err := clusterConfig.Load(ctx, tx)
if err != nil {
return err
}

// Get the local node (will be used if clustered).
serverName, err := tx.GetLocalNodeName(ctx)
if err != nil {
return err
}

d.globalConfigMu.Lock()
d.serverName = serverName
d.globalConfig = config
d.globalConfigMu.Unlock()

return nil
})
if err != nil {
return err
}

// Get specific config keys.
d.globalConfigMu.Lock()
bgpASN = d.globalConfig.BGPASN()
Expand Down

0 comments on commit 56fa98f

Please sign in to comment.