[lxc-devel] [lxd/master] lxd/images: Replicate images to the right project

stgraber on Github lxc-bot at linuxcontainers.org
Fri Apr 26 00:17:02 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190425/a1cc9bba/attachment.bin>
-------------- next part --------------
From f159f31594d66060b495de62d4bcd2782ecefa63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 25 Apr 2019 20:15:56 -0400
Subject: [PATCH] lxd/images: Replicate images to the right project
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/images.go | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lxd/images.go b/lxd/images.go
index 83f31a674f..9be4ccbc25 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -791,7 +791,7 @@ func imagesPost(d *Daemon, r *http.Request) Response {
 		}
 
 		// Sync the images between each node in the cluster on demand
-		err = imageSyncBetweenNodes(d, info.Fingerprint)
+		err = imageSyncBetweenNodes(d, project, info.Fingerprint)
 		if err != nil {
 			return errors.Wrapf(err, "Image sync between nodes")
 		}
@@ -2051,10 +2051,10 @@ func autoSyncImages(ctx context.Context, d *Daemon) error {
 		return errors.Wrap(err, "Failed to query image fingerprints of the node")
 	}
 
-	for fingerprint := range imageProjectInfo {
+	for fingerprint, projects := range imageProjectInfo {
 		ch := make(chan error)
 		go func() {
-			err := imageSyncBetweenNodes(d, fingerprint)
+			err := imageSyncBetweenNodes(d, projects[0], fingerprint)
 			if err != nil {
 				logger.Error("Failed to synchronize images", log.Ctx{"err": err, "fingerprint": fingerprint})
 			}
@@ -2071,7 +2071,7 @@ func autoSyncImages(ctx context.Context, d *Daemon) error {
 	return nil
 }
 
-func imageSyncBetweenNodes(d *Daemon, fingerprint string) error {
+func imageSyncBetweenNodes(d *Daemon, project string, fingerprint string) error {
 	var desiredSyncNodeCount int64
 
 	err := d.cluster.Transaction(func(tx *db.ClusterTx) error {
@@ -2139,6 +2139,9 @@ func imageSyncBetweenNodes(d *Daemon, fingerprint string) error {
 		return errors.Wrap(err, "Failed to connect node for image synchronization")
 	}
 
+	// Select the right project
+	client = client.UseProject(project)
+
 	createArgs := &lxd.ImageCreateArgs{}
 	imageMetaPath := shared.VarPath("images", fingerprint)
 	imageRootfsPath := shared.VarPath("images", fingerprint+".rootfs")


More information about the lxc-devel mailing list