[lxc-devel] [lxd/master] Fix network config propagation in cluster
stgraber on Github
lxc-bot at linuxcontainers.org
Tue Nov 26 06:41:34 UTC 2019
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/20191125/19be9a96/attachment.bin>
-------------- next part --------------
From e7a0a723c0806a94e2d8dd81d4267c45ff248ab5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 26 Nov 2019 00:45:26 -0500
Subject: [PATCH 1/2] lxd/networks: Merge clsuter config on create
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #6418
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/networks.go | 40 +++++++++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/lxd/networks.go b/lxd/networks.go
index 9505777088..0c5aa824cb 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -168,11 +168,6 @@ func networksPost(d *Daemon, r *http.Request) response.Response {
return resp
}
- err = networkFillConfig(&req)
- if err != nil {
- return response.SmartError(err)
- }
-
// Check if we're clustered
count, err := cluster.Count(d.State())
if err != nil {
@@ -184,9 +179,15 @@ func networksPost(d *Daemon, r *http.Request) response.Response {
if err != nil {
return response.SmartError(err)
}
+
return resp
}
+ err = networkFillConfig(&req)
+ if err != nil {
+ return response.SmartError(err)
+ }
+
// No targetNode was specified and we're either a single-node
// cluster or not clustered at all, so create the storage
// pool immediately.
@@ -221,24 +222,37 @@ func networksPostCluster(d *Daemon, req api.NetworksPost) error {
}
}
+ // 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
+ }
+ }
+
+ // Add default values.
+ err = networkFillConfig(&req)
+ if err != nil {
+ return err
+ }
+
// Check that the network is properly defined, fetch the node-specific
// configs and insert the global config.
var configs map[string]map[string]string
var nodeName string
- err := d.cluster.Transaction(func(tx *db.ClusterTx) error {
- // Check that the network was defined at all.
- networkID, err := tx.NetworkID(req.Name)
- if err != nil {
- return err
- }
-
+ err = d.cluster.Transaction(func(tx *db.ClusterTx) error {
// Fetch the node-specific configs.
configs, err = tx.NetworkNodeConfigs(networkID)
if err != nil {
return err
}
- // Take note of the name of this node
+ // Take note of the name of this node.
nodeName, err = tx.NodeName()
if err != nil {
return err
From 26098589643d83c72bb915a06da9603d913eab06 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 26 Nov 2019 01:30:19 -0500
Subject: [PATCH 2/2] lxd/networks: Forward config updates
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #6418
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/networks.go | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/lxd/networks.go b/lxd/networks.go
index 0c5aa824cb..0f7d8c6d6c 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -627,7 +627,7 @@ func networkPut(d *Daemon, r *http.Request) response.Response {
return response.BadRequest(err)
}
- return doNetworkUpdate(d, name, dbInfo.Config, req)
+ return doNetworkUpdate(d, name, dbInfo.Config, req, isClusterNotification(r))
}
func networkPatch(d *Daemon, r *http.Request) response.Response {
@@ -678,10 +678,10 @@ func networkPatch(d *Daemon, r *http.Request) response.Response {
}
}
- return doNetworkUpdate(d, name, dbInfo.Config, req)
+ return doNetworkUpdate(d, name, dbInfo.Config, req, isClusterNotification(r))
}
-func doNetworkUpdate(d *Daemon, name string, oldConfig map[string]string, req api.NetworkPut) response.Response {
+func doNetworkUpdate(d *Daemon, name string, oldConfig map[string]string, req api.NetworkPut, notify bool) response.Response {
// Validate the configuration
err := networkValidateConfig(name, req.Config)
if err != nil {
@@ -701,7 +701,7 @@ func doNetworkUpdate(d *Daemon, name string, oldConfig map[string]string, req ap
return response.NotFound(err)
}
- err = n.Update(req)
+ err = n.Update(req, notify)
if err != nil {
return response.SmartError(err)
}
@@ -2136,7 +2136,7 @@ func (n *network) Stop() error {
return nil
}
-func (n *network) Update(newNetwork api.NetworkPut) error {
+func (n *network) Update(newNetwork api.NetworkPut, notify bool) error {
err := networkFillAuto(newNetwork.Config)
if err != nil {
return err
@@ -2239,9 +2239,25 @@ func (n *network) Update(newNetwork api.NetworkPut) error {
n.description = newNetwork.Description
// Update the database
- err = n.state.Cluster.NetworkUpdate(n.name, n.description, n.config)
- if err != nil {
- return err
+ if !notify {
+ // Notify all other nodes to update the network.
+ notifier, err := cluster.NewNotifier(n.state, n.state.Endpoints.NetworkCert(), cluster.NotifyAll)
+ if err != nil {
+ return err
+ }
+
+ err = notifier(func(client lxd.InstanceServer) error {
+ return client.UpdateNetwork(n.name, newNetwork, "")
+ })
+ if err != nil {
+ return err
+ }
+
+ // Update the database.
+ err = n.state.Cluster.NetworkUpdate(n.name, n.description, n.config)
+ if err != nil {
+ return err
+ }
}
// Restart the network
More information about the lxc-devel
mailing list