[lxc-devel] [lxd/master] Image: Fixes auto update for project images

tomponline on Github lxc-bot at linuxcontainers.org
Wed Feb 19 16:09: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/20200219/4afc2d00/attachment.bin>
-------------- next part --------------
From b15100d983766081850ff67763d276f93d0bb12b Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 19 Feb 2020 16:07:27 +0000
Subject: [PATCH 1/2] lxd/images: Removes hardcoded default project arg for
 ImageGet in autoUpdateImage

When using images in projects, this was preventing updates of image and leaving orphaned volumes created on storage device.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/images.go | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lxd/images.go b/lxd/images.go
index a9f3a2309d..1fd2b6bea8 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -1126,7 +1126,6 @@ func autoUpdateImage(d *Daemon, op *operations.Operation, id int, info *api.Imag
 
 	for _, poolName := range poolNames {
 		newInfo, err := d.ImageDownload(op, source.Server, source.Protocol, source.Certificate, "", source.Alias, info.Type, false, true, poolName, false, project)
-
 		if err != nil {
 			logger.Error("Failed to update the image", log.Ctx{"err": err, "fp": fingerprint})
 			continue
@@ -1138,7 +1137,7 @@ func autoUpdateImage(d *Daemon, op *operations.Operation, id int, info *api.Imag
 			continue
 		}
 
-		newId, _, err := d.cluster.ImageGet("default", hash, false, true)
+		newID, _, err := d.cluster.ImageGet(project, hash, false, true)
 		if err != nil {
 			logger.Error("Error loading image", log.Ctx{"err": err, "fp": hash})
 			continue

From 07de45c970fe2f4cb4c7dbde61b80344d995fa56 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 19 Feb 2020 16:08:25 +0000
Subject: [PATCH 2/2] lxd/images: Golint and comments

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/images.go | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/lxd/images.go b/lxd/images.go
index 1fd2b6bea8..81b96dc2a4 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -1157,19 +1157,18 @@ func autoUpdateImage(d *Daemon, op *operations.Operation, id int, info *api.Imag
 			continue
 		}
 
-		err = d.cluster.ImageAliasesMove(id, newId)
+		err = d.cluster.ImageAliasesMove(id, newID)
 		if err != nil {
 			logger.Error("Error moving aliases", log.Ctx{"err": err, "fp": hash})
 			continue
 		}
 
-		err = d.cluster.ImageCopyDefaultProfiles(id, newId)
+		err = d.cluster.ImageCopyDefaultProfiles(id, newID)
 		if err != nil {
 			logger.Error("Copying default profiles", log.Ctx{"err": err, "fp": hash})
 		}
 
-		// If we do have optimized pools, make sure we remove
-		// the volumes associated with the image.
+		// If we do have optimized pools, make sure we remove the volumes associated with the image.
 		if poolName != "" {
 			err = doDeleteImageFromPool(d.State(), fingerprint, poolName)
 			if err != nil {


More information about the lxc-devel mailing list