Skip to content

Commit

Permalink
Merge pull request #12347 from markylaing/clustering-renew-config
Browse files Browse the repository at this point in the history
lxd: Fully configure new node from cluster config after it is added.
  • Loading branch information
tomponline authored Oct 6, 2023
2 parents 1fea376 + 1bc3065 commit 2220b4e
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions lxd/api_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/canonical/lxd/client"
"github.com/canonical/lxd/lxd/acme"
"github.com/canonical/lxd/lxd/auth/candid"
"github.com/canonical/lxd/lxd/cluster"
clusterConfig "github.com/canonical/lxd/lxd/cluster/config"
clusterRequest "github.com/canonical/lxd/lxd/cluster/request"
"github.com/canonical/lxd/lxd/db"
dbCluster "github.com/canonical/lxd/lxd/db/cluster"
Expand Down Expand Up @@ -753,30 +753,34 @@ func clusterPutJoin(d *Daemon, r *http.Request, req api.ClusterPut) response.Res
return err
}

// Connect to MAAS
url, key := s.GlobalConfig.MAASController()
machine := nodeConfig.MAASMachine()
err = d.setupMAASController(url, key, machine)
// Get the current (updated) config.
var currentClusterConfig *clusterConfig.Config
err = d.db.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
currentClusterConfig, err = clusterConfig.Load(ctx, tx)
if err != nil {
return err
}

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

// Handle external authentication/RBAC
candidAPIURL, candidAPIKey, candidExpiry, candidDomains := s.GlobalConfig.CandidServer()
rbacAPIURL, rbacAPIKey, rbacExpiry, rbacAgentURL, rbacAgentUsername, rbacAgentPrivateKey, rbacAgentPublicKey := s.GlobalConfig.RBACServer()
d.globalConfigMu.Lock()
d.localConfig = nodeConfig
d.globalConfig = currentClusterConfig
d.globalConfigMu.Unlock()

if rbacAPIURL != "" {
err = d.setupRBACServer(rbacAPIURL, rbacAPIKey, rbacExpiry, rbacAgentURL, rbacAgentUsername, rbacAgentPrivateKey, rbacAgentPublicKey)
if err != nil {
return err
}
existingConfigDump := currentClusterConfig.Dump()
changes := make(map[string]string, len(existingConfigDump))
for k, v := range existingConfigDump {
changes[k], _ = v.(string)
}

if candidAPIURL != "" {
d.candidVerifier, err = candid.NewVerifier(candidAPIURL, candidAPIKey, candidExpiry, candidDomains)
if err != nil {
return err
}
err = doApi10UpdateTriggers(d, nil, changes, nodeConfig, currentClusterConfig)
if err != nil {
return err
}

// Start up networks so any post-join changes can be applied now that we have a Node ID.
Expand Down

0 comments on commit 2220b4e

Please sign in to comment.