[lxc-devel] [lxd/master] lxd/images: Fix simplestreams cache expiry

stgraber on Github lxc-bot at linuxcontainers.org
Thu Apr 11 05:45:41 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/20190410/a1bc3215/attachment.bin>
-------------- next part --------------
From 5a87f8e61c8664a667d78d59ce864eb188c28b8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 11 Apr 2019 01:10:52 -0400
Subject: [PATCH] lxd/images: Fix simplestreams cache expiry
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/daemon_images.go | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/lxd/daemon_images.go b/lxd/daemon_images.go
index 0344436a64..e0270d323b 100644
--- a/lxd/daemon_images.go
+++ b/lxd/daemon_images.go
@@ -33,9 +33,8 @@ import (
 type imageStreamCacheEntry struct {
 	Aliases      []api.ImageAliasesEntry `yaml:"aliases"`
 	Certificate  string                  `yaml:"certificate"`
+	Expiry       time.Time               `yaml:"expiry"`
 	Fingerprints []string                `yaml:"fingerprints"`
-
-	expiry time.Time
 }
 
 var imageStreamCacheLock sync.Mutex
@@ -104,7 +103,7 @@ func (d *Daemon) ImageDownload(op *operation, server string, protocol string, ce
 		}
 
 		entry, _ := imageStreamCache[server]
-		if entry == nil || entry.expiry.Before(time.Now()) {
+		if entry == nil || entry.Expiry.Before(time.Now()) {
 			// Add a new entry to the cache
 			refresh := func() (*imageStreamCacheEntry, error) {
 				// Setup simplestreams client
@@ -135,7 +134,7 @@ func (d *Daemon) ImageDownload(op *operation, server string, protocol string, ce
 				}
 
 				// Generate cache entry
-				entry = &imageStreamCacheEntry{Aliases: aliases, Certificate: certificate, Fingerprints: fingerprints, expiry: time.Now().Add(time.Hour)}
+				entry = &imageStreamCacheEntry{Aliases: aliases, Certificate: certificate, Fingerprints: fingerprints, Expiry: time.Now().Add(time.Hour)}
 				imageStreamCache[server] = entry
 				imageSaveStreamCache(d.os, imageStreamCache)
 
@@ -149,7 +148,7 @@ func (d *Daemon) ImageDownload(op *operation, server string, protocol string, ce
 			} else if entry != nil {
 				// Failed to fetch entry but existing cache
 				logger.Warn("Unable to refresh cache, using stale entry", log.Ctx{"server": server})
-				entry.expiry = time.Now().Add(time.Hour)
+				entry.Expiry = time.Now().Add(time.Hour)
 			} else {
 				// Failed to fetch entry and nothing in cache
 				imageStreamCacheLock.Unlock()
@@ -157,7 +156,7 @@ func (d *Daemon) ImageDownload(op *operation, server string, protocol string, ce
 			}
 		} else {
 			// use the existing entry
-			logger.Debug("Using SimpleStreams cache entry", log.Ctx{"server": server, "expiry": entry.expiry})
+			logger.Debug("Using SimpleStreams cache entry", log.Ctx{"server": server, "expiry": entry.Expiry})
 
 			remote, err = lxd.ConnectSimpleStreams(server, &lxd.ConnectionArgs{
 				TLSServerCert: entry.Certificate,


More information about the lxc-devel mailing list