[lxc-devel] [lxd/master] Fix local configs in clustered networks

stgraber on Github lxc-bot at linuxcontainers.org
Wed Apr 1 02:29:59 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200331/f929bd5a/attachment.bin>
-------------- next part --------------
From 62be5451130a7bb0073a6617373ee11878c923d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 31 Mar 2020 19:59:18 -0400
Subject: [PATCH 1/2] doc/instances: Fix escaping
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 doc/instances.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/instances.md b/doc/instances.md
index 4ca969e3dd..8305efe943 100644
--- a/doc/instances.md
+++ b/doc/instances.md
@@ -473,10 +473,10 @@ mtu                     | integer   | parent MTU        | no        | The MTU of
 hwaddr                  | string    | randomly assigned | no        | The MAC address of the new interface
 ipv4.address            | string    | -                 | no        | Comma delimited list of IPv4 static addresses to add to the instance
 ipv4.gateway            | string    | auto              | no        | Whether to add an automatic default IPv4 gateway, can be "auto" or "none"
-ipv4.host_address       | string    | 169.254.0.1       | no        | The IPv4 address to add to the host-side veth interface.
+ipv4.host\_address      | string    | 169.254.0.1       | no        | The IPv4 address to add to the host-side veth interface.
 ipv6.address            | string    | -                 | no        | Comma delimited list of IPv6 static addresses to add to the instance
 ipv6.gateway            | string    | auto              | no        | Whether to add an automatic default IPv6 gateway, can be "auto" or "none"
-ipv6.host_address       | string    | fe80::1           | no        | The IPv6 address to add to the host-side veth interface.
+ipv6.host\_address      | string    | fe80::1           | no        | The IPv6 address to add to the host-side veth interface.
 vlan                    | integer   | -                 | no        | The VLAN ID to attach to
 
 #### bridged, macvlan or ipvlan for connection to physical network

From 98eb61e85fdc73079d404d7ffd8b6b379d8d46ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 31 Mar 2020 22:29:32 -0400
Subject: [PATCH 2/2] lxd/networks: Fix clustered configs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/networks.go | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/lxd/networks.go b/lxd/networks.go
index f5caebe95b..5d9c6eff6e 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -209,28 +209,18 @@ func networksPost(d *Daemon, r *http.Request) response.Response {
 }
 
 func networksPostCluster(d *Daemon, req api.NetworksPost) error {
+	logger.Errorf("here")
+
 	// Check that no node-specific config key has been defined.
 	for key := range req.Config {
 		if shared.StringInSlice(key, db.NetworkNodeConfigKeys) {
 			return fmt.Errorf("Config key '%s' is node-specific", key)
 		}
 	}
-
-	// Merge the current config.
-	networkID, dbNetwork, err := d.cluster.NetworkGet(req.Name)
-	if err != nil {
-		return err
-	}
-
-	for k, v := range dbNetwork.Config {
-		_, ok := req.Config[k]
-		if !ok {
-			req.Config[k] = v
-		}
-	}
+	logger.Errorf("here1")
 
 	// Add default values.
-	err = network.FillConfig(&req)
+	err := network.FillConfig(&req)
 	if err != nil {
 		return err
 	}
@@ -239,7 +229,14 @@ func networksPostCluster(d *Daemon, req api.NetworksPost) error {
 	// configs and insert the global config.
 	var configs map[string]map[string]string
 	var nodeName string
+	var networkID int64
 	err = d.cluster.Transaction(func(tx *db.ClusterTx) error {
+		// Fetch the network ID.
+		networkID, err = tx.NetworkID(req.Name)
+		if err != nil {
+			return err
+		}
+
 		// Fetch the node-specific configs.
 		configs, err = tx.NetworkNodeConfigs(networkID)
 		if err != nil {
@@ -253,6 +250,8 @@ func networksPostCluster(d *Daemon, req api.NetworksPost) error {
 		}
 
 		// Insert the global config keys.
+		logger.Errorf("here3, req=%+v", req)
+
 		return tx.NetworkConfigAdd(networkID, 0, req.Config)
 	})
 	if err != nil {
@@ -267,10 +266,12 @@ func networksPostCluster(d *Daemon, req api.NetworksPost) error {
 	for key, value := range configs[nodeName] {
 		nodeReq.Config[key] = value
 	}
+	logger.Errorf("here4 req=%+v", nodeReq)
 	err = doNetworksCreate(d, nodeReq, false)
 	if err != nil {
 		return err
 	}
+	logger.Errorf("here5")
 
 	// Notify all other nodes to create the network.
 	notifier, err := cluster.NewNotifier(d.State(), d.endpoints.NetworkCert(), cluster.NotifyAll)
@@ -288,12 +289,13 @@ func networksPostCluster(d *Daemon, req api.NetworksPost) error {
 			nodeReq.Config[key] = value
 		}
 
+		logger.Errorf("here6 req=%+v", nodeReq)
 		return client.CreateNetwork(nodeReq)
 	})
 
 	errored := notifyErr != nil
 
-	// Finally update the storage network state.
+	// Finally update the network state.
 	err = d.cluster.Transaction(func(tx *db.ClusterTx) error {
 		if errored {
 			return tx.NetworkErrored(req.Name)


More information about the lxc-devel mailing list