The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7813

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
With the intention of removing the old pre-clustering_join approach.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From bdd896a5297752261fc885a092a19a7d0e5c8989 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Wed, 26 Aug 2020 09:40:00 +0100
Subject: [PATCH] lxd/api/cluster: Makes ServerAddress field required for
 clusterPutJoin

With the intention of removing the old pre-clustering_join approach.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/api_cluster.go | 53 +++++++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 29 deletions(-)

diff --git a/lxd/api_cluster.go b/lxd/api_cluster.go
index 81cdd258eb..32d3e5ac1a 100644
--- a/lxd/api_cluster.go
+++ b/lxd/api_cluster.go
@@ -285,17 +285,18 @@ func clusterPutJoin(d *Daemon, req api.ClusterPut) 
response.Response {
                return response.BadRequest(fmt.Errorf("This server is already 
clustered"))
        }
 
+       // The old pre 'clustering_join' join API approach is no longer 
supported.
+       if req.ServerAddress == "" {
+               return response.BadRequest(fmt.Errorf("No server address 
provided for this member"))
+       }
+
        address, err := node.HTTPSAddress(d.db)
        if err != nil {
                return response.SmartError(err)
        }
 
        if address == "" {
-               if req.ServerAddress == "" {
-                       return response.BadRequest(fmt.Errorf("No 
core.https_address config key is set on this member"))
-               }
-
-               // The user has provided a server address, and no networking
+               // As the user always provides a server address, but no 
networking
                // was setup on this node, let's do the job and open the
                // port. We'll use the same address both for the REST API and
                // for clustering.
@@ -325,17 +326,15 @@ func clusterPutJoin(d *Daemon, req api.ClusterPut) 
response.Response {
 
                address = req.ServerAddress
        } else {
-               if req.ServerAddress != "" {
-                       // The user has previously set core.https_address and
-                       // is now providing a cluster address as well. If they
-                       // differ we need to listen to it.
-                       if !util.IsAddressCovered(req.ServerAddress, address) {
-                               err := 
d.endpoints.ClusterUpdateAddress(req.ServerAddress)
-                               if err != nil {
-                                       return response.SmartError(err)
-                               }
-                               address = req.ServerAddress
+               // The user has previously set core.https_address and
+               // is now providing a cluster address as well. If they
+               // differ we need to listen to it.
+               if !util.IsAddressCovered(req.ServerAddress, address) {
+                       err := 
d.endpoints.ClusterUpdateAddress(req.ServerAddress)
+                       if err != nil {
+                               return response.SmartError(err)
                        }
+                       address = req.ServerAddress
                }
 
                // Update the cluster.https_address config key.
@@ -384,21 +383,17 @@ func clusterPutJoin(d *Daemon, req api.ClusterPut) 
response.Response {
                        return err
                }
 
-               // If the ServerAddress field is set it means that we're using
-               // the new join API introduced with the 'clustering_join'
-               // extension.
-               if req.ServerAddress != "" {
-                       // Connect to ourselves to initialize storage pools and
-                       // networks using the API.
-                       d, err := lxd.ConnectLXDUnix(d.UnixSocket(), nil)
-                       if err != nil {
-                               return errors.Wrap(err, "Failed to connect to 
local LXD")
-                       }
+               // As ServerAddress field is required to be set it means that 
we're using the new join API
+               // introduced with the 'clustering_join' extension.
+               // Connect to ourselves to initialize storage pools and 
networks using the API.
+               localClient, err := lxd.ConnectLXDUnix(d.UnixSocket(), nil)
+               if err != nil {
+                       return errors.Wrap(err, "Failed to connect to local 
LXD")
+               }
 
-                       err = clusterInitMember(d, client, req.MemberConfig)
-                       if err != nil {
-                               return errors.Wrap(err, "Failed to initialize 
member")
-                       }
+               err = clusterInitMember(localClient, client, req.MemberConfig)
+               if err != nil {
+                       return errors.Wrap(err, "Failed to initialize member")
                }
 
                // Get all defined storage pools and networks, so they can be 
compared
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to